mirror of
https://github.com/zhigang1992/react-native-bottom-sheet.git
synced 2026-06-11 08:04:18 +08:00
148 lines
5.3 KiB
Plaintext
148 lines
5.3 KiB
Plaintext
/**
|
|
* Copyright (c) Facebook, Inc. and its affiliates.
|
|
*
|
|
* This source code is licensed under the MIT license found in the
|
|
* LICENSE file in the root directory of this source tree.
|
|
*/
|
|
|
|
#import "AppDelegate.h"
|
|
|
|
#import <React/RCTBridge.h>
|
|
#import <React/RCTBundleURLProvider.h>
|
|
#import <React/RCTRootView.h>
|
|
|
|
// Reanimated v2
|
|
#import <React/RCTCxxBridgeDelegate.h>
|
|
#import <ReactCommon/RCTTurboModuleManager.h>
|
|
|
|
#import <React/RCTDataRequestHandler.h>
|
|
#import <React/RCTFileRequestHandler.h>
|
|
#import <React/RCTHTTPRequestHandler.h>
|
|
#import <React/RCTNetworking.h>
|
|
#import <React/RCTLocalAssetImageLoader.h>
|
|
#import <React/RCTGIFImageDecoder.h>
|
|
#import <React/RCTImageLoader.h>
|
|
#import <React/JSCExecutorFactory.h>
|
|
#import <RNReanimated/REATurboModuleProvider.h>
|
|
#import <RNReanimated/REAModule.h>
|
|
// Reanimated v2
|
|
|
|
#ifdef FB_SONARKIT_ENABLED
|
|
#import <FlipperKit/FlipperClient.h>
|
|
#import <FlipperKitLayoutPlugin/FlipperKitLayoutPlugin.h>
|
|
#import <FlipperKitUserDefaultsPlugin/FKUserDefaultsPlugin.h>
|
|
#import <FlipperKitNetworkPlugin/FlipperKitNetworkPlugin.h>
|
|
#import <SKIOSNetworkPlugin/SKIOSNetworkAdapter.h>
|
|
#import <FlipperKitReactPlugin/FlipperKitReactPlugin.h>
|
|
|
|
static void InitializeFlipper(UIApplication *application) {
|
|
FlipperClient *client = [FlipperClient sharedClient];
|
|
SKDescriptorMapper *layoutDescriptorMapper = [[SKDescriptorMapper alloc] initWithDefaults];
|
|
[client addPlugin:[[FlipperKitLayoutPlugin alloc] initWithRootNode:application withDescriptorMapper:layoutDescriptorMapper]];
|
|
[client addPlugin:[[FKUserDefaultsPlugin alloc] initWithSuiteName:nil]];
|
|
[client addPlugin:[FlipperKitReactPlugin new]];
|
|
[client addPlugin:[[FlipperKitNetworkPlugin alloc] initWithNetworkAdapter:[SKIOSNetworkAdapter new]]];
|
|
[client start];
|
|
}
|
|
#endif
|
|
|
|
@interface AppDelegate() <RCTCxxBridgeDelegate, RCTTurboModuleManagerDelegate> {
|
|
RCTTurboModuleManager *_turboModuleManager;
|
|
}
|
|
@end
|
|
|
|
@implementation AppDelegate
|
|
|
|
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
|
|
{
|
|
RCTEnableTurboModule(YES);
|
|
|
|
#ifdef FB_SONARKIT_ENABLED
|
|
InitializeFlipper(application);
|
|
#endif
|
|
RCTBridge *bridge = [[RCTBridge alloc] initWithDelegate:self launchOptions:launchOptions];
|
|
RCTRootView *rootView = [[RCTRootView alloc] initWithBridge:bridge
|
|
moduleName:@"BottomSheetExample"
|
|
initialProperties:nil];
|
|
|
|
rootView.backgroundColor = [[UIColor alloc] initWithRed:1.0f green:1.0f blue:1.0f alpha:1];
|
|
|
|
self.window = [[UIWindow alloc] initWithFrame:[UIScreen mainScreen].bounds];
|
|
UIViewController *rootViewController = [UIViewController new];
|
|
rootViewController.view = rootView;
|
|
self.window.rootViewController = rootViewController;
|
|
[self.window makeKeyAndVisible];
|
|
return YES;
|
|
}
|
|
|
|
- (NSURL *)sourceURLForBridge:(RCTBridge *)bridge
|
|
{
|
|
#if DEBUG
|
|
return [[RCTBundleURLProvider sharedSettings] jsBundleURLForBundleRoot:@"index" fallbackResource:nil];
|
|
#else
|
|
return [[NSBundle mainBundle] URLForResource:@"main" withExtension:@"jsbundle"];
|
|
#endif
|
|
}
|
|
|
|
- (std::unique_ptr<facebook::react::JSExecutorFactory>)jsExecutorFactoryForBridge:(RCTBridge *)bridge
|
|
{
|
|
_bridge_reanimated = bridge;
|
|
_turboModuleManager = [[RCTTurboModuleManager alloc] initWithBridge:bridge
|
|
delegate:self
|
|
jsInvoker:bridge.jsCallInvoker];
|
|
#if RCT_DEV
|
|
// [_turboModuleManager moduleForName:"RCTDevMenu"]; // <- add
|
|
[_turboModuleManager moduleForName:"PerfMonitor"];
|
|
#endif
|
|
__weak __typeof(self) weakSelf = self;
|
|
return std::make_unique<facebook::react::JSCExecutorFactory>([weakSelf, bridge](facebook::jsi::Runtime &runtime) {
|
|
if (!bridge) {
|
|
return;
|
|
}
|
|
__typeof(self) strongSelf = weakSelf;
|
|
if (strongSelf) {
|
|
[strongSelf->_turboModuleManager installJSBindingWithRuntime:&runtime];
|
|
}
|
|
});
|
|
}
|
|
|
|
- (Class)getModuleClassFromName:(const char *)name
|
|
{
|
|
return facebook::react::REATurboModuleClassProvider(name);
|
|
}
|
|
|
|
- (std::shared_ptr<facebook::react::TurboModule>)getTurboModule:(const std::string &)name
|
|
jsInvoker:(std::shared_ptr<facebook::react::CallInvoker>)jsInvoker
|
|
{
|
|
return facebook::react::REATurboModuleProvider(name, jsInvoker);
|
|
}
|
|
|
|
- (std::shared_ptr<facebook::react::TurboModule>)getTurboModule:(const std::string &)name
|
|
instance:(id<RCTTurboModule>)instance
|
|
jsInvoker:(std::shared_ptr<facebook::react::CallInvoker>)jsInvoker
|
|
{
|
|
return facebook::react::REATurboModuleProvider(name, instance, jsInvoker);
|
|
}
|
|
|
|
- (id<RCTTurboModule>)getModuleInstanceFromClass:(Class)moduleClass
|
|
{
|
|
if (moduleClass == RCTImageLoader.class) {
|
|
return [[moduleClass alloc] initWithRedirectDelegate:nil loadersProvider:^NSArray<id<RCTImageURLLoader>> *{
|
|
return @[[RCTLocalAssetImageLoader new]];
|
|
} decodersProvider:^NSArray<id<RCTImageDataDecoder>> *{
|
|
return @[[RCTGIFImageDecoder new]];
|
|
}];
|
|
} else if (moduleClass == RCTNetworking.class) {
|
|
return [[moduleClass alloc] initWithHandlersProvider:^NSArray<id<RCTURLRequestHandler>> *{
|
|
return @[
|
|
[RCTHTTPRequestHandler new],
|
|
[RCTDataRequestHandler new],
|
|
[RCTFileRequestHandler new],
|
|
];
|
|
}];
|
|
}
|
|
return [moduleClass new];
|
|
}
|
|
|
|
@end
|