-
Notifications
You must be signed in to change notification settings - Fork 170
Move FocusZone away from bridge #4067
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
592c66b
c1341c6
706124c
631b508
496d38c
d909c6a
f993ed1
613c9ab
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,6 @@ | ||
| --- | ||
| "@fluentui-react-native/focus-zone": major | ||
| "@fluentui-react-native/tester": major | ||
| --- | ||
|
|
||
| Move FocusZone away from bridge | ||
This file was deleted.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,153 @@ | ||
| #import "RCTFocusZone.h" | ||
| #import "RCTFocusZoneManager.h" | ||
| #import <React/RCTConvert.h> | ||
| #import <React/RCTUIManager.h> | ||
|
|
||
| @implementation RCTFocusZoneManager | ||
|
|
||
| RCT_EXPORT_MODULE() | ||
|
|
||
| RCT_EXPORT_VIEW_PROPERTY(disabled, BOOL) | ||
|
|
||
| RCT_CUSTOM_VIEW_PROPERTY(navigationOrderInRenderOrder, BOOL, RCTFocusZone) | ||
| { | ||
| [view setNavigationOrderInRenderOrder:[json boolValue]]; | ||
| [[view window] recalculateKeyViewLoop]; | ||
| } | ||
|
|
||
| RCT_CUSTOM_VIEW_PROPERTY(focusZoneDirection, NSString, RCTFocusZone) | ||
| { | ||
| if ([json isEqualToString:@"bidirectional"]) | ||
| { | ||
| [view setFocusZoneDirection:FocusZoneDirectionBidirectional]; | ||
| } | ||
| else if ([json isEqualToString:@"vertical"]) | ||
| { | ||
| [view setFocusZoneDirection:FocusZoneDirectionVertical]; | ||
| } | ||
| else if ([json isEqualToString:@"horizontal"]) | ||
| { | ||
| [view setFocusZoneDirection:FocusZoneDirectionHorizontal]; | ||
| } | ||
| else if ([json isEqualToString:@"none"]) | ||
| { | ||
| [view setFocusZoneDirection:FocusZoneDirectionNone]; | ||
| } | ||
| else | ||
| { | ||
| [view setFocusZoneDirection:[defaultView focusZoneDirection]]; | ||
| } | ||
| } | ||
|
|
||
| RCT_EXPORT_VIEW_PROPERTY(navigateAtEnd, NSString) | ||
| RCT_EXPORT_VIEW_PROPERTY(tabKeyNavigation, NSString) | ||
|
|
||
| RCT_CUSTOM_VIEW_PROPERTY(defaultTabbableElement, NSNumber, RCTFocusZone) | ||
| { | ||
| NSNumber *tag = [RCTConvert NSNumber:json]; | ||
| RCTUIManager *manager = [[self bridge] uiManager]; | ||
| NSView *defaultResponder = [manager viewForReactTag:tag]; | ||
| [view setDefaultResponder:defaultResponder]; | ||
| } | ||
|
|
||
| - (RCTView *)view | ||
| { | ||
| return [RCTFocusZone new]; | ||
| } | ||
|
|
||
| @end | ||
|
|
||
| #ifdef RCT_NEW_ARCH_ENABLED | ||
|
|
||
| #include <react/renderer/components/RCTFocusZoneSpec/ComponentDescriptors.h> | ||
| #include <react/renderer/components/RCTFocusZoneSpec/Props.h> | ||
| #include <react/renderer/components/RCTFocusZoneSpec/RCTComponentViewHelpers.h> | ||
|
|
||
| #import <React/RCTFabricComponentsPlugins.h> | ||
|
|
||
| using namespace facebook::react; | ||
|
|
||
| @interface FocusZoneComponentView : RCTViewComponentView | ||
| @end | ||
|
|
||
| @implementation FocusZoneComponentView { | ||
| RCTFocusZone *_focusZoneView; | ||
| } | ||
|
|
||
| + (ComponentDescriptorProvider)componentDescriptorProvider | ||
| { | ||
| return concreteComponentDescriptorProvider<RCTFocusZoneComponentDescriptor>(); | ||
| } | ||
|
|
||
| - (instancetype)initWithFrame:(CGRect)frame | ||
| { | ||
| if (self = [super initWithFrame:frame]) { | ||
| _focusZoneView = [RCTFocusZone new]; | ||
| self.contentView = _focusZoneView; | ||
| } | ||
| return self; | ||
| } | ||
|
|
||
| - (void)updateProps:(const Props::Shared &)props oldProps:(const Props::Shared &)oldProps | ||
| { | ||
| const auto &newProps = static_cast<const RCTFocusZoneProps &>(*props); | ||
|
|
||
| _focusZoneView.disabled = newProps.disabled; | ||
| _focusZoneView.navigationOrderInRenderOrder = newProps.navigationOrderInRenderOrder; | ||
|
|
||
| switch (newProps.navigateAtEnd) { | ||
| case RCTFocusZoneNavigateAtEnd::NavigateWrap: | ||
| _focusZoneView.navigateAtEnd = @"NavigateWrap"; | ||
| break; | ||
| case RCTFocusZoneNavigateAtEnd::NavigateContinue: | ||
| _focusZoneView.navigateAtEnd = @"NavigateContinue"; | ||
| break; | ||
| case RCTFocusZoneNavigateAtEnd::NavigateStopAtEnds: | ||
| _focusZoneView.navigateAtEnd = @"NavigateStopAtEnds"; | ||
| break; | ||
| } | ||
|
|
||
| switch (newProps.focusZoneDirection) { | ||
| case RCTFocusZoneFocusZoneDirection::Bidirectional: | ||
| _focusZoneView.focusZoneDirection = FocusZoneDirectionBidirectional; | ||
| break; | ||
| case RCTFocusZoneFocusZoneDirection::Vertical: | ||
| _focusZoneView.focusZoneDirection = FocusZoneDirectionVertical; | ||
| break; | ||
| case RCTFocusZoneFocusZoneDirection::Horizontal: | ||
| _focusZoneView.focusZoneDirection = FocusZoneDirectionHorizontal; | ||
| break; | ||
| case RCTFocusZoneFocusZoneDirection::None: | ||
| _focusZoneView.focusZoneDirection = FocusZoneDirectionNone; | ||
| break; | ||
| } | ||
|
|
||
| switch (newProps.tabKeyNavigation) { | ||
| case RCTFocusZoneTabKeyNavigation::None: | ||
| _focusZoneView.tabKeyNavigation = @"None"; | ||
| break; | ||
| case RCTFocusZoneTabKeyNavigation::NavigateWrap: | ||
| _focusZoneView.tabKeyNavigation = @"NavigateWrap"; | ||
| break; | ||
| case RCTFocusZoneTabKeyNavigation::NavigateStopAtEnds: | ||
| _focusZoneView.tabKeyNavigation = @"NavigateStopAtEnds"; | ||
| break; | ||
| case RCTFocusZoneTabKeyNavigation::Normal: | ||
| _focusZoneView.tabKeyNavigation = @"Normal"; | ||
| break; | ||
| } | ||
|
|
||
| // defaultTabbableElement is not handled here: resolving a view by React tag | ||
| // requires the legacy UIManager and is not supported in the Fabric renderer. | ||
|
Comment on lines
+140
to
+141
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @acoates-ms any idea how one might be able to do this, suppose of you had to do it for windows?
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. In windows we still have a look up by tag in fabric. -- That may not have been the correct move if that isn't available in the other platforms. Also didn't we move to saying this property should be set using nativeId? - Maybe we'll have to force all SDXs to only use that method when using fabric?
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Talked offline a bit more, I think we should update this to handle setting by nativeID. And we'll need to make it backwards compatible too since internally, the JS and native code may not be in sync. |
||
|
|
||
| [super updateProps:props oldProps:oldProps]; | ||
| } | ||
|
|
||
| @end | ||
|
|
||
| Class<RCTComponentViewProtocol> RCTFocusZoneCls(void) | ||
| { | ||
| return FocusZoneComponentView.class; | ||
| } | ||
|
|
||
| #endif // RCT_NEW_ARCH_ENABLED | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@Saadnajmi please confirm
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We disallow major bumps in the repo as of now, and this should be additive not breaking. So I don' think this should be major.