react-native-navigation的迁移库

RNN.m 1.6KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. #import "RNN.h"
  2. #import "RNNEventEmitter.h"
  3. #import "RCTBridge.h"
  4. #import "RNNSplashScreen.h"
  5. @interface RNN()
  6. @property RNNEventEmitter* eventEmitter;
  7. @end
  8. @implementation RNN
  9. {
  10. RCTBridge* bridge;
  11. }
  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. bridge = [[RCTBridge alloc] initWithBundleURL:jsCodeLocation moduleProvider:nil launchOptions:launchOptions];
  33. }
  34. -(void)registerForJsEvents
  35. {
  36. [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(onJavaScriptLoaded) name:RCTJavaScriptDidLoadNotification object:nil];
  37. #pragma GCC diagnostic push
  38. #pragma GCC diagnostic ignored "-Wdeprecated-declarations"
  39. [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(onJavaScriptDevReload) name:RCTReloadNotification object:nil];
  40. #pragma GCC diagnostic pop
  41. }
  42. -(void)onJavaScriptLoaded
  43. {
  44. [self.eventEmitter sendOnAppLaunched];
  45. }
  46. -(void)onJavaScriptDevReload
  47. {
  48. UIApplication.sharedApplication.delegate.window.rootViewController = nil;
  49. }
  50. -(RCTBridge *)bridge
  51. {
  52. return bridge;
  53. }
  54. @end