react-native-navigation的迁移库

RNN.m 1.8KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  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. @end
  10. @implementation RNN
  11. # pragma mark public
  12. +(instancetype)instance
  13. {
  14. static RNN *sharedInstance = nil;
  15. static dispatch_once_t onceToken = 0;
  16. dispatch_once(&onceToken,^{
  17. if (sharedInstance == nil)
  18. {
  19. sharedInstance = [[RNN alloc] init];
  20. }
  21. });
  22. return sharedInstance;
  23. }
  24. -(void)bootstrap:(NSURL *)jsCodeLocation launchOptions:(NSDictionary *)launchOptions
  25. {
  26. self.eventEmitter = [RNNEventEmitter new];
  27. UIApplication.sharedApplication.delegate.window = [[UIWindow alloc] initWithFrame:[UIScreen mainScreen].bounds];
  28. UIApplication.sharedApplication.delegate.window.backgroundColor = [UIColor whiteColor];
  29. [RNNSplashScreen show];
  30. [self registerForJsEvents];
  31. // this will load the JS bundle
  32. self.bridge = [[RCTBridge alloc] initWithBundleURL:jsCodeLocation moduleProvider:nil launchOptions:launchOptions];
  33. }
  34. # pragma mark private
  35. -(void)registerForJsEvents
  36. {
  37. [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(onJavaScriptLoaded) name:RCTJavaScriptDidLoadNotification object:self.bridge];
  38. #pragma GCC diagnostic push
  39. #pragma GCC diagnostic ignored "-Wdeprecated-declarations"
  40. [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(onJavaScriptDevReload) name:RCTReloadNotification object:self.bridge];
  41. #pragma GCC diagnostic pop
  42. }
  43. -(void)onJavaScriptLoaded
  44. {
  45. self.isReadyToReceiveCommands = true;
  46. [self.eventEmitter sendOnAppLaunched];
  47. }
  48. -(void)onJavaScriptDevReload
  49. {
  50. UIApplication.sharedApplication.delegate.window.rootViewController = nil;
  51. }
  52. @end