Repository navigation
Make More Features animation more obvious and add tap target v2 #74540
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
996b6cc
275e66f
c0047e9
11a0af7
30e8650
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 |
|---|---|---|
|
|
@@ -2,6 +2,7 @@ import React, {useCallback, useEffect, useState} from 'react'; | |
| import {View} from 'react-native'; | ||
| import ConfirmModal from '@components/ConfirmModal'; | ||
| import HeaderWithBackButton from '@components/HeaderWithBackButton'; | ||
| import Hoverable from '@components/Hoverable'; | ||
| import * as Illustrations from '@components/Icon/Illustrations'; | ||
| import ScreenWrapper from '@components/ScreenWrapper'; | ||
| import ScrollView from '@components/ScrollView'; | ||
|
|
@@ -67,6 +68,7 @@ type Item = { | |
| pendingAction: PendingAction | undefined; | ||
| errors?: Errors; | ||
| onCloseError?: () => void; | ||
| onPress?: () => void; | ||
| }; | ||
|
|
||
| type SectionObject = { | ||
|
|
@@ -147,6 +149,12 @@ function WorkspaceMoreFeaturesPage({policy, route}: WorkspaceMoreFeaturesPagePro | |
| } | ||
| enablePolicyDistanceRates(policyID, isEnabled, distanceRateCustomUnit); | ||
| }, | ||
| onPress: () => { | ||
| if (!policyID) { | ||
| return; | ||
| } | ||
| Navigation.navigate(ROUTES.WORKSPACE_DISTANCE_RATES.getRoute(policyID)); | ||
| }, | ||
| }, | ||
| { | ||
| icon: illustrations.HandCard, | ||
|
|
@@ -164,6 +172,12 @@ function WorkspaceMoreFeaturesPage({policy, route}: WorkspaceMoreFeaturesPagePro | |
| disabledAction: () => { | ||
| setIsDisableExpensifyCardWarningModalOpen(true); | ||
| }, | ||
| onPress: () => { | ||
| if (!policyID) { | ||
| return; | ||
| } | ||
| Navigation.navigate(ROUTES.WORKSPACE_EXPENSIFY_CARD.getRoute(policyID)); | ||
| }, | ||
| }, | ||
| ]; | ||
|
|
||
|
|
@@ -183,6 +197,12 @@ function WorkspaceMoreFeaturesPage({policy, route}: WorkspaceMoreFeaturesPagePro | |
| disabledAction: () => { | ||
| setIsDisableCompanyCardsWarningModalOpen(true); | ||
| }, | ||
| onPress: () => { | ||
| if (!policyID) { | ||
| return; | ||
| } | ||
| Navigation.navigate(ROUTES.WORKSPACE_COMPANY_CARDS.getRoute(policyID)); | ||
| }, | ||
| }); | ||
|
|
||
| spendItems.push({ | ||
|
|
@@ -201,6 +221,12 @@ function WorkspaceMoreFeaturesPage({policy, route}: WorkspaceMoreFeaturesPagePro | |
| } | ||
| enablePerDiem(policyID, isEnabled, perDiemCustomUnit?.customUnitID, true, quickAction); | ||
| }, | ||
| onPress: () => { | ||
| if (!policyID) { | ||
| return; | ||
| } | ||
| Navigation.navigate(ROUTES.WORKSPACE_PER_DIEM.getRoute(policyID)); | ||
| }, | ||
| }); | ||
|
|
||
| const manageItems: Item[] = [ | ||
|
|
@@ -218,6 +244,12 @@ function WorkspaceMoreFeaturesPage({policy, route}: WorkspaceMoreFeaturesPagePro | |
| }, | ||
| disabled: isSmartLimitEnabled, | ||
| disabledAction: onDisabledWorkflowPress, | ||
| onPress: () => { | ||
| if (!policyID) { | ||
| return; | ||
| } | ||
| Navigation.navigate(ROUTES.WORKSPACE_WORKFLOWS.getRoute(policyID)); | ||
| }, | ||
| }, | ||
| { | ||
| icon: illustrations.Rules, | ||
|
|
@@ -236,6 +268,12 @@ function WorkspaceMoreFeaturesPage({policy, route}: WorkspaceMoreFeaturesPagePro | |
| } | ||
| enablePolicyRules(policyID, isEnabled); | ||
| }, | ||
| onPress: () => { | ||
| if (!policyID) { | ||
| return; | ||
| } | ||
| Navigation.navigate(ROUTES.WORKSPACE_RULES.getRoute(policyID)); | ||
| }, | ||
| }, | ||
| ]; | ||
|
|
||
|
|
@@ -252,6 +290,12 @@ function WorkspaceMoreFeaturesPage({policy, route}: WorkspaceMoreFeaturesPagePro | |
| } | ||
| enablePolicyInvoicing(policyID, isEnabled); | ||
| }, | ||
| onPress: () => { | ||
| if (!policyID) { | ||
| return; | ||
| } | ||
| Navigation.navigate(ROUTES.WORKSPACE_INVOICES.getRoute(policyID)); | ||
| }, | ||
| }, | ||
| ]; | ||
|
|
||
|
|
@@ -270,6 +314,12 @@ function WorkspaceMoreFeaturesPage({policy, route}: WorkspaceMoreFeaturesPagePro | |
| } | ||
| enablePolicyCategories(policyID, isEnabled, policyTagLists, policyCategories, allTransactionViolations, true); | ||
| }, | ||
| onPress: () => { | ||
| if (!policyID) { | ||
| return; | ||
| } | ||
| Navigation.navigate(ROUTES.WORKSPACE_CATEGORIES.getRoute(policyID)); | ||
| }, | ||
| }, | ||
| { | ||
| icon: illustrations.Tag, | ||
|
|
@@ -285,6 +335,12 @@ function WorkspaceMoreFeaturesPage({policy, route}: WorkspaceMoreFeaturesPagePro | |
| } | ||
| enablePolicyTags({policyID, enabled: isEnabled, policyTags: policyTagLists}); | ||
| }, | ||
| onPress: () => { | ||
| if (!policyID) { | ||
| return; | ||
| } | ||
| Navigation.navigate(ROUTES.WORKSPACE_TAGS.getRoute(policyID)); | ||
| }, | ||
| }, | ||
| { | ||
| icon: illustrations.Coins, | ||
|
|
@@ -300,6 +356,12 @@ function WorkspaceMoreFeaturesPage({policy, route}: WorkspaceMoreFeaturesPagePro | |
| } | ||
| enablePolicyTaxes(policyID, isEnabled); | ||
| }, | ||
| onPress: () => { | ||
| if (!policyID) { | ||
| return; | ||
| } | ||
| Navigation.navigate(ROUTES.WORKSPACE_TAXES.getRoute(policyID)); | ||
| }, | ||
| }, | ||
| ]; | ||
|
|
||
|
|
@@ -330,6 +392,12 @@ function WorkspaceMoreFeaturesPage({policy, route}: WorkspaceMoreFeaturesPagePro | |
| } | ||
| clearPolicyErrorField(policyID, CONST.POLICY.MORE_FEATURES.ARE_CONNECTIONS_ENABLED); | ||
| }, | ||
| onPress: () => { | ||
| if (!policyID) { | ||
| return; | ||
| } | ||
| Navigation.navigate(ROUTES.POLICY_ACCOUNTING.getRoute(policyID)); | ||
| }, | ||
| }, | ||
| ]; | ||
|
|
||
|
|
@@ -360,6 +428,12 @@ function WorkspaceMoreFeaturesPage({policy, route}: WorkspaceMoreFeaturesPagePro | |
| } | ||
| clearPolicyErrorField(policyID, CONST.POLICY.MORE_FEATURES.ARE_RECEIPT_PARTNERS_ENABLED); | ||
| }, | ||
| onPress: () => { | ||
| if (!policyID) { | ||
| return; | ||
| } | ||
| Navigation.navigate(ROUTES.WORKSPACE_RECEIPT_PARTNERS.getRoute(policyID)); | ||
| }, | ||
| }); | ||
| } | ||
|
|
||
|
|
@@ -391,30 +465,42 @@ function WorkspaceMoreFeaturesPage({policy, route}: WorkspaceMoreFeaturesPagePro | |
| }, | ||
| ]; | ||
|
|
||
| const getItemStyle = useCallback( | ||
| (item: Item, hovered: boolean) => [ | ||
| styles.workspaceSectionMoreFeaturesItem, | ||
| shouldUseNarrowLayout && styles.flexBasis100, | ||
| shouldUseNarrowLayout && StyleUtils.getMinimumWidth(0), | ||
| hovered && item.isActive && !!item.onPress && styles.hoveredComponentBG, | ||
| ], | ||
| [styles.workspaceSectionMoreFeaturesItem, styles.flexBasis100, styles.hoveredComponentBG, shouldUseNarrowLayout, StyleUtils], | ||
| ); | ||
|
|
||
| const renderItem = useCallback( | ||
| (item: Item) => ( | ||
| <View | ||
| key={item.titleTranslationKey} | ||
| style={[styles.workspaceSectionMoreFeaturesItem, shouldUseNarrowLayout && styles.flexBasis100, shouldUseNarrowLayout && StyleUtils.getMinimumWidth(0)]} | ||
| > | ||
| <ToggleSettingOptionRow | ||
| icon={item.icon} | ||
| disabled={item.disabled} | ||
| disabledAction={item.disabledAction} | ||
| title={translate(item.titleTranslationKey)} | ||
| titleStyle={styles.textStrong} | ||
| subtitle={translate(item.subtitleTranslationKey)} | ||
| switchAccessibilityLabel={translate(item.subtitleTranslationKey)} | ||
| isActive={item.isActive} | ||
| pendingAction={item.pendingAction} | ||
| onToggle={item.action} | ||
| showLockIcon={item.disabled} | ||
| errors={item.errors} | ||
| onCloseError={item.onCloseError} | ||
| /> | ||
| </View> | ||
| <Hoverable key={item.titleTranslationKey}> | ||
| {(hovered) => ( | ||
| <View style={getItemStyle(item, hovered)}> | ||
| <ToggleSettingOptionRow | ||
| icon={item.icon} | ||
| disabled={item.disabled} | ||
| disabledAction={item.disabledAction} | ||
| title={translate(item.titleTranslationKey)} | ||
| titleStyle={styles.textStrong} | ||
| subtitle={translate(item.subtitleTranslationKey)} | ||
| switchAccessibilityLabel={translate(item.subtitleTranslationKey)} | ||
| isActive={item.isActive} | ||
| pendingAction={item.pendingAction} | ||
| onToggle={item.action} | ||
| showLockIcon={item.disabled} | ||
| errors={item.errors} | ||
| onCloseError={item.onCloseError} | ||
| onPress={item.onPress} | ||
| /> | ||
| </View> | ||
| )} | ||
| </Hoverable> | ||
| ), | ||
|
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. ❌ PERF-6 (docs)The Suggested fix: Since |
||
| [styles, StyleUtils, shouldUseNarrowLayout, translate], | ||
| [styles, StyleUtils, shouldUseNarrowLayout, translate, getItemStyle], | ||
| ); | ||
|
|
||
| /** Used to fill row space in the Section items when there are odd number of items to create equal margins for last odd item. */ | ||
|
|
||
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.
❌ PERF-4 (docs)
The
onPressfunction is created inline on every render, creating a new function reference each time. Since this is passed as a prop to item objects used in rendering, it will cause unnecessary re-renders.Suggested fix: Use
useCallbackto memoize the function:Note: This same issue applies to all the other
onPresshandlers added in this PR (lines 175, 204, 247, 271, 289, 308, 318, 338, 359, 395, 431).