From fb511db9e1e49e95dca9e38a14d5504cbd521937 Mon Sep 17 00:00:00 2001 From: dharmik Date: Tue, 19 Apr 2022 23:09:39 +0530 Subject: [PATCH 1/3] fix: 8329: Resolve fabmenu open multiple time --- src/libs/actions/WelcomeActions.js | 6 ++--- src/pages/home/sidebar/SidebarScreen.js | 30 ++++++++++++++++--------- 2 files changed, 22 insertions(+), 14 deletions(-) diff --git a/src/libs/actions/WelcomeActions.js b/src/libs/actions/WelcomeActions.js index f1db29c89f1e..6295cf18114e 100644 --- a/src/libs/actions/WelcomeActions.js +++ b/src/libs/actions/WelcomeActions.js @@ -45,9 +45,9 @@ Onyx.connect({ * * @param {Object} params * @param {Object} params.routes - * @param {Function} params.toggleCreateMenu + * @param {Function} params.hideCreateMenu */ -function show({routes, toggleCreateMenu}) { +function show({routes, hideCreateMenu}) { // NOTE: This setTimeout is required due to a bug in react-navigation where modals do not display properly in a drawerContent // This is a short-term workaround, see this issue for updates on a long-term solution: https://github.com/Expensify/App/issues/5296 setTimeout(() => { @@ -75,7 +75,7 @@ function show({routes, toggleCreateMenu}) { // It's also possible that we already have a workspace policy. In either case we will not toggle the menu but do still want to set the NVP in this case // since the user does not need to create a workspace. if (!Policy.isAdminOfFreePolicy(allPolicies) && !isDisplayingWorkspaceRoute) { - toggleCreateMenu(); + hideCreateMenu(); } }, 1500); } diff --git a/src/pages/home/sidebar/SidebarScreen.js b/src/pages/home/sidebar/SidebarScreen.js index 3d3d06ee5115..8df67953e4dd 100755 --- a/src/pages/home/sidebar/SidebarScreen.js +++ b/src/pages/home/sidebar/SidebarScreen.js @@ -44,9 +44,10 @@ class SidebarScreen extends Component { super(props); this.onCreateMenuItemSelected = this.onCreateMenuItemSelected.bind(this); - this.toggleCreateMenu = this.toggleCreateMenu.bind(this); + this.hideCreateMenu = this.hideCreateMenu.bind(this); this.startTimer = this.startTimer.bind(this); this.navigateToSettings = this.navigateToSettings.bind(this); + this.showCreateMenu = this.showCreateMenu.bind(this); this.state = { isCreateMenuActive: false, @@ -58,14 +59,23 @@ class SidebarScreen extends Component { Timing.start(CONST.TIMING.SIDEBAR_LOADED, true); const routes = lodashGet(this.props.navigation.getState(), 'routes', []); - WelcomeAction.show({routes, toggleCreateMenu: this.toggleCreateMenu}); + WelcomeAction.show({routes, hideCreateMenu: this.hideCreateMenu}); } /** * Method called when a Create Menu item is selected. */ onCreateMenuItemSelected() { - this.toggleCreateMenu(); + this.hideCreateMenu(); + } + + /** + * Method called when we click the floating action button + */ + showCreateMenu() { + this.setState({ + isCreateMenuActive: true, + }); } /** @@ -76,16 +86,14 @@ class SidebarScreen extends Component { } /** - * Method called when we click the floating action button - * will trigger the animation * Method called either when: * Pressing the floating action button to open the CreateMenu modal * Selecting an item on CreateMenu or closing it by clicking outside of the modal component */ - toggleCreateMenu() { - this.setState(state => ({ - isCreateMenuActive: !state.isCreateMenuActive, - })); + hideCreateMenu() { + this.setState({ + isCreateMenuActive: false, + }); } /** @@ -117,11 +125,11 @@ class SidebarScreen extends Component { accessibilityLabel={this.props.translate('sidebarScreen.fabNewChat')} accessibilityRole="button" isActive={this.state.isCreateMenuActive} - onPress={this.toggleCreateMenu} + onPress={this.showCreateMenu} /> Date: Thu, 21 Apr 2022 00:09:33 +0530 Subject: [PATCH 2/3] Resolve comment: onCreateMenuItemSelected from sidebarscreen. --- src/pages/home/sidebar/SidebarScreen.js | 10 +--------- 1 file changed, 1 insertion(+), 9 deletions(-) diff --git a/src/pages/home/sidebar/SidebarScreen.js b/src/pages/home/sidebar/SidebarScreen.js index 8df67953e4dd..158ba45a26ac 100755 --- a/src/pages/home/sidebar/SidebarScreen.js +++ b/src/pages/home/sidebar/SidebarScreen.js @@ -43,7 +43,6 @@ class SidebarScreen extends Component { constructor(props) { super(props); - this.onCreateMenuItemSelected = this.onCreateMenuItemSelected.bind(this); this.hideCreateMenu = this.hideCreateMenu.bind(this); this.startTimer = this.startTimer.bind(this); this.navigateToSettings = this.navigateToSettings.bind(this); @@ -62,13 +61,6 @@ class SidebarScreen extends Component { WelcomeAction.show({routes, hideCreateMenu: this.hideCreateMenu}); } - /** - * Method called when a Create Menu item is selected. - */ - onCreateMenuItemSelected() { - this.hideCreateMenu(); - } - /** * Method called when we click the floating action button */ @@ -132,7 +124,7 @@ class SidebarScreen extends Component { onClose={this.hideCreateMenu} isVisible={this.state.isCreateMenuActive} anchorPosition={styles.createMenuPositionSidebar} - onItemSelected={this.onCreateMenuItemSelected} + onItemSelected={this.hideCreateMenu} fromSidebarMediumScreen={!this.props.isSmallScreenWidth} menuItems={[ { From 1978bf7bbe6bc902bbaa3e61086176719b9c3eec Mon Sep 17 00:00:00 2001 From: dharmik Date: Thu, 21 Apr 2022 23:53:17 +0530 Subject: [PATCH 3/3] As per comment change the message in WelcomeActions. --- src/libs/actions/WelcomeActions.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/libs/actions/WelcomeActions.js b/src/libs/actions/WelcomeActions.js index 6295cf18114e..c67fab49f2e7 100644 --- a/src/libs/actions/WelcomeActions.js +++ b/src/libs/actions/WelcomeActions.js @@ -72,7 +72,7 @@ function show({routes, hideCreateMenu}) { const exitingToWorkspaceRoute = lodashGet(loginWithShortLivedTokenRoute, 'params.exitTo', '') === 'workspace/new'; const isDisplayingWorkspaceRoute = topRouteName.toLowerCase().includes('workspace') || exitingToWorkspaceRoute; - // It's also possible that we already have a workspace policy. In either case we will not toggle the menu but do still want to set the NVP in this case + // It's also possible that we already have a workspace policy. In either case we will not hide the menu but do still want to set the NVP in this case // since the user does not need to create a workspace. if (!Policy.isAdminOfFreePolicy(allPolicies) && !isDisplayingWorkspaceRoute) { hideCreateMenu();