@fluentui-react-native/focus-zone 0.23.3 → 0.23.4
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/.cache/tsconfig.tsbuildinfo +1 -1
- package/CHANGELOG.md +6 -0
- package/RCTFocusZone.podspec +1 -1
- package/SPEC.md +42 -0
- package/lib/FocusZone.d.ts +2 -6
- package/lib/FocusZone.d.ts.map +1 -1
- package/lib/FocusZone.js +28 -45
- package/lib/FocusZone.js.map +1 -1
- package/lib/FocusZone.types.d.ts +16 -15
- package/lib/FocusZone.types.d.ts.map +1 -1
- package/lib/FocusZone.types.js.map +1 -1
- package/lib/FocusZoneNativeComponent.d.ts +5 -3
- package/lib/FocusZoneNativeComponent.d.ts.map +1 -1
- package/lib/FocusZoneNativeComponent.js +3 -1
- package/lib/FocusZoneNativeComponent.js.map +1 -1
- package/lib/FocusZoneNativeComponent.win32.d.ts +16 -0
- package/lib/FocusZoneNativeComponent.win32.d.ts.map +1 -0
- package/lib/FocusZoneNativeComponent.win32.js +3 -0
- package/lib/FocusZoneNativeComponent.win32.js.map +1 -0
- package/lib/__tests__/FocusZone.test.js +68 -70
- package/lib/__tests__/FocusZone.test.js.map +1 -1
- package/lib/__tests__/FocusZone.types.test.d.ts +2 -0
- package/lib/__tests__/FocusZone.types.test.d.ts.map +1 -0
- package/lib/__tests__/FocusZone.types.test.js +26 -0
- package/lib/__tests__/FocusZone.types.test.js.map +1 -0
- package/macos/RCTFocusZone.m +76 -17
- package/macos/RCTFocusZoneComponentView.h +14 -0
- package/macos/RCTFocusZoneComponentView.mm +201 -0
- package/package.json +30 -8
- package/react-native.config.cjs +15 -0
- package/src/FocusZone.tsx +50 -0
- package/src/FocusZone.types.ts +16 -16
- package/src/FocusZoneNativeComponent.ts +8 -6
- package/src/FocusZoneNativeComponent.win32.ts +18 -0
- package/src/__tests__/FocusZone.test.tsx +105 -125
- package/src/__tests__/FocusZone.types.test.ts +36 -0
- package/tsconfig.json +5 -7
- package/windows/ExperimentalFeatures.props +33 -0
- package/windows/FRNFocusZone/FRNFocusZone.def +3 -0
- package/windows/FRNFocusZone/FRNFocusZone.rc +0 -0
- package/windows/FRNFocusZone/FRNFocusZone.vcxproj +147 -0
- package/windows/FRNFocusZone/FRNFocusZone.vcxproj.filters +44 -0
- package/windows/FRNFocusZone/FocusZoneComponentView.cpp +590 -0
- package/windows/FRNFocusZone/FocusZoneComponentView.h +7 -0
- package/windows/FRNFocusZone/ReactPackageProvider.cpp +24 -0
- package/windows/FRNFocusZone/ReactPackageProvider.h +24 -0
- package/windows/FRNFocusZone/ReactPackageProvider.idl +9 -0
- package/windows/FRNFocusZone/codegen/.clang-format +2 -0
- package/windows/FRNFocusZone/codegen/react/components/FRNFocusZoneSpec/FocusZone.g.h +243 -0
- package/windows/FRNFocusZone/packages.lock.json +151 -0
- package/windows/FRNFocusZone/pch.cpp +1 -0
- package/windows/FRNFocusZone/pch.h +40 -0
- package/windows/FRNFocusZone/resource.h +5 -0
- package/windows/FRNFocusZone/targetver.h +8 -0
- package/windows/FRNFocusZone.sln +43 -0
- package/windows/NuGet.Config +13 -0
- package/src/FocusZone.ts +0 -57
- package/src/__tests__/__snapshots__/FocusZone.test.tsx.snap +0 -1516
package/macos/RCTFocusZone.m
CHANGED
|
@@ -21,6 +21,20 @@ static const CGFloat FocusZoneBuffer = 3;
|
|
|
21
21
|
|
|
22
22
|
@implementation RCTFocusZone
|
|
23
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
|
+
|
|
24
38
|
static inline CGFloat GetDistanceBetweenPoints(NSPoint point1, NSPoint point2)
|
|
25
39
|
{
|
|
26
40
|
NSPoint delta = NSMakePoint(point1.x - point2.x, point1.y - point2.y);
|
|
@@ -55,21 +69,15 @@ static inline CGFloat GetMinDistanceBetweenRectVerticesAndPoint(NSRect rect, NSP
|
|
|
55
69
|
/// This function does not take into account the geometric position of the view.
|
|
56
70
|
static NSView *GetFirstFocusableViewWithin(NSView *parentView)
|
|
57
71
|
{
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
72
|
+
if ([[parentView subviews] count] < 1)
|
|
73
|
+
{
|
|
74
|
+
return nil;
|
|
75
|
+
}
|
|
62
76
|
|
|
63
77
|
for (NSView *view in [parentView subviews]) {
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
if ([backedTextInputView acceptsFirstResponder]) {
|
|
68
|
-
return backedTextInputView;
|
|
69
|
-
}
|
|
70
|
-
} else {
|
|
71
|
-
return view;
|
|
72
|
-
}
|
|
78
|
+
NSView *focusableView = GetFocusableView(view);
|
|
79
|
+
if (focusableView) {
|
|
80
|
+
return focusableView;
|
|
73
81
|
}
|
|
74
82
|
|
|
75
83
|
NSView *match = GetFirstFocusableViewWithin(view);
|
|
@@ -86,8 +94,9 @@ static NSView *GetFirstFocusableViewWithin(NSView *parentView)
|
|
|
86
94
|
static NSView *GetLastFocusableViewWithin(NSView *parentView)
|
|
87
95
|
{
|
|
88
96
|
for (NSView *view in [[parentView subviews] reverseObjectEnumerator]) {
|
|
89
|
-
|
|
90
|
-
|
|
97
|
+
NSView *focusableView = GetFocusableView(view);
|
|
98
|
+
if (focusableView) {
|
|
99
|
+
return focusableView;
|
|
91
100
|
}
|
|
92
101
|
|
|
93
102
|
NSView *match = GetLastFocusableViewWithin(view);
|
|
@@ -98,6 +107,18 @@ static NSView *GetLastFocusableViewWithin(NSView *parentView)
|
|
|
98
107
|
return nil;
|
|
99
108
|
}
|
|
100
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
|
+
|
|
101
122
|
static NSView *GetFirstResponder(NSWindow *window)
|
|
102
123
|
{
|
|
103
124
|
NSResponder *responder = [window firstResponder];
|
|
@@ -533,6 +554,32 @@ static BOOL ShouldSkipFocusZone(NSView *view)
|
|
|
533
554
|
return nextViewToFocus;
|
|
534
555
|
}
|
|
535
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
|
+
|
|
536
583
|
- (NSView *)nextViewToFocusForTab:(FocusZoneAction)action
|
|
537
584
|
{
|
|
538
585
|
[[self window] recalculateKeyViewLoop];
|
|
@@ -551,7 +598,15 @@ static BOOL ShouldSkipFocusZone(NSView *view)
|
|
|
551
598
|
if (nextViewToFocus == self)
|
|
552
599
|
nextViewToFocus = forward ? [nextViewToFocus nextValidKeyView] : [nextViewToFocus previousValidKeyView];;
|
|
553
600
|
|
|
554
|
-
if ([
|
|
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])
|
|
555
610
|
return nextViewToFocus;
|
|
556
611
|
|
|
557
612
|
if ([@"NavigateStopAtEnds" isEqual:tabKeyNavigation])
|
|
@@ -565,7 +620,11 @@ static BOOL ShouldSkipFocusZone(NSView *view)
|
|
|
565
620
|
aView = forward ? [aView previousValidKeyView] : [aView nextValidKeyView];
|
|
566
621
|
}
|
|
567
622
|
|
|
568
|
-
|
|
623
|
+
if (nextViewToFocus != firstResponder)
|
|
624
|
+
return nextViewToFocus;
|
|
625
|
+
|
|
626
|
+
NSView *wrapView = forward ? GetFirstFocusableViewWithin(self) : GetLastFocusableViewWithin(self);
|
|
627
|
+
return wrapView != firstResponder ? wrapView : nil;
|
|
569
628
|
}
|
|
570
629
|
|
|
571
630
|
- (BOOL)isFlipped
|
|
@@ -0,0 +1,201 @@
|
|
|
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
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@fluentui-react-native/focus-zone",
|
|
3
|
-
"version": "0.23.
|
|
3
|
+
"version": "0.23.4",
|
|
4
4
|
"description": "A cross-platform FocusZone component using the Fluent Design System",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"author": "",
|
|
@@ -30,28 +30,28 @@
|
|
|
30
30
|
"update-snapshots": "fluentui-scripts jest -u"
|
|
31
31
|
},
|
|
32
32
|
"dependencies": {
|
|
33
|
-
"@fluentui-react-native/
|
|
34
|
-
"@fluentui-react-native/interactive-hooks": "0.28.9"
|
|
35
|
-
"@uifabricshared/foundation-composable": "0.15.3",
|
|
36
|
-
"@uifabricshared/foundation-settings": "0.16.9"
|
|
33
|
+
"@fluentui-react-native/framework-base": "0.7.0",
|
|
34
|
+
"@fluentui-react-native/interactive-hooks": "0.28.9"
|
|
37
35
|
},
|
|
38
36
|
"devDependencies": {
|
|
39
37
|
"@babel/core": "^7.20.0",
|
|
38
|
+
"@fluentui-react-native/desktop-driver": "0.2.0",
|
|
40
39
|
"@fluentui-react-native/scripts": "0.1.0",
|
|
41
40
|
"@office-iss/react-native-win32": "^0.81.8",
|
|
42
41
|
"@react-native-community/cli": "^20.0.0",
|
|
43
42
|
"@react-native-community/cli-platform-android": "^20.0.0",
|
|
44
43
|
"@react-native-community/cli-platform-ios": "^20.0.0",
|
|
45
44
|
"@react-native/babel-preset": "^0.81.0",
|
|
46
|
-
"@react-native/metro-babel-transformer": "^0.81.0",
|
|
47
45
|
"@react-native/metro-config": "^0.81.0",
|
|
46
|
+
"@testing-library/react-native": "^14.0.1",
|
|
48
47
|
"@types/react": "~19.1.4",
|
|
49
48
|
"@types/react-test-renderer": "^19.1.0",
|
|
50
49
|
"react": "19.1.4",
|
|
51
50
|
"react-native": "^0.81.6",
|
|
52
51
|
"react-native-macos": "^0.81.0",
|
|
53
52
|
"react-native-windows": "^0.81.0",
|
|
54
|
-
"react-test-renderer": "19.1.4"
|
|
53
|
+
"react-test-renderer": "19.1.4",
|
|
54
|
+
"test-renderer": "1.1.0"
|
|
55
55
|
},
|
|
56
56
|
"peerDependencies": {
|
|
57
57
|
"@office-iss/react-native-win32": "^0.74.0 || ^0.81.0",
|
|
@@ -75,9 +75,32 @@
|
|
|
75
75
|
"optional": true
|
|
76
76
|
}
|
|
77
77
|
},
|
|
78
|
+
"codegenConfig": {
|
|
79
|
+
"name": "FRNFocusZoneSpec",
|
|
80
|
+
"type": "all",
|
|
81
|
+
"jsSrcsDir": "src",
|
|
82
|
+
"ios": {
|
|
83
|
+
"componentProvider": {
|
|
84
|
+
"FocusZone": "RCTFocusZoneComponentView"
|
|
85
|
+
}
|
|
86
|
+
},
|
|
87
|
+
"windows": {
|
|
88
|
+
"generators": "componentsWindows",
|
|
89
|
+
"namespace": "FRNFocusZoneCodegen",
|
|
90
|
+
"outputDirectory": "windows/FRNFocusZone/codegen",
|
|
91
|
+
"separateDataTypes": true
|
|
92
|
+
}
|
|
93
|
+
},
|
|
78
94
|
"furn": {
|
|
79
95
|
"jestPlatform": "win32"
|
|
80
96
|
},
|
|
97
|
+
"react-native-windows": {
|
|
98
|
+
"init-windows": {
|
|
99
|
+
"name": "FRNFocusZone",
|
|
100
|
+
"namespace": "FRNFocusZone",
|
|
101
|
+
"template": "cpp-lib"
|
|
102
|
+
}
|
|
103
|
+
},
|
|
81
104
|
"rnx-kit": {
|
|
82
105
|
"kitType": "library",
|
|
83
106
|
"alignDeps": {
|
|
@@ -88,7 +111,6 @@
|
|
|
88
111
|
"core-ios",
|
|
89
112
|
"core-macos",
|
|
90
113
|
"core-windows",
|
|
91
|
-
"metro-react-native-babel-transformer",
|
|
92
114
|
"react",
|
|
93
115
|
"react-test-renderer"
|
|
94
116
|
]
|
|
@@ -0,0 +1,50 @@
|
|
|
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
CHANGED
|
@@ -1,16 +1,13 @@
|
|
|
1
1
|
import type * as React from 'react';
|
|
2
|
+
import type { ViewProps } from 'react-native';
|
|
2
3
|
|
|
3
|
-
import type { IViewProps } from '@fluentui-react-native/adapters';
|
|
4
4
|
import type { IFocusable } from '@fluentui-react-native/interactive-hooks';
|
|
5
|
-
import type { IRenderData } from '@uifabricshared/foundation-composable';
|
|
6
5
|
|
|
7
6
|
export const focusZoneName = 'FocusZone';
|
|
8
7
|
|
|
9
|
-
|
|
10
|
-
type EmptyInterface = {};
|
|
11
|
-
export type FocusZoneState = EmptyInterface;
|
|
8
|
+
export type FocusZoneState = Record<never, never>;
|
|
12
9
|
|
|
13
|
-
export
|
|
10
|
+
export interface FocusZoneProps extends ViewProps {
|
|
14
11
|
/**
|
|
15
12
|
* A RefObject to access the IFocusable interface. Use this to access the public methods and properties of the component.
|
|
16
13
|
*/
|
|
@@ -19,7 +16,7 @@ export type FocusZoneProps = IViewProps & {
|
|
|
19
16
|
/**
|
|
20
17
|
* Optionally defines the initial tabbable element inside the FocusZone
|
|
21
18
|
*/
|
|
22
|
-
defaultTabbableElement?: React.RefObject<React.Component> | string;
|
|
19
|
+
defaultTabbableElement?: React.RefObject<React.Component | null> | string;
|
|
23
20
|
|
|
24
21
|
/**
|
|
25
22
|
** Defines which arrows to react to
|
|
@@ -61,11 +58,6 @@ export type FocusZoneProps = IViewProps & {
|
|
|
61
58
|
*/
|
|
62
59
|
tabKeyNavigation?: FocusZoneTabNavigation;
|
|
63
60
|
|
|
64
|
-
/**
|
|
65
|
-
* Callback called when “focus” event triggered in FocusZone
|
|
66
|
-
*/
|
|
67
|
-
onFocus?: (e?: any) => void;
|
|
68
|
-
|
|
69
61
|
/**
|
|
70
62
|
* @platform macos
|
|
71
63
|
* By default, the Apple KeyView loop is calculated based on the UI tree hierarchy, accessibility properties,
|
|
@@ -83,9 +75,10 @@ export type FocusZoneProps = IViewProps & {
|
|
|
83
75
|
* of the MacOS KeyView loop mechanics.
|
|
84
76
|
*/
|
|
85
77
|
navigationOrderInRenderOrder?: boolean;
|
|
86
|
-
}
|
|
78
|
+
}
|
|
87
79
|
|
|
88
|
-
export interface NativeProps extends Omit<FocusZoneProps, 'isCircularNavigation'> {
|
|
80
|
+
export interface NativeProps extends Omit<FocusZoneProps, 'componentRef' | 'defaultTabbableElement' | 'isCircularNavigation'> {
|
|
81
|
+
defaultTabbableElement?: number | string;
|
|
89
82
|
navigateAtEnd?: NavigateAtEnd;
|
|
90
83
|
tabKeyNavigation?: FocusZoneTabNavigation;
|
|
91
84
|
}
|
|
@@ -107,14 +100,21 @@ export type FocusZoneTabNavigation =
|
|
|
107
100
|
| 'NavigateStopAtEnds' /* Navigate the FZ with Tab. Stop navigation at ends */
|
|
108
101
|
| 'Normal'; /* Navigate the FZ with Tab. Don't trap focus, tabbing at ends moves you out */
|
|
109
102
|
|
|
110
|
-
|
|
103
|
+
/** @deprecated FocusZone is an unstyled primitive and does not resolve tokens. */
|
|
104
|
+
export type FocusZoneTokens = Record<never, never>;
|
|
111
105
|
|
|
106
|
+
/** @deprecated Use FocusZoneProps. */
|
|
112
107
|
export interface FocusZoneSlotProps {
|
|
113
108
|
root: NativeProps;
|
|
114
109
|
}
|
|
115
110
|
|
|
116
|
-
|
|
111
|
+
/** @deprecated FocusZone uses the phased primitive component pattern. */
|
|
112
|
+
export interface FocusZoneRenderData {
|
|
113
|
+
slotProps?: FocusZoneSlotProps;
|
|
114
|
+
state?: FocusZoneState;
|
|
115
|
+
}
|
|
117
116
|
|
|
117
|
+
/** @deprecated Use FocusZoneProps. */
|
|
118
118
|
export interface FocusZoneType {
|
|
119
119
|
props: FocusZoneProps;
|
|
120
120
|
tokens: FocusZoneTokens;
|
|
@@ -5,11 +5,8 @@
|
|
|
5
5
|
*/
|
|
6
6
|
import codegenNativeComponent from 'react-native/Libraries/Utilities/codegenNativeComponent';
|
|
7
7
|
|
|
8
|
-
import type { ViewProps } from 'react-native';
|
|
9
|
-
import type {
|
|
10
|
-
|
|
11
|
-
// Should be:
|
|
12
|
-
// import type { UnsafeObject } from 'react-native/Libraries/Types/CodegenTypes';
|
|
8
|
+
import type { HostComponent, ViewProps } from 'react-native';
|
|
9
|
+
import type { UnsafeMixed, WithDefault } from 'react-native/Libraries/Types/CodegenTypes';
|
|
13
10
|
|
|
14
11
|
export interface NativeProps extends ViewProps {
|
|
15
12
|
navigateAtEnd?: WithDefault<'NavigateStopAtEnds' | 'NavigateWrap' | 'NavigateContinue', 'NavigateStopAtEnds'>;
|
|
@@ -19,6 +16,11 @@ export interface NativeProps extends ViewProps {
|
|
|
19
16
|
tabKeyNavigation?: WithDefault<'None' | 'NavigateWrap' | 'NavigateStopAtEnds' | 'Normal', 'None'>;
|
|
20
17
|
disabled?: boolean;
|
|
21
18
|
isTabNavigation?: boolean;
|
|
19
|
+
navigationOrderInRenderOrder?: boolean;
|
|
22
20
|
}
|
|
23
21
|
|
|
24
|
-
export
|
|
22
|
+
export type FocusZoneComponentType = HostComponent<NativeProps>;
|
|
23
|
+
|
|
24
|
+
export default codegenNativeComponent<NativeProps>('FocusZone', {
|
|
25
|
+
paperComponentName: 'RCTFocusZone',
|
|
26
|
+
}) as FocusZoneComponentType;
|
|
@@ -0,0 +1,18 @@
|
|
|
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;
|