react-native-navigation的迁移库

ReactNativeNavigation.m 2.0KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  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. self.bridgeManager = [[RNNBridgeManager alloc] initWithJsCodeLocation:jsCodeLocation launchOptions:launchOptions bridgeManagerDelegate:delegate];
  42. [RNNSplashScreen show];
  43. }
  44. @end