-
Notifications
You must be signed in to change notification settings - Fork 3.1k
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
Focus compose box when navigate away from RHN #2050
Conversation
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.
lgtm
src/libs/Navigation/AppNavigator/createCustomModalStackNavigator.js
Outdated
Show resolved
Hide resolved
Tbh, I think we should just make an exception for this unique case. We can't avoid using the hook provided by |
Also, sorry, didn't quite understand what is being said about the CreateMenu here. |
Here I was just saying that I tested my previous solution with toggling the CreateMenu button, and it still worked. Nothing too interesting :D Update:I found a few navigation event listeners here (https://reactnavigation.org/docs/navigation-events/)
|
Just a heads up that we have @parasharrajat working on a similar issue. I think this PR is possibly moving us in the opposite direction depending on how this all gets resolved. Said another way, if we figure out an alternative then I think these changes here won't be needed. |
Hmm I took a look at the similar PR and it kiiinda seems we may be doing the same thing in two different ways? Here's some thoughts which I thought could help: Here it looks like wrapping a component in Here is another example, without using Finally, Here you can see adding the I wonder if it's best to look for "which option is most readable / better long term"? Open to ideas though, what do you think @marcaaron ? |
That sounds right @Beamanator, the solutions work in similar ways. We have come up with some interesting ways to give other parts of the app insight into which pages or modals are in focus or not. At this point, I'm curious if we can find some other way to focus this |
@marcaaron I had an idea about this as well, here's a rough sketch: Have a interface FocusManager {
// restores focus to the last registered element
restoreFocus: () => void
// stores a react ref to a focusable item
register: (ref: ElementRef) => void
// remove stored ref
unregistrer: (ref: ElementRef) => void
} Have a render() {
return (
<WrappedComponent
{...this.props}
ref={el => this.focusableRef = el}
onFocus={(e => FocusManager.register(e.target))}
onBlur={(e => FocusManager.unregister(e.target))}
// onFocus/onBlur should also delegate to props.onFocus, props.onBlur if they exist...
/>
)
}
componentWillUnmount() {
// cleanup
FocusManager.unregister(this.focusableRef);
}
I've done something similar to support prev/next field navigation in react-native If this is something that should happen only on web/desktop a web specific modal components/solution can be used: https://reactjs.org/docs/accessibility.html#programmatically-managing-focus
|
@kidroca That sounds interesting, but probably would prefer a simpler solution to this current problem if possible. There are no multiple elements that need focus yet, just one, so I'm unsure what value there would be in implementing a focusable inputs stack. It does sound like exposing the input's ref so it can be triggered from other places is the right line of thinking. |
I agree, Kind of like By the way I see this exact behavior in mobile native for the Modals using |
…man-focusComposeWhenNavigateModalPages
[moving comment elsewhere] |
Looks like there's some undesired behavior regarding mobile device keyboards, but I believe we decided this will be fixed in a new issue / PR, so I think this can be re-reviewed & hopefully merged 👍 |
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.
This LGTM. Merging with the caveat that this will likely exacerbate some ongoing issues described here. As those issues are being worked on independently I think we can proceed here.
<If necessary, assign reviewers that know the area or changes well. Feel free to tag any additional reviewers you see fit.>
Details
Background: When users open & subsequently close a modal, focus should be given to the compose box to make the app as easy to use as possible.
This has been fixed & regressed multiple times
Now that we're more and more completely using React Navigation for our sub-pages (and moving away from pure modals), we can't rely on
BaseModal
'scomponentWillUnmount
as a catch-all for hiding modals (and therefore allowingReportActionCompose
to move the cursor to the compose box).We now have to rely on pure React Navigation components / functions in order to help us determine when those modal-like pages open & close.
Therefore, I set up Navigation listeners
focus
andbeforeRemove
which are used on modal screens to setmodal.isVisible
astrue
when the modal opens (a.k.a. is focused) andfalse
when the modal closes (a.k.a when we navigate away from a modal screen)Fixed Issues
Fixes https://github.com/Expensify/Expensify/issues/154180Fixes #1513
Tests
Tested On
Mobile Web(not needed)Android(not needed)Screenshots
Web
Screen.Recording.2021-03-24.at.9.40.58.PM.mov
Mobile Web
N/A because on mobile, closing a modal-page takes you to the LHN view
Desktop
Same as "Web"
iOS
Screen.Recording.2021-03-25.at.3.52.58.PM.mov
Android
N/A because on mobile, closing a modal-page takes you to the LHN view