react-native-navigation的迁移库

ReactNativeNavigation.m 2.5KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  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. keyWindow.backgroundColor = [UIColor whiteColor];
  51. UIApplication.sharedApplication.delegate.window = keyWindow;
  52. return keyWindow;
  53. }
  54. @end