@fluentui-react-native/focus-zone 0.17.1 → 0.19.0
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.json +31 -1
- package/CHANGELOG.md +18 -2
- package/lib/FocusZone.types.d.ts +18 -6
- package/lib/FocusZone.types.d.ts.map +1 -1
- package/lib-commonjs/FocusZone.types.d.ts +18 -6
- package/lib-commonjs/FocusZone.types.d.ts.map +1 -1
- package/macos/RCTFocusZone.h +2 -0
- package/macos/RCTFocusZone.m +126 -27
- package/macos/RCTFocusZoneManager.m +7 -0
- package/package.json +2 -1
- package/src/FocusZone.types.ts +18 -6
package/CHANGELOG.json
CHANGED
|
@@ -2,7 +2,37 @@
|
|
|
2
2
|
"name": "@fluentui-react-native/focus-zone",
|
|
3
3
|
"entries": [
|
|
4
4
|
{
|
|
5
|
-
"date": "
|
|
5
|
+
"date": "Wed, 24 Jul 2024 16:31:50 GMT",
|
|
6
|
+
"version": "0.19.0",
|
|
7
|
+
"tag": "@fluentui-react-native/focus-zone_v0.19.0",
|
|
8
|
+
"comments": {
|
|
9
|
+
"minor": [
|
|
10
|
+
{
|
|
11
|
+
"author": "patboyd@microsoft.com",
|
|
12
|
+
"package": "@fluentui-react-native/focus-zone",
|
|
13
|
+
"commit": "94f1248b7cc169c26b9c685704965a275be6e5d8",
|
|
14
|
+
"comment": "Implementation of FocusZone navigationOrderInRenderOrder for MacOS"
|
|
15
|
+
}
|
|
16
|
+
]
|
|
17
|
+
}
|
|
18
|
+
},
|
|
19
|
+
{
|
|
20
|
+
"date": "Tue, 23 Jul 2024 16:56:54 GMT",
|
|
21
|
+
"version": "0.18.0",
|
|
22
|
+
"tag": "@fluentui-react-native/focus-zone_v0.18.0",
|
|
23
|
+
"comments": {
|
|
24
|
+
"minor": [
|
|
25
|
+
{
|
|
26
|
+
"author": "nakambo@microsoft.com",
|
|
27
|
+
"package": "@fluentui-react-native/focus-zone",
|
|
28
|
+
"commit": "ddf90fafdfaccd6318bb66f1d114f632bc5eb485",
|
|
29
|
+
"comment": "Implement Focus Zone circular navigation and tab key behaviors for macOS"
|
|
30
|
+
}
|
|
31
|
+
]
|
|
32
|
+
}
|
|
33
|
+
},
|
|
34
|
+
{
|
|
35
|
+
"date": "Mon, 15 Apr 2024 21:31:44 GMT",
|
|
6
36
|
"version": "0.17.1",
|
|
7
37
|
"tag": "@fluentui-react-native/focus-zone_v0.17.1",
|
|
8
38
|
"comments": {
|
package/CHANGELOG.md
CHANGED
|
@@ -1,12 +1,28 @@
|
|
|
1
1
|
# Change Log - @fluentui-react-native/focus-zone
|
|
2
2
|
|
|
3
|
-
This log was last generated on
|
|
3
|
+
This log was last generated on Wed, 24 Jul 2024 16:31:50 GMT and should not be manually modified.
|
|
4
4
|
|
|
5
5
|
<!-- Start content -->
|
|
6
6
|
|
|
7
|
+
## 0.19.0
|
|
8
|
+
|
|
9
|
+
Wed, 24 Jul 2024 16:31:50 GMT
|
|
10
|
+
|
|
11
|
+
### Minor changes
|
|
12
|
+
|
|
13
|
+
- Implementation of FocusZone navigationOrderInRenderOrder for MacOS (patboyd@microsoft.com)
|
|
14
|
+
|
|
15
|
+
## 0.18.0
|
|
16
|
+
|
|
17
|
+
Tue, 23 Jul 2024 16:56:54 GMT
|
|
18
|
+
|
|
19
|
+
### Minor changes
|
|
20
|
+
|
|
21
|
+
- Implement Focus Zone circular navigation and tab key behaviors for macOS (nakambo@microsoft.com)
|
|
22
|
+
|
|
7
23
|
## 0.17.1
|
|
8
24
|
|
|
9
|
-
Mon, 15 Apr 2024 21:
|
|
25
|
+
Mon, 15 Apr 2024 21:31:44 GMT
|
|
10
26
|
|
|
11
27
|
### Patches
|
|
12
28
|
|
package/lib/FocusZone.types.d.ts
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
import type * as React from 'react';
|
|
2
|
-
import type {
|
|
2
|
+
import type { IViewProps } from '@fluentui-react-native/adapters';
|
|
3
3
|
import type { IFocusable } from '@fluentui-react-native/interactive-hooks';
|
|
4
4
|
import type { IRenderData } from '@uifabricshared/foundation-composable';
|
|
5
5
|
export declare const focusZoneName = "FocusZone";
|
|
6
6
|
export interface FocusZoneState {
|
|
7
7
|
}
|
|
8
|
-
export type FocusZoneProps =
|
|
8
|
+
export type FocusZoneProps = IViewProps & {
|
|
9
9
|
/**
|
|
10
10
|
* A RefObject to access the IFocusable interface. Use this to access the public methods and properties of the component.
|
|
11
11
|
*/
|
|
@@ -29,7 +29,6 @@ export type FocusZoneProps = React.PropsWithChildren<{
|
|
|
29
29
|
*/
|
|
30
30
|
use2DNavigation?: boolean;
|
|
31
31
|
/**
|
|
32
|
-
* @platform win32
|
|
33
32
|
* By default, pressing Tab within a FocusZone moves focus out of the FocusZone.
|
|
34
33
|
* This prop allows you to change that behavior.
|
|
35
34
|
*
|
|
@@ -54,10 +53,23 @@ export type FocusZoneProps = React.PropsWithChildren<{
|
|
|
54
53
|
*/
|
|
55
54
|
onFocus?: (e?: any) => void;
|
|
56
55
|
/**
|
|
57
|
-
*
|
|
56
|
+
* @platform macos
|
|
57
|
+
* By default, the Apple KeyView loop is calculated based on the UI tree hierarchy, accessibility properties,
|
|
58
|
+
* custom element overrides of navigation order, and positions in layout.
|
|
59
|
+
*
|
|
60
|
+
* Normally this produces the appropriate accessible experience for users, but occasionally we may need to
|
|
61
|
+
* clarify the intended order of navigation. The navigationOrderInRenderOrder prop will have the FocusZone
|
|
62
|
+
* establish the navigation order of its children according to their order in the UI tree
|
|
63
|
+
* (i.e. as returned by accessibilityChildren).
|
|
64
|
+
*
|
|
65
|
+
* Note that to participate in the KeyView loop calculation, the FocusZone itself must be part of the
|
|
66
|
+
* accessibility tree (i.e. 'accessible') with an appropriate role, e.g. 'group'.
|
|
67
|
+
*
|
|
68
|
+
* Extra note: This property is unlikely to perform well if changed from its initial value due to finer details
|
|
69
|
+
* of the MacOS KeyView loop mechanics.
|
|
58
70
|
*/
|
|
59
|
-
|
|
60
|
-
}
|
|
71
|
+
navigationOrderInRenderOrder?: boolean;
|
|
72
|
+
};
|
|
61
73
|
export interface NativeProps extends Omit<FocusZoneProps, 'isCircularNavigation'> {
|
|
62
74
|
navigateAtEnd?: NavigateAtEnd;
|
|
63
75
|
tabKeyNavigation?: FocusZoneTabNavigation;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"FocusZone.types.d.ts","sourceRoot":"","sources":["../src/FocusZone.types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAK,KAAK,MAAM,OAAO,CAAC;
|
|
1
|
+
{"version":3,"file":"FocusZone.types.d.ts","sourceRoot":"","sources":["../src/FocusZone.types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAK,KAAK,MAAM,OAAO,CAAC;AAEpC,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,iCAAiC,CAAC;AAClE,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,0CAA0C,CAAC;AAC3E,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,uCAAuC,CAAC;AAEzE,eAAO,MAAM,aAAa,cAAc,CAAC;AAEzC,MAAM,WAAW,cAAc;CAAG;AAElC,MAAM,MAAM,cAAc,GAAG,UAAU,GAAG;IACxC;;OAEG;IACH,YAAY,CAAC,EAAE,KAAK,CAAC,SAAS,CAAC,UAAU,CAAC,CAAC;IAE3C;;OAEG;IACH,sBAAsB,CAAC,EAAE,KAAK,CAAC,SAAS,CAAC,KAAK,CAAC,SAAS,CAAC,CAAC;IAE1D;;OAEG;IACH,kBAAkB,CAAC,EAAE,kBAAkB,CAAC;IAExC;;OAEG;IACH,QAAQ,CAAC,EAAE,OAAO,CAAC;IAGnB,oBAAoB,CAAC,EAAE,OAAO,CAAC;IAE/B;;;OAGG;IACH,eAAe,CAAC,EAAE,OAAO,CAAC;IAE1B;;;;;;;;;;;;;;;;;;OAkBG;IACH,gBAAgB,CAAC,EAAE,sBAAsB,CAAC;IAE1C;;OAEG;IACH,OAAO,CAAC,EAAE,CAAC,CAAC,CAAC,EAAE,GAAG,KAAK,IAAI,CAAC;IAE5B;;;;;;;;;;;;;;;OAeG;IACH,4BAA4B,CAAC,EAAE,OAAO,CAAC;CACxC,CAAC;AAEF,MAAM,WAAW,WAAY,SAAQ,IAAI,CAAC,cAAc,EAAE,sBAAsB,CAAC;IAC/E,aAAa,CAAC,EAAE,aAAa,CAAC;IAC9B,gBAAgB,CAAC,EAAE,sBAAsB,CAAC;CAC3C;AAED,MAAM,MAAM,kBAAkB,GAC1B,eAAe,CAAC,2BAA2B,GAC3C,UAAU,CAAC,oCAAoC,GAC/C,YAAY,CAAC,uCAAuC,GACpD,MAAM,CAAC,CAAC,yCAAyC;AAErD,MAAM,MAAM,aAAa,GACrB,oBAAoB,GACpB,cAAc,GACd,kBAAkB,CAAC;AAEvB,MAAM,MAAM,sBAAsB,GAC9B,MAAM,GACN,cAAc,GACd,oBAAoB,GACpB,QAAQ,CAAC;AAEb,MAAM,WAAW,eAAe;CAAG;AAEnC,MAAM,WAAW,kBAAkB;IACjC,IAAI,EAAE,WAAW,CAAC;CACnB;AAED,MAAM,MAAM,mBAAmB,GAAG,WAAW,CAAC,kBAAkB,EAAE,cAAc,CAAC,CAAC;AAElF,MAAM,WAAW,aAAa;IAC5B,KAAK,EAAE,cAAc,CAAC;IACtB,MAAM,EAAE,eAAe,CAAC;IACxB,SAAS,EAAE,kBAAkB,CAAC;IAC9B,KAAK,EAAE,cAAc,CAAC;CACvB"}
|
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
import type * as React from 'react';
|
|
2
|
-
import type {
|
|
2
|
+
import type { IViewProps } from '@fluentui-react-native/adapters';
|
|
3
3
|
import type { IFocusable } from '@fluentui-react-native/interactive-hooks';
|
|
4
4
|
import type { IRenderData } from '@uifabricshared/foundation-composable';
|
|
5
5
|
export declare const focusZoneName = "FocusZone";
|
|
6
6
|
export interface FocusZoneState {
|
|
7
7
|
}
|
|
8
|
-
export type FocusZoneProps =
|
|
8
|
+
export type FocusZoneProps = IViewProps & {
|
|
9
9
|
/**
|
|
10
10
|
* A RefObject to access the IFocusable interface. Use this to access the public methods and properties of the component.
|
|
11
11
|
*/
|
|
@@ -29,7 +29,6 @@ export type FocusZoneProps = React.PropsWithChildren<{
|
|
|
29
29
|
*/
|
|
30
30
|
use2DNavigation?: boolean;
|
|
31
31
|
/**
|
|
32
|
-
* @platform win32
|
|
33
32
|
* By default, pressing Tab within a FocusZone moves focus out of the FocusZone.
|
|
34
33
|
* This prop allows you to change that behavior.
|
|
35
34
|
*
|
|
@@ -54,10 +53,23 @@ export type FocusZoneProps = React.PropsWithChildren<{
|
|
|
54
53
|
*/
|
|
55
54
|
onFocus?: (e?: any) => void;
|
|
56
55
|
/**
|
|
57
|
-
*
|
|
56
|
+
* @platform macos
|
|
57
|
+
* By default, the Apple KeyView loop is calculated based on the UI tree hierarchy, accessibility properties,
|
|
58
|
+
* custom element overrides of navigation order, and positions in layout.
|
|
59
|
+
*
|
|
60
|
+
* Normally this produces the appropriate accessible experience for users, but occasionally we may need to
|
|
61
|
+
* clarify the intended order of navigation. The navigationOrderInRenderOrder prop will have the FocusZone
|
|
62
|
+
* establish the navigation order of its children according to their order in the UI tree
|
|
63
|
+
* (i.e. as returned by accessibilityChildren).
|
|
64
|
+
*
|
|
65
|
+
* Note that to participate in the KeyView loop calculation, the FocusZone itself must be part of the
|
|
66
|
+
* accessibility tree (i.e. 'accessible') with an appropriate role, e.g. 'group'.
|
|
67
|
+
*
|
|
68
|
+
* Extra note: This property is unlikely to perform well if changed from its initial value due to finer details
|
|
69
|
+
* of the MacOS KeyView loop mechanics.
|
|
58
70
|
*/
|
|
59
|
-
|
|
60
|
-
}
|
|
71
|
+
navigationOrderInRenderOrder?: boolean;
|
|
72
|
+
};
|
|
61
73
|
export interface NativeProps extends Omit<FocusZoneProps, 'isCircularNavigation'> {
|
|
62
74
|
navigateAtEnd?: NavigateAtEnd;
|
|
63
75
|
tabKeyNavigation?: FocusZoneTabNavigation;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"FocusZone.types.d.ts","sourceRoot":"","sources":["../src/FocusZone.types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAK,KAAK,MAAM,OAAO,CAAC;
|
|
1
|
+
{"version":3,"file":"FocusZone.types.d.ts","sourceRoot":"","sources":["../src/FocusZone.types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAK,KAAK,MAAM,OAAO,CAAC;AAEpC,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,iCAAiC,CAAC;AAClE,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,0CAA0C,CAAC;AAC3E,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,uCAAuC,CAAC;AAEzE,eAAO,MAAM,aAAa,cAAc,CAAC;AAEzC,MAAM,WAAW,cAAc;CAAG;AAElC,MAAM,MAAM,cAAc,GAAG,UAAU,GAAG;IACxC;;OAEG;IACH,YAAY,CAAC,EAAE,KAAK,CAAC,SAAS,CAAC,UAAU,CAAC,CAAC;IAE3C;;OAEG;IACH,sBAAsB,CAAC,EAAE,KAAK,CAAC,SAAS,CAAC,KAAK,CAAC,SAAS,CAAC,CAAC;IAE1D;;OAEG;IACH,kBAAkB,CAAC,EAAE,kBAAkB,CAAC;IAExC;;OAEG;IACH,QAAQ,CAAC,EAAE,OAAO,CAAC;IAGnB,oBAAoB,CAAC,EAAE,OAAO,CAAC;IAE/B;;;OAGG;IACH,eAAe,CAAC,EAAE,OAAO,CAAC;IAE1B;;;;;;;;;;;;;;;;;;OAkBG;IACH,gBAAgB,CAAC,EAAE,sBAAsB,CAAC;IAE1C;;OAEG;IACH,OAAO,CAAC,EAAE,CAAC,CAAC,CAAC,EAAE,GAAG,KAAK,IAAI,CAAC;IAE5B;;;;;;;;;;;;;;;OAeG;IACH,4BAA4B,CAAC,EAAE,OAAO,CAAC;CACxC,CAAC;AAEF,MAAM,WAAW,WAAY,SAAQ,IAAI,CAAC,cAAc,EAAE,sBAAsB,CAAC;IAC/E,aAAa,CAAC,EAAE,aAAa,CAAC;IAC9B,gBAAgB,CAAC,EAAE,sBAAsB,CAAC;CAC3C;AAED,MAAM,MAAM,kBAAkB,GAC1B,eAAe,CAAC,2BAA2B,GAC3C,UAAU,CAAC,oCAAoC,GAC/C,YAAY,CAAC,uCAAuC,GACpD,MAAM,CAAC,CAAC,yCAAyC;AAErD,MAAM,MAAM,aAAa,GACrB,oBAAoB,GACpB,cAAc,GACd,kBAAkB,CAAC;AAEvB,MAAM,MAAM,sBAAsB,GAC9B,MAAM,GACN,cAAc,GACd,oBAAoB,GACpB,QAAQ,CAAC;AAEb,MAAM,WAAW,eAAe;CAAG;AAEnC,MAAM,WAAW,kBAAkB;IACjC,IAAI,EAAE,WAAW,CAAC;CACnB;AAED,MAAM,MAAM,mBAAmB,GAAG,WAAW,CAAC,kBAAkB,EAAE,cAAc,CAAC,CAAC;AAElF,MAAM,WAAW,aAAa;IAC5B,KAAK,EAAE,cAAc,CAAC;IACtB,MAAM,EAAE,eAAe,CAAC;IACxB,SAAS,EAAE,kBAAkB,CAAC;IAC9B,KAAK,EAAE,cAAc,CAAC;CACvB"}
|
package/macos/RCTFocusZone.h
CHANGED
|
@@ -13,8 +13,10 @@ typedef NS_ENUM(NSInteger, FocusZoneDirection) {
|
|
|
13
13
|
@interface RCTFocusZone : RCTView
|
|
14
14
|
|
|
15
15
|
@property(nonatomic) BOOL disabled;
|
|
16
|
+
@property(nonatomic) BOOL navigationOrderInRenderOrder;
|
|
16
17
|
@property(nonatomic) FocusZoneDirection focusZoneDirection;
|
|
17
18
|
@property(nonatomic) NSString *navigateAtEnd;
|
|
19
|
+
@property(nonatomic) NSString *tabKeyNavigation;
|
|
18
20
|
@property(nonatomic) NSView *defaultResponder;
|
|
19
21
|
|
|
20
22
|
@end
|
package/macos/RCTFocusZone.m
CHANGED
|
@@ -186,6 +186,17 @@ static BOOL ShouldSkipFocusZone(NSView *view)
|
|
|
186
186
|
return NO;
|
|
187
187
|
}
|
|
188
188
|
|
|
189
|
+
/// FocusZone bases its return to accessibilityChildrenInNavigationOrder on the navigationOrderInRenderOrder property.
|
|
190
|
+
/// If navigationOrderInRenderOrder is set to YES, the accessible children are returned in the same order as returned by [(NSView) accessibilityChildren].
|
|
191
|
+
/// If navigationOrderInRenderOrder is set to NO, the accessible children are returned in the order determined by [(NSView) accessibilityChildrenInNavigationOrder].
|
|
192
|
+
- (NSArray *)accessibilityChildrenInNavigationOrder {
|
|
193
|
+
if ([self navigationOrderInRenderOrder]) {
|
|
194
|
+
return [self accessibilityChildren];
|
|
195
|
+
}
|
|
196
|
+
|
|
197
|
+
return [super accessibilityChildrenInNavigationOrder];
|
|
198
|
+
}
|
|
199
|
+
|
|
189
200
|
/// Accept firstResponder on FocusZone itself in order to reassign it within the FocusZone.
|
|
190
201
|
- (BOOL)acceptsFirstResponder
|
|
191
202
|
{
|
|
@@ -308,6 +319,73 @@ static BOOL ShouldSkipFocusZone(NSView *view)
|
|
|
308
319
|
return [self nextViewToFocusForCondition:block];
|
|
309
320
|
}
|
|
310
321
|
|
|
322
|
+
- (NSView *)nextViewToFocusForCircularAction:(FocusZoneAction)action
|
|
323
|
+
{
|
|
324
|
+
BOOL isAdvance = IsAdvanceWithinZoneAction(action);
|
|
325
|
+
BOOL isHorizontal = IsHorizontalNavigationWithinZoneAction(action);
|
|
326
|
+
|
|
327
|
+
NSView *firstResponder = GetFirstResponder([self window]);
|
|
328
|
+
NSRect firstResponderRect = [firstResponder convertRect:[firstResponder bounds] toView:self];
|
|
329
|
+
NSPoint anchorPoint = isHorizontal
|
|
330
|
+
? NSMakePoint(isAdvance ? 0 : [self bounds].size.width, NSMidY(firstResponderRect))
|
|
331
|
+
: NSMakePoint(NSMidX(firstResponderRect), isAdvance ? 0 : [self bounds].size.height);
|
|
332
|
+
|
|
333
|
+
__block CGFloat closestDistance = CGFLOAT_MAX;
|
|
334
|
+
|
|
335
|
+
IsViewLeadingCandidateForNextFocus block = ^BOOL(NSView *candidateView)
|
|
336
|
+
{
|
|
337
|
+
BOOL isLeadingCandidate = NO;
|
|
338
|
+
BOOL skip = NO;
|
|
339
|
+
NSRect candidateRect = [candidateView convertRect:[candidateView bounds] toView:self];
|
|
340
|
+
BOOL subviewRelationExists = [candidateView isDescendantOf:firstResponder] || [firstResponder isDescendantOf:candidateView];
|
|
341
|
+
|
|
342
|
+
if (isHorizontal)
|
|
343
|
+
{
|
|
344
|
+
if (subviewRelationExists)
|
|
345
|
+
{
|
|
346
|
+
skip = (isAdvance && NSMinX(candidateRect) > NSMinX(firstResponderRect))
|
|
347
|
+
|| (!isAdvance && NSMaxX(candidateRect) < NSMaxX(firstResponderRect));
|
|
348
|
+
}
|
|
349
|
+
else
|
|
350
|
+
{
|
|
351
|
+
skip = (isAdvance && NSMidX(candidateRect) > NSMidX(firstResponderRect))
|
|
352
|
+
|| (!isAdvance && NSMidX(candidateRect) < NSMidX(firstResponderRect));
|
|
353
|
+
}
|
|
354
|
+
}
|
|
355
|
+
else
|
|
356
|
+
{
|
|
357
|
+
if (subviewRelationExists)
|
|
358
|
+
{
|
|
359
|
+
skip = (isAdvance && NSMinY(candidateRect) > NSMinY(firstResponderRect))
|
|
360
|
+
|| (!isAdvance && NSMaxY(candidateRect) < NSMaxY(firstResponderRect));
|
|
361
|
+
}
|
|
362
|
+
else
|
|
363
|
+
{
|
|
364
|
+
skip = (isAdvance && NSMidY(candidateRect) > NSMidY(firstResponderRect))
|
|
365
|
+
|| (!isAdvance && NSMidY(candidateRect) < NSMidY(firstResponderRect));
|
|
366
|
+
}
|
|
367
|
+
}
|
|
368
|
+
|
|
369
|
+
if (!skip)
|
|
370
|
+
{
|
|
371
|
+
NSPoint candidatePoint = isHorizontal
|
|
372
|
+
? NSMakePoint(isAdvance ? NSMinX(candidateRect) : NSMaxX(candidateRect), NSMidY(candidateRect))
|
|
373
|
+
: NSMakePoint(NSMidX(candidateRect), isAdvance ? NSMinY(candidateRect) : NSMaxY(candidateRect));
|
|
374
|
+
|
|
375
|
+
CGFloat distance = GetDistanceBetweenPoints(anchorPoint, candidatePoint);
|
|
376
|
+
if (closestDistance > distance)
|
|
377
|
+
{
|
|
378
|
+
closestDistance = distance;
|
|
379
|
+
isLeadingCandidate = YES;
|
|
380
|
+
}
|
|
381
|
+
}
|
|
382
|
+
|
|
383
|
+
return isLeadingCandidate;
|
|
384
|
+
};
|
|
385
|
+
|
|
386
|
+
return [self nextViewToFocusForCondition:block];
|
|
387
|
+
}
|
|
388
|
+
|
|
311
389
|
- (NSView *)nextViewToFocusForHorizontalNavigation:(FocusZoneAction)action
|
|
312
390
|
{
|
|
313
391
|
BOOL isAdvance = IsAdvanceWithinZoneAction(action);
|
|
@@ -347,9 +425,8 @@ static BOOL ShouldSkipFocusZone(NSView *view)
|
|
|
347
425
|
return [self nextViewToFocusForCondition:block];
|
|
348
426
|
}
|
|
349
427
|
|
|
350
|
-
- (NSView *)nextViewToFocusWithFallback:(FocusZoneAction)action
|
|
428
|
+
- (NSView *)nextViewToFocusWithFallback:(FocusZoneAction)action considerCircular:(BOOL)shouldTryCircular
|
|
351
429
|
{
|
|
352
|
-
|
|
353
430
|
// Special case if we're currently focused on self
|
|
354
431
|
NSView *firstResponder = GetFirstResponder([self window]);
|
|
355
432
|
if (self == firstResponder)
|
|
@@ -364,18 +441,37 @@ static BOOL ShouldSkipFocusZone(NSView *view)
|
|
|
364
441
|
}
|
|
365
442
|
}
|
|
366
443
|
|
|
444
|
+
BOOL isHorizontal = IsHorizontalNavigationWithinZoneAction(action);
|
|
445
|
+
BOOL isAdvance = IsAdvanceWithinZoneAction(action);
|
|
367
446
|
NSView *nextViewToFocus = [self nextViewToFocusForAction:action];
|
|
368
447
|
|
|
369
448
|
if (nextViewToFocus == nil)
|
|
370
449
|
{
|
|
371
|
-
if (
|
|
450
|
+
if (isHorizontal)
|
|
372
451
|
{
|
|
373
452
|
nextViewToFocus = [self nextViewToFocusForHorizontalNavigation:action];
|
|
374
453
|
}
|
|
375
454
|
else
|
|
376
455
|
{
|
|
377
|
-
FocusZoneAction horizontalAction =
|
|
378
|
-
nextViewToFocus = [self nextViewToFocusWithFallback:horizontalAction];
|
|
456
|
+
FocusZoneAction horizontalAction = isAdvance ? FocusZoneActionRightArrow : FocusZoneActionLeftArrow;
|
|
457
|
+
nextViewToFocus = [self nextViewToFocusWithFallback:horizontalAction considerCircular:NO];
|
|
458
|
+
}
|
|
459
|
+
}
|
|
460
|
+
|
|
461
|
+
if (nextViewToFocus == nil && shouldTryCircular)
|
|
462
|
+
{
|
|
463
|
+
nextViewToFocus = [self nextViewToFocusForCircularAction:action];
|
|
464
|
+
|
|
465
|
+
if (nextViewToFocus == firstResponder)
|
|
466
|
+
{
|
|
467
|
+
nextViewToFocus = isHorizontal ?
|
|
468
|
+
[self nextViewToFocusForCircularAction:isAdvance ? FocusZoneActionDownArrow : FocusZoneActionUpArrow] :
|
|
469
|
+
[self nextViewToFocusForCircularAction:isAdvance ? FocusZoneActionRightArrow : FocusZoneActionLeftArrow];
|
|
470
|
+
}
|
|
471
|
+
|
|
472
|
+
if (nextViewToFocus == firstResponder)
|
|
473
|
+
{
|
|
474
|
+
nextViewToFocus = nil;
|
|
379
475
|
}
|
|
380
476
|
}
|
|
381
477
|
|
|
@@ -440,29 +536,42 @@ static BOOL ShouldSkipFocusZone(NSView *view)
|
|
|
440
536
|
{
|
|
441
537
|
FocusZoneAction action = GetActionForEvent(event);
|
|
442
538
|
FocusZoneDirection focusZoneDirection = [self focusZoneDirection];
|
|
539
|
+
NSString *navigateAtEnd = [self navigateAtEnd];
|
|
540
|
+
NSString *tabKeyNavigation = [self tabKeyNavigation];
|
|
541
|
+
|
|
542
|
+
BOOL tabAllowed = [@"NavigateWrap" isEqual:tabKeyNavigation]
|
|
543
|
+
|| [@"NavigateStopAtEnds" isEqual:tabKeyNavigation]
|
|
544
|
+
|| [@"Normal" isEqual:tabKeyNavigation];
|
|
443
545
|
|
|
444
546
|
BOOL passthrough = NO;
|
|
445
547
|
NSView *viewToFocus = nil;
|
|
446
|
-
|
|
447
|
-
|
|
548
|
+
if ([self disabled] || action == FocusZoneActionNone
|
|
549
|
+
|| (focusZoneDirection == FocusZoneDirectionVertical
|
|
550
|
+
&& (action == FocusZoneActionRightArrow || action == FocusZoneActionLeftArrow))
|
|
551
|
+
|| (focusZoneDirection == FocusZoneDirectionHorizontal
|
|
552
|
+
&& (action == FocusZoneActionUpArrow || action == FocusZoneActionDownArrow)))
|
|
448
553
|
{
|
|
449
554
|
passthrough = YES;
|
|
450
555
|
}
|
|
451
|
-
else if (action == FocusZoneActionTab || action == FocusZoneActionShiftTab)
|
|
556
|
+
else if (!tabAllowed && (action == FocusZoneActionTab || action == FocusZoneActionShiftTab))
|
|
452
557
|
{
|
|
453
558
|
viewToFocus = [self nextViewToFocusOutsideZone:action];
|
|
454
559
|
}
|
|
455
|
-
else if ((focusZoneDirection == FocusZoneDirectionVertical
|
|
456
|
-
&& (action == FocusZoneActionRightArrow || action == FocusZoneActionLeftArrow))
|
|
457
|
-
|| (focusZoneDirection == FocusZoneDirectionHorizontal
|
|
458
|
-
&& (action == FocusZoneActionUpArrow || action == FocusZoneActionDownArrow))
|
|
459
|
-
|| (focusZoneDirection == FocusZoneDirectionNone))
|
|
460
|
-
{
|
|
461
|
-
passthrough = YES;
|
|
462
|
-
}
|
|
463
560
|
else
|
|
464
561
|
{
|
|
465
|
-
|
|
562
|
+
FocusZoneAction directionalAction = action == FocusZoneActionTab ? FocusZoneActionDownArrow
|
|
563
|
+
: (action == FocusZoneActionShiftTab ? FocusZoneActionUpArrow : action);
|
|
564
|
+
|
|
565
|
+
BOOL allowCircular = [@"NavigateWrap" isEqual:action == FocusZoneActionTab || action == FocusZoneActionShiftTab
|
|
566
|
+
? tabKeyNavigation : navigateAtEnd];
|
|
567
|
+
|
|
568
|
+
viewToFocus = [self nextViewToFocusWithFallback:directionalAction considerCircular:allowCircular];
|
|
569
|
+
|
|
570
|
+
if (viewToFocus == nil && action != directionalAction && [@"Normal" isEqual:tabKeyNavigation]) // tab, shift+tab
|
|
571
|
+
{
|
|
572
|
+
// didn't find a view IN the zone -- look outside
|
|
573
|
+
viewToFocus = [self nextViewToFocusOutsideZone:action];
|
|
574
|
+
}
|
|
466
575
|
}
|
|
467
576
|
|
|
468
577
|
if (viewToFocus != nil)
|
|
@@ -478,14 +587,4 @@ static BOOL ShouldSkipFocusZone(NSView *view)
|
|
|
478
587
|
}
|
|
479
588
|
}
|
|
480
589
|
|
|
481
|
-
- (void)setNavigateAtEnd:(NSString *)value
|
|
482
|
-
{
|
|
483
|
-
// do nothing
|
|
484
|
-
}
|
|
485
|
-
|
|
486
|
-
- (NSString *)navigateAtEnd
|
|
487
|
-
{
|
|
488
|
-
return @"NavigateStopAtEnds";
|
|
489
|
-
}
|
|
490
|
-
|
|
491
590
|
@end
|
|
@@ -9,6 +9,12 @@ RCT_EXPORT_MODULE()
|
|
|
9
9
|
|
|
10
10
|
RCT_EXPORT_VIEW_PROPERTY(disabled, BOOL)
|
|
11
11
|
|
|
12
|
+
RCT_CUSTOM_VIEW_PROPERTY(navigationOrderInRenderOrder, BOOL, RCTFocusZone)
|
|
13
|
+
{
|
|
14
|
+
[view setNavigationOrderInRenderOrder:[json boolValue]];
|
|
15
|
+
[[view window] recalculateKeyViewLoop];
|
|
16
|
+
}
|
|
17
|
+
|
|
12
18
|
RCT_CUSTOM_VIEW_PROPERTY(focusZoneDirection, NSString, RCTFocusZone)
|
|
13
19
|
{
|
|
14
20
|
if ([json isEqualToString:@"bidirectional"])
|
|
@@ -34,6 +40,7 @@ RCT_CUSTOM_VIEW_PROPERTY(focusZoneDirection, NSString, RCTFocusZone)
|
|
|
34
40
|
}
|
|
35
41
|
|
|
36
42
|
RCT_EXPORT_VIEW_PROPERTY(navigateAtEnd, NSString)
|
|
43
|
+
RCT_EXPORT_VIEW_PROPERTY(tabKeyNavigation, NSString)
|
|
37
44
|
|
|
38
45
|
RCT_CUSTOM_VIEW_PROPERTY(defaultTabbableElement, NSNumber, RCTFocusZone)
|
|
39
46
|
{
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@fluentui-react-native/focus-zone",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.19.0",
|
|
4
4
|
"description": "A cross-platform FocusZone component using the Fluent Design System",
|
|
5
5
|
"main": "lib-commonjs/index.js",
|
|
6
6
|
"module": "lib/index.js",
|
|
@@ -22,6 +22,7 @@
|
|
|
22
22
|
"directory": "packages/components/FocusZone"
|
|
23
23
|
},
|
|
24
24
|
"dependencies": {
|
|
25
|
+
"@fluentui-react-native/adapters": "0.13.0",
|
|
25
26
|
"@fluentui-react-native/interactive-hooks": "0.27.0",
|
|
26
27
|
"@uifabricshared/foundation-composable": "0.13.0",
|
|
27
28
|
"@uifabricshared/foundation-settings": "0.15.0"
|
package/src/FocusZone.types.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type * as React from 'react';
|
|
2
|
-
import type { ViewStyle } from 'react-native';
|
|
3
2
|
|
|
3
|
+
import type { IViewProps } from '@fluentui-react-native/adapters';
|
|
4
4
|
import type { IFocusable } from '@fluentui-react-native/interactive-hooks';
|
|
5
5
|
import type { IRenderData } from '@uifabricshared/foundation-composable';
|
|
6
6
|
|
|
@@ -8,7 +8,7 @@ export const focusZoneName = 'FocusZone';
|
|
|
8
8
|
|
|
9
9
|
export interface FocusZoneState {}
|
|
10
10
|
|
|
11
|
-
export type FocusZoneProps =
|
|
11
|
+
export type FocusZoneProps = IViewProps & {
|
|
12
12
|
/**
|
|
13
13
|
* A RefObject to access the IFocusable interface. Use this to access the public methods and properties of the component.
|
|
14
14
|
*/
|
|
@@ -39,7 +39,6 @@ export type FocusZoneProps = React.PropsWithChildren<{
|
|
|
39
39
|
use2DNavigation?: boolean;
|
|
40
40
|
|
|
41
41
|
/**
|
|
42
|
-
* @platform win32
|
|
43
42
|
* By default, pressing Tab within a FocusZone moves focus out of the FocusZone.
|
|
44
43
|
* This prop allows you to change that behavior.
|
|
45
44
|
*
|
|
@@ -66,10 +65,23 @@ export type FocusZoneProps = React.PropsWithChildren<{
|
|
|
66
65
|
onFocus?: (e?: any) => void;
|
|
67
66
|
|
|
68
67
|
/**
|
|
69
|
-
*
|
|
68
|
+
* @platform macos
|
|
69
|
+
* By default, the Apple KeyView loop is calculated based on the UI tree hierarchy, accessibility properties,
|
|
70
|
+
* custom element overrides of navigation order, and positions in layout.
|
|
71
|
+
*
|
|
72
|
+
* Normally this produces the appropriate accessible experience for users, but occasionally we may need to
|
|
73
|
+
* clarify the intended order of navigation. The navigationOrderInRenderOrder prop will have the FocusZone
|
|
74
|
+
* establish the navigation order of its children according to their order in the UI tree
|
|
75
|
+
* (i.e. as returned by accessibilityChildren).
|
|
76
|
+
*
|
|
77
|
+
* Note that to participate in the KeyView loop calculation, the FocusZone itself must be part of the
|
|
78
|
+
* accessibility tree (i.e. 'accessible') with an appropriate role, e.g. 'group'.
|
|
79
|
+
*
|
|
80
|
+
* Extra note: This property is unlikely to perform well if changed from its initial value due to finer details
|
|
81
|
+
* of the MacOS KeyView loop mechanics.
|
|
70
82
|
*/
|
|
71
|
-
|
|
72
|
-
}
|
|
83
|
+
navigationOrderInRenderOrder?: boolean;
|
|
84
|
+
};
|
|
73
85
|
|
|
74
86
|
export interface NativeProps extends Omit<FocusZoneProps, 'isCircularNavigation'> {
|
|
75
87
|
navigateAtEnd?: NavigateAtEnd;
|