react-native-navigation的迁移库

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. #import "RNNStore.h"
  2. #import "RNNRootViewController.h"
  3. @interface RNNStore ()
  4. @end
  5. @implementation RNNStore {
  6. NSMapTable* _containerStore;
  7. NSMutableArray* _pendingModalIdsToDismiss;
  8. BOOL _isReadyToReceiveCommands;
  9. }
  10. -(instancetype)init {
  11. self = [super init];
  12. _isReadyToReceiveCommands = false;
  13. _containerStore = [NSMapTable strongToWeakObjectsMapTable];
  14. _pendingModalIdsToDismiss = [NSMutableArray new];
  15. return self;
  16. }
  17. -(UIViewController *)findContainerForId:(NSString *)containerId {
  18. return [_containerStore objectForKey:containerId];
  19. }
  20. - (void)setContainer:(UIViewController*)viewController containerId:(NSString*)containerId {
  21. UIViewController *existingVewController = [self findContainerForId:containerId];
  22. if (existingVewController) {
  23. @throw [NSException exceptionWithName:@"MultipleContainerId" reason:[@"Container id already exists " stringByAppendingString:containerId] userInfo:nil];
  24. }
  25. [_containerStore setObject:viewController forKey:containerId];
  26. }
  27. - (void)removeContainer:(NSString*)containerId {
  28. [_containerStore removeObjectForKey:containerId];
  29. }
  30. - (void)removeContainerByViewControllerInstance:(UIViewController*)containerInstance {
  31. NSString *foundKey = [self containerKeyForInstance:containerInstance];
  32. if (foundKey) {
  33. [self removeContainer:foundKey];
  34. }
  35. }
  36. -(void)setReadyToReceiveCommands:(BOOL)isReady {
  37. _isReadyToReceiveCommands = isReady;
  38. }
  39. -(BOOL)isReadyToReceiveCommands {
  40. return _isReadyToReceiveCommands;
  41. }
  42. -(NSMutableArray *)pendingModalIdsToDismiss {
  43. return _pendingModalIdsToDismiss;
  44. }
  45. -(void)clean {
  46. _isReadyToReceiveCommands = false;
  47. [_pendingModalIdsToDismiss removeAllObjects];
  48. [_containerStore removeAllObjects];
  49. }
  50. -(NSString*)containerKeyForInstance:(UIViewController*)instance {
  51. for (NSString *key in _containerStore) {
  52. UIViewController *value = [_containerStore objectForKey:key];
  53. if (value == instance) {
  54. return key;
  55. }
  56. }
  57. return nil;
  58. }
  59. @end