@fluentui-react-native/focus-zone 0.23.6 → 0.23.8
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 +39 -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 -56
- 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 -592
- 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
|
@@ -1,201 +0,0 @@
|
|
|
1
|
-
#ifdef RCT_NEW_ARCH_ENABLED
|
|
2
|
-
|
|
3
|
-
#import "RCTFocusZoneComponentView.h"
|
|
4
|
-
|
|
5
|
-
#import <react/renderer/components/FRNFocusZoneSpec/ComponentDescriptors.h>
|
|
6
|
-
#import <react/renderer/components/FRNFocusZoneSpec/EventEmitters.h>
|
|
7
|
-
#import <react/renderer/components/FRNFocusZoneSpec/Props.h>
|
|
8
|
-
#import <react/renderer/components/FRNFocusZoneSpec/RCTComponentViewHelpers.h>
|
|
9
|
-
|
|
10
|
-
#import <React/RCTComponentViewProtocol.h>
|
|
11
|
-
|
|
12
|
-
#import "RCTFocusZone.h"
|
|
13
|
-
|
|
14
|
-
using namespace facebook::react;
|
|
15
|
-
|
|
16
|
-
static FocusZoneDirection RCTFocusZoneDirectionFromProp(FocusZoneFocusZoneDirection direction)
|
|
17
|
-
{
|
|
18
|
-
switch (direction) {
|
|
19
|
-
case FocusZoneFocusZoneDirection::Bidirectional:
|
|
20
|
-
return FocusZoneDirectionBidirectional;
|
|
21
|
-
case FocusZoneFocusZoneDirection::Horizontal:
|
|
22
|
-
return FocusZoneDirectionHorizontal;
|
|
23
|
-
case FocusZoneFocusZoneDirection::Vertical:
|
|
24
|
-
return FocusZoneDirectionVertical;
|
|
25
|
-
case FocusZoneFocusZoneDirection::None:
|
|
26
|
-
return FocusZoneDirectionNone;
|
|
27
|
-
}
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
static NSString *RCTNavigateAtEndFromProp(FocusZoneNavigateAtEnd navigateAtEnd)
|
|
31
|
-
{
|
|
32
|
-
switch (navigateAtEnd) {
|
|
33
|
-
case FocusZoneNavigateAtEnd::NavigateStopAtEnds:
|
|
34
|
-
return @"NavigateStopAtEnds";
|
|
35
|
-
case FocusZoneNavigateAtEnd::NavigateWrap:
|
|
36
|
-
return @"NavigateWrap";
|
|
37
|
-
case FocusZoneNavigateAtEnd::NavigateContinue:
|
|
38
|
-
return @"NavigateContinue";
|
|
39
|
-
}
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
static NSString *RCTTabKeyNavigationFromProp(FocusZoneTabKeyNavigation tabKeyNavigation)
|
|
43
|
-
{
|
|
44
|
-
switch (tabKeyNavigation) {
|
|
45
|
-
case FocusZoneTabKeyNavigation::None:
|
|
46
|
-
return @"None";
|
|
47
|
-
case FocusZoneTabKeyNavigation::NavigateWrap:
|
|
48
|
-
return @"NavigateWrap";
|
|
49
|
-
case FocusZoneTabKeyNavigation::NavigateStopAtEnds:
|
|
50
|
-
return @"NavigateStopAtEnds";
|
|
51
|
-
case FocusZoneTabKeyNavigation::Normal:
|
|
52
|
-
return @"Normal";
|
|
53
|
-
}
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
static RCTPlatformView *RCTFindComponentViewWithTag(RCTPlatformView *rootView, NSInteger tag)
|
|
57
|
-
{
|
|
58
|
-
if ([rootView conformsToProtocol:@protocol(RCTComponentViewProtocol)] &&
|
|
59
|
-
[((id<RCTComponentViewProtocol>)rootView).reactTag integerValue] == tag) {
|
|
60
|
-
return rootView;
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
for (RCTPlatformView *subview in rootView.subviews) {
|
|
64
|
-
RCTPlatformView *match = RCTFindComponentViewWithTag(subview, tag);
|
|
65
|
-
if (match) {
|
|
66
|
-
return match;
|
|
67
|
-
}
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
return nil;
|
|
71
|
-
}
|
|
72
|
-
|
|
73
|
-
static RCTPlatformView *RCTFindComponentViewWithNativeID(RCTPlatformView *rootView, NSString *nativeID)
|
|
74
|
-
{
|
|
75
|
-
if ([rootView isKindOfClass:[RCTViewComponentView class]] &&
|
|
76
|
-
[((RCTViewComponentView *)rootView).nativeId isEqualToString:nativeID]) {
|
|
77
|
-
return rootView;
|
|
78
|
-
}
|
|
79
|
-
|
|
80
|
-
for (RCTPlatformView *subview in rootView.subviews) {
|
|
81
|
-
RCTPlatformView *match = RCTFindComponentViewWithNativeID(subview, nativeID);
|
|
82
|
-
if (match) {
|
|
83
|
-
return match;
|
|
84
|
-
}
|
|
85
|
-
}
|
|
86
|
-
|
|
87
|
-
return nil;
|
|
88
|
-
}
|
|
89
|
-
|
|
90
|
-
@interface RCTFocusZoneComponentView () <RCTFocusZoneViewProtocol>
|
|
91
|
-
@end
|
|
92
|
-
|
|
93
|
-
@implementation RCTFocusZoneComponentView {
|
|
94
|
-
NSString *_defaultResponderNativeID;
|
|
95
|
-
NSInteger _defaultResponderTag;
|
|
96
|
-
RCTFocusZone *_focusZone;
|
|
97
|
-
}
|
|
98
|
-
|
|
99
|
-
+ (ComponentDescriptorProvider)componentDescriptorProvider
|
|
100
|
-
{
|
|
101
|
-
// Fabric normalizes the legacy RCT-prefixed view name before component lookup.
|
|
102
|
-
return concreteComponentDescriptorProvider<FocusZoneComponentDescriptor>();
|
|
103
|
-
}
|
|
104
|
-
|
|
105
|
-
- (instancetype)initWithFrame:(CGRect)frame
|
|
106
|
-
{
|
|
107
|
-
if (self = [super initWithFrame:frame]) {
|
|
108
|
-
static const auto defaultProps = std::make_shared<const FocusZoneProps>();
|
|
109
|
-
_props = defaultProps;
|
|
110
|
-
|
|
111
|
-
_focusZone = [[RCTFocusZone alloc] initWithFrame:self.bounds];
|
|
112
|
-
self.contentView = _focusZone;
|
|
113
|
-
}
|
|
114
|
-
return self;
|
|
115
|
-
}
|
|
116
|
-
|
|
117
|
-
- (NSView *)accessibilityElement
|
|
118
|
-
{
|
|
119
|
-
return _focusZone;
|
|
120
|
-
}
|
|
121
|
-
|
|
122
|
-
- (void)mountChildComponentView:(RCTUIView<RCTComponentViewProtocol> *)childComponentView index:(NSInteger)index
|
|
123
|
-
{
|
|
124
|
-
[_focusZone insertSubview:childComponentView atIndex:index];
|
|
125
|
-
[self updateDefaultResponder];
|
|
126
|
-
}
|
|
127
|
-
|
|
128
|
-
- (void)unmountChildComponentView:(RCTUIView<RCTComponentViewProtocol> *)childComponentView index:(__unused NSInteger)index
|
|
129
|
-
{
|
|
130
|
-
[childComponentView removeFromSuperview];
|
|
131
|
-
[self updateDefaultResponder];
|
|
132
|
-
}
|
|
133
|
-
|
|
134
|
-
- (void)updateProps:(const Props::Shared &)props oldProps:(const Props::Shared &)oldProps
|
|
135
|
-
{
|
|
136
|
-
const auto &newProps = *std::static_pointer_cast<const FocusZoneProps>(props);
|
|
137
|
-
|
|
138
|
-
_focusZone.disabled = newProps.disabled;
|
|
139
|
-
_focusZone.focusZoneDirection = RCTFocusZoneDirectionFromProp(newProps.focusZoneDirection);
|
|
140
|
-
_focusZone.navigateAtEnd = RCTNavigateAtEndFromProp(newProps.navigateAtEnd);
|
|
141
|
-
_focusZone.navigationOrderInRenderOrder = newProps.navigationOrderInRenderOrder;
|
|
142
|
-
_focusZone.tabKeyNavigation = RCTTabKeyNavigationFromProp(newProps.tabKeyNavigation);
|
|
143
|
-
|
|
144
|
-
_defaultResponderNativeID = nil;
|
|
145
|
-
_defaultResponderTag = 0;
|
|
146
|
-
if (newProps.defaultTabbableElement.isNumber()) {
|
|
147
|
-
_defaultResponderTag = (NSInteger)newProps.defaultTabbableElement.asDouble();
|
|
148
|
-
} else if (newProps.defaultTabbableElement.isString()) {
|
|
149
|
-
_defaultResponderNativeID = [NSString stringWithUTF8String:newProps.defaultTabbableElement.getString().c_str()];
|
|
150
|
-
}
|
|
151
|
-
[self updateDefaultResponder];
|
|
152
|
-
[self.window recalculateKeyViewLoop];
|
|
153
|
-
|
|
154
|
-
[super updateProps:props oldProps:oldProps];
|
|
155
|
-
}
|
|
156
|
-
|
|
157
|
-
- (void)viewDidMoveToWindow
|
|
158
|
-
{
|
|
159
|
-
[super viewDidMoveToWindow];
|
|
160
|
-
[self updateDefaultResponder];
|
|
161
|
-
}
|
|
162
|
-
|
|
163
|
-
- (void)prepareForRecycle
|
|
164
|
-
{
|
|
165
|
-
[super prepareForRecycle];
|
|
166
|
-
_defaultResponderNativeID = nil;
|
|
167
|
-
_defaultResponderTag = 0;
|
|
168
|
-
_focusZone.defaultResponder = nil;
|
|
169
|
-
}
|
|
170
|
-
|
|
171
|
-
- (BOOL)acceptsFirstResponder
|
|
172
|
-
{
|
|
173
|
-
// The content view owns key-loop participation; the Fabric wrapper only forwards programmatic focus.
|
|
174
|
-
return NO;
|
|
175
|
-
}
|
|
176
|
-
|
|
177
|
-
- (BOOL)becomeFirstResponder
|
|
178
|
-
{
|
|
179
|
-
return [_focusZone becomeFirstResponder];
|
|
180
|
-
}
|
|
181
|
-
|
|
182
|
-
- (void)keyDown:(NSEvent *)event
|
|
183
|
-
{
|
|
184
|
-
[_focusZone keyDown:event];
|
|
185
|
-
}
|
|
186
|
-
|
|
187
|
-
- (void)updateDefaultResponder
|
|
188
|
-
{
|
|
189
|
-
RCTPlatformView *rootView = self.window.contentView;
|
|
190
|
-
if (_defaultResponderTag > 0 && rootView) {
|
|
191
|
-
_focusZone.defaultResponder = RCTFindComponentViewWithTag(rootView, _defaultResponderTag);
|
|
192
|
-
} else if (_defaultResponderNativeID && rootView) {
|
|
193
|
-
_focusZone.defaultResponder = RCTFindComponentViewWithNativeID(rootView, _defaultResponderNativeID);
|
|
194
|
-
} else {
|
|
195
|
-
_focusZone.defaultResponder = nil;
|
|
196
|
-
}
|
|
197
|
-
}
|
|
198
|
-
|
|
199
|
-
@end
|
|
200
|
-
|
|
201
|
-
#endif
|
|
@@ -1,58 +0,0 @@
|
|
|
1
|
-
#import "RCTFocusZone.h"
|
|
2
|
-
#import "RCTFocusZoneManager.h"
|
|
3
|
-
#import <React/RCTConvert.h>
|
|
4
|
-
#import <React/RCTUIManager.h>
|
|
5
|
-
|
|
6
|
-
@implementation RCTFocusZoneManager
|
|
7
|
-
|
|
8
|
-
RCT_EXPORT_MODULE()
|
|
9
|
-
|
|
10
|
-
RCT_EXPORT_VIEW_PROPERTY(disabled, BOOL)
|
|
11
|
-
|
|
12
|
-
RCT_CUSTOM_VIEW_PROPERTY(navigationOrderInRenderOrder, BOOL, RCTFocusZone)
|
|
13
|
-
{
|
|
14
|
-
[view setNavigationOrderInRenderOrder:[json boolValue]];
|
|
15
|
-
[[view window] recalculateKeyViewLoop];
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
RCT_CUSTOM_VIEW_PROPERTY(focusZoneDirection, NSString, RCTFocusZone)
|
|
19
|
-
{
|
|
20
|
-
if ([json isEqualToString:@"bidirectional"])
|
|
21
|
-
{
|
|
22
|
-
[view setFocusZoneDirection:FocusZoneDirectionBidirectional];
|
|
23
|
-
}
|
|
24
|
-
else if ([json isEqualToString:@"vertical"])
|
|
25
|
-
{
|
|
26
|
-
[view setFocusZoneDirection:FocusZoneDirectionVertical];
|
|
27
|
-
}
|
|
28
|
-
else if ([json isEqualToString:@"horizontal"])
|
|
29
|
-
{
|
|
30
|
-
[view setFocusZoneDirection:FocusZoneDirectionHorizontal];
|
|
31
|
-
}
|
|
32
|
-
else if ([json isEqualToString:@"none"])
|
|
33
|
-
{
|
|
34
|
-
[view setFocusZoneDirection:FocusZoneDirectionNone];
|
|
35
|
-
}
|
|
36
|
-
else
|
|
37
|
-
{
|
|
38
|
-
[view setFocusZoneDirection:[defaultView focusZoneDirection]];
|
|
39
|
-
}
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
RCT_EXPORT_VIEW_PROPERTY(navigateAtEnd, NSString)
|
|
43
|
-
RCT_EXPORT_VIEW_PROPERTY(tabKeyNavigation, NSString)
|
|
44
|
-
|
|
45
|
-
RCT_CUSTOM_VIEW_PROPERTY(defaultTabbableElement, NSNumber, RCTFocusZone)
|
|
46
|
-
{
|
|
47
|
-
NSNumber *tag = [RCTConvert NSNumber:json];
|
|
48
|
-
RCTUIManager *manager = [[self bridge] uiManager];
|
|
49
|
-
NSView *defaultResponder = [manager viewForReactTag:tag];
|
|
50
|
-
[view setDefaultResponder:defaultResponder];
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
- (RCTView *)view
|
|
54
|
-
{
|
|
55
|
-
return [RCTFocusZone new];
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
@end
|
package/react-native.config.cjs
DELETED
package/src/FocusZone.tsx
DELETED
|
@@ -1,50 +0,0 @@
|
|
|
1
|
-
/** @jsxImportSource @fluentui-react-native/framework-base */
|
|
2
|
-
import * as React from 'react';
|
|
3
|
-
import { findNodeHandle } from 'react-native';
|
|
4
|
-
|
|
5
|
-
import { directComponent, mergeProps, phasedComponent } from '@fluentui-react-native/framework-base';
|
|
6
|
-
import { useViewCommandFocus } from '@fluentui-react-native/interactive-hooks';
|
|
7
|
-
|
|
8
|
-
import type { FocusZoneProps } from './FocusZone.types';
|
|
9
|
-
import { focusZoneName } from './FocusZone.types';
|
|
10
|
-
import NativeFocusZone from './FocusZoneNativeComponent';
|
|
11
|
-
|
|
12
|
-
/**
|
|
13
|
-
* Renders the native FocusZone without applying theme or appearance defaults.
|
|
14
|
-
*/
|
|
15
|
-
export const FocusZone = phasedComponent<FocusZoneProps>((props) => {
|
|
16
|
-
const { componentRef, defaultTabbableElement } = props;
|
|
17
|
-
const nativeRef = useViewCommandFocus(componentRef);
|
|
18
|
-
const [nativeDefaultTabbableElement, setNativeDefaultTabbableElement] = React.useState<number | string>();
|
|
19
|
-
|
|
20
|
-
React.useLayoutEffect(() => {
|
|
21
|
-
if (typeof defaultTabbableElement === 'string') {
|
|
22
|
-
setNativeDefaultTabbableElement(defaultTabbableElement);
|
|
23
|
-
} else if (defaultTabbableElement?.current) {
|
|
24
|
-
setNativeDefaultTabbableElement(findNodeHandle(defaultTabbableElement.current) ?? undefined);
|
|
25
|
-
} else {
|
|
26
|
-
setNativeDefaultTabbableElement(undefined);
|
|
27
|
-
}
|
|
28
|
-
}, [defaultTabbableElement]);
|
|
29
|
-
|
|
30
|
-
return directComponent<FocusZoneProps>((renderProps) => {
|
|
31
|
-
const {
|
|
32
|
-
componentRef: _componentRef,
|
|
33
|
-
defaultTabbableElement: _defaultTabbableElement,
|
|
34
|
-
isCircularNavigation,
|
|
35
|
-
navigateAtEnd = isCircularNavigation ? 'NavigateWrap' : 'NavigateStopAtEnds',
|
|
36
|
-
...nativeProps
|
|
37
|
-
} = mergeProps(props, renderProps) as FocusZoneProps & { navigateAtEnd?: 'NavigateStopAtEnds' | 'NavigateWrap' | 'NavigateContinue' };
|
|
38
|
-
|
|
39
|
-
return (
|
|
40
|
-
<NativeFocusZone
|
|
41
|
-
{...nativeProps}
|
|
42
|
-
defaultTabbableElement={nativeDefaultTabbableElement}
|
|
43
|
-
navigateAtEnd={navigateAtEnd}
|
|
44
|
-
ref={nativeRef}
|
|
45
|
-
/>
|
|
46
|
-
);
|
|
47
|
-
});
|
|
48
|
-
});
|
|
49
|
-
|
|
50
|
-
FocusZone.displayName = focusZoneName;
|
package/src/FocusZone.types.ts
DELETED
|
@@ -1,124 +0,0 @@
|
|
|
1
|
-
import type * as React from 'react';
|
|
2
|
-
import type { ViewProps } from 'react-native';
|
|
3
|
-
|
|
4
|
-
import type { IFocusable } from '@fluentui-react-native/interactive-hooks';
|
|
5
|
-
|
|
6
|
-
export const focusZoneName = 'FocusZone';
|
|
7
|
-
|
|
8
|
-
export type FocusZoneState = Record<never, never>;
|
|
9
|
-
|
|
10
|
-
export interface FocusZoneProps extends ViewProps {
|
|
11
|
-
/**
|
|
12
|
-
* A RefObject to access the IFocusable interface. Use this to access the public methods and properties of the component.
|
|
13
|
-
*/
|
|
14
|
-
componentRef?: React.RefObject<IFocusable>;
|
|
15
|
-
|
|
16
|
-
/**
|
|
17
|
-
* Optionally defines the initial tabbable element inside the FocusZone
|
|
18
|
-
*/
|
|
19
|
-
defaultTabbableElement?: React.RefObject<React.Component | null> | string;
|
|
20
|
-
|
|
21
|
-
/**
|
|
22
|
-
** Defines which arrows to react to
|
|
23
|
-
*/
|
|
24
|
-
focusZoneDirection?: FocusZoneDirection;
|
|
25
|
-
|
|
26
|
-
/**
|
|
27
|
-
** If set, the FocusZone will not be tabbable and keyboard navigation will be disabled
|
|
28
|
-
*/
|
|
29
|
-
disabled?: boolean;
|
|
30
|
-
|
|
31
|
-
/* Circular Navigation prop */
|
|
32
|
-
isCircularNavigation?: boolean;
|
|
33
|
-
|
|
34
|
-
/**
|
|
35
|
-
* Enables geometric rather than linear navigation on Windows/Win32.
|
|
36
|
-
* macOS always uses geometric directional navigation.
|
|
37
|
-
* @platform windows, win32
|
|
38
|
-
*/
|
|
39
|
-
use2DNavigation?: boolean;
|
|
40
|
-
|
|
41
|
-
/**
|
|
42
|
-
* By default, pressing Tab within a FocusZone moves focus out of the FocusZone.
|
|
43
|
-
* This prop allows you to change that behavior.
|
|
44
|
-
*
|
|
45
|
-
* "None" : Default
|
|
46
|
-
* "NavigateWrap" : Tab allowed within FZ with circular navigation behavior
|
|
47
|
-
* "NavigateStopAtEnds" : Tab allowed within FZ and stops at ends
|
|
48
|
-
* "Normal" : Tab allowed within FZ, and focus is not trapped. Tabbing at the last element bring you out of the FZ.
|
|
49
|
-
*
|
|
50
|
-
* Recommended Usage - Moving focus OUT of the FocusZone - Custom Key Handlers
|
|
51
|
-
* Example: Subscribe to key events. On the pressing of "Escape", move focus out of the FocusZone.
|
|
52
|
-
*
|
|
53
|
-
* Recommended Usage - Moving focus INTO the FocusZone
|
|
54
|
-
* Let's take a CardList, for example. If a user is navigating through elements of the List, we don't want
|
|
55
|
-
* focus to land within the FocusZone on initial focus. If it does, it will trap focus within the FocusZone and
|
|
56
|
-
* ruin the user's workflow.
|
|
57
|
-
* Instead, once focus lands on the parent of the FocusZone, implement a custom key handler that will enable
|
|
58
|
-
* the FocusZone.
|
|
59
|
-
*/
|
|
60
|
-
tabKeyNavigation?: FocusZoneTabNavigation;
|
|
61
|
-
|
|
62
|
-
/**
|
|
63
|
-
* @platform macos
|
|
64
|
-
* By default, the Apple KeyView loop is calculated based on the UI tree hierarchy, accessibility properties,
|
|
65
|
-
* custom element overrides of navigation order, and positions in layout.
|
|
66
|
-
*
|
|
67
|
-
* Normally this produces the appropriate accessible experience for users, but occasionally we may need to
|
|
68
|
-
* clarify the intended order of navigation. The navigationOrderInRenderOrder prop will have the FocusZone
|
|
69
|
-
* establish the navigation order of its children according to their order in the UI tree
|
|
70
|
-
* (i.e. as returned by accessibilityChildren).
|
|
71
|
-
*
|
|
72
|
-
* Note that to participate in the KeyView loop calculation, the FocusZone itself must be part of the
|
|
73
|
-
* accessibility tree (i.e. 'accessible') with an appropriate role, e.g. 'group'.
|
|
74
|
-
*
|
|
75
|
-
* Extra note: This property is unlikely to perform well if changed from its initial value due to finer details
|
|
76
|
-
* of the MacOS KeyView loop mechanics.
|
|
77
|
-
*/
|
|
78
|
-
navigationOrderInRenderOrder?: boolean;
|
|
79
|
-
}
|
|
80
|
-
|
|
81
|
-
export interface NativeProps extends Omit<FocusZoneProps, 'componentRef' | 'defaultTabbableElement' | 'isCircularNavigation'> {
|
|
82
|
-
defaultTabbableElement?: number | string;
|
|
83
|
-
navigateAtEnd?: NavigateAtEnd;
|
|
84
|
-
tabKeyNavigation?: FocusZoneTabNavigation;
|
|
85
|
-
}
|
|
86
|
-
|
|
87
|
-
export type FocusZoneDirection =
|
|
88
|
-
| 'bidirectional' /** React to all arrows. */
|
|
89
|
-
| 'vertical' /** Only react to up/down arrows. */
|
|
90
|
-
| 'horizontal' /** Only react to left/right arrows. */
|
|
91
|
-
| 'none'; /** Doesn't respond to any arrow keys. */
|
|
92
|
-
|
|
93
|
-
export type NavigateAtEnd =
|
|
94
|
-
| 'NavigateStopAtEnds' /* Focus will stay on the last element in the FocusZone. Only way to navigate out is Tab. For macOS, this is the only available option. */
|
|
95
|
-
| 'NavigateWrap' /* Circular Navigation Functionality */
|
|
96
|
-
| 'NavigateContinue'; /* At the last element of the FocusZone, focus will move to the first focusable element outside the FocusZone */
|
|
97
|
-
|
|
98
|
-
export type FocusZoneTabNavigation =
|
|
99
|
-
| 'None' /* Tab navigates you out of the FocusZone. This is Default */
|
|
100
|
-
| 'NavigateWrap' /* Navigate the FZ with Tab. Circular navigation at ends */
|
|
101
|
-
| 'NavigateStopAtEnds' /* Navigate the FZ with Tab. Stop navigation at ends */
|
|
102
|
-
| 'Normal'; /* Navigate the FZ with Tab. Don't trap focus, tabbing at ends moves you out */
|
|
103
|
-
|
|
104
|
-
/** @deprecated FocusZone is an unstyled primitive and does not resolve tokens. */
|
|
105
|
-
export type FocusZoneTokens = Record<never, never>;
|
|
106
|
-
|
|
107
|
-
/** @deprecated Use FocusZoneProps. */
|
|
108
|
-
export interface FocusZoneSlotProps {
|
|
109
|
-
root: NativeProps;
|
|
110
|
-
}
|
|
111
|
-
|
|
112
|
-
/** @deprecated FocusZone uses the phased primitive component pattern. */
|
|
113
|
-
export interface FocusZoneRenderData {
|
|
114
|
-
slotProps?: FocusZoneSlotProps;
|
|
115
|
-
state?: FocusZoneState;
|
|
116
|
-
}
|
|
117
|
-
|
|
118
|
-
/** @deprecated Use FocusZoneProps. */
|
|
119
|
-
export interface FocusZoneType {
|
|
120
|
-
props: FocusZoneProps;
|
|
121
|
-
tokens: FocusZoneTokens;
|
|
122
|
-
slotProps: FocusZoneSlotProps;
|
|
123
|
-
state: FocusZoneState;
|
|
124
|
-
}
|
|
@@ -1,26 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Copyright (c) Microsoft Corporation.
|
|
3
|
-
* Licensed under the MIT License.
|
|
4
|
-
* @format
|
|
5
|
-
*/
|
|
6
|
-
import codegenNativeComponent from 'react-native/Libraries/Utilities/codegenNativeComponent';
|
|
7
|
-
|
|
8
|
-
import type { HostComponent, ViewProps } from 'react-native';
|
|
9
|
-
import type { UnsafeMixed, WithDefault } from 'react-native/Libraries/Types/CodegenTypes';
|
|
10
|
-
|
|
11
|
-
export interface NativeProps extends ViewProps {
|
|
12
|
-
navigateAtEnd?: WithDefault<'NavigateStopAtEnds' | 'NavigateWrap' | 'NavigateContinue', 'NavigateStopAtEnds'>;
|
|
13
|
-
defaultTabbableElement?: UnsafeMixed;
|
|
14
|
-
focusZoneDirection?: WithDefault<'bidirectional' | 'vertical' | 'horizontal' | 'none', 'bidirectional'>;
|
|
15
|
-
use2DNavigation?: boolean;
|
|
16
|
-
tabKeyNavigation?: WithDefault<'None' | 'NavigateWrap' | 'NavigateStopAtEnds' | 'Normal', 'None'>;
|
|
17
|
-
disabled?: boolean;
|
|
18
|
-
isTabNavigation?: boolean;
|
|
19
|
-
navigationOrderInRenderOrder?: boolean;
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
export type FocusZoneComponentType = HostComponent<NativeProps>;
|
|
23
|
-
|
|
24
|
-
export default codegenNativeComponent<NativeProps>('FocusZone', {
|
|
25
|
-
paperComponentName: 'RCTFocusZone',
|
|
26
|
-
}) as FocusZoneComponentType;
|
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
import { requireNativeComponent } from 'react-native';
|
|
2
|
-
import type { HostComponent, ViewProps } from 'react-native';
|
|
3
|
-
import type { UnsafeMixed, WithDefault } from 'react-native/Libraries/Types/CodegenTypes';
|
|
4
|
-
|
|
5
|
-
export interface NativeProps extends ViewProps {
|
|
6
|
-
navigateAtEnd?: WithDefault<'NavigateStopAtEnds' | 'NavigateWrap' | 'NavigateContinue', 'NavigateStopAtEnds'>;
|
|
7
|
-
defaultTabbableElement?: UnsafeMixed;
|
|
8
|
-
focusZoneDirection?: WithDefault<'bidirectional' | 'vertical' | 'horizontal' | 'none', 'bidirectional'>;
|
|
9
|
-
use2DNavigation?: boolean;
|
|
10
|
-
tabKeyNavigation?: WithDefault<'None' | 'NavigateWrap' | 'NavigateStopAtEnds' | 'Normal', 'None'>;
|
|
11
|
-
disabled?: boolean;
|
|
12
|
-
isTabNavigation?: boolean;
|
|
13
|
-
navigationOrderInRenderOrder?: boolean;
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
export type FocusZoneComponentType = HostComponent<NativeProps>;
|
|
17
|
-
|
|
18
|
-
export default requireNativeComponent<NativeProps>('RCTFocusZone') as FocusZoneComponentType;
|
|
@@ -1,131 +0,0 @@
|
|
|
1
|
-
/** @jsxImportSource @fluentui-react-native/framework-base */
|
|
2
|
-
import * as React from 'react';
|
|
3
|
-
import { StyleSheet, Text, View } from 'react-native';
|
|
4
|
-
|
|
5
|
-
import { isPhasedComponent, useSlot } from '@fluentui-react-native/framework-base';
|
|
6
|
-
import type { SlotProp } from '@fluentui-react-native/framework-base';
|
|
7
|
-
import { render } from '@testing-library/react-native';
|
|
8
|
-
|
|
9
|
-
import { FocusZone } from '../FocusZone';
|
|
10
|
-
import type { NavigateAtEnd } from '../FocusZone.types';
|
|
11
|
-
|
|
12
|
-
jest.mock('react-native/Libraries/ReactNative/RendererProxy', () => ({
|
|
13
|
-
...jest.requireActual('react-native/Libraries/ReactNative/RendererProxy'),
|
|
14
|
-
findNodeHandle: jest.fn(() => 42),
|
|
15
|
-
}));
|
|
16
|
-
|
|
17
|
-
type FocusZoneSlotConsumerProps = {
|
|
18
|
-
focusZone: SlotProp<typeof FocusZone> & { navigateAtEnd?: NavigateAtEnd };
|
|
19
|
-
};
|
|
20
|
-
|
|
21
|
-
function FocusZoneSlotConsumer({ focusZone }: FocusZoneSlotConsumerProps) {
|
|
22
|
-
const FocusZoneSlot = useSlot(FocusZone, focusZone);
|
|
23
|
-
return (
|
|
24
|
-
<FocusZoneSlot accessibilityHint="rendered as a slot" testID="slotted-focus-zone">
|
|
25
|
-
<Text>Slot content</Text>
|
|
26
|
-
</FocusZoneSlot>
|
|
27
|
-
);
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
describe('FocusZone', () => {
|
|
31
|
-
afterEach(() => {
|
|
32
|
-
jest.restoreAllMocks();
|
|
33
|
-
});
|
|
34
|
-
|
|
35
|
-
it('uses phased rendering and applies no styling defaults', async () => {
|
|
36
|
-
expect(isPhasedComponent(FocusZone)).toBe(true);
|
|
37
|
-
|
|
38
|
-
const component = await render(<FocusZone testID="focus-zone" />);
|
|
39
|
-
const focusZone = component.getByTestId('focus-zone');
|
|
40
|
-
|
|
41
|
-
expect(focusZone.type).toBe('RCTFocusZone');
|
|
42
|
-
expect(focusZone.props.navigateAtEnd).toBe('NavigateStopAtEnds');
|
|
43
|
-
expect(focusZone.props.style).toBeUndefined();
|
|
44
|
-
});
|
|
45
|
-
|
|
46
|
-
it('forwards native behavior, accessibility, style, callbacks, and children', async () => {
|
|
47
|
-
const onFocus = jest.fn();
|
|
48
|
-
const style = { opacity: 0.5 };
|
|
49
|
-
const component = await render(
|
|
50
|
-
<FocusZone
|
|
51
|
-
accessibilityLabel="Formatting tools"
|
|
52
|
-
disabled
|
|
53
|
-
focusZoneDirection="vertical"
|
|
54
|
-
navigationOrderInRenderOrder
|
|
55
|
-
onFocus={onFocus}
|
|
56
|
-
style={style}
|
|
57
|
-
tabKeyNavigation="Normal"
|
|
58
|
-
testID="focus-zone"
|
|
59
|
-
use2DNavigation
|
|
60
|
-
>
|
|
61
|
-
<Text>FocusZone content</Text>
|
|
62
|
-
</FocusZone>,
|
|
63
|
-
);
|
|
64
|
-
const focusZone = component.getByTestId('focus-zone');
|
|
65
|
-
|
|
66
|
-
expect(focusZone.props).toMatchObject({
|
|
67
|
-
accessibilityLabel: 'Formatting tools',
|
|
68
|
-
disabled: true,
|
|
69
|
-
focusZoneDirection: 'vertical',
|
|
70
|
-
navigationOrderInRenderOrder: true,
|
|
71
|
-
onFocus,
|
|
72
|
-
tabKeyNavigation: 'Normal',
|
|
73
|
-
use2DNavigation: true,
|
|
74
|
-
});
|
|
75
|
-
expect(StyleSheet.flatten(focusZone.props.style)).toEqual(style);
|
|
76
|
-
expect(component.getByText('FocusZone content')).toBeTruthy();
|
|
77
|
-
});
|
|
78
|
-
|
|
79
|
-
it('maps circular navigation to the native end behavior', async () => {
|
|
80
|
-
const component = await render(<FocusZone isCircularNavigation testID="focus-zone" />);
|
|
81
|
-
|
|
82
|
-
expect(component.getByTestId('focus-zone').props.navigateAtEnd).toBe('NavigateWrap');
|
|
83
|
-
});
|
|
84
|
-
|
|
85
|
-
it('preserves a native end behavior supplied by a legacy slot consumer', async () => {
|
|
86
|
-
const component = await render(<FocusZoneSlotConsumer focusZone={{ navigateAtEnd: 'NavigateContinue' }} />);
|
|
87
|
-
|
|
88
|
-
expect(component.getByTestId('slotted-focus-zone').props.navigateAtEnd).toBe('NavigateContinue');
|
|
89
|
-
});
|
|
90
|
-
|
|
91
|
-
it('forwards a registered native identifier as the default tabbable element', async () => {
|
|
92
|
-
const component = await render(<FocusZone defaultTabbableElement="preferred-item" testID="focus-zone" />);
|
|
93
|
-
|
|
94
|
-
expect(component.getByTestId('focus-zone').props.defaultTabbableElement).toBe('preferred-item');
|
|
95
|
-
});
|
|
96
|
-
|
|
97
|
-
it('resolves a default tabbable element ref to its native handle', async () => {
|
|
98
|
-
const defaultTabbableElement = React.createRef<View>();
|
|
99
|
-
const component = await render(
|
|
100
|
-
<FocusZone defaultTabbableElement={defaultTabbableElement} testID="focus-zone">
|
|
101
|
-
<View ref={defaultTabbableElement} />
|
|
102
|
-
</FocusZone>,
|
|
103
|
-
);
|
|
104
|
-
|
|
105
|
-
expect(defaultTabbableElement.current).not.toBeNull();
|
|
106
|
-
expect(component.getByTestId('focus-zone').props.defaultTabbableElement).toBe(42);
|
|
107
|
-
});
|
|
108
|
-
|
|
109
|
-
it('forwards componentRef without exposing it as a native prop', async () => {
|
|
110
|
-
const componentRef = React.createRef<View>();
|
|
111
|
-
const component = await render(<FocusZone componentRef={componentRef} testID="focus-zone" />);
|
|
112
|
-
const focusZone = component.getByTestId('focus-zone');
|
|
113
|
-
|
|
114
|
-
expect(componentRef.current).not.toBeNull();
|
|
115
|
-
expect(focusZone.props.componentRef).toBeUndefined();
|
|
116
|
-
});
|
|
117
|
-
|
|
118
|
-
it('can be consumed as a slot with merged render props', async () => {
|
|
119
|
-
const component = await render(
|
|
120
|
-
<FocusZoneSlotConsumer focusZone={{ accessibilityLabel: 'Slotted FocusZone', focusZoneDirection: 'horizontal' }} />,
|
|
121
|
-
);
|
|
122
|
-
const focusZone = component.getByTestId('slotted-focus-zone');
|
|
123
|
-
|
|
124
|
-
expect(focusZone.props).toMatchObject({
|
|
125
|
-
accessibilityHint: 'rendered as a slot',
|
|
126
|
-
accessibilityLabel: 'Slotted FocusZone',
|
|
127
|
-
focusZoneDirection: 'horizontal',
|
|
128
|
-
});
|
|
129
|
-
expect(component.getByText('Slot content')).toBeTruthy();
|
|
130
|
-
});
|
|
131
|
-
});
|
|
@@ -1,36 +0,0 @@
|
|
|
1
|
-
/* eslint-disable @typescript-eslint/no-unused-vars */
|
|
2
|
-
import * as React from 'react';
|
|
3
|
-
|
|
4
|
-
import type { SlotProp } from '@fluentui-react-native/framework-base';
|
|
5
|
-
import type { IFocusable } from '@fluentui-react-native/interactive-hooks';
|
|
6
|
-
|
|
7
|
-
import type { FocusZone } from '../FocusZone';
|
|
8
|
-
import type { FocusZoneProps, NativeProps } from '../FocusZone.types';
|
|
9
|
-
|
|
10
|
-
const componentRef = React.createRef<IFocusable>();
|
|
11
|
-
const defaultTabbableElement = React.createRef<React.Component>();
|
|
12
|
-
|
|
13
|
-
const props: FocusZoneProps = {
|
|
14
|
-
accessibilityLabel: 'Formatting tools',
|
|
15
|
-
componentRef,
|
|
16
|
-
defaultTabbableElement,
|
|
17
|
-
focusZoneDirection: 'horizontal',
|
|
18
|
-
isCircularNavigation: true,
|
|
19
|
-
};
|
|
20
|
-
|
|
21
|
-
const focusZoneSlot: SlotProp<typeof FocusZone> = props;
|
|
22
|
-
const nativeProps: NativeProps = {
|
|
23
|
-
defaultTabbableElement: 42,
|
|
24
|
-
focusZoneDirection: 'vertical',
|
|
25
|
-
navigateAtEnd: 'NavigateWrap',
|
|
26
|
-
};
|
|
27
|
-
|
|
28
|
-
// @ts-expect-error FocusZone direction must be one of the supported navigation axes.
|
|
29
|
-
const invalidDirection: FocusZoneProps = { focusZoneDirection: 'diagonal' };
|
|
30
|
-
|
|
31
|
-
describe('FocusZone types', () => {
|
|
32
|
-
it('accepts public props as a slot contract', () => {
|
|
33
|
-
expect(focusZoneSlot).toBeDefined();
|
|
34
|
-
expect(nativeProps).toBeDefined();
|
|
35
|
-
});
|
|
36
|
-
});
|