react-native-navigation的迁移库

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  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. self.store = [RNNStore new];
  29. UIApplication.sharedApplication.delegate.window = [[UIWindow alloc] initWithFrame:[UIScreen mainScreen].bounds];
  30. UIApplication.sharedApplication.delegate.window.backgroundColor = [UIColor whiteColor];
  31. [RNNSplashScreen show];
  32. [self registerForJsEvents];
  33. // this will load the JS bundle
  34. self.bridge = [[RCTBridge alloc] initWithBundleURL:jsCodeLocation moduleProvider:nil launchOptions:launchOptions];
  35. }
  36. # pragma mark private
  37. -(void)registerForJsEvents
  38. {
  39. [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(onJavaScriptLoaded) name:RCTJavaScriptDidLoadNotification object:self.bridge];
  40. #pragma GCC diagnostic push
  41. #pragma GCC diagnostic ignored "-Wdeprecated-declarations"
  42. // [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(onJavaScriptDevReload) name:RCTReloadNotification object:self.bridge];
  43. #pragma GCC diagnostic pop
  44. }
  45. -(void)onJavaScriptLoaded
  46. {
  47. self.isReadyToReceiveCommands = true;
  48. [self.eventEmitter sendOnAppLaunched];
  49. }
  50. -(void)onJavaScriptDevReload
  51. {
  52. self.store = [RNNStore new];
  53. UIApplication.sharedApplication.delegate.window.rootViewController = nil;
  54. }
  55. @end