mirror of
https://github.com/facebook/react-native.git
synced 2025-11-01 09:14:26 +00:00
Make RCTStatusBarManager TurboModule-compatible
Summary: See title. Changelog: [iOS][Added] - Make RCTStatusBarManager TurboModule-compatible Reviewed By: shergin Differential Revision: D18130374 fbshipit-source-id: 3ec226bcff17e47ffd9eba05e32c1eb68d6135b2
This commit is contained in:
1 parent
a257083d2b
commit
dc12676e3a
8 files changed
+52
-12
No files matched your search
@@ -16,7 +16,7 @@ import * as TurboModuleRegistry from '../../TurboModule/TurboModuleRegistry';
|
||||
export interface Spec extends TurboModule {
|
||||
+getConstants: () => {|
|
||||
+HEIGHT: number,
|
||||
+DEFAULT_BACKGROUND_COLOR: number,
|
||||
+DEFAULT_BACKGROUND_COLOR?: number,
|
||||
|};
|
||||
|
||||
// TODO(T47754272) Can we remove this method?
|
||||
|
||||
@@ -2236,7 +2236,7 @@ namespace JS {
|
||||
struct Builder {
|
||||
struct Input {
|
||||
RCTRequired<double> HEIGHT;
|
||||
RCTRequired<double> DEFAULT_BACKGROUND_COLOR;
|
||||
folly::Optional<double> DEFAULT_BACKGROUND_COLOR;
|
||||
};
|
||||
|
||||
/** Initialize with a set of values */
|
||||
@@ -3378,8 +3378,8 @@ inline JS::NativeStatusBarManagerIOS::Constants::Builder::Builder(const Input i)
|
||||
NSMutableDictionary *d = [NSMutableDictionary new];
|
||||
auto HEIGHT = i.HEIGHT.get();
|
||||
d[@"HEIGHT"] = @(HEIGHT);
|
||||
auto DEFAULT_BACKGROUND_COLOR = i.DEFAULT_BACKGROUND_COLOR.get();
|
||||
d[@"DEFAULT_BACKGROUND_COLOR"] = @(DEFAULT_BACKGROUND_COLOR);
|
||||
auto DEFAULT_BACKGROUND_COLOR = i.DEFAULT_BACKGROUND_COLOR;
|
||||
d[@"DEFAULT_BACKGROUND_COLOR"] = DEFAULT_BACKGROUND_COLOR.hasValue() ? @((double)DEFAULT_BACKGROUND_COLOR.value()) : nil;
|
||||
return d;
|
||||
}) {}
|
||||
inline JS::NativeStatusBarManagerIOS::Constants::Builder::Builder(Constants i) : _factory(^{
|
||||
|
||||
@@ -75,6 +75,9 @@ rn_apple_library(
|
||||
) + react_module_plugin_providers(
|
||||
name = "Timing",
|
||||
native_class_func = "RCTTimingCls",
|
||||
) + react_module_plugin_providers(
|
||||
name = "StatusBarManager",
|
||||
native_class_func = "RCTStatusBarManagerCls",
|
||||
),
|
||||
plugins_header = "FBCoreModulesPlugins.h",
|
||||
preprocessor_flags = OBJC_ARC_PREPROCESSOR_FLAGS + get_debug_preprocessor_flags() + rn_extra_build_flags() + [
|
||||
|
||||
@@ -41,6 +41,7 @@ Class RCTActionSheetManagerCls(void) __attribute__((used));
|
||||
Class RCTAlertManagerCls(void) __attribute__((used));
|
||||
Class RCTAsyncLocalStorageCls(void) __attribute__((used));
|
||||
Class RCTTimingCls(void) __attribute__((used));
|
||||
Class RCTStatusBarManagerCls(void) __attribute__((used));
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
|
||||
@@ -30,6 +30,7 @@ Class RCTCoreModulesClassProvider(const char *name) {
|
||||
{"AlertManager", RCTAlertManagerCls},
|
||||
{"AsyncLocalStorage", RCTAsyncLocalStorageCls},
|
||||
{"Timing", RCTTimingCls},
|
||||
{"StatusBarManager", RCTStatusBarManagerCls},
|
||||
};
|
||||
|
||||
auto p = sCoreModuleClassMap.find(name);
|
||||
|
||||
File renamed without changes.
@@ -6,12 +6,15 @@
|
||||
*/
|
||||
|
||||
#import "RCTStatusBarManager.h"
|
||||
#import "CoreModulesPlugins.h"
|
||||
|
||||
#import "RCTEventDispatcher.h"
|
||||
#import "RCTLog.h"
|
||||
#import "RCTUtils.h"
|
||||
#import <React/RCTEventDispatcher.h>
|
||||
#import <React/RCTLog.h>
|
||||
#import <React/RCTUtils.h>
|
||||
|
||||
#if !TARGET_OS_TV
|
||||
#import <FBReactNativeSpec/FBReactNativeSpec.h>
|
||||
|
||||
@implementation RCTConvert (UIStatusBar)
|
||||
|
||||
+ (UIStatusBarStyle)UIStatusBarStyle:(id)json RCT_DYNAMIC
|
||||
@@ -40,7 +43,7 @@
|
||||
}
|
||||
});
|
||||
return _RCT_CAST(
|
||||
type, [RCTConvertEnumValue("UIStatusBarStyle", mapping, @(UIStatusBarStyleDefault), json) integerValue]);
|
||||
UIStatusBarStyle, [RCTConvertEnumValue("UIStatusBarStyle", mapping, @(UIStatusBarStyleDefault), json) integerValue]);
|
||||
}
|
||||
|
||||
RCT_ENUM_CONVERTER(
|
||||
@@ -56,6 +59,13 @@ RCT_ENUM_CONVERTER(
|
||||
@end
|
||||
#endif
|
||||
|
||||
#if !TARGET_OS_TV
|
||||
|
||||
@interface RCTStatusBarManager() <NativeStatusBarManagerIOSSpec>
|
||||
@end
|
||||
|
||||
#endif
|
||||
|
||||
@implementation RCTStatusBarManager
|
||||
|
||||
static BOOL RCTViewControllerBasedStatusBarAppearance()
|
||||
@@ -134,8 +144,9 @@ RCT_EXPORT_METHOD(getHeight : (RCTResponseSenderBlock)callback)
|
||||
} ]);
|
||||
}
|
||||
|
||||
RCT_EXPORT_METHOD(setStyle : (UIStatusBarStyle)statusBarStyle animated : (BOOL)animated)
|
||||
RCT_EXPORT_METHOD(setStyle : (NSString *)style animated : (BOOL)animated)
|
||||
{
|
||||
UIStatusBarStyle statusBarStyle = [RCTConvert UIStatusBarStyle:style];
|
||||
if (RCTViewControllerBasedStatusBarAppearance()) {
|
||||
RCTLogError(@"RCTStatusBarManager module requires that the \
|
||||
UIViewControllerBasedStatusBarAppearance key in the Info.plist is set to NO");
|
||||
@@ -147,8 +158,9 @@ RCT_EXPORT_METHOD(setStyle : (UIStatusBarStyle)statusBarStyle animated : (BOOL)a
|
||||
#pragma clang diagnostic pop
|
||||
}
|
||||
|
||||
RCT_EXPORT_METHOD(setHidden : (BOOL)hidden withAnimation : (UIStatusBarAnimation)animation)
|
||||
RCT_EXPORT_METHOD(setHidden : (BOOL)hidden withAnimation : (NSString *)withAnimation)
|
||||
{
|
||||
UIStatusBarAnimation animation = [RCTConvert UIStatusBarAnimation:withAnimation];
|
||||
if (RCTViewControllerBasedStatusBarAppearance()) {
|
||||
RCTLogError(@"RCTStatusBarManager module requires that the \
|
||||
UIViewControllerBasedStatusBarAppearance key in the Info.plist is set to NO");
|
||||
@@ -165,6 +177,28 @@ RCT_EXPORT_METHOD(setNetworkActivityIndicatorVisible : (BOOL)visible)
|
||||
RCTSharedApplication().networkActivityIndicatorVisible = visible;
|
||||
}
|
||||
|
||||
- (facebook::react::ModuleConstants<JS::NativeStatusBarManagerIOS::Constants>)getConstants
|
||||
{
|
||||
return facebook::react::typedConstants<JS::NativeStatusBarManagerIOS::Constants>({
|
||||
.HEIGHT = RCTSharedApplication().statusBarFrame.size.height,
|
||||
.DEFAULT_BACKGROUND_COLOR = folly::none,
|
||||
});
|
||||
}
|
||||
|
||||
- (facebook::react::ModuleConstants<JS::NativeStatusBarManagerIOS::Constants>)constantsToExport
|
||||
{
|
||||
return (facebook::react::ModuleConstants<JS::NativeStatusBarManagerIOS::Constants>)[self getConstants];
|
||||
}
|
||||
|
||||
- (std::shared_ptr<facebook::react::TurboModule>)getTurboModuleWithJsInvoker:(std::shared_ptr<facebook::react::CallInvoker>)jsInvoker
|
||||
{
|
||||
return std::make_shared<facebook::react::NativeStatusBarManagerIOSSpecJSI>(self, jsInvoker);
|
||||
}
|
||||
|
||||
#endif // TARGET_OS_TV
|
||||
|
||||
@end
|
||||
|
||||
Class RCTStatusBarManagerCls(void) {
|
||||
return RCTStatusBarManager.class;
|
||||
}
|
||||
+3
-2
@@ -55,10 +55,11 @@ public abstract class NativeStatusBarManagerIOSSpec extends ReactContextBaseJava
|
||||
Map<String, Object> constants = getTypedExportedConstants();
|
||||
if (ReactBuildConfig.DEBUG || ReactBuildConfig.IS_INTERNAL_BUILD) {
|
||||
Set<String> obligatoryFlowConstants = new HashSet<>(Arrays.asList(
|
||||
"DEFAULT_BACKGROUND_COLOR",
|
||||
"HEIGHT"
|
||||
));
|
||||
Set<String> optionalFlowConstants = new HashSet<>();
|
||||
Set<String> optionalFlowConstants = new HashSet<>(Arrays.asList(
|
||||
"DEFAULT_BACKGROUND_COLOR"
|
||||
));
|
||||
Set<String> undeclaredConstants = new HashSet<>(constants.keySet());
|
||||
undeclaredConstants.removeAll(obligatoryFlowConstants);
|
||||
undeclaredConstants.removeAll(optionalFlowConstants);
|
||||
|
||||
Reference in new issue
Block a user