-
Notifications
You must be signed in to change notification settings - Fork 135
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
Fixing setting focus when RCTView is not yet in window #1398
Conversation
I have a scenario where I send the `focus` command to a component from it's `componentDidMount` lifecycle, which leads native code to try to set focus to a RCTView with a zero frame (okay...) that isn't in a window (also seems unexpected). I see there's existing code that tries to deal with this for a particular RCTBaseTextInputView, but nothing generically for RCTView. I'm trying to extend that to the RCTView. As part of that, I considered using the existing pending focus flag, but that seems suspect because we could have multiple views competing for focus -- so I am opting to change it to a single, weak ref for the currently *pending* focus view (which we clear if someone else grabs, or attempts to grab focus, or if the pending view later resigns focus, in addition to the scenario already handled viz. pending focus view gets focus). I have been able to validate these changes against 0.66 for my scenario.
Two questions:
EDIT: I see now you kept
|
How about I add the tags for now? I need this to mitigate a11y concerns for my feature, which can't proceed without these fixes, which is also why for expediency I am making (proposing) these changes to the Microsoft fork. |
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.
Wanna double check the diffs with Core, but tested and works fine! Textinput autofocus isn't broken on iOS or macOS, and the new FocusOnMount page works on macOS :)
Cherry picking from main branch -- 8b8fc61
Cherry picking from main branch -- 8b8fc61
Please select one of the following
Summary
I have a scenario where I send the
focus
command to a component from it'scomponentDidMount
lifecycle, which leads native code to try to set focus to a RCTView with a zero frame (okay...) that isn't in a window (also seems unexpected). Not surprisingly, not being in a window means the view can't be focused. For comparison, I have the same behavior working as expected on the Win32\Office flavor of React Native.I see there's existing code that tries to deal with this for a particular RCTBaseTextInputView, but nothing generically for RCTView. I'm trying to extend that to the RCTView. As part of that, I considered using the existing pending focus flag, but that seems suspect because we could have multiple views competing for focus -- so I am opting to change it to a single, weak ref for the currently pending focus view (which we clear if someone else grabs, or attempts to grab focus, or if the pending view later resigns focus, in addition to the scenario already handled viz. pending focus view gets focus).
Changelog
[macOS/iOS] [Changed] - Extend reactFocusIfNeeded to work with any generic RCTView
Test Plan
I have been able to validate these changes against 0.66 for my scenario.
I have added a test page to RNTester to check before\after (repro before, resolved after)