react-native-navigation的迁移库

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. #import "RNN.h"
  2. #import "RNNEventEmitter.h"
  3. #import "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. UIApplication.sharedApplication.delegate.window.rootViewController = nil;
  53. }
  54. @end