react-native-navigation的迁移库

RNN.m 1.9KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. #import "RNN.h"
  2. #import "RNNEventEmitter.h"
  3. #import <React/RCTBridge.h>
  4. #import "RNNSplashScreen.h"
  5. @interface RNN()
  6. @property (readwrite) RCTBridge* bridge;
  7. @property (readwrite) BOOL isReadyToReceiveCommands;
  8. @property (readwrite) RNNEventEmitter* eventEmitter;
  9. @property (readwrite) RNNStore *store;
  10. @end
  11. @implementation RNN
  12. # pragma mark public
  13. +(instancetype)instance
  14. {
  15. static RNN *sharedInstance = nil;
  16. static dispatch_once_t onceToken = 0;
  17. dispatch_once(&onceToken,^{
  18. if (sharedInstance == nil)
  19. {
  20. sharedInstance = [[RNN alloc] init];
  21. }
  22. });
  23. return sharedInstance;
  24. }
  25. -(void)bootstrap:(NSURL *)jsCodeLocation launchOptions:(NSDictionary *)launchOptions
  26. {
  27. self.eventEmitter = [RNNEventEmitter new];
  28. UIApplication.sharedApplication.delegate.window = [[UIWindow alloc] initWithFrame:[UIScreen mainScreen].bounds];
  29. UIApplication.sharedApplication.delegate.window.backgroundColor = [UIColor whiteColor];
  30. [RNNSplashScreen show];
  31. [self registerForJsEvents];
  32. // this will load the JS bundle
  33. self.bridge = [[RCTBridge alloc] initWithBundleURL:jsCodeLocation moduleProvider:nil launchOptions:launchOptions];
  34. }
  35. # pragma mark private
  36. -(void)registerForJsEvents
  37. {
  38. [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(onJavaScriptLoaded) name:RCTJavaScriptDidLoadNotification object:self.bridge];
  39. [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(onJavaScriptWillLoad) name:RCTJavaScriptWillStartLoadingNotification object:self.bridge];
  40. }
  41. -(void)onJavaScriptLoaded
  42. {
  43. self.isReadyToReceiveCommands = true;
  44. [self.eventEmitter sendOnAppLaunched];
  45. }
  46. -(void)onJavaScriptWillLoad
  47. {
  48. self.store = [RNNStore new];
  49. if(![UIApplication.sharedApplication.delegate.window.rootViewController isKindOfClass:[RNNSplashScreen class]]) {
  50. UIApplication.sharedApplication.delegate.window.rootViewController = nil;
  51. }
  52. }
  53. @end