-
Notifications
You must be signed in to change notification settings - Fork 3.2k
Block activation of primary buttons on background screens #8802
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
Merged
Merged
Changes from 7 commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
4beb1d6
Add navigation fallback HOC
parasharrajat 1f4e219
Attach the navigation fallback to the Button component
parasharrajat 7ee9f64
Merge branch 'main' of github.com:Expensify/Expensify.cash into butto…
parasharrajat 879794f
Add PressOnEnter on the Request Call page
parasharrajat 17c28a5
chg: refactor fallback HOC to class component and fix the noop functions
parasharrajat 17e974e
Add PressOnEnter story
parasharrajat 7af9eb7
fix: imports
parasharrajat 4f273cc
Only trigger pressOnEnter when Button on active screen
parasharrajat File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
import React, {Component} from 'react'; | ||
import PropTypes from 'prop-types'; | ||
import {NavigationContext} from '@react-navigation/core'; | ||
import getComponentDisplayName from '../libs/getComponentDisplayName'; | ||
|
||
export default function (WrappedComponent) { | ||
class WithNavigationFallback extends Component { | ||
parasharrajat marked this conversation as resolved.
Show resolved
Hide resolved
|
||
render() { | ||
if (!this.context) { | ||
return ( | ||
<NavigationContext.Provider | ||
value={{ | ||
isFocused: () => true, | ||
addListener: () => () => {}, | ||
removeListener: () => () => {}, | ||
}} | ||
> | ||
<WrappedComponent | ||
// eslint-disable-next-line react/jsx-props-no-spreading | ||
{...this.props} | ||
ref={this.props.forwardedRef} | ||
/> | ||
</NavigationContext.Provider> | ||
); | ||
} | ||
|
||
// eslint-disable-next-line react/jsx-props-no-spreading | ||
return <WrappedComponent {...this.props} ref={this.props.forwardedRef} />; | ||
} | ||
} | ||
WithNavigationFallback.contextType = NavigationContext; | ||
WithNavigationFallback.displayName = `WithNavigationFocusWithFallback(${getComponentDisplayName(WrappedComponent)})`; | ||
WithNavigationFallback.propTypes = { | ||
forwardedRef: PropTypes.oneOfType([ | ||
PropTypes.func, | ||
PropTypes.shape({current: PropTypes.instanceOf(React.Component)}), | ||
]), | ||
}; | ||
WithNavigationFallback.defaultProps = { | ||
forwardedRef: undefined, | ||
}; | ||
return React.forwardRef((props, ref) => ( | ||
// eslint-disable-next-line react/jsx-props-no-spreading | ||
<WithNavigationFallback {...props} forwardedRef={ref} /> | ||
)); | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
What does the withNavigationFocus do here?
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.
Oh, I forgot to push the final commit. Good catch.
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.
I'm still not seeing how it is used, could you explain please?
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 HOC gives is a new prop called
isFocused
and we are using that to determine if the button is visible on the currently focused/active screen. This way all the buttons on the backgrounded screens will not trigge withenter
press.