@fluentui-react-native/focus-zone 0.23.5 → 0.23.7
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.
- package/CHANGELOG.md +20 -0
- package/README.md +19 -0
- package/lib/index.d.ts +2 -3
- package/lib/index.d.ts.map +1 -1
- package/lib/index.js +1 -2
- package/lib/index.js.map +1 -1
- package/package.json +12 -29
- package/src/index.ts +3 -4
- package/.cache/tsconfig.tsbuildinfo +0 -1
- package/RCTFocusZone.podspec +0 -21
- package/SPEC.md +0 -47
- package/jest.config.cjs +0 -1
- package/lib/FocusZone.d.ts +0 -5
- package/lib/FocusZone.d.ts.map +0 -1
- package/lib/FocusZone.js +0 -33
- package/lib/FocusZone.js.map +0 -1
- package/lib/FocusZone.types.d.ts +0 -94
- package/lib/FocusZone.types.d.ts.map +0 -1
- package/lib/FocusZone.types.js +0 -2
- package/lib/FocusZone.types.js.map +0 -1
- package/lib/FocusZoneNativeComponent.d.ts +0 -16
- package/lib/FocusZoneNativeComponent.d.ts.map +0 -1
- package/lib/FocusZoneNativeComponent.js +0 -10
- package/lib/FocusZoneNativeComponent.js.map +0 -1
- package/lib/FocusZoneNativeComponent.win32.d.ts +0 -16
- package/lib/FocusZoneNativeComponent.win32.d.ts.map +0 -1
- package/lib/FocusZoneNativeComponent.win32.js +0 -3
- package/lib/FocusZoneNativeComponent.win32.js.map +0 -1
- package/lib/__tests__/FocusZone.test.d.ts +0 -2
- package/lib/__tests__/FocusZone.test.d.ts.map +0 -1
- package/lib/__tests__/FocusZone.test.js +0 -81
- package/lib/__tests__/FocusZone.test.js.map +0 -1
- package/lib/__tests__/FocusZone.types.test.d.ts +0 -2
- package/lib/__tests__/FocusZone.types.test.d.ts.map +0 -1
- package/lib/__tests__/FocusZone.types.test.js +0 -26
- package/lib/__tests__/FocusZone.types.test.js.map +0 -1
- package/macos/KeyCodes.h +0 -10
- package/macos/RCTFocusZone.h +0 -22
- package/macos/RCTFocusZone.m +0 -677
- package/macos/RCTFocusZoneComponentView.h +0 -14
- package/macos/RCTFocusZoneComponentView.mm +0 -201
- package/macos/RCTFocusZoneManager.h +0 -6
- package/macos/RCTFocusZoneManager.m +0 -58
- package/react-native.config.cjs +0 -15
- package/src/FocusZone.tsx +0 -50
- package/src/FocusZone.types.ts +0 -124
- package/src/FocusZoneNativeComponent.ts +0 -26
- package/src/FocusZoneNativeComponent.win32.ts +0 -18
- package/src/__tests__/FocusZone.test.tsx +0 -131
- package/src/__tests__/FocusZone.types.test.ts +0 -36
- package/tsconfig.json +0 -25
- package/windows/ExperimentalFeatures.props +0 -33
- package/windows/FRNFocusZone/FRNFocusZone.def +0 -3
- package/windows/FRNFocusZone/FRNFocusZone.rc +0 -0
- package/windows/FRNFocusZone/FRNFocusZone.vcxproj +0 -147
- package/windows/FRNFocusZone/FRNFocusZone.vcxproj.filters +0 -44
- package/windows/FRNFocusZone/FocusZoneComponentView.cpp +0 -590
- package/windows/FRNFocusZone/FocusZoneComponentView.h +0 -7
- package/windows/FRNFocusZone/ReactPackageProvider.cpp +0 -24
- package/windows/FRNFocusZone/ReactPackageProvider.h +0 -24
- package/windows/FRNFocusZone/ReactPackageProvider.idl +0 -9
- package/windows/FRNFocusZone/codegen/.clang-format +0 -2
- package/windows/FRNFocusZone/codegen/react/components/FRNFocusZoneSpec/FocusZone.g.h +0 -243
- package/windows/FRNFocusZone/packages.lock.json +0 -151
- package/windows/FRNFocusZone/pch.cpp +0 -1
- package/windows/FRNFocusZone/pch.h +0 -40
- package/windows/FRNFocusZone/resource.h +0 -5
- package/windows/FRNFocusZone/targetver.h +0 -8
- package/windows/FRNFocusZone.sln +0 -43
- package/windows/NuGet.Config +0 -13
package/macos/RCTFocusZone.m
DELETED
|
@@ -1,677 +0,0 @@
|
|
|
1
|
-
#import "KeyCodes.h"
|
|
2
|
-
#import <React/RCTBaseTextInputView.h>
|
|
3
|
-
#import "RCTFocusZone.h"
|
|
4
|
-
#import "RCTi18nUtil.h"
|
|
5
|
-
|
|
6
|
-
typedef enum {
|
|
7
|
-
FocusZoneActionNone,
|
|
8
|
-
FocusZoneActionTab,
|
|
9
|
-
FocusZoneActionShiftTab,
|
|
10
|
-
FocusZoneActionRightArrow,
|
|
11
|
-
FocusZoneActionLeftArrow,
|
|
12
|
-
FocusZoneActionDownArrow,
|
|
13
|
-
FocusZoneActionUpArrow,
|
|
14
|
-
} FocusZoneAction;
|
|
15
|
-
|
|
16
|
-
typedef BOOL (^IsViewLeadingCandidateForNextFocus)(NSView *candidateView);
|
|
17
|
-
|
|
18
|
-
// Maximum vertical (or horizontal) displacement for a candidate view to be
|
|
19
|
-
// enumerated in the same row (or column) as the current focused view
|
|
20
|
-
static const CGFloat FocusZoneBuffer = 3;
|
|
21
|
-
|
|
22
|
-
@implementation RCTFocusZone
|
|
23
|
-
|
|
24
|
-
static NSView *GetFocusableView(NSView *view)
|
|
25
|
-
{
|
|
26
|
-
if (![view acceptsFirstResponder]) {
|
|
27
|
-
return nil;
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
if ([view isKindOfClass:[RCTBaseTextInputView class]]) {
|
|
31
|
-
RCTUIView *backedTextInputView = [(RCTBaseTextInputView *)view backedTextInputView];
|
|
32
|
-
return [backedTextInputView acceptsFirstResponder] ? backedTextInputView : nil;
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
return view;
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
static inline CGFloat GetDistanceBetweenPoints(NSPoint point1, NSPoint point2)
|
|
39
|
-
{
|
|
40
|
-
NSPoint delta = NSMakePoint(point1.x - point2.x, point1.y - point2.y);
|
|
41
|
-
return sqrt(delta.x * delta.x + delta.y * delta.y);
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
static inline CGFloat GetDistanceBetweenRects(NSRect rect1, NSRect rect2)
|
|
45
|
-
{
|
|
46
|
-
// Get the top left corner of the rect, top right in RTL
|
|
47
|
-
bool isRTL = [[RCTI18nUtil sharedInstance] isRTL];
|
|
48
|
-
|
|
49
|
-
CGFloat rect1Offset = isRTL ? rect1.size.width : 0;
|
|
50
|
-
CGFloat rect2Offset = isRTL ? rect2.size.width : 0;
|
|
51
|
-
|
|
52
|
-
NSPoint rect1Corner = NSMakePoint(rect1.origin.x + rect1Offset , rect1.origin.y);
|
|
53
|
-
NSPoint rect2Corner = NSMakePoint(rect2.origin.x + rect2Offset , rect2.origin.y);
|
|
54
|
-
|
|
55
|
-
return GetDistanceBetweenPoints(rect1Corner, rect2Corner);
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
static inline CGFloat GetMinDistanceBetweenRectVerticesAndPoint(NSRect rect, NSPoint point)
|
|
59
|
-
{
|
|
60
|
-
return fmin(
|
|
61
|
-
fmin(GetDistanceBetweenPoints(point, NSMakePoint(NSMinX(rect), NSMinY(rect))),
|
|
62
|
-
GetDistanceBetweenPoints(point, NSMakePoint(NSMaxX(rect), NSMaxY(rect)))),
|
|
63
|
-
fmin(GetDistanceBetweenPoints(point, NSMakePoint(NSMaxX(rect), NSMinY(rect))),
|
|
64
|
-
GetDistanceBetweenPoints(point, NSMakePoint(NSMinX(rect), NSMaxY(rect))))
|
|
65
|
-
);
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
/// Performs a depth first search looking for the first view that accepts responder status in a parent view's view hierarchy.
|
|
69
|
-
/// This function does not take into account the geometric position of the view.
|
|
70
|
-
static NSView *GetFirstFocusableViewWithin(NSView *parentView)
|
|
71
|
-
{
|
|
72
|
-
if ([[parentView subviews] count] < 1)
|
|
73
|
-
{
|
|
74
|
-
return nil;
|
|
75
|
-
}
|
|
76
|
-
|
|
77
|
-
for (NSView *view in [parentView subviews]) {
|
|
78
|
-
NSView *focusableView = GetFocusableView(view);
|
|
79
|
-
if (focusableView) {
|
|
80
|
-
return focusableView;
|
|
81
|
-
}
|
|
82
|
-
|
|
83
|
-
NSView *match = GetFirstFocusableViewWithin(view);
|
|
84
|
-
if (match) {
|
|
85
|
-
return match;
|
|
86
|
-
}
|
|
87
|
-
}
|
|
88
|
-
return nil;
|
|
89
|
-
}
|
|
90
|
-
|
|
91
|
-
/// Performs a depth first search looking for the last that accepts responder status in a parent view's view hierarchy.
|
|
92
|
-
/// We find the last view by simply reversing the order of the subview array.
|
|
93
|
-
/// This function does not take into account the geometric position of the view.
|
|
94
|
-
static NSView *GetLastFocusableViewWithin(NSView *parentView)
|
|
95
|
-
{
|
|
96
|
-
for (NSView *view in [[parentView subviews] reverseObjectEnumerator]) {
|
|
97
|
-
NSView *focusableView = GetFocusableView(view);
|
|
98
|
-
if (focusableView) {
|
|
99
|
-
return focusableView;
|
|
100
|
-
}
|
|
101
|
-
|
|
102
|
-
NSView *match = GetLastFocusableViewWithin(view);
|
|
103
|
-
if (match) {
|
|
104
|
-
return match;
|
|
105
|
-
}
|
|
106
|
-
}
|
|
107
|
-
return nil;
|
|
108
|
-
}
|
|
109
|
-
|
|
110
|
-
static void AppendFocusableViewsWithin(NSView *parentView, NSMutableArray<NSView *> *focusableViews)
|
|
111
|
-
{
|
|
112
|
-
for (NSView *view in [parentView subviews]) {
|
|
113
|
-
NSView *focusableView = GetFocusableView(view);
|
|
114
|
-
if (focusableView) {
|
|
115
|
-
[focusableViews addObject:focusableView];
|
|
116
|
-
} else {
|
|
117
|
-
AppendFocusableViewsWithin(view, focusableViews);
|
|
118
|
-
}
|
|
119
|
-
}
|
|
120
|
-
}
|
|
121
|
-
|
|
122
|
-
static NSView *GetFirstResponder(NSWindow *window)
|
|
123
|
-
{
|
|
124
|
-
NSResponder *responder = [window firstResponder];
|
|
125
|
-
while (responder != nil && ![responder isKindOfClass:[NSView class]])
|
|
126
|
-
{
|
|
127
|
-
responder = [responder nextResponder];
|
|
128
|
-
}
|
|
129
|
-
return [responder isKindOfClass:[NSView class]] ? (NSView *)responder : nil;
|
|
130
|
-
}
|
|
131
|
-
|
|
132
|
-
static FocusZoneAction GetActionForEvent(NSEvent *event)
|
|
133
|
-
{
|
|
134
|
-
FocusZoneAction action = FocusZoneActionNone;
|
|
135
|
-
|
|
136
|
-
NSEventModifierFlags modifierFlags = [event modifierFlags]
|
|
137
|
-
& (NSEventModifierFlagShift | NSEventModifierFlagControl
|
|
138
|
-
| NSEventModifierFlagOption | NSEventModifierFlagCommand);
|
|
139
|
-
|
|
140
|
-
switch ([event keyCode])
|
|
141
|
-
{
|
|
142
|
-
case kVK_UpArrow:
|
|
143
|
-
action = FocusZoneActionUpArrow;
|
|
144
|
-
break;
|
|
145
|
-
|
|
146
|
-
case kVK_DownArrow:
|
|
147
|
-
action = FocusZoneActionDownArrow;
|
|
148
|
-
break;
|
|
149
|
-
|
|
150
|
-
case kVK_LeftArrow:
|
|
151
|
-
action = FocusZoneActionLeftArrow;
|
|
152
|
-
break;
|
|
153
|
-
|
|
154
|
-
case kVK_RightArrow:
|
|
155
|
-
action = FocusZoneActionRightArrow;
|
|
156
|
-
break;
|
|
157
|
-
|
|
158
|
-
case kVK_Tab:
|
|
159
|
-
if (modifierFlags == 0)
|
|
160
|
-
{
|
|
161
|
-
action = FocusZoneActionTab;
|
|
162
|
-
break;
|
|
163
|
-
}
|
|
164
|
-
else if (modifierFlags == NSEventModifierFlagShift)
|
|
165
|
-
{
|
|
166
|
-
action = FocusZoneActionShiftTab;
|
|
167
|
-
break;
|
|
168
|
-
}
|
|
169
|
-
}
|
|
170
|
-
|
|
171
|
-
return action;
|
|
172
|
-
}
|
|
173
|
-
|
|
174
|
-
static inline BOOL IsAdvanceWithinZoneAction(FocusZoneAction action)
|
|
175
|
-
{
|
|
176
|
-
return action == FocusZoneActionRightArrow || action == FocusZoneActionDownArrow;
|
|
177
|
-
}
|
|
178
|
-
|
|
179
|
-
static inline BOOL IsHorizontalNavigationWithinZoneAction(FocusZoneAction action)
|
|
180
|
-
{
|
|
181
|
-
return action == FocusZoneActionRightArrow || action == FocusZoneActionLeftArrow;
|
|
182
|
-
}
|
|
183
|
-
|
|
184
|
-
/// Returns the topmost view of the given view's superview heirarchy that is a FocusZone.
|
|
185
|
-
/// Returns nil if no FocusZone is found.
|
|
186
|
-
static RCTFocusZone *GetFocusZoneAncestor(NSView *view)
|
|
187
|
-
{
|
|
188
|
-
NSView *candidateView = view;
|
|
189
|
-
NSView *topLevelView = [[view window] contentView];
|
|
190
|
-
RCTFocusZone *focusZoneAncestor = nil;
|
|
191
|
-
while (candidateView != nil && candidateView != topLevelView)
|
|
192
|
-
{
|
|
193
|
-
if ([candidateView isKindOfClass:[RCTFocusZone class]])
|
|
194
|
-
{
|
|
195
|
-
focusZoneAncestor = (RCTFocusZone *)candidateView;
|
|
196
|
-
}
|
|
197
|
-
candidateView = [candidateView superview];
|
|
198
|
-
}
|
|
199
|
-
return focusZoneAncestor;
|
|
200
|
-
}
|
|
201
|
-
|
|
202
|
-
/// Bypass FocusZone if it's empty or has no focusable elements
|
|
203
|
-
static BOOL ShouldSkipFocusZone(NSView *view)
|
|
204
|
-
{
|
|
205
|
-
if([view isKindOfClass:[RCTFocusZone class]])
|
|
206
|
-
{
|
|
207
|
-
NSView *keyView = GetFirstFocusableViewWithin(view);
|
|
208
|
-
// FocusZone is empty or has no focusable elements
|
|
209
|
-
if (keyView == nil)
|
|
210
|
-
{
|
|
211
|
-
return YES;
|
|
212
|
-
}
|
|
213
|
-
}
|
|
214
|
-
|
|
215
|
-
return NO;
|
|
216
|
-
}
|
|
217
|
-
|
|
218
|
-
/// FocusZone bases its return to accessibilityChildrenInNavigationOrder on the navigationOrderInRenderOrder property.
|
|
219
|
-
/// If navigationOrderInRenderOrder is set to YES, the accessible children are returned in the same order as returned by [(NSView) accessibilityChildren].
|
|
220
|
-
/// If navigationOrderInRenderOrder is set to NO, the accessible children are returned in the order determined by [(NSView) accessibilityChildrenInNavigationOrder].
|
|
221
|
-
- (NSArray *)accessibilityChildrenInNavigationOrder {
|
|
222
|
-
if ([self navigationOrderInRenderOrder]) {
|
|
223
|
-
return [self accessibilityChildren];
|
|
224
|
-
}
|
|
225
|
-
|
|
226
|
-
return [super accessibilityChildrenInNavigationOrder];
|
|
227
|
-
}
|
|
228
|
-
|
|
229
|
-
/// Accept firstResponder on FocusZone itself in order to reassign it within the FocusZone.
|
|
230
|
-
- (BOOL)acceptsFirstResponder
|
|
231
|
-
{
|
|
232
|
-
// Reject first responder if FocusZone is disabled or should be skipped.
|
|
233
|
-
return !_disabled && !ShouldSkipFocusZone(self);
|
|
234
|
-
}
|
|
235
|
-
|
|
236
|
-
- (BOOL)becomeFirstResponder
|
|
237
|
-
{
|
|
238
|
-
NSView *keyView = _defaultResponder ?: GetFirstFocusableViewWithin(self);
|
|
239
|
-
return !_disabled && [[self window] makeFirstResponder:keyView];
|
|
240
|
-
}
|
|
241
|
-
|
|
242
|
-
- (NSView *)nextViewToFocusForCondition:(IsViewLeadingCandidateForNextFocus)isLeadingCandidate
|
|
243
|
-
{
|
|
244
|
-
NSView *nextViewToFocus;
|
|
245
|
-
NSMutableArray<NSView *> *queue = [NSMutableArray array];
|
|
246
|
-
[queue addObject:self];
|
|
247
|
-
|
|
248
|
-
while ([queue count] > 0)
|
|
249
|
-
{
|
|
250
|
-
NSView *candidateView = [queue firstObject];
|
|
251
|
-
[queue removeObjectAtIndex:0];
|
|
252
|
-
|
|
253
|
-
if ([candidateView isNotEqualTo:self] && [candidateView acceptsFirstResponder] && isLeadingCandidate(candidateView))
|
|
254
|
-
{
|
|
255
|
-
nextViewToFocus = candidateView;
|
|
256
|
-
}
|
|
257
|
-
[queue addObjectsFromArray:[candidateView subviews]];
|
|
258
|
-
}
|
|
259
|
-
|
|
260
|
-
return nextViewToFocus;
|
|
261
|
-
}
|
|
262
|
-
|
|
263
|
-
- (NSView *)nextViewToFocusForAction:(FocusZoneAction)action
|
|
264
|
-
{
|
|
265
|
-
BOOL isAdvance = IsAdvanceWithinZoneAction(action);
|
|
266
|
-
BOOL isHorizontal = IsHorizontalNavigationWithinZoneAction(action);
|
|
267
|
-
|
|
268
|
-
NSView *firstResponder = GetFirstResponder([self window]);
|
|
269
|
-
NSRect firstResponderRect = [firstResponder convertRect:[firstResponder bounds] toView:self];
|
|
270
|
-
NSScrollView * firstResponderEnclosingScrollView = [firstResponder enclosingScrollView];
|
|
271
|
-
|
|
272
|
-
__block CGFloat closestDistance = CGFLOAT_MAX;
|
|
273
|
-
__block CGFloat closestDistanceWithinEnclosingScrollView = CGFLOAT_MAX;
|
|
274
|
-
|
|
275
|
-
IsViewLeadingCandidateForNextFocus block = ^BOOL(NSView *candidateView)
|
|
276
|
-
{
|
|
277
|
-
BOOL isLeadingCandidate = NO;
|
|
278
|
-
BOOL skip = candidateView == firstResponder;
|
|
279
|
-
NSRect candidateRect = [candidateView convertRect:[candidateView bounds] toView:self];
|
|
280
|
-
BOOL subviewRelationExists = [candidateView isDescendantOf:firstResponder] || [firstResponder isDescendantOf:candidateView];
|
|
281
|
-
|
|
282
|
-
if (isHorizontal)
|
|
283
|
-
{
|
|
284
|
-
if (subviewRelationExists)
|
|
285
|
-
{
|
|
286
|
-
skip = skip
|
|
287
|
-
|| (isAdvance && NSMinX(candidateRect) < NSMinX(firstResponderRect))
|
|
288
|
-
|| (!isAdvance && NSMaxX(candidateRect) > NSMaxX(firstResponderRect))
|
|
289
|
-
|| NSMinY(candidateRect) > NSMaxY(firstResponderRect) - FocusZoneBuffer
|
|
290
|
-
|| NSMaxY(candidateRect) < NSMinY(firstResponderRect) + FocusZoneBuffer;
|
|
291
|
-
}
|
|
292
|
-
else
|
|
293
|
-
{
|
|
294
|
-
skip = skip
|
|
295
|
-
|| (isAdvance && NSMidX(candidateRect) < NSMidX(firstResponderRect))
|
|
296
|
-
|| (!isAdvance && NSMidX(candidateRect) > NSMidX(firstResponderRect))
|
|
297
|
-
|| NSMinY(candidateRect) > NSMaxY(firstResponderRect) - FocusZoneBuffer
|
|
298
|
-
|| NSMaxY(candidateRect) < NSMinY(firstResponderRect) + FocusZoneBuffer;
|
|
299
|
-
}
|
|
300
|
-
}
|
|
301
|
-
else
|
|
302
|
-
{
|
|
303
|
-
if (subviewRelationExists)
|
|
304
|
-
{
|
|
305
|
-
skip = skip
|
|
306
|
-
|| (isAdvance && NSMinY(candidateRect) < NSMinY(firstResponderRect))
|
|
307
|
-
|| (!isAdvance && NSMaxY(candidateRect) > NSMaxY(firstResponderRect))
|
|
308
|
-
|| NSMaxX(candidateRect) < NSMinX(firstResponderRect) + FocusZoneBuffer
|
|
309
|
-
|| NSMinX(candidateRect) > NSMaxX(firstResponderRect) - FocusZoneBuffer;
|
|
310
|
-
}
|
|
311
|
-
else
|
|
312
|
-
{
|
|
313
|
-
skip = skip
|
|
314
|
-
|| (isAdvance && NSMidY(candidateRect) < NSMidY(firstResponderRect))
|
|
315
|
-
|| (!isAdvance && NSMidY(candidateRect) > NSMidY(firstResponderRect))
|
|
316
|
-
|| NSMaxX(candidateRect) < NSMinX(firstResponderRect) + FocusZoneBuffer
|
|
317
|
-
|| NSMinX(candidateRect) > NSMaxX(firstResponderRect) - FocusZoneBuffer;
|
|
318
|
-
}
|
|
319
|
-
}
|
|
320
|
-
|
|
321
|
-
if (!skip)
|
|
322
|
-
{
|
|
323
|
-
CGFloat distance = GetDistanceBetweenRects(firstResponderRect, candidateRect);
|
|
324
|
-
|
|
325
|
-
// If there are other candidate views inside the same ScrollView as the firstResponder,
|
|
326
|
-
// prefer those views over other views outside the scrollview, even if they are closer.
|
|
327
|
-
if ([firstResponderEnclosingScrollView isEqualTo:[candidateView enclosingScrollView]])
|
|
328
|
-
{
|
|
329
|
-
if (closestDistanceWithinEnclosingScrollView > distance)
|
|
330
|
-
{
|
|
331
|
-
closestDistanceWithinEnclosingScrollView = distance;
|
|
332
|
-
isLeadingCandidate = YES;
|
|
333
|
-
}
|
|
334
|
-
}
|
|
335
|
-
else
|
|
336
|
-
{
|
|
337
|
-
if (closestDistance > distance)
|
|
338
|
-
{
|
|
339
|
-
closestDistance = distance;
|
|
340
|
-
isLeadingCandidate = YES;
|
|
341
|
-
}
|
|
342
|
-
}
|
|
343
|
-
}
|
|
344
|
-
|
|
345
|
-
return isLeadingCandidate;
|
|
346
|
-
};
|
|
347
|
-
|
|
348
|
-
return [self nextViewToFocusForCondition:block];
|
|
349
|
-
}
|
|
350
|
-
|
|
351
|
-
- (NSView *)nextViewToFocusForCircularAction:(FocusZoneAction)action
|
|
352
|
-
{
|
|
353
|
-
BOOL isAdvance = IsAdvanceWithinZoneAction(action);
|
|
354
|
-
BOOL isHorizontal = IsHorizontalNavigationWithinZoneAction(action);
|
|
355
|
-
|
|
356
|
-
NSView *firstResponder = GetFirstResponder([self window]);
|
|
357
|
-
NSRect firstResponderRect = [firstResponder convertRect:[firstResponder bounds] toView:self];
|
|
358
|
-
NSPoint anchorPoint = isHorizontal
|
|
359
|
-
? NSMakePoint(isAdvance ? 0 : [self bounds].size.width, NSMidY(firstResponderRect))
|
|
360
|
-
: NSMakePoint(NSMidX(firstResponderRect), isAdvance ? 0 : [self bounds].size.height);
|
|
361
|
-
|
|
362
|
-
__block CGFloat closestDistance = CGFLOAT_MAX;
|
|
363
|
-
|
|
364
|
-
IsViewLeadingCandidateForNextFocus block = ^BOOL(NSView *candidateView)
|
|
365
|
-
{
|
|
366
|
-
BOOL isLeadingCandidate = NO;
|
|
367
|
-
BOOL skip = NO;
|
|
368
|
-
NSRect candidateRect = [candidateView convertRect:[candidateView bounds] toView:self];
|
|
369
|
-
BOOL subviewRelationExists = [candidateView isDescendantOf:firstResponder] || [firstResponder isDescendantOf:candidateView];
|
|
370
|
-
|
|
371
|
-
if (isHorizontal)
|
|
372
|
-
{
|
|
373
|
-
if (subviewRelationExists)
|
|
374
|
-
{
|
|
375
|
-
skip = (isAdvance && NSMinX(candidateRect) > NSMinX(firstResponderRect))
|
|
376
|
-
|| (!isAdvance && NSMaxX(candidateRect) < NSMaxX(firstResponderRect));
|
|
377
|
-
}
|
|
378
|
-
else
|
|
379
|
-
{
|
|
380
|
-
skip = (isAdvance && NSMidX(candidateRect) > NSMidX(firstResponderRect))
|
|
381
|
-
|| (!isAdvance && NSMidX(candidateRect) < NSMidX(firstResponderRect));
|
|
382
|
-
}
|
|
383
|
-
}
|
|
384
|
-
else
|
|
385
|
-
{
|
|
386
|
-
if (subviewRelationExists)
|
|
387
|
-
{
|
|
388
|
-
skip = (isAdvance && NSMinY(candidateRect) > NSMinY(firstResponderRect))
|
|
389
|
-
|| (!isAdvance && NSMaxY(candidateRect) < NSMaxY(firstResponderRect));
|
|
390
|
-
}
|
|
391
|
-
else
|
|
392
|
-
{
|
|
393
|
-
skip = (isAdvance && NSMidY(candidateRect) > NSMidY(firstResponderRect))
|
|
394
|
-
|| (!isAdvance && NSMidY(candidateRect) < NSMidY(firstResponderRect));
|
|
395
|
-
}
|
|
396
|
-
}
|
|
397
|
-
|
|
398
|
-
if (!skip)
|
|
399
|
-
{
|
|
400
|
-
NSPoint candidatePoint = isHorizontal
|
|
401
|
-
? NSMakePoint(isAdvance ? NSMinX(candidateRect) : NSMaxX(candidateRect), NSMidY(candidateRect))
|
|
402
|
-
: NSMakePoint(NSMidX(candidateRect), isAdvance ? NSMinY(candidateRect) : NSMaxY(candidateRect));
|
|
403
|
-
|
|
404
|
-
CGFloat distance = GetDistanceBetweenPoints(anchorPoint, candidatePoint);
|
|
405
|
-
if (closestDistance > distance)
|
|
406
|
-
{
|
|
407
|
-
closestDistance = distance;
|
|
408
|
-
isLeadingCandidate = YES;
|
|
409
|
-
}
|
|
410
|
-
}
|
|
411
|
-
|
|
412
|
-
return isLeadingCandidate;
|
|
413
|
-
};
|
|
414
|
-
|
|
415
|
-
return [self nextViewToFocusForCondition:block];
|
|
416
|
-
}
|
|
417
|
-
|
|
418
|
-
- (NSView *)nextViewToFocusForHorizontalNavigation:(FocusZoneAction)action
|
|
419
|
-
{
|
|
420
|
-
BOOL isAdvance = IsAdvanceWithinZoneAction(action);
|
|
421
|
-
|
|
422
|
-
NSView *firstResponder = GetFirstResponder([self window]);
|
|
423
|
-
NSRect firstResponderRect = [firstResponder convertRect:[firstResponder bounds] toView:self];
|
|
424
|
-
|
|
425
|
-
__block CGFloat closestDistance = CGFLOAT_MAX;
|
|
426
|
-
|
|
427
|
-
NSRect selfBounds = [self bounds];
|
|
428
|
-
NSPoint targetPoint = isAdvance
|
|
429
|
-
? NSMakePoint(0, NSMaxY(firstResponderRect))
|
|
430
|
-
: NSMakePoint(selfBounds.size.width, NSMinY(firstResponderRect));
|
|
431
|
-
|
|
432
|
-
IsViewLeadingCandidateForNextFocus block = ^BOOL(NSView *candidateView)
|
|
433
|
-
{
|
|
434
|
-
BOOL isLeadingCandidate = NO;
|
|
435
|
-
NSRect candidateRect = [candidateView convertRect:[candidateView bounds] toView:self];
|
|
436
|
-
|
|
437
|
-
BOOL skip = candidateView == firstResponder
|
|
438
|
-
|| (isAdvance && NSMinY(candidateRect) < NSMaxY(firstResponderRect) - FocusZoneBuffer)
|
|
439
|
-
|| (!isAdvance && NSMaxY(candidateRect) > NSMinY(firstResponderRect) + FocusZoneBuffer);
|
|
440
|
-
|
|
441
|
-
if (!skip)
|
|
442
|
-
{
|
|
443
|
-
CGFloat distance = GetMinDistanceBetweenRectVerticesAndPoint(candidateRect, targetPoint);
|
|
444
|
-
if (closestDistance > distance)
|
|
445
|
-
{
|
|
446
|
-
closestDistance = distance;
|
|
447
|
-
isLeadingCandidate = YES;
|
|
448
|
-
}
|
|
449
|
-
}
|
|
450
|
-
|
|
451
|
-
return isLeadingCandidate;
|
|
452
|
-
};
|
|
453
|
-
|
|
454
|
-
return [self nextViewToFocusForCondition:block];
|
|
455
|
-
}
|
|
456
|
-
|
|
457
|
-
- (NSView *)nextViewToFocusWithFallback:(FocusZoneAction)action considerCircular:(BOOL)shouldTryCircular
|
|
458
|
-
{
|
|
459
|
-
// Special case if we're currently focused on self
|
|
460
|
-
NSView *firstResponder = GetFirstResponder([self window]);
|
|
461
|
-
if (self == firstResponder)
|
|
462
|
-
{
|
|
463
|
-
if (action == FocusZoneActionDownArrow)
|
|
464
|
-
{
|
|
465
|
-
return GetFirstFocusableViewWithin(self);
|
|
466
|
-
}
|
|
467
|
-
else if (action == FocusZoneActionUpArrow)
|
|
468
|
-
{
|
|
469
|
-
return GetLastFocusableViewWithin(self);
|
|
470
|
-
}
|
|
471
|
-
}
|
|
472
|
-
|
|
473
|
-
BOOL isHorizontal = IsHorizontalNavigationWithinZoneAction(action);
|
|
474
|
-
BOOL isAdvance = IsAdvanceWithinZoneAction(action);
|
|
475
|
-
NSView *nextViewToFocus = [self nextViewToFocusForAction:action];
|
|
476
|
-
|
|
477
|
-
if (nextViewToFocus == nil)
|
|
478
|
-
{
|
|
479
|
-
if (isHorizontal)
|
|
480
|
-
{
|
|
481
|
-
nextViewToFocus = [self nextViewToFocusForHorizontalNavigation:action];
|
|
482
|
-
}
|
|
483
|
-
else
|
|
484
|
-
{
|
|
485
|
-
FocusZoneAction horizontalAction = isAdvance ? FocusZoneActionRightArrow : FocusZoneActionLeftArrow;
|
|
486
|
-
nextViewToFocus = [self nextViewToFocusWithFallback:horizontalAction considerCircular:NO];
|
|
487
|
-
}
|
|
488
|
-
}
|
|
489
|
-
|
|
490
|
-
if (nextViewToFocus == nil && shouldTryCircular)
|
|
491
|
-
{
|
|
492
|
-
nextViewToFocus = [self nextViewToFocusForCircularAction:action];
|
|
493
|
-
|
|
494
|
-
if (nextViewToFocus == firstResponder)
|
|
495
|
-
{
|
|
496
|
-
nextViewToFocus = isHorizontal ?
|
|
497
|
-
[self nextViewToFocusForCircularAction:isAdvance ? FocusZoneActionDownArrow : FocusZoneActionUpArrow] :
|
|
498
|
-
[self nextViewToFocusForCircularAction:isAdvance ? FocusZoneActionRightArrow : FocusZoneActionLeftArrow];
|
|
499
|
-
}
|
|
500
|
-
|
|
501
|
-
if (nextViewToFocus == firstResponder)
|
|
502
|
-
{
|
|
503
|
-
nextViewToFocus = nil;
|
|
504
|
-
}
|
|
505
|
-
}
|
|
506
|
-
|
|
507
|
-
return nextViewToFocus;
|
|
508
|
-
}
|
|
509
|
-
|
|
510
|
-
- (NSView *)nextViewToFocusOutsideZone:(FocusZoneAction)action
|
|
511
|
-
{
|
|
512
|
-
NSView *nextViewToFocus;
|
|
513
|
-
|
|
514
|
-
// Find the first view outside the FocusZone (or any parent FocusZones) to place focus
|
|
515
|
-
RCTFocusZone *focusZoneAncestor = GetFocusZoneAncestor(self);
|
|
516
|
-
|
|
517
|
-
if (action == FocusZoneActionTab) // Advance to next zone
|
|
518
|
-
{
|
|
519
|
-
nextViewToFocus = [self nextValidKeyView];
|
|
520
|
-
while([nextViewToFocus isDescendantOf:focusZoneAncestor])
|
|
521
|
-
{
|
|
522
|
-
// there are no views left in the key view loop
|
|
523
|
-
if ([nextViewToFocus isEqual:focusZoneAncestor])
|
|
524
|
-
{
|
|
525
|
-
nextViewToFocus = nil;
|
|
526
|
-
break;
|
|
527
|
-
}
|
|
528
|
-
nextViewToFocus = [nextViewToFocus nextValidKeyView];
|
|
529
|
-
}
|
|
530
|
-
}
|
|
531
|
-
else if (action == FocusZoneActionShiftTab)
|
|
532
|
-
{
|
|
533
|
-
nextViewToFocus = [self previousValidKeyView];
|
|
534
|
-
while([nextViewToFocus isDescendantOf:focusZoneAncestor])
|
|
535
|
-
{
|
|
536
|
-
// there are no views left in the key view loop
|
|
537
|
-
if ([nextViewToFocus isEqual:focusZoneAncestor])
|
|
538
|
-
{
|
|
539
|
-
nextViewToFocus = nil;
|
|
540
|
-
break;
|
|
541
|
-
}
|
|
542
|
-
nextViewToFocus = [nextViewToFocus previousValidKeyView];
|
|
543
|
-
}
|
|
544
|
-
|
|
545
|
-
// If the previous view is in a FocusZone, focus on its defaultKeyView
|
|
546
|
-
// (For FocusZoneActionTab, this is handled by becomeFirstResponder).
|
|
547
|
-
focusZoneAncestor = GetFocusZoneAncestor(nextViewToFocus);
|
|
548
|
-
NSView *ancestorKeyView = [focusZoneAncestor defaultResponder];
|
|
549
|
-
if (ancestorKeyView != nil) {
|
|
550
|
-
nextViewToFocus = [focusZoneAncestor defaultResponder];
|
|
551
|
-
}
|
|
552
|
-
}
|
|
553
|
-
|
|
554
|
-
return nextViewToFocus;
|
|
555
|
-
}
|
|
556
|
-
|
|
557
|
-
- (NSView *)nextViewToFocusInHierarchyForAction:(FocusZoneAction)action
|
|
558
|
-
{
|
|
559
|
-
NSMutableArray<NSView *> *focusableViews = [NSMutableArray array];
|
|
560
|
-
AppendFocusableViewsWithin(self, focusableViews);
|
|
561
|
-
|
|
562
|
-
NSView *firstResponder = GetFirstResponder([self window]);
|
|
563
|
-
NSUInteger currentIndex = [focusableViews indexOfObjectPassingTest:^BOOL(NSView *candidateView, NSUInteger index, BOOL *stop) {
|
|
564
|
-
return candidateView == firstResponder
|
|
565
|
-
|| [candidateView isDescendantOf:firstResponder]
|
|
566
|
-
|| [firstResponder isDescendantOf:candidateView];
|
|
567
|
-
}];
|
|
568
|
-
if (currentIndex == NSNotFound) {
|
|
569
|
-
return nil;
|
|
570
|
-
}
|
|
571
|
-
|
|
572
|
-
BOOL forward = action != FocusZoneActionShiftTab;
|
|
573
|
-
if (forward && currentIndex + 1 < [focusableViews count]) {
|
|
574
|
-
return focusableViews[currentIndex + 1];
|
|
575
|
-
}
|
|
576
|
-
if (!forward && currentIndex > 0) {
|
|
577
|
-
return focusableViews[currentIndex - 1];
|
|
578
|
-
}
|
|
579
|
-
|
|
580
|
-
return nil;
|
|
581
|
-
}
|
|
582
|
-
|
|
583
|
-
- (NSView *)nextViewToFocusForTab:(FocusZoneAction)action
|
|
584
|
-
{
|
|
585
|
-
[[self window] recalculateKeyViewLoop];
|
|
586
|
-
|
|
587
|
-
NSString *tabKeyNavigation = [self tabKeyNavigation];
|
|
588
|
-
if (![@"NavigateWrap" isEqual:tabKeyNavigation] && ![@"NavigateStopAtEnds" isEqual:tabKeyNavigation]
|
|
589
|
-
&& ![@"Normal" isEqual:tabKeyNavigation])
|
|
590
|
-
{
|
|
591
|
-
return [self nextViewToFocusOutsideZone:action];
|
|
592
|
-
}
|
|
593
|
-
|
|
594
|
-
BOOL forward = action != FocusZoneActionShiftTab;
|
|
595
|
-
NSView *firstResponder = GetFirstResponder([self window]);
|
|
596
|
-
NSView *nextViewToFocus = forward ? [firstResponder nextValidKeyView] : [firstResponder previousValidKeyView];
|
|
597
|
-
|
|
598
|
-
if (nextViewToFocus == self)
|
|
599
|
-
nextViewToFocus = forward ? [nextViewToFocus nextValidKeyView] : [nextViewToFocus previousValidKeyView];;
|
|
600
|
-
|
|
601
|
-
if ([nextViewToFocus isDescendantOf:self])
|
|
602
|
-
return nextViewToFocus;
|
|
603
|
-
|
|
604
|
-
// AppKit can collapse a Fabric-backed FocusZone to one key-loop entry.
|
|
605
|
-
NSView *hierarchyViewToFocus = [self nextViewToFocusInHierarchyForAction:action];
|
|
606
|
-
if (hierarchyViewToFocus != nil)
|
|
607
|
-
return hierarchyViewToFocus;
|
|
608
|
-
|
|
609
|
-
if ([@"Normal" isEqual:tabKeyNavigation])
|
|
610
|
-
return nextViewToFocus;
|
|
611
|
-
|
|
612
|
-
if ([@"NavigateStopAtEnds" isEqual:tabKeyNavigation])
|
|
613
|
-
return nil;
|
|
614
|
-
|
|
615
|
-
// wrap around -- find first (tab) or last (shift+tab)
|
|
616
|
-
NSView *aView = firstResponder;
|
|
617
|
-
while (aView != self && [aView isDescendantOf:self])
|
|
618
|
-
{
|
|
619
|
-
nextViewToFocus = aView;
|
|
620
|
-
aView = forward ? [aView previousValidKeyView] : [aView nextValidKeyView];
|
|
621
|
-
}
|
|
622
|
-
|
|
623
|
-
if (nextViewToFocus != firstResponder)
|
|
624
|
-
return nextViewToFocus;
|
|
625
|
-
|
|
626
|
-
NSView *wrapView = forward ? GetFirstFocusableViewWithin(self) : GetLastFocusableViewWithin(self);
|
|
627
|
-
return wrapView != firstResponder ? wrapView : nil;
|
|
628
|
-
}
|
|
629
|
-
|
|
630
|
-
- (BOOL)isFlipped
|
|
631
|
-
{
|
|
632
|
-
return YES;
|
|
633
|
-
}
|
|
634
|
-
|
|
635
|
-
- (void)keyDown:(NSEvent *)event
|
|
636
|
-
{
|
|
637
|
-
FocusZoneAction action = GetActionForEvent(event);
|
|
638
|
-
FocusZoneDirection focusZoneDirection = [self focusZoneDirection];
|
|
639
|
-
NSString *navigateAtEnd = [self navigateAtEnd];
|
|
640
|
-
|
|
641
|
-
BOOL passthrough = NO;
|
|
642
|
-
NSView *viewToFocus = nil;
|
|
643
|
-
if ([self disabled] || action == FocusZoneActionNone)
|
|
644
|
-
{
|
|
645
|
-
passthrough = YES;
|
|
646
|
-
}
|
|
647
|
-
else if (action == FocusZoneActionTab || action == FocusZoneActionShiftTab)
|
|
648
|
-
{
|
|
649
|
-
viewToFocus = [self nextViewToFocusForTab:action];
|
|
650
|
-
}
|
|
651
|
-
else if ((focusZoneDirection == FocusZoneDirectionVertical
|
|
652
|
-
&& (action == FocusZoneActionRightArrow || action == FocusZoneActionLeftArrow))
|
|
653
|
-
|| (focusZoneDirection == FocusZoneDirectionHorizontal
|
|
654
|
-
&& (action == FocusZoneActionUpArrow || action == FocusZoneActionDownArrow))
|
|
655
|
-
|| (focusZoneDirection == FocusZoneDirectionNone))
|
|
656
|
-
{
|
|
657
|
-
passthrough = YES;
|
|
658
|
-
}
|
|
659
|
-
else
|
|
660
|
-
{
|
|
661
|
-
viewToFocus = [self nextViewToFocusWithFallback:action considerCircular:[@"NavigateWrap" isEqual:navigateAtEnd]];
|
|
662
|
-
}
|
|
663
|
-
|
|
664
|
-
if (viewToFocus != nil)
|
|
665
|
-
{
|
|
666
|
-
[[self window] makeFirstResponder:viewToFocus];
|
|
667
|
-
[viewToFocus scrollRectToVisible:[viewToFocus bounds]];
|
|
668
|
-
}
|
|
669
|
-
else if (passthrough)
|
|
670
|
-
{
|
|
671
|
-
// Only call super if we explicitly want to passthrough the event
|
|
672
|
-
// I.E: FocusZone don't handle this specific key
|
|
673
|
-
[super keyDown:event];
|
|
674
|
-
}
|
|
675
|
-
}
|
|
676
|
-
|
|
677
|
-
@end
|