-
Notifications
You must be signed in to change notification settings - Fork 3.9k
35756 close emoji when navigation back #38693
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
Changes from all commits
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 | ||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -1,12 +1,12 @@ | ||||||||||||||||||||||||
| import React, {useState} from 'react'; | ||||||||||||||||||||||||
| import React, {useEffect, useRef, useState} from 'react'; | ||||||||||||||||||||||||
| import useStyleUtils from '@hooks/useStyleUtils'; | ||||||||||||||||||||||||
| import useTheme from '@hooks/useTheme'; | ||||||||||||||||||||||||
| import StatusBar from '@libs/StatusBar'; | ||||||||||||||||||||||||
| import CONST from '@src/CONST'; | ||||||||||||||||||||||||
| import BaseModal from './BaseModal'; | ||||||||||||||||||||||||
| import type BaseModalProps from './types'; | ||||||||||||||||||||||||
|
|
||||||||||||||||||||||||
| function Modal({fullscreen = true, onModalHide = () => {}, type, onModalShow = () => {}, children, ...rest}: BaseModalProps) { | ||||||||||||||||||||||||
| function Modal({fullscreen = true, onModalHide = () => {}, type, onModalShow = () => {}, children, shouldHandleNavigationBack, ...rest}: BaseModalProps) { | ||||||||||||||||||||||||
| const theme = useTheme(); | ||||||||||||||||||||||||
| const StyleUtils = useStyleUtils(); | ||||||||||||||||||||||||
| const [previousStatusBarColor, setPreviousStatusBarColor] = useState<string>(); | ||||||||||||||||||||||||
|
|
@@ -22,8 +22,15 @@ function Modal({fullscreen = true, onModalHide = () => {}, type, onModalShow = ( | |||||||||||||||||||||||
| const hideModal = () => { | ||||||||||||||||||||||||
| setStatusBarColor(previousStatusBarColor); | ||||||||||||||||||||||||
| onModalHide(); | ||||||||||||||||||||||||
| if (window.history.state.shouldGoBack) { | ||||||||||||||||||||||||
| window.history.back(); | ||||||||||||||||||||||||
| } | ||||||||||||||||||||||||
| }; | ||||||||||||||||||||||||
|
|
||||||||||||||||||||||||
| const handlePopStateRef = useRef(() => { | ||||||||||||||||||||||||
| rest.onClose(); | ||||||||||||||||||||||||
| }); | ||||||||||||||||||||||||
|
|
||||||||||||||||||||||||
| const showModal = () => { | ||||||||||||||||||||||||
| const statusBarColor = StatusBar.getBackgroundColor() ?? theme.appBG; | ||||||||||||||||||||||||
|
|
||||||||||||||||||||||||
|
|
@@ -35,9 +42,20 @@ function Modal({fullscreen = true, onModalHide = () => {}, type, onModalShow = ( | |||||||||||||||||||||||
| setStatusBarColor(isFullScreenModal ? theme.appBG : StyleUtils.getThemeBackgroundColor(statusBarColor)); | ||||||||||||||||||||||||
| } | ||||||||||||||||||||||||
|
|
||||||||||||||||||||||||
| if (shouldHandleNavigationBack) { | ||||||||||||||||||||||||
| window.history.pushState({shouldGoBack: true}, '', null); | ||||||||||||||||||||||||
| window.addEventListener('popstate', handlePopStateRef.current); | ||||||||||||||||||||||||
| } | ||||||||||||||||||||||||
|
Comment on lines
+45
to
+48
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. This addition contributed to creating the following issue: Explanation: (from this proposal RCA) App/src/components/Modal/index.tsx Lines 46 to 49 in dd96852
It's triggered when we call App/src/components/Modal/index.tsx Lines 23 to 29 in dd96852
However, the Long-press comment -> context menu shown -> press add emoji reaction -> push state, shouldGoBack: true -> context menu hides -> history.back -> triggers popstate -> emoji picker closes. |
||||||||||||||||||||||||
| onModalShow?.(); | ||||||||||||||||||||||||
| }; | ||||||||||||||||||||||||
|
|
||||||||||||||||||||||||
| useEffect( | ||||||||||||||||||||||||
| () => () => { | ||||||||||||||||||||||||
| window.removeEventListener('popstate', handlePopStateRef.current); | ||||||||||||||||||||||||
| }, | ||||||||||||||||||||||||
| [], | ||||||||||||||||||||||||
| ); | ||||||||||||||||||||||||
|
|
||||||||||||||||||||||||
| return ( | ||||||||||||||||||||||||
| <BaseModal | ||||||||||||||||||||||||
| // eslint-disable-next-line react/jsx-props-no-spreading | ||||||||||||||||||||||||
|
|
||||||||||||||||||||||||
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 are using a ref for the
popstate, and in some cases, the 'popstate' event uses a staleonClosefunction, which caused the issue described in Expensify/App#69781. We have applied the fix here:#70820
#72200