react-native-navigation的迁移库

RNNStore.m 1.9KB

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