-
Notifications
You must be signed in to change notification settings - Fork 570
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
fix(EMI-1396): Fix Android hardware back button in WebViews #9354
fix(EMI-1396): Fix Android hardware back button in WebViews #9354
Conversation
userAgent={userAgent} | ||
applicationNameForUserAgent={userAgent} |
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.
Updated the userAgent due to this reported issue
jest.mock("react-native-webview", () => { | ||
const React = require("react") | ||
const { View } = require("react-native") | ||
|
||
return { | ||
__esModule: true, | ||
default: React.forwardRef((props: any, ref: any) => { | ||
return <View ref={ref} {...props} /> | ||
}), | ||
} | ||
}) | ||
|
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 have to mock the package after the update due to the new architecture (react-native-webview/react-native-webview#2686 (comment))
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.
The tests should be fixed if you move the lines below to setupJEst file:
jest.mock("react-native-webview", () => {
const React = require("react")
const { View } = require("react-native")
return {
__esModule: true,
default: React.forwardRef((props: any, ref: any) => {
return <View ref={ref} {...props} />
}),
}
})
jest.mock("react-native-webview", () => { | ||
const React = require("react") | ||
const { View } = require("react-native") | ||
|
||
return { | ||
__esModule: true, | ||
default: React.forwardRef((props: any, ref: any) => { | ||
return <View ref={ref} {...props} /> | ||
}), | ||
} | ||
}) | ||
|
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.
fancy 🤑
src/app/Components/ArtsyWebView.tsx
Outdated
} | ||
} | ||
} | ||
onLeftButtonPress={useRightCloseButton && !canGoBack ? undefined : handleBackButtonPress} |
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.
nitpick(non-blocking): could we move this to an actual function with explicit returns over implicit ternary hell?
onLeftButtonPress={useRightCloseButton && !canGoBack ? undefined : handleBackButtonPress} | |
const handleLeftButtonPress = () => { | |
if (useRightCloseButton && !canGoBack) { | |
return | |
} | |
handleBackButtonPress() | |
} |
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.
➕
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 think you may have to make the onLeftOnButtonPress undefined explicitly if I remember correct otherwise the component renders buttons or something, 🤔 I may be remembering wrong but something to check
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.
@brainbicycle Yes! I tried a return
when the condition is met, and there was a button showing. I'll try to explicitly return undefined and see
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.
It always shows a button unless the prop is undefined (not a function) 🤷
But I will extract the trenary fo readability
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.
maybe we can update the component to not do that at some point, but def can be separate from this!
@@ -197,7 +197,7 @@ | |||
"react-native-url-polyfill": "1.3.0", | |||
"react-native-view-shot": "3.4.0", | |||
"react-native-vimeo-iframe": "1.2.1", | |||
"react-native-webview": "11.22.7", |
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.
nice!
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.
👋 bye bye old dependency
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.
nice one!
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.
🔥👏 awesome!
handleGoBack() | ||
} else { | ||
if (systemBackAction) { | ||
systemBackAction() |
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.
thought: I assume systemBackAction
does the same as above
if (isPresentedModally && !canGoBack) {
dismissModal()
} else if (!canGoBack) {
handleGoBack()
}
return true | ||
}) | ||
|
||
const leftButton = useRightCloseButton && !canGoBack ? undefined : handleBackButtonPress |
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.
suggestion: onLeftButtonPress*
This PR resolves EMI-1396
Description
This PR upgrades
react-native-webview
, and adds a handler for the back button in WebViewsVideos
android-before.mp4
android-after.mp4
ios-before.mov
ios-after.mov
PR Checklist
To the reviewers 👀
Changelog updates
Changelog updates
Cross-platform user-facing changes
iOS user-facing changes
Android user-facing changes
Dev changes
Need help with something? Have a look at our docs, or get in touch with us.