react-native-navigation的迁移库

ReactNativeNavigation.m 2.8KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  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<RCTBridgeDelegate>)delegate {
  15. [[ReactNativeNavigation sharedInstance] bootstrap:jsCodeLocation launchOptions:launchOptions bridgeManagerDelegate:delegate];
  16. }
  17. + (void)bootstrapWithDelegate:(id<RCTBridgeDelegate>)bridgeDelegate launchOptions:(NSDictionary *)launchOptions {
  18. [[ReactNativeNavigation sharedInstance] bootstrapWithDelegate:bridgeDelegate launchOptions:launchOptions];
  19. }
  20. + (void)registerExternalComponent:(NSString *)name callback:(RNNExternalViewCreator)callback {
  21. [[ReactNativeNavigation sharedInstance].bridgeManager registerExternalComponent:name callback:callback];
  22. }
  23. + (RCTBridge *)getBridge {
  24. return [[ReactNativeNavigation sharedInstance].bridgeManager bridge];
  25. }
  26. + (UIViewController *)findViewController:(NSString *)componentId {
  27. return [RNNLayoutManager findComponentForId:componentId];
  28. }
  29. + (void)setJSCodeLocation:(NSURL *)jsCodeLocation {
  30. [[ReactNativeNavigation sharedInstance].bridgeManager setJSCodeLocation:jsCodeLocation];
  31. }
  32. # pragma mark - instance
  33. + (instancetype) sharedInstance {
  34. static ReactNativeNavigation *instance = nil;
  35. static dispatch_once_t onceToken = 0;
  36. dispatch_once(&onceToken,^{
  37. if (instance == nil) {
  38. instance = [[ReactNativeNavigation alloc] init];
  39. }
  40. });
  41. return instance;
  42. }
  43. - (void)bootstrap:(NSURL *)jsCodeLocation launchOptions:(NSDictionary *)launchOptions {
  44. [self bootstrap:jsCodeLocation launchOptions:launchOptions bridgeManagerDelegate:nil];
  45. }
  46. - (void)bootstrapWithDelegate:(id<RCTBridgeDelegate>)bridgeDelegate launchOptions:(NSDictionary *)launchOptions {
  47. [self bootstrap:nil launchOptions:launchOptions bridgeManagerDelegate:bridgeDelegate];
  48. }
  49. - (void)bootstrap:(NSURL *)jsCodeLocation launchOptions:(NSDictionary *)launchOptions bridgeManagerDelegate:(id<RCTBridgeDelegate>)delegate {
  50. UIWindow* mainWindow = [self initializeKeyWindow];
  51. self.bridgeManager = [[RNNBridgeManager alloc] initWithJsCodeLocation:jsCodeLocation launchOptions:launchOptions bridgeManagerDelegate:delegate mainWindow:mainWindow];
  52. [RNNSplashScreen showOnWindow:mainWindow];
  53. }
  54. - (UIWindow *)initializeKeyWindow {
  55. UIWindow* keyWindow = [[UIWindow alloc] initWithFrame:[UIScreen mainScreen].bounds];
  56. UIApplication.sharedApplication.delegate.window = keyWindow;
  57. return keyWindow;
  58. }
  59. @end