Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
17 commits
Select commit Hold shift + click to select a range
1d4d4c7
Fix FAB button state synchronization with create menu activity
Amoralchik Mar 5, 2025
c6be5eb
Merge remote-tracking branch 'origin/main' into fix-for-clickable-emoji
Amoralchik Mar 6, 2025
6249f33
Revert "Revert "Merge pull request #56602 from Amoralchik/clickable-e…
Amoralchik Mar 6, 2025
6b5c4ca
Fix FAB button state synchronization with create menu activity
Amoralchik Mar 6, 2025
4ee9f17
Merge branch 'main' into fix-for-clickable-emoji
Amoralchik Mar 9, 2025
caaae0c
Refactor FABPopoverProvider and related components to use MutableRefO…
Amoralchik Mar 9, 2025
d482b1b
Merge remote-tracking branch 'origin/main' into fix-for-clickable-emoji
Amoralchik Mar 19, 2025
e183203
Refactor FABPopoverProvider to manage active state
Amoralchik Mar 20, 2025
3152bfe
Merge remote-tracking branch 'origin/main' into fix-for-clickable-emoji
Amoralchik Mar 20, 2025
18210a8
Merge remote-tracking branch 'origin/main' into fix-for-clickable-emoji
Amoralchik Mar 22, 2025
fadbb95
Merge remote-tracking branch 'origin/main' into fix-for-clickable-emoji
Amoralchik Mar 26, 2025
3581e14
Merge remote-tracking branch 'origin/main' into fix-for-clickable-emoji
Amoralchik Mar 27, 2025
d2c9d57
Merge remote-tracking branch 'origin/main' into fix-for-clickable-emoji
Amoralchik Mar 28, 2025
8bef304
Merge remote-tracking branch 'origin/main' into fix-for-clickable-emoji
Amoralchik Mar 31, 2025
a47ea85
Merge remote-tracking branch 'origin/main' into fix-for-clickable-emoji
Amoralchik Apr 1, 2025
a6586bd
Merge remote-tracking branch 'origin/main' into fix-for-clickable-emoji
Amoralchik Apr 5, 2025
4f3c67f
Add task types in onboarding data preparation, after merge
Amoralchik Apr 5, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions assets/images/customEmoji/global-create.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
14 changes: 7 additions & 7 deletions src/CONST.ts
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@ const onboardingEmployerOrSubmitMessage: OnboardingMessage = {
'\n' +
'Here’s how to submit an expense:\n' +
'\n' +
'1. Click the green *+* button.\n' +
'1. Press the <custom-emoji emoji="actionMenuIcon" pressablewithdefaultaction /> button.\n' +
'2. Choose *Create expense*.\n' +
'3. Enter an amount or scan a receipt.\n' +
'4. Add your reimburser to the request.\n' +
Expand All @@ -199,7 +199,7 @@ const combinedTrackSubmitOnboardingEmployerOrSubmitMessage: OnboardingMessage =
'\n' +
'Here’s how to submit an expense:\n' +
'\n' +
'1. Click the green *+* button.\n' +
'1. Press the <custom-emoji emoji="actionMenuIcon" pressablewithdefaultaction /> button.\n' +
'2. Choose *Create expense*.\n' +
'3. Enter an amount or scan a receipt.\n' +
'4. Add your reimburser to the request.\n' +
Expand All @@ -224,7 +224,7 @@ const onboardingPersonalSpendMessage: OnboardingMessage = {
'\n' +
'Here’s how to track an expense:\n' +
'\n' +
'1. Click the green *+* button.\n' +
'1. Press the <custom-emoji emoji="actionMenuIcon" pressablewithdefaultaction /> button.\n' +
'2. Choose *Create expense*.\n' +
'3. Enter an amount or scan a receipt.\n' +
'4. Choose your *personal* space.\n' +
Expand All @@ -248,7 +248,7 @@ const combinedTrackSubmitOnboardingPersonalSpendMessage: OnboardingMessage = {
'\n' +
'Here’s how to track an expense:\n' +
'\n' +
'1. Click the green *+* button.\n' +
'1. Press the <custom-emoji emoji="actionMenuIcon" pressablewithdefaultaction /> button.\n' +
'2. Choose *Create expense*.\n' +
'3. Enter an amount or scan a receipt.\n' +
'4. Choose your *personal* space.\n' +
Expand Down Expand Up @@ -5462,7 +5462,7 @@ const CONST = {
'\n' +
'Here’s how to start a chat:\n' +
'\n' +
'1. Click the green *+* button.\n' +
'1. Press the <custom-emoji emoji="actionMenuIcon" pressablewithdefaultaction /> button.\n' +
'2. Choose *Start chat*.\n' +
'3. Enter emails or phone numbers.\n' +
'\n' +
Expand All @@ -5480,7 +5480,7 @@ const CONST = {
'\n' +
'Here’s how to request money:\n' +
'\n' +
'1. Click the green *+* button.\n' +
'1. Press the <custom-emoji emoji="actionMenuIcon" pressablewithdefaultaction /> 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' +
Expand Down Expand Up @@ -5516,7 +5516,7 @@ const CONST = {
'\n' +
'Here’s how to submit an expense:\n' +
'\n' +
'1. Click the green *+* button.\n' +
'1. Press the <custom-emoji emoji="actionMenuIcon" pressablewithdefaultaction /> button.\n' +
'2. Choose *Create expense*.\n' +
'3. Enter an amount or scan a receipt.\n' +
'4. Add your reimburser to the request.\n' +
Expand Down
133 changes: 133 additions & 0 deletions src/components/FABPopoverProvider.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,133 @@
import {useIsFocused} from '@react-navigation/native';
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';
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: (localFabRef: React.RefObject<HTMLDivElement>, localFabState: boolean) => void;
fabRef: MutableRefObject<HTMLDivElement | View | null>;
};

const FABPopoverContext = createContext<FABPopoverContextValue>({
isCreateMenuActive: false,
hideCreateMenu: () => {},
toggleCreateMenu: () => {},
fabRef: {current: null},
});

type FABPopoverProviderProps = {
children: ReactNode;
};

function FABPopoverProvider({children}: FABPopoverProviderProps) {
const [isCreateMenuActive, setIsCreateMenuActive] = useState(false);
const {shouldUseNarrowLayout} = useResponsiveLayout();
const fabRef = useRef<HTMLDivElement | null>(null);
const isFocused = useIsFocused();
const platform = getPlatform();

const popoverModal = useRef<FloatingActionButtonPopoverMenuRef>(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(
(fab: React.RefObject<HTMLDivElement>, isFabActionActive: boolean) => {
fabRef.current = fab.current;
if (isFabActionActive) {
return hideCreateMenu();
}
return showCreateMenu();
},
[hideCreateMenu, showCreateMenu],
);

const value = useMemo(
() => ({
isCreateMenuActive,
hideCreateMenu,
toggleCreateMenu,
fabRef,
}),
[isCreateMenuActive, toggleCreateMenu, hideCreateMenu, fabRef],
);

return (
<FABPopoverContext.Provider value={value}>
<FloatingActionButtonPopover ref={popoverModal} />
{children}
</FABPopoverContext.Provider>
);
}

export default FABPopoverProvider;
export {FABPopoverContext};
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,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}),
'mention-short': HTMLElementModel.fromCustomModel({tagName: 'mention-short', contentModel: HTMLContentModel.textual}),
'next-step': HTMLElementModel.fromCustomModel({
tagName: 'next-step',
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
import type {ReactNode} 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';
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 {toggleCreateMenu, isCreateMenuActive} = useContext(FABPopoverContext);
const [isFabActionActive, setIsFabActionActive] = useState(isCreateMenuActive);
useEffect(() => {
setIsFabActionActive(isCreateMenuActive);
}, [isCreateMenuActive]);
const localFabRef = useRef<HTMLDivElement>(null);

const {translate} = useLocalize();

if (emojiKey === 'actionMenuIcon') {
return (
<PressableWithoutFeedback
onPress={() => toggleCreateMenu(localFabRef, isFabActionActive)}
ref={localFabRef}
onLongPress={() => {}}
style={[styles.verticalAlignBottom, styles.userSelectNone]}
role={CONST.ROLE.BUTTON}
shouldUseHapticsOnLongPress={false}
accessibilityLabel={translate('sidebarScreen.fabNewChatExplained')}
>
{children}
</PressableWithoutFeedback>
);
}

return children;
}

export default CustomEmojiWithDefaultPressableAction;
Original file line number Diff line number Diff line change
@@ -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<string, FC<SvgProps>> = {
actionMenuIcon: GlobalCreateIcon,
};

function CustomEmojiRenderer({tnode}: CustomRendererProps<TText | TPhrasing>) {
const styles = useThemeStyles();
const emojiKey = tnode.attributes.emoji;

if (emojiMap[emojiKey]) {
const image = (
<View style={styles.customEmoji}>
<ImageSVG
height={variables.fontSizeNormalHeight}
width={variables.fontSizeNormalHeight}
src={emojiMap[emojiKey]}
/>
</View>
);

if ('pressablewithdefaultaction' in tnode.attributes) {
return <CustomEmojiWithDefaultPressableAction emojiKey={emojiKey}>{image}</CustomEmojiWithDefaultPressableAction>;
}

return image;
}

return null;
}

export default CustomEmojiRenderer;
export {emojiMap};
2 changes: 2 additions & 0 deletions src/components/HTMLEngineProvider/HTMLRenderers/index.ts
Original file line number Diff line number Diff line change
@@ -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';
Expand Down Expand Up @@ -38,6 +39,7 @@ const HTMLEngineProviderComponentList: CustomTagRendererRecord = {
'mention-user': MentionUserRenderer,
'mention-report': MentionReportRenderer,
'mention-here': MentionHereRenderer,
'custom-emoji': CustomEmojiRenderer,
'mention-short': ShortMentionRenderer,
emoji: EmojiRenderer,
'next-step-email': NextStepEmailRenderer,
Expand Down
21 changes: 18 additions & 3 deletions src/components/Navigation/BottomTabBar/index.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
import React, {memo, useCallback, 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';
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';
Expand All @@ -27,7 +29,6 @@ import Navigation from '@navigation/Navigation';
import navigationRef from '@navigation/navigationRef';
import type {RootNavigatorParamList, SearchFullscreenNavigatorParamList, 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';
Expand All @@ -42,6 +43,8 @@ type BottomTabBarProps = {
};

function BottomTabBar({selectedTab, isTooltipAllowed = false}: BottomTabBarProps) {
const {isCreateMenuActive, toggleCreateMenu} = useContext(FABPopoverContext);
const localFabRef = useRef<HTMLDivElement>(null);
const theme = useTheme();
const styles = useThemeStyles();
const {translate} = useLocalize();
Expand All @@ -58,6 +61,11 @@ 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, reports));
// We need to get a new brick road state when report actions are updated, otherwise we'll be showing an outdated brick road.
Expand Down Expand Up @@ -259,7 +267,14 @@ function BottomTabBar({selectedTab, isTooltipAllowed = false}: BottomTabBarProps
onPress={showSettingsPage}
/>
<View style={[styles.flex1, styles.bottomTabBarItem]}>
<BottomTabBarFloatingActionButton isTooltipAllowed={isTooltipAllowed} />
<FloatingActionButton
accessibilityLabel={translate('sidebarScreen.fabNewChatExplained')}
role={CONST.ROLE.BUTTON}
isActive={isCreateMenuActive}
ref={localFabRef}
onPress={() => toggleCreateMenu(localFabRef, isFabActionActive)}
isTooltipAllowed={isTooltipAllowed}
/>
</View>
</View>
</>
Expand Down
Loading