From 1d4d4c77763211063be58ae93ddb5424d17177f3 Mon Sep 17 00:00:00 2001 From: Amoralchik Date: Wed, 5 Mar 2025 19:59:55 +0200 Subject: [PATCH 1/6] Fix FAB button state synchronization with create menu activity --- src/components/Navigation/BottomTabBar/index.tsx | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/components/Navigation/BottomTabBar/index.tsx b/src/components/Navigation/BottomTabBar/index.tsx index eb9170a1d3fe..a5dc7b319667 100644 --- a/src/components/Navigation/BottomTabBar/index.tsx +++ b/src/components/Navigation/BottomTabBar/index.tsx @@ -74,6 +74,10 @@ function handleQueryWithPolicyID(query: SearchQueryString, activePolicyID?: stri function BottomTabBar({selectedTab, isTooltipAllowed = false}: BottomTabBarProps) { const {isCreateMenuActive, toggleCreateMenu, fabRef} = useContext(FABPopoverContext); + const [isFabActionActive, setIsFabActionActive] = useState(isCreateMenuActive); + useEffect(() => { + setIsFabActionActive(isCreateMenuActive); + }, [isCreateMenuActive]); const theme = useTheme(); const styles = useThemeStyles(); const {translate} = useLocalize(); @@ -288,9 +292,9 @@ function BottomTabBar({selectedTab, isTooltipAllowed = false}: BottomTabBarProps toggleCreateMenu(isCreateMenuActive)} + onPress={() => toggleCreateMenu(isFabActionActive)} isTooltipAllowed={isTooltipAllowed} /> From 6249f335be1dc47cbceccccbaebfa6ae16db1605 Mon Sep 17 00:00:00 2001 From: Amoralchik Date: Thu, 6 Mar 2025 05:44:11 +0200 Subject: [PATCH 2/6] Revert "Revert "Merge pull request #56602 from Amoralchik/clickable-emoji-for-exoense-task"" This reverts commit 65d675b382374ab7c792ad89cc1c76631fad835f. --- assets/images/customEmoji/global-create.svg | 14 ++ src/CONST.ts | 14 +- src/components/FABPopoverProvider.tsx | 133 ++++++++++++++++++ .../BaseHTMLEngineProvider.tsx | 1 + .../CustomEmojiWithDefaultPressableAction.tsx | 45 ++++++ .../HTMLRenderers/CustomEmojiRenderer.tsx | 42 ++++++ .../HTMLEngineProvider/HTMLRenderers/index.ts | 2 + .../Navigation/BottomTabBar/index.tsx | 15 +- src/libs/Navigation/NavigationRoot.tsx | 5 +- src/libs/ReportUtils.ts | 3 +- src/libs/actions/Policy/Policy.ts | 2 +- src/libs/actions/Report.ts | 1 + .../index.native.tsx | 3 - .../index.tsx | 46 ------ .../BottomTabBarFloatingActionButton/types.ts | 5 - ...er.tsx => FloatingActionButtonPopover.tsx} | 82 ++--------- src/styles/index.ts | 14 ++ src/styles/variables.ts | 1 + 18 files changed, 290 insertions(+), 138 deletions(-) create mode 100644 assets/images/customEmoji/global-create.svg create mode 100644 src/components/FABPopoverProvider.tsx create mode 100644 src/components/HTMLEngineProvider/CustomEmojiWithDefaultPressableAction.tsx create mode 100644 src/components/HTMLEngineProvider/HTMLRenderers/CustomEmojiRenderer.tsx delete mode 100644 src/pages/home/sidebar/BottomTabBarFloatingActionButton/index.native.tsx delete mode 100644 src/pages/home/sidebar/BottomTabBarFloatingActionButton/index.tsx delete mode 100644 src/pages/home/sidebar/BottomTabBarFloatingActionButton/types.ts rename src/pages/home/sidebar/{FloatingActionButtonAndPopover.tsx => FloatingActionButtonPopover.tsx} (90%) diff --git a/assets/images/customEmoji/global-create.svg b/assets/images/customEmoji/global-create.svg new file mode 100644 index 000000000000..60b46eb97aed --- /dev/null +++ b/assets/images/customEmoji/global-create.svg @@ -0,0 +1,14 @@ + + + + + + + diff --git a/src/CONST.ts b/src/CONST.ts index 122ab114d40e..2500b8fffb3e 100755 --- a/src/CONST.ts +++ b/src/CONST.ts @@ -156,7 +156,7 @@ const onboardingEmployerOrSubmitMessage: OnboardingMessage = { '\n' + 'Here’s how to submit an expense:\n' + '\n' + - '1. Click the green *+* button.\n' + + '1. Press the button.\n' + '2. Choose *Create expense*.\n' + '3. Enter an amount or scan a receipt.\n' + '4. Add your reimburser to the request.\n' + @@ -179,7 +179,7 @@ const combinedTrackSubmitOnboardingEmployerOrSubmitMessage: OnboardingMessage = '\n' + 'Here’s how to submit an expense:\n' + '\n' + - '1. Click the green *+* button.\n' + + '1. Press the button.\n' + '2. Choose *Create expense*.\n' + '3. Enter an amount or scan a receipt.\n' + '4. Add your reimburser to the request.\n' + @@ -203,7 +203,7 @@ const onboardingPersonalSpendMessage: OnboardingMessage = { '\n' + 'Here’s how to track an expense:\n' + '\n' + - '1. Click the green *+* button.\n' + + '1. Press the button.\n' + '2. Choose *Create expense*.\n' + '3. Enter an amount or scan a receipt.\n' + '4. Choose your *personal* space.\n' + @@ -226,7 +226,7 @@ const combinedTrackSubmitOnboardingPersonalSpendMessage: OnboardingMessage = { '\n' + 'Here’s how to track an expense:\n' + '\n' + - '1. Click the green *+* button.\n' + + '1. Press the button.\n' + '2. Choose *Create expense*.\n' + '3. Enter an amount or scan a receipt.\n' + '4. Choose your *personal* space.\n' + @@ -5337,7 +5337,7 @@ const CONST = { '\n' + 'Here’s how to start a chat:\n' + '\n' + - '1. Click the green *+* button.\n' + + '1. Press the button.\n' + '2. Choose *Start chat*.\n' + '3. Enter emails or phone numbers.\n' + '\n' + @@ -5354,7 +5354,7 @@ const CONST = { '\n' + 'Here’s how to request money:\n' + '\n' + - '1. Click the green *+* button.\n' + + '1. Press the button.\n' + '2. Choose *Start chat*.\n' + '3. Enter any email, SMS, or name of who you want to split with.\n' + '4. From within the chat, click the *+* button on the message bar, and click *Split expense*.\n' + @@ -5388,7 +5388,7 @@ const CONST = { '\n' + 'Here’s how to submit an expense:\n' + '\n' + - '1. Click the green *+* button.\n' + + '1. Press the button.\n' + '2. Choose *Create expense*.\n' + '3. Enter an amount or scan a receipt.\n' + '4. Add your reimburser to the request.\n' + diff --git a/src/components/FABPopoverProvider.tsx b/src/components/FABPopoverProvider.tsx new file mode 100644 index 000000000000..0436c973463f --- /dev/null +++ b/src/components/FABPopoverProvider.tsx @@ -0,0 +1,133 @@ +import {useIsFocused} from '@react-navigation/native'; +import type {ReactNode} from 'react'; +import React, {createContext, useCallback, useMemo, useRef, useState} from 'react'; +import type {View} from 'react-native'; +import useResponsiveLayout from '@hooks/useResponsiveLayout'; +import getPlatform from '@libs/getPlatform'; +import FloatingActionButtonPopover from '@pages/home/sidebar/FloatingActionButtonPopover'; +import CONST from '@src/CONST'; + +type FloatingActionButtonPopoverMenuRef = { + hideCreateMenu: () => void; +}; + +type FABPopoverContextValue = { + isCreateMenuActive: boolean; + hideCreateMenu: () => void; + toggleCreateMenu: (isFabActionActive: boolean) => void; + fabRef: React.RefObject; +}; + +const FABPopoverContext = createContext({ + isCreateMenuActive: false, + hideCreateMenu: () => {}, + toggleCreateMenu: () => {}, + fabRef: {current: null}, +}); + +type FABPopoverProviderProps = { + children: ReactNode; +}; + +function FABPopoverProvider({children}: FABPopoverProviderProps) { + const [isCreateMenuActive, setIsCreateMenuActive] = useState(false); + const fabRef = useRef(null); + const {shouldUseNarrowLayout} = useResponsiveLayout(); + const isFocused = useIsFocused(); + const platform = getPlatform(); + + const popoverModal = useRef(null); + + /** + * Method to hide popover when dragover. + */ + const hidePopoverOnDragOver = useCallback(() => { + if (!popoverModal.current) { + return; + } + popoverModal.current.hideCreateMenu(); + }, []); + + /** + * Method create event listener + */ + const createDragoverListener = () => { + if (platform !== CONST.PLATFORM.WEB) { + return; + } + document.addEventListener('dragover', hidePopoverOnDragOver); + }; + + /** + * Method remove event listener. + */ + const removeDragoverListener = () => { + if (platform !== CONST.PLATFORM.WEB) { + return; + } + document.removeEventListener('dragover', hidePopoverOnDragOver); + }; + + /** + * 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 + */ + const hideCreateMenu = useCallback( + () => { + if (!isCreateMenuActive) { + return; + } + setIsCreateMenuActive(false); + removeDragoverListener(); + }, + // eslint-disable-next-line react-compiler/react-compiler, react-hooks/exhaustive-deps + [isCreateMenuActive], + ); + + /** + * Method called when we click the floating action button + */ + const showCreateMenu = useCallback( + () => { + if (!isFocused && shouldUseNarrowLayout) { + return; + } + setIsCreateMenuActive(true); + createDragoverListener(); + }, + // eslint-disable-next-line react-compiler/react-compiler, react-hooks/exhaustive-deps + [isFocused, shouldUseNarrowLayout], + ); + + const toggleCreateMenu = useCallback( + (isFabActionActive: boolean) => { + if (isFabActionActive) { + hideCreateMenu(); + } else { + showCreateMenu(); + } + }, + [hideCreateMenu, showCreateMenu], + ); + + const value = useMemo( + () => ({ + isCreateMenuActive, + hideCreateMenu, + toggleCreateMenu, + fabRef, + }), + [isCreateMenuActive, toggleCreateMenu, hideCreateMenu, fabRef], + ); + + return ( + + + {children} + + ); +} + +export default FABPopoverProvider; +export {FABPopoverContext}; diff --git a/src/components/HTMLEngineProvider/BaseHTMLEngineProvider.tsx b/src/components/HTMLEngineProvider/BaseHTMLEngineProvider.tsx index 12b515194928..332255e53995 100755 --- a/src/components/HTMLEngineProvider/BaseHTMLEngineProvider.tsx +++ b/src/components/HTMLEngineProvider/BaseHTMLEngineProvider.tsx @@ -80,6 +80,7 @@ function BaseHTMLEngineProvider({textSelectable = false, children, enableExperim 'mention-user': HTMLElementModel.fromCustomModel({tagName: 'mention-user', contentModel: HTMLContentModel.textual}), 'mention-report': HTMLElementModel.fromCustomModel({tagName: 'mention-report', contentModel: HTMLContentModel.textual}), 'mention-here': HTMLElementModel.fromCustomModel({tagName: 'mention-here', contentModel: HTMLContentModel.textual}), + 'custom-emoji': HTMLElementModel.fromCustomModel({tagName: 'custom-emoji', contentModel: HTMLContentModel.textual}), 'next-step': HTMLElementModel.fromCustomModel({ tagName: 'next-step', mixedUAStyles: {...styles.textLabelSupporting, ...styles.lh16}, diff --git a/src/components/HTMLEngineProvider/CustomEmojiWithDefaultPressableAction.tsx b/src/components/HTMLEngineProvider/CustomEmojiWithDefaultPressableAction.tsx new file mode 100644 index 000000000000..325de14cdccb --- /dev/null +++ b/src/components/HTMLEngineProvider/CustomEmojiWithDefaultPressableAction.tsx @@ -0,0 +1,45 @@ +import type {ReactNode} from 'react'; +import React, {useContext, useEffect, useState} from 'react'; +import {FABPopoverContext} from '@components/FABPopoverProvider'; +import {PressableWithoutFeedback} from '@components/Pressable'; +import useLocalize from '@hooks/useLocalize'; +import useThemeStyles from '@hooks/useThemeStyles'; +import CONST from '@src/CONST'; + +type CustomEmojiWithDefaultPressableActionProps = { + /* Key name identifying the emoji */ + emojiKey: string; + + /* Emoji content to render */ + children: ReactNode; +}; + +function CustomEmojiWithDefaultPressableAction({emojiKey, children}: CustomEmojiWithDefaultPressableActionProps) { + const styles = useThemeStyles(); + + const {isCreateMenuActive, toggleCreateMenu} = useContext(FABPopoverContext); + const [isFabActionActive, setIsFabActionActive] = useState(isCreateMenuActive); + useEffect(() => { + setIsFabActionActive(isCreateMenuActive); + }, [isCreateMenuActive]); + const {translate} = useLocalize(); + + if (emojiKey === 'actionMenuIcon') { + return ( + toggleCreateMenu(isFabActionActive)} + onLongPress={() => {}} + style={[styles.verticalAlignBottom, styles.userSelectNone]} + role={CONST.ROLE.BUTTON} + shouldUseHapticsOnLongPress={false} + accessibilityLabel={translate('sidebarScreen.fabNewChatExplained')} + > + {children} + + ); + } + + return children; +} + +export default CustomEmojiWithDefaultPressableAction; diff --git a/src/components/HTMLEngineProvider/HTMLRenderers/CustomEmojiRenderer.tsx b/src/components/HTMLEngineProvider/HTMLRenderers/CustomEmojiRenderer.tsx new file mode 100644 index 000000000000..3fc258ab94c3 --- /dev/null +++ b/src/components/HTMLEngineProvider/HTMLRenderers/CustomEmojiRenderer.tsx @@ -0,0 +1,42 @@ +import React from 'react'; +import type {FC} from 'react'; +import {View} from 'react-native'; +import type {CustomRendererProps, TPhrasing, TText} from 'react-native-render-html'; +import type {SvgProps} from 'react-native-svg'; +import GlobalCreateIcon from '@assets/images/customEmoji/global-create.svg'; +import CustomEmojiWithDefaultPressableAction from '@components/HTMLEngineProvider/CustomEmojiWithDefaultPressableAction'; +import ImageSVG from '@components/ImageSVG'; +import useThemeStyles from '@hooks/useThemeStyles'; +import variables from '@styles/variables'; + +const emojiMap: Record> = { + actionMenuIcon: GlobalCreateIcon, +}; + +function CustomEmojiRenderer({tnode}: CustomRendererProps) { + const styles = useThemeStyles(); + const emojiKey = tnode.attributes.emoji; + + if (emojiMap[emojiKey]) { + const image = ( + + + + ); + + if ('pressablewithdefaultaction' in tnode.attributes) { + return {image}; + } + + return image; + } + + return null; +} + +export default CustomEmojiRenderer; +export {emojiMap}; diff --git a/src/components/HTMLEngineProvider/HTMLRenderers/index.ts b/src/components/HTMLEngineProvider/HTMLRenderers/index.ts index 91ed66f8b931..bcf3d4dfaf94 100644 --- a/src/components/HTMLEngineProvider/HTMLRenderers/index.ts +++ b/src/components/HTMLEngineProvider/HTMLRenderers/index.ts @@ -1,6 +1,7 @@ import type {CustomTagRendererRecord} from 'react-native-render-html'; import AnchorRenderer from './AnchorRenderer'; import CodeRenderer from './CodeRenderer'; +import CustomEmojiRenderer from './CustomEmojiRenderer'; import DeletedActionRenderer from './DeletedActionRenderer'; import EditedRenderer from './EditedRenderer'; import EmojiRenderer from './EmojiRenderer'; @@ -29,6 +30,7 @@ const HTMLEngineProviderComponentList: CustomTagRendererRecord = { 'mention-user': MentionUserRenderer, 'mention-report': MentionReportRenderer, 'mention-here': MentionHereRenderer, + 'custom-emoji': CustomEmojiRenderer, emoji: EmojiRenderer, 'next-step-email': NextStepEmailRenderer, 'deleted-action': DeletedActionRenderer, diff --git a/src/components/Navigation/BottomTabBar/index.tsx b/src/components/Navigation/BottomTabBar/index.tsx index c69b262a5b1f..754258f0702e 100644 --- a/src/components/Navigation/BottomTabBar/index.tsx +++ b/src/components/Navigation/BottomTabBar/index.tsx @@ -1,7 +1,9 @@ -import React, {memo, useCallback, useEffect, useState} from 'react'; +import React, {memo, useCallback, useContext, useEffect, useState} from 'react'; import {View} from 'react-native'; import {useOnyx} from 'react-native-onyx'; import type {ValueOf} from 'type-fest'; +import {FABPopoverContext} from '@components/FABPopoverProvider'; +import FloatingActionButton from '@components/FloatingActionButton'; import Icon from '@components/Icon'; import * as Expensicons from '@components/Icon/Expensicons'; import DebugTabView from '@components/Navigation/DebugTabView'; @@ -29,7 +31,6 @@ import Navigation from '@navigation/Navigation'; import navigationRef from '@navigation/navigationRef'; import type {AuthScreensParamList, RootNavigatorParamList, State, WorkspaceSplitNavigatorParamList} from '@navigation/types'; import BottomTabAvatar from '@pages/home/sidebar/BottomTabAvatar'; -import BottomTabBarFloatingActionButton from '@pages/home/sidebar/BottomTabBarFloatingActionButton'; import variables from '@styles/variables'; import CONST from '@src/CONST'; import NAVIGATORS from '@src/NAVIGATORS'; @@ -72,6 +73,7 @@ function handleQueryWithPolicyID(query: SearchQueryString, activePolicyID?: stri } function BottomTabBar({selectedTab, isTooltipAllowed = false}: BottomTabBarProps) { + const {isCreateMenuActive, toggleCreateMenu, fabRef} = useContext(FABPopoverContext); const theme = useTheme(); const styles = useThemeStyles(); const {translate} = useLocalize(); @@ -283,7 +285,14 @@ function BottomTabBar({selectedTab, isTooltipAllowed = false}: BottomTabBarProps onPress={showSettingsPage} /> - + toggleCreateMenu(isCreateMenuActive)} + isTooltipAllowed={isTooltipAllowed} + /> diff --git a/src/libs/Navigation/NavigationRoot.tsx b/src/libs/Navigation/NavigationRoot.tsx index 38ae0f2f3ea4..fd7f50335ed3 100644 --- a/src/libs/Navigation/NavigationRoot.tsx +++ b/src/libs/Navigation/NavigationRoot.tsx @@ -3,6 +3,7 @@ import {DarkTheme, DefaultTheme, findFocusedRoute, NavigationContainer} from '@r import React, {useContext, useEffect, useMemo, useRef} from 'react'; import {NativeModules} from 'react-native'; import {useOnyx} from 'react-native-onyx'; +import FABPopoverProvider from '@components/FABPopoverProvider'; import {ScrollOffsetContext} from '@components/ScrollOffsetContextProvider'; import {usePlaybackContext} from '@components/VideoPlayerContexts/PlaybackContext'; import useCurrentReportID from '@hooks/useCurrentReportID'; @@ -223,7 +224,9 @@ function NavigationRoot({authenticated, lastVisitedPath, initialUrl, onReady, sh enabled: false, }} > - + + + ); } diff --git a/src/libs/ReportUtils.ts b/src/libs/ReportUtils.ts index 61ad34bf6c0a..32c0af6c57be 100644 --- a/src/libs/ReportUtils.ts +++ b/src/libs/ReportUtils.ts @@ -6689,6 +6689,7 @@ function buildOptimisticTaskReport( description?: string, policyID: string = CONST.POLICY.OWNER_EMAIL_FAKE, notificationPreference: NotificationPreference = CONST.REPORT.NOTIFICATION_PREFERENCE.HIDDEN, + shouldEscapeText = true, ): OptimisticTaskReport { const participants: Participants = { [ownerAccountID]: { @@ -6703,7 +6704,7 @@ function buildOptimisticTaskReport( return { reportID: generateReportID(), reportName: title, - description: getParsedComment(description ?? ''), + description: getParsedComment(description ?? '', {shouldEscapeText}), ownerAccountID, participants, managerID: assigneeAccountID, diff --git a/src/libs/actions/Policy/Policy.ts b/src/libs/actions/Policy/Policy.ts index f8395e992afb..b2c0d255998d 100644 --- a/src/libs/actions/Policy/Policy.ts +++ b/src/libs/actions/Policy/Policy.ts @@ -76,7 +76,7 @@ import * as PhoneNumber from '@libs/PhoneNumber'; import * as PolicyUtils from '@libs/PolicyUtils'; import {goBackWhenEnableFeature, navigateToExpensifyCardPage} from '@libs/PolicyUtils'; import * as ReportUtils from '@libs/ReportUtils'; -import type {PolicySelector} from '@pages/home/sidebar/FloatingActionButtonAndPopover'; +import type {PolicySelector} from '@pages/home/sidebar/FloatingActionButtonPopover'; import * as PaymentMethods from '@userActions/PaymentMethods'; import * as PersistedRequests from '@userActions/PersistedRequests'; import type {OnboardingPurpose} from '@src/CONST'; diff --git a/src/libs/actions/Report.ts b/src/libs/actions/Report.ts index 1810ffb726f5..ef05799df353 100644 --- a/src/libs/actions/Report.ts +++ b/src/libs/actions/Report.ts @@ -3762,6 +3762,7 @@ function prepareOnboardingOnyxData( taskDescription, targetChatPolicyID, CONST.REPORT.NOTIFICATION_PREFERENCE.HIDDEN, + !['submitExpense', 'trackExpense', 'startChat', 'splitExpense'].includes(task.type), ); const emailCreatingAction = engagementChoice === CONST.ONBOARDING_CHOICES.MANAGE_TEAM ? allPersonalDetails?.[actorAccountID]?.login ?? CONST.EMAIL.CONCIERGE : CONST.EMAIL.CONCIERGE; diff --git a/src/pages/home/sidebar/BottomTabBarFloatingActionButton/index.native.tsx b/src/pages/home/sidebar/BottomTabBarFloatingActionButton/index.native.tsx deleted file mode 100644 index a85dac28b81c..000000000000 --- a/src/pages/home/sidebar/BottomTabBarFloatingActionButton/index.native.tsx +++ /dev/null @@ -1,3 +0,0 @@ -import FloatingActionButtonAndPopover from '@pages/home/sidebar/FloatingActionButtonAndPopover'; - -export default FloatingActionButtonAndPopover; diff --git a/src/pages/home/sidebar/BottomTabBarFloatingActionButton/index.tsx b/src/pages/home/sidebar/BottomTabBarFloatingActionButton/index.tsx deleted file mode 100644 index 9d2ca36e7c9e..000000000000 --- a/src/pages/home/sidebar/BottomTabBarFloatingActionButton/index.tsx +++ /dev/null @@ -1,46 +0,0 @@ -import React, {useCallback, useRef} from 'react'; -import FloatingActionButtonAndPopover from '@pages/home/sidebar/FloatingActionButtonAndPopover'; -import type FloatingActionButtonPopoverMenuRef from './types'; - -type BottomTabBarFloatingActionButtonProps = { - isTooltipAllowed: boolean; -}; - -function BottomTabBarFloatingActionButton({isTooltipAllowed}: BottomTabBarFloatingActionButtonProps) { - const popoverModal = useRef(null); - - /** - * Method to hide popover when dragover. - */ - const hidePopoverOnDragOver = useCallback(() => { - if (!popoverModal.current) { - return; - } - popoverModal.current.hideCreateMenu(); - }, []); - - /** - * Method create event listener - */ - const createDragoverListener = () => { - document.addEventListener('dragover', hidePopoverOnDragOver); - }; - - /** - * Method remove event listener. - */ - const removeDragoverListener = () => { - document.removeEventListener('dragover', hidePopoverOnDragOver); - }; - - return ( - - ); -} - -export default BottomTabBarFloatingActionButton; diff --git a/src/pages/home/sidebar/BottomTabBarFloatingActionButton/types.ts b/src/pages/home/sidebar/BottomTabBarFloatingActionButton/types.ts deleted file mode 100644 index e8fd03ee2adc..000000000000 --- a/src/pages/home/sidebar/BottomTabBarFloatingActionButton/types.ts +++ /dev/null @@ -1,5 +0,0 @@ -type FloatingActionButtonPopoverMenuRef = { - hideCreateMenu: () => void; -}; - -export default FloatingActionButtonPopoverMenuRef; diff --git a/src/pages/home/sidebar/FloatingActionButtonAndPopover.tsx b/src/pages/home/sidebar/FloatingActionButtonPopover.tsx similarity index 90% rename from src/pages/home/sidebar/FloatingActionButtonAndPopover.tsx rename to src/pages/home/sidebar/FloatingActionButtonPopover.tsx index 5f3aba4b3a28..7ea090280d11 100644 --- a/src/pages/home/sidebar/FloatingActionButtonAndPopover.tsx +++ b/src/pages/home/sidebar/FloatingActionButtonPopover.tsx @@ -1,14 +1,14 @@ import {useIsFocused} from '@react-navigation/native'; import type {ImageContentFit} from 'expo-image'; import type {ForwardedRef} from 'react'; -import React, {forwardRef, useCallback, useContext, useEffect, useImperativeHandle, useMemo, useRef, useState} from 'react'; -import {NativeModules, View} from 'react-native'; +import React, {forwardRef, useCallback, useContext, useEffect, useImperativeHandle, useMemo, useState} from 'react'; +import {NativeModules} from 'react-native'; import type {OnyxCollection, OnyxEntry} from 'react-native-onyx'; import {useOnyx} from 'react-native-onyx'; import type {SvgProps} from 'react-native-svg'; import ConfirmModal from '@components/ConfirmModal'; import CustomStatusBarAndBackgroundContext from '@components/CustomStatusBarAndBackground/CustomStatusBarAndBackgroundContext'; -import FloatingActionButton from '@components/FloatingActionButton'; +import {FABPopoverContext} from '@components/FABPopoverProvider'; import * as Expensicons from '@components/Icon/Expensicons'; import type {PopoverMenuItem} from '@components/PopoverMenu'; import PopoverMenu from '@components/PopoverMenu'; @@ -51,18 +51,7 @@ import mapOnyxCollectionItems from '@src/utils/mapOnyxCollectionItems'; type PolicySelector = Pick; -type FloatingActionButtonAndPopoverProps = { - /* Callback function when the menu is shown */ - onShowCreateMenu?: () => void; - - /* Callback function before the menu is hidden */ - onHideCreateMenu?: () => void; - - /* If the tooltip is allowed to be shown */ - isTooltipAllowed: boolean; -}; - -type FloatingActionButtonAndPopoverRef = { +type FloatingActionButtonPopoverRef = { hideCreateMenu: () => void; }; @@ -161,7 +150,7 @@ const getQuickActionTitle = (action: QuickActionName): TranslationPaths => { * Responsible for rendering the {@link PopoverMenu}, and the accompanying * FAB that can open or close the menu. */ -function FloatingActionButtonAndPopover({onHideCreateMenu, onShowCreateMenu, isTooltipAllowed}: FloatingActionButtonAndPopoverProps, ref: ForwardedRef) { +function FloatingActionButtonPopover(_: unknown, ref: ForwardedRef) { const styles = useThemeStyles(); const theme = useTheme(); const {translate} = useLocalize(); @@ -184,9 +173,8 @@ function FloatingActionButtonAndPopover({onHideCreateMenu, onShowCreateMenu, isT const [quickActionPolicy] = useOnyx(`${ONYXKEYS.COLLECTION.POLICY}${quickActionReport?.policyID}`); const [allPolicies] = useOnyx(ONYXKEYS.COLLECTION.POLICY, {selector: (c) => mapOnyxCollectionItems(c, policySelector)}); - const [isCreateMenuActive, setIsCreateMenuActive] = useState(false); + const {isCreateMenuActive, hideCreateMenu, fabRef} = useContext(FABPopoverContext); const [modalVisible, setModalVisible] = useState(false); - const fabRef = useRef(null); const {windowHeight} = useWindowDimensions(); const {shouldUseNarrowLayout} = useResponsiveLayout(); const isFocused = useIsFocused(); @@ -280,38 +268,6 @@ function FloatingActionButtonAndPopover({onHideCreateMenu, onShowCreateMenu, isT [isFocused, prevIsFocused], ); - /** - * Method called when we click the floating action button - */ - const showCreateMenu = useCallback( - () => { - if (!isFocused && shouldUseNarrowLayout) { - return; - } - setIsCreateMenuActive(true); - onShowCreateMenu?.(); - }, - // eslint-disable-next-line react-compiler/react-compiler, react-hooks/exhaustive-deps - [isFocused, shouldUseNarrowLayout], - ); - - /** - * 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 - */ - const hideCreateMenu = useCallback( - () => { - if (!isCreateMenuActive) { - return; - } - setIsCreateMenuActive(false); - onHideCreateMenu?.(); - }, - // eslint-disable-next-line react-compiler/react-compiler, react-hooks/exhaustive-deps - [isCreateMenuActive], - ); - useEffect(() => { if (!didScreenBecomeInactive()) { return; @@ -327,14 +283,6 @@ function FloatingActionButtonAndPopover({onHideCreateMenu, onShowCreateMenu, isT }, })); - const toggleCreateMenu = () => { - if (isCreateMenuActive) { - hideCreateMenu(); - } else { - showCreateMenu(); - } - }; - const expenseMenuItems = useMemo((): PopoverMenuItem[] => { return [ { @@ -541,10 +489,10 @@ function FloatingActionButtonAndPopover({onHideCreateMenu, onShowCreateMenu, isT ]; return ( - + <> - - + ); } -FloatingActionButtonAndPopover.displayName = 'FloatingActionButtonAndPopover'; +FloatingActionButtonPopover.displayName = 'FloatingActionButtonPopover'; -export default forwardRef(FloatingActionButtonAndPopover); +export default forwardRef(FloatingActionButtonPopover); export type {PolicySelector}; diff --git a/src/styles/index.ts b/src/styles/index.ts index 2f052564303b..490f95f07b5f 100644 --- a/src/styles/index.ts +++ b/src/styles/index.ts @@ -13,6 +13,7 @@ import type {ValueOf} from 'type-fest'; import type DotLottieAnimation from '@components/LottieAnimations/types'; import {ACTIVE_LABEL_SCALE} from '@components/TextInput/styleConst'; import {getBrowser, isMobile, isMobileSafari, isSafari} from '@libs/Browser'; +import getPlatform from '@libs/getPlatform'; import CONST from '@src/CONST'; import {defaultTheme} from './theme'; import colors from './theme/colors'; @@ -372,6 +373,9 @@ const styles = (theme: ThemeColors) => verticalAlignTop: { verticalAlign: 'top', }, + verticalAlignBottom: { + verticalAlign: 'bottom', + }, lineHeightLarge: { lineHeight: variables.lineHeightLarge, }, @@ -1703,6 +1707,16 @@ const styles = (theme: ThemeColors) => justifyContent: 'center', }, + customEmoji: { + alignItems: 'center', + justifyContent: 'center', + verticalAlign: 'bottom', + ...(getPlatform() === CONST.PLATFORM.IOS ? {marginBottom: -variables.fontSizeNormalHeight / 4} : {}), + // `fontSizeNormal` value for scale factor 1 is 15 + ...(getPlatform() === CONST.PLATFORM.ANDROID ? {marginBottom: -(variables.fontSizeEmojiNormal - 10)} : {}), + ...(getPlatform() === CONST.PLATFORM.ANDROID ? {marginRight: -(variables.fontSizeEmojiNormal - 15)} : {}), + }, + sidebarFooterUsername: { color: theme.heading, fontSize: variables.fontSizeLabel, diff --git a/src/styles/variables.ts b/src/styles/variables.ts index 22b60bd51d2e..ed6d8e99976a 100644 --- a/src/styles/variables.ts +++ b/src/styles/variables.ts @@ -52,6 +52,7 @@ export default { fontSizeExtraSmall: 9, fontSizeLabel: getValueUsingPixelRatio(13, 19), fontSizeNormal: getValueUsingPixelRatio(15, 21), + fontSizeEmojiNormal: getValueUsingPixelRatio(15, 28), fontSizeMedium: getValueUsingPixelRatio(16, 22), fontSizeLarge: getValueUsingPixelRatio(17, 19), fontSizeHero: 36, From 6b5c4ca4b259adc4778450bc7e506d3a6979260e Mon Sep 17 00:00:00 2001 From: Amoralchik Date: Thu, 6 Mar 2025 05:45:18 +0200 Subject: [PATCH 3/6] Fix FAB button state synchronization with create menu activity --- src/components/Navigation/BottomTabBar/index.tsx | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/src/components/Navigation/BottomTabBar/index.tsx b/src/components/Navigation/BottomTabBar/index.tsx index 754258f0702e..96135c31f241 100644 --- a/src/components/Navigation/BottomTabBar/index.tsx +++ b/src/components/Navigation/BottomTabBar/index.tsx @@ -74,6 +74,7 @@ function handleQueryWithPolicyID(query: SearchQueryString, activePolicyID?: stri function BottomTabBar({selectedTab, isTooltipAllowed = false}: BottomTabBarProps) { const {isCreateMenuActive, toggleCreateMenu, fabRef} = useContext(FABPopoverContext); + const [isFabActionActive, setIsFabActionActive] = useState(isCreateMenuActive); const theme = useTheme(); const styles = useThemeStyles(); const {translate} = useLocalize(); @@ -89,6 +90,11 @@ function BottomTabBar({selectedTab, isTooltipAllowed = false}: BottomTabBarProps CONST.PRODUCT_TRAINING_TOOLTIP_NAMES.BOTTOM_NAV_INBOX_TOOLTIP, isTooltipAllowed && selectedTab !== BOTTOM_TABS.HOME, ); + + useEffect(() => { + setIsFabActionActive(isCreateMenuActive); + }, [isCreateMenuActive]); + useEffect(() => { setChatTabBrickRoad(getChatTabBrickRoad(activeWorkspaceID, orderedReportIDs)); // We need to get a new brick road state when report actions are updated, otherwise we'll be showing an outdated brick road. @@ -288,9 +294,9 @@ function BottomTabBar({selectedTab, isTooltipAllowed = false}: BottomTabBarProps toggleCreateMenu(isCreateMenuActive)} + onPress={() => toggleCreateMenu(isFabActionActive)} isTooltipAllowed={isTooltipAllowed} /> From caaae0cdfe556d15adc0da3c9179bf2fcfc3dbf3 Mon Sep 17 00:00:00 2001 From: Amoralchik Date: Sun, 9 Mar 2025 18:54:02 +0200 Subject: [PATCH 4/6] Refactor FABPopoverProvider and related components to use MutableRefObject for better handling of refs --- src/components/FABPopoverProvider.tsx | 15 ++++++++------- .../CustomEmojiWithDefaultPressableAction.tsx | 13 ++++++------- src/components/Navigation/BottomTabBar/index.tsx | 16 ++++++---------- 3 files changed, 20 insertions(+), 24 deletions(-) diff --git a/src/components/FABPopoverProvider.tsx b/src/components/FABPopoverProvider.tsx index 0436c973463f..d541106b7df9 100644 --- a/src/components/FABPopoverProvider.tsx +++ b/src/components/FABPopoverProvider.tsx @@ -1,5 +1,5 @@ import {useIsFocused} from '@react-navigation/native'; -import type {ReactNode} from 'react'; +import type {MutableRefObject, ReactNode} from 'react'; import React, {createContext, useCallback, useMemo, useRef, useState} from 'react'; import type {View} from 'react-native'; import useResponsiveLayout from '@hooks/useResponsiveLayout'; @@ -14,8 +14,8 @@ type FloatingActionButtonPopoverMenuRef = { type FABPopoverContextValue = { isCreateMenuActive: boolean; hideCreateMenu: () => void; - toggleCreateMenu: (isFabActionActive: boolean) => void; - fabRef: React.RefObject; + toggleCreateMenu: (fabRef: React.RefObject) => void; + fabRef: MutableRefObject; }; const FABPopoverContext = createContext({ @@ -31,7 +31,7 @@ type FABPopoverProviderProps = { function FABPopoverProvider({children}: FABPopoverProviderProps) { const [isCreateMenuActive, setIsCreateMenuActive] = useState(false); - const fabRef = useRef(null); + const fabRef = useRef(null); const {shouldUseNarrowLayout} = useResponsiveLayout(); const isFocused = useIsFocused(); const platform = getPlatform(); @@ -101,14 +101,15 @@ function FABPopoverProvider({children}: FABPopoverProviderProps) { ); const toggleCreateMenu = useCallback( - (isFabActionActive: boolean) => { - if (isFabActionActive) { + (fab: React.RefObject) => { + fabRef.current = fab.current; + if (isCreateMenuActive) { hideCreateMenu(); } else { showCreateMenu(); } }, - [hideCreateMenu, showCreateMenu], + [hideCreateMenu, isCreateMenuActive, showCreateMenu], ); const value = useMemo( diff --git a/src/components/HTMLEngineProvider/CustomEmojiWithDefaultPressableAction.tsx b/src/components/HTMLEngineProvider/CustomEmojiWithDefaultPressableAction.tsx index 325de14cdccb..b272ae6e2075 100644 --- a/src/components/HTMLEngineProvider/CustomEmojiWithDefaultPressableAction.tsx +++ b/src/components/HTMLEngineProvider/CustomEmojiWithDefaultPressableAction.tsx @@ -1,5 +1,5 @@ import type {ReactNode} from 'react'; -import React, {useContext, useEffect, useState} from 'react'; +import React, {useContext, useRef} from 'react'; import {FABPopoverContext} from '@components/FABPopoverProvider'; import {PressableWithoutFeedback} from '@components/Pressable'; import useLocalize from '@hooks/useLocalize'; @@ -17,18 +17,17 @@ type CustomEmojiWithDefaultPressableActionProps = { function CustomEmojiWithDefaultPressableAction({emojiKey, children}: CustomEmojiWithDefaultPressableActionProps) { const styles = useThemeStyles(); - const {isCreateMenuActive, toggleCreateMenu} = useContext(FABPopoverContext); - const [isFabActionActive, setIsFabActionActive] = useState(isCreateMenuActive); - useEffect(() => { - setIsFabActionActive(isCreateMenuActive); - }, [isCreateMenuActive]); + const {toggleCreateMenu} = useContext(FABPopoverContext); + const localFabRef = useRef(null); + const {translate} = useLocalize(); if (emojiKey === 'actionMenuIcon') { return ( toggleCreateMenu(isFabActionActive)} + onPress={() => toggleCreateMenu(localFabRef)} onLongPress={() => {}} + ref={localFabRef} style={[styles.verticalAlignBottom, styles.userSelectNone]} role={CONST.ROLE.BUTTON} shouldUseHapticsOnLongPress={false} diff --git a/src/components/Navigation/BottomTabBar/index.tsx b/src/components/Navigation/BottomTabBar/index.tsx index 04476f12db83..670684a40328 100644 --- a/src/components/Navigation/BottomTabBar/index.tsx +++ b/src/components/Navigation/BottomTabBar/index.tsx @@ -1,4 +1,4 @@ -import React, {memo, useCallback, useContext, useEffect, useState} from 'react'; +import React, {memo, useCallback, useContext, useEffect, useRef, useState} from 'react'; import {View} from 'react-native'; import {useOnyx} from 'react-native-onyx'; import type {ValueOf} from 'type-fest'; @@ -43,8 +43,8 @@ type BottomTabBarProps = { }; function BottomTabBar({selectedTab, isTooltipAllowed = false}: BottomTabBarProps) { - const {isCreateMenuActive, toggleCreateMenu, fabRef} = useContext(FABPopoverContext); - const [isFabActionActive, setIsFabActionActive] = useState(isCreateMenuActive); + const {isCreateMenuActive, toggleCreateMenu} = useContext(FABPopoverContext); + const localFabRef = useRef(null); const theme = useTheme(); const styles = useThemeStyles(); const {translate} = useLocalize(); @@ -61,10 +61,6 @@ function BottomTabBar({selectedTab, isTooltipAllowed = false}: BottomTabBarProps isTooltipAllowed && selectedTab !== BOTTOM_TABS.HOME, ); - useEffect(() => { - setIsFabActionActive(isCreateMenuActive); - }, [isCreateMenuActive]); - useEffect(() => { setChatTabBrickRoad(getChatTabBrickRoad(activeWorkspaceID, orderedReportIDs)); // We need to get a new brick road state when report actions are updated, otherwise we'll be showing an outdated brick road. @@ -248,9 +244,9 @@ function BottomTabBar({selectedTab, isTooltipAllowed = false}: BottomTabBarProps toggleCreateMenu(isFabActionActive)} + isActive={isCreateMenuActive} + ref={localFabRef} + onPress={() => toggleCreateMenu(localFabRef)} isTooltipAllowed={isTooltipAllowed} /> From e1832030ee7345a589628f6ba03e9b888a5e1578 Mon Sep 17 00:00:00 2001 From: Amoralchik Date: Thu, 20 Mar 2025 12:06:12 +0200 Subject: [PATCH 5/6] Refactor FABPopoverProvider to manage active state --- src/components/FABPopoverProvider.tsx | 15 +++++++-------- .../CustomEmojiWithDefaultPressableAction.tsx | 13 ++++++++----- src/components/Navigation/BottomTabBar/index.tsx | 6 +++++- src/libs/actions/Report.ts | 2 +- 4 files changed, 21 insertions(+), 15 deletions(-) diff --git a/src/components/FABPopoverProvider.tsx b/src/components/FABPopoverProvider.tsx index d541106b7df9..ac018c77a9a9 100644 --- a/src/components/FABPopoverProvider.tsx +++ b/src/components/FABPopoverProvider.tsx @@ -14,7 +14,7 @@ type FloatingActionButtonPopoverMenuRef = { type FABPopoverContextValue = { isCreateMenuActive: boolean; hideCreateMenu: () => void; - toggleCreateMenu: (fabRef: React.RefObject) => void; + toggleCreateMenu: (localFabRef: React.RefObject, localFabState: boolean) => void; fabRef: MutableRefObject; }; @@ -31,8 +31,8 @@ type FABPopoverProviderProps = { function FABPopoverProvider({children}: FABPopoverProviderProps) { const [isCreateMenuActive, setIsCreateMenuActive] = useState(false); - const fabRef = useRef(null); const {shouldUseNarrowLayout} = useResponsiveLayout(); + const fabRef = useRef(null); const isFocused = useIsFocused(); const platform = getPlatform(); @@ -101,15 +101,14 @@ function FABPopoverProvider({children}: FABPopoverProviderProps) { ); const toggleCreateMenu = useCallback( - (fab: React.RefObject) => { + (fab: React.RefObject, isFabActionActive: boolean) => { fabRef.current = fab.current; - if (isCreateMenuActive) { - hideCreateMenu(); - } else { - showCreateMenu(); + if (isFabActionActive) { + return hideCreateMenu(); } + return showCreateMenu(); }, - [hideCreateMenu, isCreateMenuActive, showCreateMenu], + [hideCreateMenu, showCreateMenu], ); const value = useMemo( diff --git a/src/components/HTMLEngineProvider/CustomEmojiWithDefaultPressableAction.tsx b/src/components/HTMLEngineProvider/CustomEmojiWithDefaultPressableAction.tsx index b272ae6e2075..51bb6ba5ffc2 100644 --- a/src/components/HTMLEngineProvider/CustomEmojiWithDefaultPressableAction.tsx +++ b/src/components/HTMLEngineProvider/CustomEmojiWithDefaultPressableAction.tsx @@ -1,5 +1,5 @@ import type {ReactNode} from 'react'; -import React, {useContext, useRef} from 'react'; +import React, {useContext, useEffect, useRef, useState} from 'react'; import {FABPopoverContext} from '@components/FABPopoverProvider'; import {PressableWithoutFeedback} from '@components/Pressable'; import useLocalize from '@hooks/useLocalize'; @@ -16,8 +16,11 @@ type CustomEmojiWithDefaultPressableActionProps = { function CustomEmojiWithDefaultPressableAction({emojiKey, children}: CustomEmojiWithDefaultPressableActionProps) { const styles = useThemeStyles(); - - const {toggleCreateMenu} = useContext(FABPopoverContext); + const {toggleCreateMenu, isCreateMenuActive} = useContext(FABPopoverContext); + const [isFabActionActive, setIsFabActionActive] = useState(isCreateMenuActive); + useEffect(() => { + setIsFabActionActive(isCreateMenuActive); + }, [isCreateMenuActive]); const localFabRef = useRef(null); const {translate} = useLocalize(); @@ -25,9 +28,9 @@ function CustomEmojiWithDefaultPressableAction({emojiKey, children}: CustomEmoji if (emojiKey === 'actionMenuIcon') { return ( toggleCreateMenu(localFabRef)} - onLongPress={() => {}} + onPress={() => toggleCreateMenu(localFabRef, isFabActionActive)} ref={localFabRef} + onLongPress={() => {}} style={[styles.verticalAlignBottom, styles.userSelectNone]} role={CONST.ROLE.BUTTON} shouldUseHapticsOnLongPress={false} diff --git a/src/components/Navigation/BottomTabBar/index.tsx b/src/components/Navigation/BottomTabBar/index.tsx index b22dcec02eb3..29f7715c5e9b 100644 --- a/src/components/Navigation/BottomTabBar/index.tsx +++ b/src/components/Navigation/BottomTabBar/index.tsx @@ -60,6 +60,10 @@ function BottomTabBar({selectedTab, isTooltipAllowed = false}: BottomTabBarProps CONST.PRODUCT_TRAINING_TOOLTIP_NAMES.BOTTOM_NAV_INBOX_TOOLTIP, isTooltipAllowed && selectedTab !== BOTTOM_TABS.HOME, ); + const [isFabActionActive, setIsFabActionActive] = useState(isCreateMenuActive); + useEffect(() => { + setIsFabActionActive(isCreateMenuActive); + }, [isCreateMenuActive]); useEffect(() => { setChatTabBrickRoad(getChatTabBrickRoad(activeWorkspaceID, orderedReportIDs)); @@ -267,7 +271,7 @@ function BottomTabBar({selectedTab, isTooltipAllowed = false}: BottomTabBarProps role={CONST.ROLE.BUTTON} isActive={isCreateMenuActive} ref={localFabRef} - onPress={() => toggleCreateMenu(localFabRef)} + onPress={() => toggleCreateMenu(localFabRef, isFabActionActive)} isTooltipAllowed={isTooltipAllowed} /> diff --git a/src/libs/actions/Report.ts b/src/libs/actions/Report.ts index 98b336d09a95..0aef5be6792e 100644 --- a/src/libs/actions/Report.ts +++ b/src/libs/actions/Report.ts @@ -3918,8 +3918,8 @@ function prepareOnboardingOnyxData( taskDescription, targetChatPolicyID, CONST.REPORT.NOTIFICATION_PREFERENCE.HIDDEN, - !['submitExpense', 'trackExpense', 'startChat', 'splitExpense'].includes(task.type), task.mediaAttributes, + !['submitExpense', 'trackExpense', 'startChat', 'splitExpense'].includes(task.type), ); const emailCreatingAction = engagementChoice === CONST.ONBOARDING_CHOICES.MANAGE_TEAM ? allPersonalDetails?.[actorAccountID]?.login ?? CONST.EMAIL.CONCIERGE : CONST.EMAIL.CONCIERGE; From 4f3c67fdfc173fb31d642309d7c04d9f9ced3b54 Mon Sep 17 00:00:00 2001 From: Amoralchik Date: Sat, 5 Apr 2025 22:21:29 +0300 Subject: [PATCH 6/6] Add task types in onboarding data preparation, after merge --- src/libs/ReportUtils.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/src/libs/ReportUtils.ts b/src/libs/ReportUtils.ts index b327d70dd59a..380b5fa877c7 100644 --- a/src/libs/ReportUtils.ts +++ b/src/libs/ReportUtils.ts @@ -9425,6 +9425,7 @@ function prepareOnboardingOnyxData( targetChatPolicyID, CONST.REPORT.NOTIFICATION_PREFERENCE.HIDDEN, task.mediaAttributes, + !['submitExpense', 'trackExpense', 'startChat', 'splitExpense'].includes(task.type), ); const emailCreatingAction = engagementChoice === CONST.ONBOARDING_CHOICES.MANAGE_TEAM ? allPersonalDetails?.[actorAccountID]?.login ?? CONST.EMAIL.CONCIERGE : CONST.EMAIL.CONCIERGE;