react-native-external-keyboard 0.6.8 → 0.7.1

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 (123) hide show
  1. package/README.md +37 -129
  2. package/android/src/main/java/com/externalkeyboard/ExternalKeyboardViewPackage.java +2 -0
  3. package/android/src/main/java/com/externalkeyboard/helper/FocusHelper.java +70 -0
  4. package/android/src/main/java/com/externalkeyboard/views/ExternalKeyboardLockView/ExternalKeyboardLockView.java +115 -0
  5. package/android/src/main/java/com/externalkeyboard/views/ExternalKeyboardLockView/ExternalKeyboardLockViewManager.java +32 -0
  6. package/android/src/main/java/com/externalkeyboard/views/ExternalKeyboardLockView/LockService.java +44 -0
  7. package/android/src/newarch/ExternalKeyboardLockViewManagerSpec.java +8 -0
  8. package/android/src/oldarch/ExternalKeyboardLockViewManagerSpec.java +12 -0
  9. package/ios/Delegates/RNCEKVFocusOrderDelegate/RNCEKVFocusGuideDelegate/RNCEKVFocusGuideDelegate.h +36 -0
  10. package/ios/Delegates/RNCEKVFocusOrderDelegate/RNCEKVFocusGuideDelegate/RNCEKVFocusGuideDelegate.mm +150 -0
  11. package/ios/Delegates/RNCEKVFocusOrderDelegate/RNCEKVFocusOrderDelegate.h +14 -0
  12. package/ios/Delegates/RNCEKVFocusOrderDelegate/RNCEKVFocusOrderDelegate.mm +98 -349
  13. package/ios/Extensions/RCTTextInputComponentView+RNCEKVExternalKeyboard.h +1 -1
  14. package/ios/Extensions/RCTTextInputComponentView+RNCEKVExternalKeyboard.mm +11 -3
  15. package/ios/Extensions/UIViewController+RNCEKVExternalKeyboard.h +1 -1
  16. package/ios/Extensions/UIViewController+RNCEKVExternalKeyboard.mm +17 -17
  17. package/ios/Helpers/RNCEKVFocusGuideHelper/RNCEKVFocusGuideHelper.h +32 -0
  18. package/ios/Helpers/RNCEKVFocusGuideHelper/RNCEKVFocusGuideHelper.mm +81 -0
  19. package/ios/Helpers/RNCEKVSwizzlingHelper/RNCEKVSwizzlingHelper.h +16 -0
  20. package/ios/Helpers/RNCEKVSwizzlingHelper/RNCEKVSwizzlingHelper.mm +27 -0
  21. package/ios/Modules/RNCEKVExternalKeyboardModule.mm +3 -3
  22. package/ios/Services/RNCEKVFocusLinkObserver.h +7 -1
  23. package/ios/Services/RNCEKVFocusLinkObserver.mm +31 -6
  24. package/ios/Services/RNCEKVKeyboardOrderManager/RNCEKVKeyboardOrderManager.h +17 -0
  25. package/ios/Services/RNCEKVKeyboardOrderManager/RNCEKVKeyboardOrderManager.mm +15 -0
  26. package/ios/Services/{RNCEKVRelashioship.h → RNCEKVKeyboardOrderManager/RNCEKVOrderRelationship/RNCEKVOrderRelationship.h} +8 -7
  27. package/ios/Services/{RNCEKVRelashioship.mm → RNCEKVKeyboardOrderManager/RNCEKVOrderRelationship/RNCEKVOrderRelationship.mm} +36 -13
  28. package/ios/Services/RNCEKVOrderLinking.h +2 -7
  29. package/ios/Services/RNCEKVOrderLinking.mm +27 -64
  30. package/ios/Services/RNCEKVOrderSubscriber.h +4 -3
  31. package/ios/Services/RNCEKVOrderSubscriber.mm +2 -1
  32. package/ios/Views/RNCEKVExternalKeyboardLockView/RNCEKVExternalKeyboardLockView.h +38 -0
  33. package/ios/Views/RNCEKVExternalKeyboardLockView/RNCEKVExternalKeyboardLockView.mm +62 -0
  34. package/ios/Views/RNCEKVExternalKeyboardLockView/RNCEKVExternalKeyboardLockViewManager.h +14 -0
  35. package/ios/Views/RNCEKVExternalKeyboardLockView/RNCEKVExternalKeyboardLockViewManager.mm +25 -0
  36. package/ios/Views/RNCEKVExternalKeyboardView/Helpers/RNCEKVFabricEventHelper/RNCEKVFabricEventHelper.mm +6 -4
  37. package/ios/Views/RNCEKVExternalKeyboardView/RNCEKVExternalKeyboardView.mm +2 -2
  38. package/ios/Views/RNCEKVKeyboardFocusGroupView/RNCEKVKeyboardFocusGroup.mm +0 -1
  39. package/ios/Views/RNCEKVTextInputFocusWrapper/RNCEKVTextInputFocusWrapper.mm +1 -15
  40. package/lib/commonjs/components/KeyboardFocusLock/FocusFrame/FocusFrame.android.js +21 -0
  41. package/lib/commonjs/components/KeyboardFocusLock/FocusFrame/FocusFrame.android.js.map +1 -0
  42. package/lib/commonjs/components/KeyboardFocusLock/FocusFrame/FocusFrame.js +11 -0
  43. package/lib/commonjs/components/KeyboardFocusLock/FocusFrame/FocusFrame.js.map +1 -0
  44. package/lib/commonjs/components/KeyboardFocusLock/FocusTrap/FocusTrap.android.js +19 -0
  45. package/lib/commonjs/components/KeyboardFocusLock/FocusTrap/FocusTrap.android.js.map +1 -0
  46. package/lib/commonjs/components/KeyboardFocusLock/FocusTrap/FocusTrap.js +15 -0
  47. package/lib/commonjs/components/KeyboardFocusLock/FocusTrap/FocusTrap.js.map +1 -0
  48. package/lib/commonjs/components/KeyboardFocusLock/FocusTrap/FocusTrapMountWrapper.js +46 -0
  49. package/lib/commonjs/components/KeyboardFocusLock/FocusTrap/FocusTrapMountWrapper.js.map +1 -0
  50. package/lib/commonjs/components/KeyboardFocusLock/KeyboardFocusLockBase/KeyboardFocusLockBase.android.js +21 -0
  51. package/lib/commonjs/components/KeyboardFocusLock/KeyboardFocusLockBase/KeyboardFocusLockBase.android.js.map +1 -0
  52. package/lib/commonjs/components/KeyboardFocusLock/KeyboardFocusLockBase/KeyboardFocusLockBase.js +9 -0
  53. package/lib/commonjs/components/KeyboardFocusLock/KeyboardFocusLockBase/KeyboardFocusLockBase.js.map +1 -0
  54. package/lib/commonjs/context/FocusFrameProviderContext.js +28 -0
  55. package/lib/commonjs/context/FocusFrameProviderContext.js.map +1 -0
  56. package/lib/commonjs/index.js +7 -1
  57. package/lib/commonjs/index.js.map +1 -1
  58. package/lib/commonjs/nativeSpec/ExternalKeyboardLockViewNativeComponent.js +10 -0
  59. package/lib/commonjs/nativeSpec/ExternalKeyboardLockViewNativeComponent.js.map +1 -0
  60. package/lib/commonjs/types/KeyboardFocusLock.types.js +6 -0
  61. package/lib/commonjs/types/KeyboardFocusLock.types.js.map +1 -0
  62. package/lib/module/components/KeyboardFocusLock/FocusFrame/FocusFrame.android.js +14 -0
  63. package/lib/module/components/KeyboardFocusLock/FocusFrame/FocusFrame.android.js.map +1 -0
  64. package/lib/module/components/KeyboardFocusLock/FocusFrame/FocusFrame.js +4 -0
  65. package/lib/module/components/KeyboardFocusLock/FocusFrame/FocusFrame.js.map +1 -0
  66. package/lib/module/components/KeyboardFocusLock/FocusTrap/FocusTrap.android.js +12 -0
  67. package/lib/module/components/KeyboardFocusLock/FocusTrap/FocusTrap.android.js.map +1 -0
  68. package/lib/module/components/KeyboardFocusLock/FocusTrap/FocusTrap.js +8 -0
  69. package/lib/module/components/KeyboardFocusLock/FocusTrap/FocusTrap.js.map +1 -0
  70. package/lib/module/components/KeyboardFocusLock/FocusTrap/FocusTrapMountWrapper.js +39 -0
  71. package/lib/module/components/KeyboardFocusLock/FocusTrap/FocusTrapMountWrapper.js.map +1 -0
  72. package/lib/module/components/KeyboardFocusLock/KeyboardFocusLockBase/KeyboardFocusLockBase.android.js +14 -0
  73. package/lib/module/components/KeyboardFocusLock/KeyboardFocusLockBase/KeyboardFocusLockBase.android.js.map +1 -0
  74. package/lib/module/components/KeyboardFocusLock/KeyboardFocusLockBase/KeyboardFocusLockBase.js +3 -0
  75. package/lib/module/components/KeyboardFocusLock/KeyboardFocusLockBase/KeyboardFocusLockBase.js.map +1 -0
  76. package/lib/module/context/FocusFrameProviderContext.js +20 -0
  77. package/lib/module/context/FocusFrameProviderContext.js.map +1 -0
  78. package/lib/module/index.js +6 -0
  79. package/lib/module/index.js.map +1 -1
  80. package/lib/module/nativeSpec/ExternalKeyboardLockViewNativeComponent.js +3 -0
  81. package/lib/module/nativeSpec/ExternalKeyboardLockViewNativeComponent.js.map +1 -0
  82. package/lib/module/types/KeyboardFocusLock.types.js +2 -0
  83. package/lib/module/types/KeyboardFocusLock.types.js.map +1 -0
  84. package/lib/typescript/src/components/KeyboardFocusLock/FocusFrame/FocusFrame.android.d.ts +4 -0
  85. package/lib/typescript/src/components/KeyboardFocusLock/FocusFrame/FocusFrame.android.d.ts.map +1 -0
  86. package/lib/typescript/src/components/KeyboardFocusLock/FocusFrame/FocusFrame.d.ts +3 -0
  87. package/lib/typescript/src/components/KeyboardFocusLock/FocusFrame/FocusFrame.d.ts.map +1 -0
  88. package/lib/typescript/src/components/KeyboardFocusLock/FocusTrap/FocusTrap.android.d.ts +4 -0
  89. package/lib/typescript/src/components/KeyboardFocusLock/FocusTrap/FocusTrap.android.d.ts.map +1 -0
  90. package/lib/typescript/src/components/KeyboardFocusLock/FocusTrap/FocusTrap.d.ts +3 -0
  91. package/lib/typescript/src/components/KeyboardFocusLock/FocusTrap/FocusTrap.d.ts.map +1 -0
  92. package/lib/typescript/src/components/KeyboardFocusLock/FocusTrap/FocusTrapMountWrapper.d.ts +3 -0
  93. package/lib/typescript/src/components/KeyboardFocusLock/FocusTrap/FocusTrapMountWrapper.d.ts.map +1 -0
  94. package/lib/typescript/src/components/KeyboardFocusLock/KeyboardFocusLockBase/KeyboardFocusLockBase.android.d.ts +4 -0
  95. package/lib/typescript/src/components/KeyboardFocusLock/KeyboardFocusLockBase/KeyboardFocusLockBase.android.d.ts.map +1 -0
  96. package/lib/typescript/src/components/KeyboardFocusLock/KeyboardFocusLockBase/KeyboardFocusLockBase.d.ts +3 -0
  97. package/lib/typescript/src/components/KeyboardFocusLock/KeyboardFocusLockBase/KeyboardFocusLockBase.d.ts.map +1 -0
  98. package/lib/typescript/src/components/Touchable/Pressable.d.ts +1 -1
  99. package/lib/typescript/src/context/FocusFrameProviderContext.d.ts +12 -0
  100. package/lib/typescript/src/context/FocusFrameProviderContext.d.ts.map +1 -0
  101. package/lib/typescript/src/index.d.ts +4 -0
  102. package/lib/typescript/src/index.d.ts.map +1 -1
  103. package/lib/typescript/src/nativeSpec/ExternalKeyboardLockViewNativeComponent.d.ts +9 -0
  104. package/lib/typescript/src/nativeSpec/ExternalKeyboardLockViewNativeComponent.d.ts.map +1 -0
  105. package/lib/typescript/src/types/KeyboardFocusLock.types.d.ts +6 -0
  106. package/lib/typescript/src/types/KeyboardFocusLock.types.d.ts.map +1 -0
  107. package/lib/typescript/src/utils/withKeyboardFocus.d.ts +1 -1
  108. package/package.json +4 -3
  109. package/src/components/KeyboardFocusLock/FocusFrame/FocusFrame.android.tsx +18 -0
  110. package/src/components/KeyboardFocusLock/FocusFrame/FocusFrame.tsx +8 -0
  111. package/src/components/KeyboardFocusLock/FocusTrap/FocusTrap.android.tsx +17 -0
  112. package/src/components/KeyboardFocusLock/FocusTrap/FocusTrap.tsx +9 -0
  113. package/src/components/KeyboardFocusLock/FocusTrap/FocusTrapMountWrapper.ts +40 -0
  114. package/src/components/KeyboardFocusLock/KeyboardFocusLockBase/KeyboardFocusLockBase.android.tsx +16 -0
  115. package/src/components/KeyboardFocusLock/KeyboardFocusLockBase/KeyboardFocusLockBase.tsx +5 -0
  116. package/src/context/FocusFrameProviderContext.tsx +36 -0
  117. package/src/index.tsx +8 -0
  118. package/src/nativeSpec/ExternalKeyboardLockViewNativeComponent.ts +13 -0
  119. package/src/types/KeyboardFocusLock.types.ts +6 -0
  120. package/ios/Services/RNCEKVFocusLinkObserverManager.h +0 -23
  121. package/ios/Services/RNCEKVFocusLinkObserverManager.mm +0 -30
  122. /package/ios/Services/{RNCEKVSortedMap.h → RNCEKVKeyboardOrderManager/RNCEKVOrderRelationship/RNCEKVSortedMap/RNCEKVSortedMap.h} +0 -0
  123. /package/ios/Services/{RNCEKVSortedMap.mm → RNCEKVKeyboardOrderManager/RNCEKVOrderRelationship/RNCEKVSortedMap/RNCEKVSortedMap.mm} +0 -0
@@ -14,8 +14,10 @@
14
14
  #import "RNCEKVOrderLinking.h"
15
15
  #import "RNCEKVExternalKeyboardView.h"
16
16
  #import "UIViewController+RNCEKVExternalKeyboard.h"
17
- #import "RNCEKVFocusLinkObserverManager.h"
18
17
  #import "RNCEKVOrderSubscriber.h"
18
+ #import "RNCEKVFocusLinkObserver.h"
19
+ #import "RNCEKVFocusGuideHelper.h"
20
+ #import "RNCEKVFocusGuideDelegate.h"
19
21
 
20
22
  static NSNumber *const FOCUS_DEFAULT = nil;
21
23
  static NSNumber *const FOCUS_LOCK = @0;
@@ -27,50 +29,66 @@ static NSNumber *const FOCUS_UPDATE = @1;
27
29
  UIView* _entry;
28
30
  UIView* _exit;
29
31
  UIView* _lock;
30
- LinkUpdatedCallback _leftLinkUpdated;
31
- LinkRemovedCallback _leftLinkRemoved;
32
- LinkUpdatedCallback _rightLinkUpdated;
33
- LinkRemovedCallback _rightLinkRemoved;
34
- LinkUpdatedCallback _upLinkUpdated;
35
- LinkRemovedCallback _upLinkRemoved;
36
- LinkUpdatedCallback _downLinkUpdated;
37
- LinkRemovedCallback _downLinkRemoved;
38
32
 
39
- UIFocusGuide *_leftFocusGuide;
40
- UIFocusGuide *_rightFocusGuide;
41
- UIFocusGuide *_upFocusGuide;
42
- UIFocusGuide *_downFocusGuide;
33
+ RNCEKVFocusGuideDelegate *_focusGuideDelegate;
34
+ NSMutableDictionary<NSNumber *, id> *_updateLinks;
35
+ NSMutableDictionary<NSNumber *, id> *_removeLinks;
36
+
43
37
  }
44
38
 
45
39
  - (instancetype _Nonnull )initWithView:(UIView<RNCEKVFocusOrderProtocol> *_Nonnull)delegate{
46
40
  self = [super init];
47
41
  if (self) {
48
42
  _delegate = delegate;
43
+ _focusGuideDelegate = [[RNCEKVFocusGuideDelegate alloc] initWithView:delegate];
44
+ _subscribers = [NSMutableDictionary dictionary];
49
45
  _isFocused = false;
50
46
  }
51
47
  return self;
52
48
  }
53
49
 
54
- #pragma mark - Get Order Focus List
55
- - (NSArray<UIView *> *)getOrder {
56
- RNCEKVRelashioship* orderRelationship = [[RNCEKVOrderLinking sharedInstance] getInfo: _delegate.orderGroup];
57
- return [orderRelationship getArray];
50
+ - (void)subscribeToDirection:(RNCEKVFocusGuideDirection)direction
51
+ linkId:(NSString *)linkId {
52
+ if (!linkId) {
53
+ return;
54
+ }
55
+
56
+ if(_subscribers[@(direction)]) {
57
+ [self clearDirection: direction];
58
+ }
59
+
60
+ __typeof(self) __weak weakSelf = self;
61
+ RNCEKVFocusGuideDirection capturedDirection = direction;
62
+
63
+ LinkUpdatedCallback onLinkUpdated = ^(UIView *link) {
64
+ [self->_focusGuideDelegate setGuideFor:capturedDirection withView: link];
65
+ };
66
+
67
+ LinkRemovedCallback onLinkRemoved = ^{
68
+ [self->_focusGuideDelegate removeGuideFor: capturedDirection];
69
+ };
70
+
71
+ RNCEKVOrderSubscriber* subscriber = [[RNCEKVFocusLinkObserver sharedManager] subscribe:linkId
72
+ onLinkUpdated:onLinkUpdated
73
+ onLinkRemoved:onLinkRemoved];
74
+ self.subscribers[@(direction)] = subscriber;
58
75
  }
59
76
 
60
-
61
- #pragma mark - Find Index of Focus Order Element
62
- - (int)findOrderIndex:(NSArray *)order element:(UIView*)el {
63
- int resultIndex = -1;
64
-
65
- for (int i = 0; i < order.count; i++) {
66
- UIView *element = order[i];
67
- if (element.subviews[0] == el) { //ToDo focus element
68
- resultIndex = i;
69
- break;
70
- }
77
+ - (void)clearDirection:(RNCEKVFocusGuideDirection)direction {
78
+ if (!self.subscribers[@(direction)]) {
79
+ return;
71
80
  }
72
81
 
73
- return resultIndex;
82
+ [[RNCEKVFocusLinkObserver sharedManager] unsubscribe:self.subscribers[@(direction)]];
83
+ self.subscribers[@(direction)] = nil;
84
+ [_focusGuideDelegate removeGuideFor: direction];
85
+ }
86
+
87
+ - (void)refreshDirection:(RNCEKVFocusGuideDirection)direction
88
+ prevId:(NSString *)prevId
89
+ nextId:(NSString *)nextId {
90
+ [self clearDirection:direction];
91
+ [self subscribeToDirection:direction linkId:nextId];
74
92
  }
75
93
 
76
94
  - (void)keyboardedViewFocus:(UIView *)view {
@@ -83,7 +101,7 @@ static NSNumber *const FOCUS_UPDATE = @1;
83
101
  UIViewController *controller = _delegate.reactViewController;
84
102
 
85
103
  if (controller != nil) {
86
- controller.customFocusView = view;
104
+ controller.rncekvCustomFocusView = view;
87
105
  dispatch_async(dispatch_get_main_queue(), ^{
88
106
  [controller setNeedsFocusUpdate];
89
107
  [controller updateFocusIfNeeded];
@@ -94,25 +112,24 @@ static NSNumber *const FOCUS_UPDATE = @1;
94
112
 
95
113
  #pragma mark - Next Focus Handling
96
114
  - (void)handleNextFocus:(UIView *)current currentIndex:(NSInteger)currentIndex {
97
- NSArray<UIView *> * order = [self getOrder];
98
- RNCEKVRelashioship* orderRelationship = [[RNCEKVOrderLinking sharedInstance] getInfo: _delegate.orderGroup];
115
+ RNCEKVOrderRelationship* orderRelationship = [[RNCEKVOrderLinking sharedInstance] getInfo: _delegate.orderGroup];
99
116
  UIView* _entry = orderRelationship.entry;
100
117
  UIView* _exit = orderRelationship.exit;
101
118
 
102
119
  BOOL isEntry = _entry == current;
103
120
  if (isEntry) {
104
- UIView* firstElement = order[0];
121
+ UIView* firstElement = [orderRelationship getItem: 0];
105
122
  [self keyboardedViewFocus: firstElement];
106
123
  }
107
124
 
108
- BOOL isLast = currentIndex == order.count - 1 && _exit;
125
+ BOOL isLast = currentIndex == orderRelationship.count - 1 && _exit;
109
126
  if (isLast) {
110
127
  [self defaultViewFocus: _exit];
111
128
  }
112
129
 
113
- BOOL inOrderRange = currentIndex >= 0 && currentIndex < order.count - 1;
130
+ BOOL inOrderRange = currentIndex >= 0 && currentIndex < orderRelationship.count - 1;
114
131
  if (inOrderRange) {
115
- UIView* nextElement = order[currentIndex + 1];
132
+ UIView* nextElement = [orderRelationship getItem: currentIndex + 1];
116
133
  [self keyboardedViewFocus: nextElement];
117
134
  }
118
135
  }
@@ -120,15 +137,15 @@ static NSNumber *const FOCUS_UPDATE = @1;
120
137
 
121
138
  #pragma mark - Prev Focus Handling
122
139
  - (void)handlePrevFocus:(UIView *)current currentIndex:(NSInteger)currentIndex {
123
- NSArray<UIView *> * order = [self getOrder];
124
- RNCEKVRelashioship* orderRelationship = [[RNCEKVOrderLinking sharedInstance] getInfo: _delegate.orderGroup];
140
+ RNCEKVOrderRelationship* orderRelationship = [[RNCEKVOrderLinking sharedInstance] getInfo: _delegate.orderGroup];
125
141
 
126
142
  UIView* _exit = orderRelationship.exit;
127
143
  UIView* _entry = orderRelationship.entry;
128
144
 
129
145
  BOOL isExit = _exit == current;
146
+ int orderCount = [orderRelationship count];
130
147
  if (isExit) {
131
- UIView* lastElement = order[order.count - 1];
148
+ UIView* lastElement = [orderRelationship getItem: orderCount - 1];
132
149
  [self keyboardedViewFocus: lastElement];
133
150
  }
134
151
 
@@ -137,9 +154,9 @@ static NSNumber *const FOCUS_UPDATE = @1;
137
154
  [self defaultViewFocus: _entry];
138
155
  }
139
156
 
140
- BOOL inRange = currentIndex > 0 && currentIndex <= order.count - 1;
157
+ BOOL inRange = currentIndex > 0 && currentIndex <= orderCount - 1;
141
158
  if (inRange) {
142
- UIView* prevElement = order[currentIndex - 1];
159
+ UIView* prevElement = [orderRelationship getItem: currentIndex - 1];
143
160
  [self keyboardedViewFocus: prevElement];
144
161
  }
145
162
  }
@@ -186,7 +203,7 @@ static NSNumber *const FOCUS_UPDATE = @1;
186
203
  }
187
204
 
188
205
  if(_delegate.orderGroup && _delegate.orderPosition != nil) {
189
- RNCEKVRelashioship* orderRelationship = [[RNCEKVOrderLinking sharedInstance] getInfo: _delegate.orderGroup];
206
+ RNCEKVOrderRelationship* orderRelationship = [[RNCEKVOrderLinking sharedInstance] getInfo: _delegate.orderGroup];
190
207
  NSArray *order = [orderRelationship getArray];
191
208
  if(order.count == 0) {
192
209
  return FOCUS_DEFAULT;
@@ -194,8 +211,12 @@ static NSNumber *const FOCUS_UPDATE = @1;
194
211
 
195
212
  UIView* _exit = orderRelationship.exit;
196
213
  UIView* _entry = orderRelationship.entry;
197
- int currentIndex = [self findOrderIndex:order element:current];
198
- int nextIndex = [self findOrderIndex:order element:next];
214
+
215
+ int currentIndex = [orderRelationship getItemIndex:current];
216
+ int nextIndex = [orderRelationship getItemIndex:next];
217
+ // [self findOrderIndex:order element:current];
218
+
219
+ // [self findOrderIndex:order element:next];
199
220
 
200
221
  BOOL isEntryElement = _entry == nil && currentIndex == -1 && movementHint == UIFocusHeadingNext;
201
222
 
@@ -223,225 +244,8 @@ static NSNumber *const FOCUS_UPDATE = @1;
223
244
  return FOCUS_DEFAULT;
224
245
  }
225
246
 
226
-
227
-
228
- - (void)setLeftGuide:(UIView *)view {
229
- if (!view) {
230
- return;
231
- }
232
-
233
- [self removeLeftGuide];
234
-
235
- _leftFocusGuide = [[UIFocusGuide alloc] init];
236
- [_delegate addLayoutGuide:_leftFocusGuide];
237
-
238
- [NSLayoutConstraint activateConstraints:@[
239
- [_leftFocusGuide.topAnchor constraintEqualToAnchor:_delegate.topAnchor],
240
- [_leftFocusGuide.bottomAnchor constraintEqualToAnchor:_delegate.bottomAnchor],
241
- [_leftFocusGuide.rightAnchor constraintEqualToAnchor:_delegate.leftAnchor],
242
- [_leftFocusGuide.widthAnchor constraintEqualToConstant:1]
243
- ]];
244
-
245
- _leftFocusGuide.preferredFocusEnvironments = @[view];
246
-
247
- _leftFocusGuide.enabled = _isFocused;
248
- }
249
-
250
- - (void)setRightGuide:(UIView *)view {
251
- if (!view) return;
252
-
253
- [self removeRightGuide];
254
-
255
- _rightFocusGuide = [[UIFocusGuide alloc] init];
256
- [_delegate addLayoutGuide: _rightFocusGuide];
257
-
258
- [NSLayoutConstraint activateConstraints:@[
259
- [_rightFocusGuide.topAnchor constraintEqualToAnchor: _delegate.topAnchor],
260
- [_rightFocusGuide.bottomAnchor constraintEqualToAnchor: _delegate.bottomAnchor],
261
- [_rightFocusGuide.leftAnchor constraintEqualToAnchor: _delegate.rightAnchor],
262
- [_rightFocusGuide.widthAnchor constraintEqualToConstant: 1]
263
- ]];
264
-
265
- _rightFocusGuide.preferredFocusEnvironments = @[view];
266
-
267
- _rightFocusGuide.enabled = _isFocused;
268
- }
269
-
270
- - (void)setUpGuide:(UIView *)view {
271
- if (!view) return;
272
-
273
- [self removeUpGuide];
274
-
275
- _upFocusGuide = [[UIFocusGuide alloc] init];
276
- [_delegate addLayoutGuide: _upFocusGuide];
277
-
278
- [NSLayoutConstraint activateConstraints:@[
279
- [_upFocusGuide.leftAnchor constraintEqualToAnchor:_delegate.leftAnchor],
280
- [_upFocusGuide.rightAnchor constraintEqualToAnchor:_delegate.rightAnchor],
281
- [_upFocusGuide.bottomAnchor constraintEqualToAnchor:_delegate.topAnchor],
282
- [_upFocusGuide.heightAnchor constraintEqualToConstant:1]
283
- ]];
284
-
285
- _upFocusGuide.preferredFocusEnvironments = @[view];
286
-
287
- _upFocusGuide.enabled = _isFocused;
288
- }
289
-
290
- - (void)setDownGuide:(UIView *)view {
291
- if (!view) return;
292
-
293
- [self removeDownGuide];
294
-
295
- _downFocusGuide = [[UIFocusGuide alloc] init];
296
- [_delegate addLayoutGuide:_downFocusGuide];
297
-
298
- [NSLayoutConstraint activateConstraints:@[
299
- [_downFocusGuide.leftAnchor constraintEqualToAnchor:_delegate.leftAnchor],
300
- [_downFocusGuide.rightAnchor constraintEqualToAnchor:_delegate.rightAnchor],
301
- [_downFocusGuide.topAnchor constraintEqualToAnchor:_delegate.bottomAnchor],
302
- [_downFocusGuide.heightAnchor constraintEqualToConstant:1]
303
- ]];
304
-
305
- _downFocusGuide.preferredFocusEnvironments = @[view];
306
-
307
- _downFocusGuide.enabled = _isFocused;
308
- }
309
-
310
- - (void)setIsFocused:(BOOL)value {
311
- _isFocused = value;
312
-
313
- if(_leftFocusGuide != nil) {
314
- _leftFocusGuide.enabled = value;
315
- }
316
-
317
- if(_rightFocusGuide != nil) {
318
- _rightFocusGuide.enabled = value;
319
- }
320
-
321
- if(_upFocusGuide != nil) {
322
- _upFocusGuide.enabled = value;
323
- }
324
-
325
- if(_downFocusGuide != nil) {
326
- _downFocusGuide.enabled = value;
327
- }
328
- }
329
-
330
- - (void)removeLeftGuide {
331
- if (_leftFocusGuide) {
332
- [_delegate removeLayoutGuide: _leftFocusGuide];
333
- _leftFocusGuide = nil;
334
- }
335
- }
336
-
337
- - (void)removeRightGuide {
338
- if (_rightFocusGuide) {
339
- [_delegate removeLayoutGuide: _rightFocusGuide];
340
- _rightFocusGuide = nil;
341
- }
342
- }
343
-
344
- - (void)removeUpGuide {
345
- if (_upFocusGuide) {
346
- [_delegate removeLayoutGuide:_upFocusGuide];
347
- _upFocusGuide = nil;
348
- }
349
- }
350
-
351
- - (void)removeDownGuide {
352
- if (_downFocusGuide) {
353
- [_delegate removeLayoutGuide:_downFocusGuide];
354
- _downFocusGuide = nil;
355
- }
356
- }
357
-
358
- - (void)orderLeftLink:(NSString*) linkId {
359
- RNCEKVFocusLinkObserverManager *manager = [RNCEKVFocusLinkObserverManager sharedManager];
360
- RNCEKVFocusLinkObserver *focusLinkObserver = manager.focusLinkObserver;
361
-
362
- if(linkId != nil && !_leftLinkUpdated && !_leftLinkRemoved) {
363
- __typeof(self) __weak weakSelf = self;
364
-
365
- _leftLinkUpdated = ^(UIView *link) {
366
- if (!weakSelf) return;
367
- [weakSelf setLeftGuide:link];
368
- };
369
-
370
- _leftLinkRemoved = ^{
371
- if (!weakSelf) return;
372
- [weakSelf removeLeftGuide];
373
- };
374
-
375
- [focusLinkObserver subscribeWithId: linkId
376
- onLinkUpdated:_leftLinkUpdated
377
- onLinkRemoved:_leftLinkRemoved];
378
- }
379
- }
380
-
381
- -(void)orderUpLink:(NSString*) linkId {
382
- RNCEKVFocusLinkObserverManager *manager = [RNCEKVFocusLinkObserverManager sharedManager];
383
- RNCEKVFocusLinkObserver *focusLinkObserver = manager.focusLinkObserver;
384
-
385
- if(linkId != nil && !_upLinkUpdated && !_upLinkRemoved) {
386
- __typeof(self) __weak weakSelf = self;
387
- _upLinkUpdated = ^(UIView *link) {
388
- if (!weakSelf) return;
389
- [weakSelf setUpGuide: link];
390
- };
391
- _upLinkRemoved = ^{
392
- if (!weakSelf) return;
393
- [weakSelf removeUpGuide];
394
- };
395
- [focusLinkObserver subscribeWithId: linkId
396
- onLinkUpdated:_upLinkUpdated
397
- onLinkRemoved:_upLinkRemoved];
398
- }
399
- }
400
-
401
- -(void)orderDownLink:(NSString*) linkId {
402
- RNCEKVFocusLinkObserverManager *manager = [RNCEKVFocusLinkObserverManager sharedManager];
403
- RNCEKVFocusLinkObserver *focusLinkObserver = manager.focusLinkObserver;
404
-
405
- if(linkId != nil && !_downLinkUpdated && !_downLinkRemoved) {
406
- __typeof(self) __weak weakSelf = self;
407
- _downLinkUpdated = ^(UIView *link) {
408
- if (!weakSelf) return;
409
- [weakSelf setDownGuide: link];
410
- };
411
- _downLinkRemoved = ^{
412
- if (!weakSelf) return;
413
- [weakSelf removeDownGuide];
414
- };
415
- [focusLinkObserver subscribeWithId: linkId
416
- onLinkUpdated:_downLinkUpdated
417
- onLinkRemoved:_downLinkRemoved];
418
- }
419
- }
420
-
421
- -(void)orderRightLink: (NSString*) linkId {
422
- RNCEKVFocusLinkObserverManager *manager = [RNCEKVFocusLinkObserverManager sharedManager];
423
- RNCEKVFocusLinkObserver *focusLinkObserver = manager.focusLinkObserver;
424
-
425
-
426
- if(linkId != nil && !_rightLinkUpdated && !_rightLinkRemoved) {
427
- __typeof(self) __weak weakSelf = self;
428
- _rightLinkUpdated = ^(UIView *link) {
429
- if (!weakSelf) return;
430
- [weakSelf setRightGuide: link];
431
- };
432
- _rightLinkRemoved = ^{
433
- if (!weakSelf) return;
434
- [weakSelf removeRightGuide];
435
- };
436
- [focusLinkObserver subscribeWithId: linkId
437
- onLinkUpdated:_rightLinkUpdated
438
- onLinkRemoved:_rightLinkRemoved];
439
- }
440
- }
441
-
442
247
  - (void)linkId {
443
- RNCEKVFocusLinkObserverManager *manager = [RNCEKVFocusLinkObserverManager sharedManager];
444
- RNCEKVFocusLinkObserver *focusLinkObserver = manager.focusLinkObserver;
248
+ RNCEKVFocusLinkObserver *focusLinkObserver = [RNCEKVFocusLinkObserver sharedManager];
445
249
 
446
250
  NSString* orderId = _delegate.orderId;
447
251
  UIView* view = [_delegate getFocusTargetView];
@@ -450,23 +254,30 @@ static NSNumber *const FOCUS_UPDATE = @1;
450
254
  [focusLinkObserver emitWithId:orderId link:view];
451
255
  }
452
256
 
257
+ [self subscribeToDirection:RNCEKVFocusGuideDirectionLeft
258
+ linkId:_delegate.orderLeft];
453
259
 
260
+ [self subscribeToDirection:RNCEKVFocusGuideDirectionRight
261
+ linkId:_delegate.orderRight
262
+ ];
454
263
 
455
- [self orderLeftLink: _delegate.orderLeft];
456
- [self orderRightLink: _delegate.orderRight];
457
- [self orderUpLink: _delegate.orderUp];
458
- [self orderDownLink: _delegate.orderDown];
264
+ [self subscribeToDirection:RNCEKVFocusGuideDirectionUp
265
+ linkId:_delegate.orderUp
266
+ ];
267
+
268
+ [self subscribeToDirection:RNCEKVFocusGuideDirectionDown
269
+ linkId:_delegate.orderDown
270
+ ];
459
271
  }
460
272
 
461
273
  - (void)refreshId: (NSString*)prev next:(NSString*)next {
462
- RNCEKVFocusLinkObserverManager *manager = [RNCEKVFocusLinkObserverManager sharedManager];
463
- RNCEKVFocusLinkObserver *focusLinkObserver = manager.focusLinkObserver;
274
+ RNCEKVFocusLinkObserver *focusLinkObserver = [RNCEKVFocusLinkObserver sharedManager];
464
275
  UIView* view = [_delegate getFocusTargetView];
465
276
 
466
277
 
467
278
  if(prev != nil) {
468
- [[RNCEKVOrderLinking sharedInstance] cleanOrderId: prev];
469
279
  [focusLinkObserver emitRemoveWithId: prev];
280
+ [[RNCEKVOrderLinking sharedInstance] cleanOrderId: prev];
470
281
  }
471
282
 
472
283
  if(next != nil && view != nil) {
@@ -475,103 +286,41 @@ static NSNumber *const FOCUS_UPDATE = @1;
475
286
  }
476
287
  };
477
288
 
478
- - (void) clearLeftLink: (NSString*) linkId {
479
- RNCEKVFocusLinkObserverManager *manager = [RNCEKVFocusLinkObserverManager sharedManager];
480
- RNCEKVFocusLinkObserver *focusLinkObserver = manager.focusLinkObserver;
481
-
482
- if(linkId != nil && _leftLinkUpdated != nil && _leftLinkRemoved != nil) {
483
- [focusLinkObserver unsubscribeWithId:linkId
484
- onLinkUpdated:_leftLinkUpdated
485
- onLinkRemoved:_leftLinkRemoved];
486
- _leftLinkUpdated = nil;
487
- _leftLinkRemoved = nil;
488
- [self removeLeftGuide];
489
- }
490
- }
491
-
492
- -(void)clearRightLink: (NSString*) linkId {
493
- RNCEKVFocusLinkObserverManager *manager = [RNCEKVFocusLinkObserverManager sharedManager];
494
- RNCEKVFocusLinkObserver *focusLinkObserver = manager.focusLinkObserver;
495
-
496
- if(linkId != nil && _rightLinkUpdated != nil && _rightLinkRemoved != nil) {
497
- [focusLinkObserver unsubscribeWithId:linkId
498
- onLinkUpdated:_rightLinkUpdated
499
- onLinkRemoved:_rightLinkRemoved];
500
-
501
- _rightLinkUpdated = nil;
502
- _rightLinkRemoved = nil;
503
- [self removeRightGuide];
504
- }
505
- }
506
-
507
- -(void)clearUpLink: (NSString*) linkId {
508
- RNCEKVFocusLinkObserverManager *manager = [RNCEKVFocusLinkObserverManager sharedManager];
509
- RNCEKVFocusLinkObserver *focusLinkObserver = manager.focusLinkObserver;
510
-
511
- if(linkId != nil && _upLinkUpdated != nil && _upLinkRemoved != nil) {
512
- [focusLinkObserver unsubscribeWithId:linkId
513
- onLinkUpdated:_upLinkUpdated
514
- onLinkRemoved:_upLinkRemoved];
515
- _upLinkUpdated = nil;
516
- _upLinkRemoved = nil;
517
-
518
- [self removeUpGuide];
519
- }
520
- }
521
-
522
- -(void)clearDownLink: (NSString*) linkId {
523
- RNCEKVFocusLinkObserverManager *manager = [RNCEKVFocusLinkObserverManager sharedManager];
524
- RNCEKVFocusLinkObserver *focusLinkObserver = manager.focusLinkObserver;
525
-
526
- if(linkId != nil && _downLinkUpdated != nil && _downLinkRemoved != nil) {
527
- [focusLinkObserver unsubscribeWithId:linkId
528
- onLinkUpdated:_downLinkUpdated
529
- onLinkRemoved:_downLinkRemoved];
530
-
531
- _downLinkUpdated = nil;
532
- _downLinkRemoved = nil;
533
-
534
- [self removeDownGuide];
535
- }
536
-
289
+ - (void)setIsFocused:(BOOL)value {
290
+ return [_focusGuideDelegate setIsFocused: value];
537
291
  }
538
292
 
539
293
  - (void)refreshLeft:(NSString*)prev next:(NSString*)next {
540
- [self clearLeftLink: prev];
541
- [self orderLeftLink: next];
294
+ [self refreshDirection:RNCEKVFocusGuideDirectionLeft
295
+ prevId:prev
296
+ nextId:next];
542
297
  }
543
298
 
544
299
  - (void)refreshRight:(NSString*)prev next:(NSString*)next{
545
-
546
- [self clearRightLink: prev];
547
- [self orderRightLink: next];
300
+ [self refreshDirection:RNCEKVFocusGuideDirectionRight
301
+ prevId:prev
302
+ nextId:next];
548
303
  }
549
304
 
550
305
  - (void)refreshUp:(NSString*)prev next:(NSString*)next{
551
- [self clearUpLink: prev];
552
- [self orderUpLink: next];
306
+ [self refreshDirection:RNCEKVFocusGuideDirectionUp
307
+ prevId:prev
308
+ nextId:next];
553
309
  }
554
310
 
555
311
  - (void)refreshDown:(NSString*)prev next:(NSString*)next{
556
- [self clearDownLink: prev];
557
- [self orderDownLink: next];
312
+ [self refreshDirection:RNCEKVFocusGuideDirectionDown
313
+ prevId:prev
314
+ nextId:next];
558
315
  }
559
316
 
560
317
  - (void)clear {
561
- NSString* orderId = _delegate.orderId;
562
- if(orderId != nil) {
563
- [[RNCEKVOrderLinking sharedInstance] cleanOrderId: orderId];
564
- }
565
-
566
- [self clearLeftLink: _delegate.orderLeft];
567
- [self clearRightLink: _delegate.orderRight];
568
- [self clearUpLink: _delegate.orderUp];
569
- [self clearDownLink: _delegate.orderDown];
318
+ [self clearDirection:RNCEKVFocusGuideDirectionLeft];
319
+ [self clearDirection:RNCEKVFocusGuideDirectionRight];
320
+ [self clearDirection:RNCEKVFocusGuideDirectionUp];
321
+ [self clearDirection:RNCEKVFocusGuideDirectionDown];
570
322
 
571
323
  [self refreshId: _delegate.orderId next:nil];
572
-
573
324
  }
574
325
 
575
-
576
-
577
326
  @end
@@ -12,7 +12,7 @@
12
12
 
13
13
  @interface RCTTextInputComponentView (RNCEKVExternalKeyboard)
14
14
 
15
- @property (nonatomic, readonly) UIView<RCTBackedTextInputViewProtocol> *backedTextInputView;
15
+ @property (nonatomic, readonly) UIView* rncekbBackedTextInputView;
16
16
 
17
17
  @end
18
18
 
@@ -11,9 +11,17 @@
11
11
 
12
12
  @implementation RCTTextInputComponentView (RNCEKVExternalKeyboard)
13
13
 
14
- - (UIView<RCTBackedTextInputViewProtocol> *)backedTextInputView {
15
- Ivar ivar = class_getInstanceVariable([self class], "_backedTextInputView");
16
- return object_getIvar(self, ivar);
14
+ - (UIView *)rncekbBackedTextInputView {
15
+ Ivar ivar = class_getInstanceVariable([self class], "_backedTextInputView");
16
+ if (!ivar) {
17
+ return nil;
18
+ }
19
+
20
+ id value = object_getIvar(self, ivar);
21
+ if ([value isKindOfClass:[UIView class]]) {
22
+ return (UIView*)value;
23
+ }
24
+ return nil;
17
25
  }
18
26
 
19
27
  @end
@@ -11,7 +11,7 @@
11
11
  #import <UIKit/UIKit.h>
12
12
 
13
13
  @interface UIViewController (RNCEKVExternalKeyboard)
14
- @property (nonatomic, strong) UIView *customFocusView;
14
+ @property (nonatomic, strong) UIView *rncekvCustomFocusView;
15
15
  @end
16
16
 
17
17
  #endif /* UIViewController_RNCEKVExternalKeyboard_h */
@@ -18,18 +18,18 @@ static char kCustomFocusViewKey;
18
18
 
19
19
  @implementation UIViewController (RNCEKVExternalKeyboard)
20
20
 
21
- - (UIView *)customFocusView {
22
- return objc_getAssociatedObject(self, &kCustomFocusViewKey);
21
+ - (UIView *)rncekvCustomFocusView {
22
+ return objc_getAssociatedObject(self, &kCustomFocusViewKey);
23
23
  }
24
24
 
25
- - (void)setCustomFocusView:(UIView *)customFocusView {
26
- objc_setAssociatedObject(self, &kCustomFocusViewKey, customFocusView, OBJC_ASSOCIATION_RETAIN_NONATOMIC);
25
+ - (void)setRncekvCustomFocusView:(UIView *)customFocusView {
26
+ objc_setAssociatedObject(self, &kCustomFocusViewKey, customFocusView, OBJC_ASSOCIATION_RETAIN_NONATOMIC);
27
27
  }
28
28
 
29
29
  + (void)load
30
30
  {
31
31
  static dispatch_once_t once_token;
32
-
32
+
33
33
  dispatch_once(&once_token, ^{
34
34
  RNCEKVSwizzleInstanceMethod([self class], @selector(viewDidAppear:), @selector(keyboardedViewDidAppear:));
35
35
  RNCEKVSwizzleInstanceMethod([self class], @selector(preferredFocusEnvironments), @selector(keyboardedPreferredFocusEnvironments));
@@ -37,21 +37,21 @@ static char kCustomFocusViewKey;
37
37
  }
38
38
 
39
39
  - (void)keyboardedViewDidAppear:(BOOL)animated {
40
- [self keyboardedViewDidAppear:animated];
41
- [[NSNotificationCenter defaultCenter] postNotificationName:@"ViewControllerChangedNotification" object:self];
40
+ [self keyboardedViewDidAppear:animated];
41
+ [[NSNotificationCenter defaultCenter] postNotificationName:@"ViewControllerChangedNotification" object:self];
42
42
  }
43
43
 
44
44
  - (NSArray<id<UIFocusEnvironment>> *)keyboardedPreferredFocusEnvironments {
45
- NSArray<id<UIFocusEnvironment>> *originalEnvironments = [self keyboardedPreferredFocusEnvironments];
46
-
47
- NSMutableArray *focusEnvironments = [originalEnvironments mutableCopy];
48
-
49
- UIView *customFocusView = self.customFocusView;
50
- if (customFocusView) {
51
- [focusEnvironments insertObject:customFocusView atIndex:0];
52
- }
53
-
54
- return focusEnvironments;
45
+ NSArray<id<UIFocusEnvironment>> *originalEnvironments = [self keyboardedPreferredFocusEnvironments];
46
+
47
+ NSMutableArray *focusEnvironments = [originalEnvironments mutableCopy];
48
+
49
+ UIView *customFocusView = self.rncekvCustomFocusView;
50
+ if (customFocusView) {
51
+ [focusEnvironments insertObject:customFocusView atIndex:0];
52
+ }
53
+
54
+ return focusEnvironments;
55
55
  }
56
56
 
57
57