react-native-a11y-order 0.8.2 → 0.9.1-rc

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (61) hide show
  1. package/README.md +25 -152
  2. package/android/build.gradle +0 -18
  3. package/android/src/main/java/com/a11yorder/services/focus/A11yFocusDelegate.java +10 -32
  4. package/android/src/main/java/com/a11yorder/services/order/A11yOrderService.java +70 -65
  5. package/android/src/main/java/com/a11yorder/services/order/linking/A11yLinkingQueue.java +37 -63
  6. package/android/src/main/java/com/a11yorder/services/order/linking/A11yOrderLinking.java +11 -14
  7. package/android/src/main/java/com/a11yorder/services/order/linking/WeakTreeMap.java +53 -31
  8. package/android/src/main/java/com/a11yorder/utils/A11yHelper.java +39 -59
  9. package/android/src/main/java/com/a11yorder/utils/ChoreographerUtils.java +7 -12
  10. package/android/src/main/java/com/a11yorder/utils/FragmentUtils.java +8 -48
  11. package/android/src/main/java/com/a11yorder/views/A11yIndexView/A11yIndexView.java +1 -1
  12. package/android/src/main/java/com/a11yorder/views/A11yLockView/A11yLockViewManager.java +5 -0
  13. package/android/src/main/java/com/a11yorder/views/A11yView/A11yView.java +1 -1
  14. package/android/src/oldarch/A11yLockViewManagerSpec.java +2 -0
  15. package/ios/delegates/RNAOViewItemDelegate/RNAOViewItemDelegate.mm +1 -1
  16. package/ios/extensions/RCTModalHostViewComponentView+RNAOA11yOrder.mm +21 -21
  17. package/ios/extensions/UIView+RNAOA11yOrder.mm +17 -20
  18. package/ios/extensions/UIViewController+RNAOA11yOrder.mm +8 -8
  19. package/ios/helpers/RNAOSwizzleInstall.h +30 -0
  20. package/ios/services/RNAOA11yItemDelegate/RNAOA11yItemDelegate.h +4 -6
  21. package/ios/services/RNAOA11yItemDelegate/RNAOA11yItemDelegate.mm +98 -87
  22. package/ios/services/RNAOA11yOrderLinking/RNAOA11yOrderLinking.h +5 -3
  23. package/ios/services/RNAOA11yOrderLinking/RNAOA11yOrderLinking.mm +49 -49
  24. package/ios/services/RNAOA11yRelationship/RNAOA11yRelationship.h +1 -0
  25. package/ios/services/RNAOA11yRelationship/RNAOA11yRelationship.mm +42 -36
  26. package/ios/services/RNAOSortedMap/RNAOSortedMap.h +2 -1
  27. package/ios/services/RNAOSortedMap/RNAOSortedMap.mm +48 -47
  28. package/ios/views/RNAOA11yLockView/RNAOA11yLockView.h +4 -2
  29. package/ios/views/RNAOA11yLockView/RNAOA11yLockView.mm +89 -3
  30. package/ios/views/RNAOA11yLockView/RNAOA11yLockViewManager.mm +3 -0
  31. package/lib/commonjs/components/A11yLock/A11yBaseLock/A11yBaseLock.js +18 -2
  32. package/lib/commonjs/components/A11yLock/A11yBaseLock/A11yBaseLock.js.map +1 -1
  33. package/lib/commonjs/components/A11yLock/A11yFocusTrap/A11yFocusTrap.js +23 -7
  34. package/lib/commonjs/components/A11yLock/A11yFocusTrap/A11yFocusTrap.js.map +1 -1
  35. package/lib/commonjs/nativeSpecs/A11yLockNativeComponent.ts +1 -0
  36. package/lib/module/components/A11yLock/A11yBaseLock/A11yBaseLock.js +17 -2
  37. package/lib/module/components/A11yLock/A11yBaseLock/A11yBaseLock.js.map +1 -1
  38. package/lib/module/components/A11yLock/A11yFocusTrap/A11yFocusTrap.js +23 -7
  39. package/lib/module/components/A11yLock/A11yFocusTrap/A11yFocusTrap.js.map +1 -1
  40. package/lib/module/nativeSpecs/A11yLockNativeComponent.ts +1 -0
  41. package/lib/typescript/src/components/A11yLock/A11yBaseLock/A11yBaseLock.d.ts +2 -1
  42. package/lib/typescript/src/components/A11yLock/A11yBaseLock/A11yBaseLock.d.ts.map +1 -1
  43. package/lib/typescript/src/components/A11yLock/A11yFocusTrap/A11yFocusTrap.d.ts +1 -1
  44. package/lib/typescript/src/components/A11yLock/A11yFocusTrap/A11yFocusTrap.d.ts.map +1 -1
  45. package/lib/typescript/src/index.d.ts +1 -1
  46. package/lib/typescript/src/nativeSpecs/A11yLockNativeComponent.d.ts +1 -0
  47. package/lib/typescript/src/nativeSpecs/A11yLockNativeComponent.d.ts.map +1 -1
  48. package/lib/typescript/src/types/A11yLock.types.d.ts +1 -0
  49. package/lib/typescript/src/types/A11yLock.types.d.ts.map +1 -1
  50. package/package.json +3 -2
  51. package/src/components/A11yLock/A11yBaseLock/A11yBaseLock.tsx +20 -3
  52. package/src/components/A11yLock/A11yFocusTrap/A11yFocusTrap.tsx +24 -5
  53. package/src/nativeSpecs/A11yLockNativeComponent.ts +1 -0
  54. package/src/types/A11yLock.types.ts +1 -0
  55. package/lib/commonjs/components/A11yLock/A11yBaseLock/A11yBaseLock.android.js +0 -23
  56. package/lib/commonjs/components/A11yLock/A11yBaseLock/A11yBaseLock.android.js.map +0 -1
  57. package/lib/module/components/A11yLock/A11yBaseLock/A11yBaseLock.android.js +0 -18
  58. package/lib/module/components/A11yLock/A11yBaseLock/A11yBaseLock.android.js.map +0 -1
  59. package/lib/typescript/src/components/A11yLock/A11yBaseLock/A11yBaseLock.android.d.ts +0 -4
  60. package/lib/typescript/src/components/A11yLock/A11yBaseLock/A11yBaseLock.android.d.ts.map +0 -1
  61. package/src/components/A11yLock/A11yBaseLock/A11yBaseLock.android.tsx +0 -16
@@ -12,13 +12,12 @@
12
12
 
13
13
  @interface RNAOA11yItemDelegate : NSObject
14
14
 
15
- - (instancetype _Nonnull)initWithView:
16
- (UIView<RNAOViewItemProtocol> *_Nonnull)delegate;
15
+ - (instancetype _Nonnull)initWithView:(UIView<RNAOViewItemProtocol> *_Nonnull)delegate;
17
16
 
18
17
  @property (nonatomic, weak) UIView *linkView;
19
- @property (atomic, strong) NSNumber* position;
20
- @property NSString* orderKey;
21
- @property NSNumber* orderFocusType;
18
+ @property (nonatomic, strong) NSNumber *position;
19
+ @property (nonatomic, copy) NSString *orderKey;
20
+ @property (nonatomic, strong) NSNumber *orderFocusType;
22
21
 
23
22
  - (void)willRemoveSubview:(UIView *)subview;
24
23
  - (void)didAddSubview:(UIView *)subview;
@@ -27,5 +26,4 @@
27
26
 
28
27
  @end
29
28
 
30
-
31
29
  #endif /* RNAOA11yItemDelegate_h */
@@ -8,146 +8,157 @@
8
8
  #import <Foundation/Foundation.h>
9
9
  #import "RNAOA11yItemDelegate.h"
10
10
  #import "RNAOA11yOrderLinking.h"
11
- #import "RNAOA11yItemProtocol.h"
12
11
 
13
12
  typedef NS_ENUM(NSInteger, A11yOrderType) {
14
- A11yOrderTypeDefault = 0,
15
- A11yOrderTypeChild = 1,
16
- A11yOrderTypeLegacy = 2,
13
+ A11yOrderTypeDefault = 0,
14
+ A11yOrderTypeChild = 1,
15
+ A11yOrderTypeLegacy = 2,
17
16
  };
18
17
 
19
-
20
18
  @implementation RNAOA11yItemDelegate {
21
19
  __weak UIView<RNAOViewItemProtocol> *_delegate;
20
+ __weak UIView *_focusDelegateView;
22
21
  BOOL _isLinked;
23
22
  }
24
23
 
25
- - (instancetype _Nonnull)initWithView:
26
- (UIView<RNAOA11yItemProtocol, RNAOViewItemProtocol> *_Nonnull)delegate {
24
+ - (instancetype _Nonnull)initWithView:(UIView<RNAOViewItemProtocol> *_Nonnull)delegate {
27
25
  self = [super init];
28
26
  if (self) {
29
27
  _delegate = delegate;
30
- _isLinked = false;
28
+ _isLinked = NO;
31
29
  }
32
30
  return self;
33
31
  }
34
32
 
33
+ #pragma mark - Prop setters
34
+
35
35
  - (void)setPosition:(NSNumber *)position {
36
- NSNumber *_lastPostion = _position;
36
+ NSNumber *lastPosition = _position;
37
37
  _position = position;
38
-
39
- if(_lastPostion != nil && _lastPostion != position) {
40
- [self relink: position lastPosition: _lastPostion];
38
+ if (lastPosition != nil && ![lastPosition isEqualToNumber:position]) {
39
+ [self relink:position lastPosition:lastPosition];
41
40
  }
42
41
  }
43
42
 
44
- - (void)setOrderFocusType:(NSNumber *)orderFocusType {
45
- if(_orderFocusType != nil && _orderFocusType != orderFocusType) {
46
- _orderFocusType = orderFocusType;
47
- [self relink: _position lastPosition: _position];
43
+ - (void)setOrderKey:(NSString *)orderKey {
44
+ if ([_orderKey isEqualToString:orderKey]) return;
45
+ NSString *prevKey = _orderKey;
46
+ _orderKey = orderKey;
47
+ if (_isLinked) {
48
+ // Atomic: remove from old group and register in new group in one call.
49
+ // _isLinked = YES guarantees _position and _linkView are non-nil.
50
+ [[RNAOA11yOrderLinking sharedInstance] updateOrderKey:prevKey next:orderKey position:_position withView:_linkView];
51
+ _isLinked = (orderKey != nil);
48
52
  } else {
49
- _orderFocusType = orderFocusType;
50
- }
51
- }
52
-
53
- - (void)finalizeUpdates {
54
- if(!_delegate) return;
55
- if(_delegate.subviews.count > 0) {
56
- [self setLinkView: _delegate.subviews[0]];
53
+ // Not yet registered — try now (handles old arch prop-arrival ordering).
54
+ [self link];
57
55
  }
58
56
  }
59
57
 
60
- - (void)setLinkView: (UIView*) view {
61
- if(_isLinked) return;
62
- _linkView = view;
63
-
64
- [self link];
65
- UIView* firstAccessible = [self findFirstAccessibleChild: _delegate];
66
- if(firstAccessible) {
67
- [_delegate onFocusItemLinked: firstAccessible];
68
- }
58
+ - (void)setOrderFocusType:(NSNumber *)orderFocusType {
59
+ if ([_orderFocusType isEqualToNumber:orderFocusType]) return;
60
+ _orderFocusType = orderFocusType;
61
+ if (!_isLinked || _delegate.subviews.count == 0) return;
62
+ UIView *newView = [self getFocusView:_delegate.subviews[0]];
63
+ if (newView == nil || newView == _linkView) return;
64
+ [self clear];
65
+ [self setLinkView:newView];
69
66
  }
70
67
 
68
+ #pragma mark - Subview lifecycle
71
69
 
72
70
  - (void)didAddSubview:(UIView *)subview {
73
- if(!_linkView) {
74
- _isLinked = false;
75
- UIView* view = [self getFocusView: subview];
76
- [self setLinkView: view];
71
+ if (!_linkView) {
72
+ _isLinked = NO;
73
+ [self setLinkView:[self getFocusView:subview]];
77
74
  }
78
75
  }
79
76
 
80
77
  - (void)willRemoveSubview:(UIView *)subview {
81
- if(_linkView == subview) {
78
+ if (_linkView == subview) {
82
79
  [self clear];
83
- UIView* firstAccessible = [self findFirstAccessibleChild: _delegate];
84
- if(firstAccessible) {
85
- [_delegate onFocusItemRemoved: subview];
86
- }
87
80
  }
88
81
  }
89
82
 
90
- - (void)relink:(NSNumber *)position lastPosition:(NSNumber*)lastPosition {
91
- if(!_delegate) return;
92
-
93
- if(_orderKey != nil && position != nil && _isLinked) {
94
- UIView* view = _linkView ? _linkView : [self getFocusView: _delegate.subviews[0]];
95
- [[RNAOA11yOrderLinking sharedInstance] update: position lastPosition:lastPosition withOrderKey: _orderKey withView: view];
96
- }
83
+ - (void)finalizeUpdates {
84
+ if (!_delegate || _delegate.subviews.count == 0) return;
85
+ [self setLinkView:[self getFocusView:_delegate.subviews[0]]];
86
+ }
87
+
88
+ #pragma mark - Registration
89
+
90
+ - (void)setLinkView:(UIView *)view {
91
+ if (_isLinked) return;
92
+ _linkView = view;
93
+ [self link];
97
94
  }
98
95
 
99
96
  - (void)link {
100
- if(!_delegate) return;
101
-
102
- if(self.position && self.orderKey && self.linkView && !_isLinked) {
103
- [[RNAOA11yOrderLinking sharedInstance] add: _position withOrderKey:_orderKey withObject:self.linkView];
104
-
105
- _isLinked = true;
97
+ if (!_delegate) return;
98
+ if (_position && _orderKey && _linkView && !_isLinked) {
99
+ [[RNAOA11yOrderLinking sharedInstance] add:_position withOrderKey:_orderKey withObject:_linkView];
100
+ _isLinked = YES;
101
+ [self registerFocusDelegate];
102
+ }
103
+ }
104
+
105
+ - (void)registerFocusDelegate {
106
+ UIView *firstAccessible = [self findFirstAccessibleChild:_delegate];
107
+ UIView *focusView = firstAccessible ?: _linkView;
108
+ if (focusView) {
109
+ _focusDelegateView = focusView;
110
+ [_delegate onFocusItemLinked:focusView];
106
111
  }
107
112
  }
108
113
 
114
+ - (void)relink:(NSNumber *)position lastPosition:(NSNumber *)lastPosition {
115
+ if (!_delegate || !_isLinked || !_orderKey || !position) return;
116
+ UIView *view = _delegate.subviews.count > 0
117
+ ? [self getFocusView:_delegate.subviews[0]]
118
+ : _linkView;
119
+ if (!view) return;
120
+ [[RNAOA11yOrderLinking sharedInstance] update:position lastPosition:lastPosition withOrderKey:_orderKey withView:view];
121
+ }
122
+
109
123
  - (void)clear {
110
- if(!_delegate) return;
111
- _isLinked = false;
112
- if(_position != nil && _orderKey != nil) {
113
- [[RNAOA11yOrderLinking sharedInstance] remove:_position withOrderKey:_orderKey];
124
+ if (!_delegate) return;
125
+ if (_focusDelegateView) {
126
+ [_delegate onFocusItemRemoved:_focusDelegateView];
127
+ _focusDelegateView = nil;
128
+ }
129
+ _isLinked = NO;
130
+ if (_position && _orderKey) {
131
+ [[RNAOA11yOrderLinking sharedInstance] remove:_position withOrderKey:_orderKey];
114
132
  }
115
133
  }
116
134
 
135
+ #pragma mark - Focus view resolution
136
+
117
137
  - (UIView *)getFocusView:(UIView *)subview {
118
- if(!_delegate) return nil;
119
- switch ([_orderFocusType intValue]) {
120
- case A11yOrderTypeDefault:
121
- return _delegate;
122
- case A11yOrderTypeLegacy:
123
- return subview;
124
- case A11yOrderTypeChild:
125
- return [self findFirstAccessibleChild: _delegate];
126
- default:
127
- return _delegate;
128
- }
138
+ if (!_delegate) return nil;
139
+ switch ([_orderFocusType intValue]) {
140
+ case A11yOrderTypeChild:
141
+ return [self findFirstAccessibleChild:_delegate];
142
+ case A11yOrderTypeLegacy:
143
+ return subview;
144
+ case A11yOrderTypeDefault:
145
+ default:
146
+ return _delegate;
147
+ }
129
148
  }
130
149
 
131
150
  - (UIView *)findFirstAccessibleChild:(UIView *)parentView {
132
- if (!parentView) {
133
- return nil;
134
- }
135
-
136
- for (UIView *child in parentView.subviews) {
137
- if ([self isAccessibleView:child]) {
138
- return child;
139
- }
140
-
141
- UIView *accessibleChild = [self findFirstAccessibleChild:child];
142
- if (accessibleChild != nil) {
143
- return accessibleChild;
144
- }
145
- }
146
-
147
- return nil;
151
+ if (!parentView) return nil;
152
+ for (UIView *child in parentView.subviews) {
153
+ if ([self isAccessibleView:child]) return child;
154
+ UIView *found = [self findFirstAccessibleChild:child];
155
+ if (found) return found;
156
+ }
157
+ return nil;
148
158
  }
149
159
 
150
160
  - (BOOL)isAccessibleView:(UIView *)view {
151
- return view.isAccessibilityElement && view.hidden == NO && view.alpha > 0;
161
+ return view.isAccessibilityElement && !view.hidden && view.alpha > 0;
152
162
  }
163
+
153
164
  @end
@@ -15,10 +15,12 @@
15
15
 
16
16
  - (void)add:(NSNumber*)position withOrderKey:(NSString*)orderKey withObject:(NSObject*)obj;
17
17
  - (void)remove:(NSNumber*)position withOrderKey:(NSString*)orderKey;
18
- - (void)setContainer:(NSString*)orderKey withView:(UIView*) view;
19
- - (void)setContainer:(NSString*)orderKey withView:(UIView*) view withDebounce:(BOOL)debounced;
18
+ - (void)setContainer:(NSString*)orderKey withView:(UIView*)view;
19
+ - (void)setContainer:(NSString*)orderKey withView:(UIView*)view withDebounce:(BOOL)debounced;
20
+ - (void)update:(NSNumber*)position lastPosition:(NSNumber*)lastPosition withOrderKey:(NSString*)orderKey withView:(UIView*)view;
21
+ - (void)updateOrderKey:(NSString*)prev next:(NSString*)next position:(NSNumber*)position withView:(UIView*)view;
20
22
  - (void)removeContainer:(NSString*)orderKey;
21
- - (void)update:(NSNumber*)position lastPosition:(NSNumber*)_position withOrderKey:(NSString*)_orderKey withView:(UIView*) view;
23
+
22
24
  @end
23
25
 
24
26
  #endif /* RNAOA11yOrderLinking_h */
@@ -11,80 +11,80 @@
11
11
  #import "RNAOA11yRelationship.h"
12
12
 
13
13
  @implementation RNAOA11yOrderLinking {
14
- NSMutableDictionary *_relationships;
14
+ NSMutableDictionary<NSString *, RNAOA11yRelationship *> *_relationships;
15
15
  }
16
16
 
17
17
  + (instancetype)sharedInstance {
18
- static RNAOA11yOrderLinking *sharedInstance = nil;
19
- static dispatch_once_t onceToken;
20
- dispatch_once(&onceToken, ^{
21
- sharedInstance = [[self alloc] init];
22
- });
23
- return sharedInstance;
18
+ static RNAOA11yOrderLinking *sharedInstance = nil;
19
+ static dispatch_once_t onceToken;
20
+ dispatch_once(&onceToken, ^{
21
+ sharedInstance = [[self alloc] init];
22
+ });
23
+ return sharedInstance;
24
24
  }
25
25
 
26
26
  - (id)init {
27
27
  if (self = [super init]) {
28
- _relationships = [NSMutableDictionary dictionary];
28
+ _relationships = [NSMutableDictionary dictionary];
29
29
  }
30
-
31
30
  return self;
32
31
  }
33
32
 
34
- - (void)add:(NSNumber*)position withOrderKey:(NSString*)orderKey withObject:(NSObject*)obj {
35
- RNAOA11yRelationship* relationship = [_relationships objectForKey: orderKey];
36
- if(relationship == nil) {
37
- relationship = [[RNAOA11yRelationship alloc] init];
38
- [_relationships setObject: relationship forKey:orderKey];
39
- }
40
- [relationship add:position withObject:obj];
33
+ - (RNAOA11yRelationship *)relationshipForKey:(NSString *)orderKey {
34
+ RNAOA11yRelationship *relationship = _relationships[orderKey];
35
+ if (relationship == nil) {
36
+ relationship = [[RNAOA11yRelationship alloc] init];
37
+ _relationships[orderKey] = relationship;
38
+ }
39
+ return relationship;
41
40
  }
42
41
 
43
- -(void)remove:(NSNumber*)position withOrderKey:(NSString*)orderKey {
44
- RNAOA11yRelationship* relationship = [_relationships objectForKey: orderKey];
45
- if(relationship != nil) {
46
- [relationship remove:position];
47
- }
42
+ - (void)add:(NSNumber *)position withOrderKey:(NSString *)orderKey withObject:(NSObject *)obj {
43
+ [[self relationshipForKey:orderKey] add:position withObject:obj];
48
44
  }
49
45
 
50
- -(void)setContainer:(NSString*)orderKey withView:(UIView*)view withDebounce:(BOOL)debounced {
51
- RNAOA11yRelationship* relationship = [_relationships objectForKey: orderKey];
52
- if(relationship == nil) {
53
- relationship = [[RNAOA11yRelationship alloc] init];
54
- [_relationships setObject: relationship forKey:orderKey];
55
- }
56
-
57
- [relationship setContainer:view withDebounce: debounced];
46
+ - (void)remove:(NSNumber *)position withOrderKey:(NSString *)orderKey {
47
+ RNAOA11yRelationship *relationship = _relationships[orderKey];
48
+ if (relationship == nil) return;
49
+ [relationship remove:position];
50
+ if ([relationship isEmpty]) {
51
+ [_relationships removeObjectForKey:orderKey];
52
+ }
58
53
  }
59
54
 
60
- - (void)setContainer:(NSString*)orderKey withView:(UIView*)view {
61
- [self setContainer: orderKey withView:view withDebounce: NO];
55
+ - (void)setContainer:(NSString *)orderKey withView:(UIView *)view withDebounce:(BOOL)debounced {
56
+ [[self relationshipForKey:orderKey] setContainer:view withDebounce:debounced];
62
57
  }
63
58
 
64
- - (void)update:(NSNumber*)position lastPosition:(NSNumber*)lastPosition withOrderKey:(NSString*)orderKey withView:(UIView*) view {
65
- RNAOA11yRelationship* relationship = [_relationships objectForKey: orderKey];
66
- if(relationship != nil) {
67
- [relationship update:lastPosition withPosition:position withObject:view];
68
- }
59
+ - (void)setContainer:(NSString *)orderKey withView:(UIView *)view {
60
+ [self setContainer:orderKey withView:view withDebounce:NO];
69
61
  }
70
62
 
71
- - (void)removeContainer:(NSString*)orderKey {
72
- RNAOA11yRelationship* relationship = [_relationships objectForKey: orderKey];
73
- if(relationship != nil) {
74
- [_relationships removeObjectForKey:orderKey];
75
- [relationship clear];
76
- }
77
- [self setAccessibilityElements: nil];
63
+ - (void)update:(NSNumber *)position lastPosition:(NSNumber *)lastPosition withOrderKey:(NSString *)orderKey withView:(UIView *)view {
64
+ [_relationships[orderKey] update:lastPosition withPosition:position withObject:view];
78
65
  }
79
66
 
80
- -(UIView*)getContainer:(NSString*)orderKey withView:(UIView*) view {
81
- RNAOA11yRelationship* relationship = [_relationships objectForKey: orderKey];
82
- if(relationship != nil) {
83
- return [relationship getContainer];
67
+ - (void)updateOrderKey:(NSString *)prev next:(NSString *)next position:(NSNumber *)position withView:(UIView *)view {
68
+ if (prev != nil) {
69
+ RNAOA11yRelationship *old = _relationships[prev];
70
+ [old remove:position];
71
+ if ([old isEmpty]) {
72
+ [_relationships removeObjectForKey:prev];
84
73
  }
85
-
86
- return nil;
74
+ }
75
+ if (next != nil) {
76
+ [[self relationshipForKey:next] add:position withObject:view];
77
+ }
87
78
  }
88
79
 
80
+ - (void)removeContainer:(NSString *)orderKey {
81
+ RNAOA11yRelationship *relationship = _relationships[orderKey];
82
+ if (relationship != nil) {
83
+ UIView *container = [relationship getContainer];
84
+ [_relationships removeObjectForKey:orderKey];
85
+ [relationship clear];
86
+ [container setAccessibilityElements:nil];
87
+ }
88
+ }
89
89
 
90
90
  @end
@@ -20,6 +20,7 @@
20
20
  - (void)setContainer:(UIView*)view;
21
21
  - (void)setContainer:(UIView*)view withDebounce:(BOOL)debounced;
22
22
  - (UIView*)getContainer;
23
+ - (BOOL)isEmpty;
23
24
 
24
25
  @property (nonatomic, strong) RNAODebouncer *debouncer;
25
26
 
@@ -12,63 +12,69 @@
12
12
  #import "RNAODebouncer.h"
13
13
 
14
14
  @implementation RNAOA11yRelationship {
15
- __weak UIView *_container;
16
- RNAOSortedMap *_positions;
17
- BOOL _debounced;
15
+ __weak UIView *_container;
16
+ RNAOSortedMap *_positions;
18
17
  }
19
18
 
20
19
  - (instancetype)init {
21
- self = [super init];
22
- if (self) {
23
- _positions = [[RNAOSortedMap alloc] init];
24
- _container = nil;
25
- _debounced = false;
26
- self.debouncer = [[RNAODebouncer alloc] initWithInterval: 0.01];
27
- }
28
- return self;
20
+ self = [super init];
21
+ if (self) {
22
+ _positions = [[RNAOSortedMap alloc] init];
23
+ }
24
+ return self;
29
25
  }
30
26
 
31
- - (void)add:(NSNumber*)position withObject:(NSObject*)obj {
32
- [_positions put:position withObject:obj];
33
- if(_debounced) {
34
- [self.debouncer debounceAction:^{
35
- [self updateAccessibilityElements];
36
- }];
37
- }
27
+ - (void)updateAccessibilityElements {
28
+ if (_container != nil) {
29
+ [_container setAccessibilityElements:[_positions getValues]];
30
+ }
38
31
  }
39
32
 
40
- - (void)updateAccessibilityElements {
41
- if(_container != nil) {
42
- [_container setAccessibilityElements: [_positions getValues]];
33
+ - (void)scheduleAccessibilityUpdate {
34
+ if (self.debouncer) {
35
+ [self.debouncer debounceAction:^{ [self updateAccessibilityElements]; }];
36
+ } else {
37
+ [self updateAccessibilityElements];
43
38
  }
44
39
  }
45
40
 
46
- -(void)remove:(NSNumber*)position {
47
- [_positions remove:position];
41
+ - (void)add:(NSNumber *)position withObject:(NSObject *)obj {
42
+ [_positions put:position withObject:obj];
43
+ [self scheduleAccessibilityUpdate];
48
44
  }
49
45
 
50
- -(void)setContainer:(UIView*)view {
51
- _container = view;
52
- [self updateAccessibilityElements];
46
+ - (void)remove:(NSNumber *)position {
47
+ [_positions remove:position];
48
+ [self scheduleAccessibilityUpdate];
53
49
  }
54
50
 
55
- - (void)setContainer:(UIView*)view withDebounce:(BOOL)debounced {
56
- [self setContainer: view];
57
- _debounced = debounced;
51
+ - (void)update:(NSNumber *)lastPosition withPosition:(NSNumber *)position withObject:(NSObject *)obj {
52
+ [_positions update:lastPosition withPosition:position withObject:obj];
53
+ [self scheduleAccessibilityUpdate];
58
54
  }
59
55
 
60
- - (void)update:(NSNumber*)lastPosition withPosition:(NSNumber*)position withObject:(NSObject*)obj {
61
- [_positions update:lastPosition withPosition:position withObject:obj];
62
- [self updateAccessibilityElements];
56
+ - (void)setContainer:(UIView *)view {
57
+ _container = view;
58
+ [self updateAccessibilityElements];
63
59
  }
64
60
 
65
- -(void)clear {
66
- [_positions clear];
61
+ - (void)setContainer:(UIView *)view withDebounce:(BOOL)debounced {
62
+ if (debounced && !self.debouncer) {
63
+ self.debouncer = [[RNAODebouncer alloc] initWithInterval:0.01];
64
+ }
65
+ [self setContainer:view];
67
66
  }
68
67
 
69
- -(UIView*)getContainer {
70
- return _container;
68
+ - (void)clear {
69
+ [_positions clear];
71
70
  }
72
71
 
72
+ - (UIView *)getContainer {
73
+ return _container;
74
+ }
75
+
76
+ - (BOOL)isEmpty {
77
+ return [_positions isEmpty];
78
+ }
73
79
 
74
80
  @end
@@ -13,9 +13,10 @@
13
13
 
14
14
  - (void)put:(NSNumber*)position withObject:(NSObject*)obj;
15
15
  - (void)remove:(NSNumber*)position;
16
- - (void)update:(NSNumber*)position withPosition:(NSNumber*)position withObject:(NSObject*)obj;
16
+ - (void)update:(NSNumber*)lastPosition withPosition:(NSNumber*)position withObject:(NSObject*)obj;
17
17
  - (void)clear;
18
18
  - (NSArray*)getValues;
19
+ - (BOOL)isEmpty;
19
20
 
20
21
  @end
21
22