react-native-navigation的迁移库

ReactNativeNavigation.m 2.3KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  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. # 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