react-native-navigation的迁移库

ReactNativeNavigation.m 2.4KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. #import "ReactNativeNavigation.h"
  2. #import <React/RCTUIManager.h>
  3. #import "RNNBridgeManager.h"
  4. #import "RNNSplashScreen.h"
  5. #import "RNNLayoutManager.h"
  6. @interface ReactNativeNavigation()
  7. @property (nonatomic, strong) RNNBridgeManager *bridgeManager;
  8. @end
  9. @implementation ReactNativeNavigation
  10. # pragma mark - public API
  11. +(void)bootstrap:(NSURL *)jsCodeLocation launchOptions:(NSDictionary *)launchOptions {
  12. [[ReactNativeNavigation sharedInstance] bootstrap:jsCodeLocation launchOptions:launchOptions];
  13. }
  14. +(void)bootstrap:(NSURL *)jsCodeLocation launchOptions:(NSDictionary *)launchOptions bridgeManagerDelegate:(id<RNNBridgeManagerDelegate>)delegate {
  15. [[ReactNativeNavigation sharedInstance] bootstrap:jsCodeLocation launchOptions:launchOptions bridgeManagerDelegate:delegate];
  16. }
  17. + (void)registerExternalComponent:(NSString *)name callback:(RNNExternalViewCreator)callback {
  18. [[ReactNativeNavigation sharedInstance].bridgeManager registerExternalComponent:name callback:callback];
  19. }
  20. + (RCTBridge *)getBridge {
  21. return [[ReactNativeNavigation sharedInstance].bridgeManager bridge];
  22. }
  23. + (UIViewController *)findViewController:(NSString *)componentId {
  24. return [RNNLayoutManager findComponentForId:componentId];
  25. }
  26. + (void)setJSCodeLocation:(NSURL *)jsCodeLocation {
  27. [[ReactNativeNavigation sharedInstance].bridgeManager setJSCodeLocation:jsCodeLocation];
  28. }
  29. # pragma mark - instance
  30. + (instancetype) sharedInstance {
  31. static ReactNativeNavigation *instance = nil;
  32. static dispatch_once_t onceToken = 0;
  33. dispatch_once(&onceToken,^{
  34. if (instance == nil) {
  35. instance = [[ReactNativeNavigation alloc] init];
  36. }
  37. });
  38. return instance;
  39. }
  40. -(void)bootstrap:(NSURL *)jsCodeLocation launchOptions:(NSDictionary *)launchOptions {
  41. [self bootstrap:jsCodeLocation launchOptions:launchOptions bridgeManagerDelegate:nil];
  42. }
  43. -(void)bootstrap:(NSURL *)jsCodeLocation launchOptions:(NSDictionary *)launchOptions bridgeManagerDelegate:(id<RNNBridgeManagerDelegate>)delegate {
  44. UIWindow* mainWindow = [self initializeKeyWindow];
  45. self.bridgeManager = [[RNNBridgeManager alloc] initWithJsCodeLocation:jsCodeLocation launchOptions:launchOptions bridgeManagerDelegate:delegate mainWindow:mainWindow];
  46. [RNNSplashScreen showOnWindow:mainWindow];
  47. }
  48. - (UIWindow *)initializeKeyWindow {
  49. UIWindow* keyWindow = [[UIWindow alloc] initWithFrame:[UIScreen mainScreen].bounds];
  50. UIApplication.sharedApplication.delegate.window = keyWindow;
  51. return keyWindow;
  52. }
  53. @end