react-native-navigation的迁移库

ReactNativeNavigation.m 2.4KB

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