Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
2 changes: 1 addition & 1 deletion assets/images/camera.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 0 additions & 1 deletion assets/images/plus-circle.svg

This file was deleted.

120 changes: 37 additions & 83 deletions src/components/FloatingActionButton.tsx
Original file line number Diff line number Diff line change
@@ -1,21 +1,15 @@
import type {ForwardedRef} from 'react';
import React, {useEffect, useRef} from 'react';
// eslint-disable-next-line no-restricted-imports
import type {GestureResponderEvent, Role, Text as TextType, View as ViewType} from 'react-native';
import {View} from 'react-native';
import type {GestureResponderEvent, Role, Text, View} from 'react-native';
import Animated, {Easing, interpolateColor, useAnimatedStyle, useSharedValue, withTiming} from 'react-native-reanimated';
import Svg, {Path} from 'react-native-svg';
import useLocalize from '@hooks/useLocalize';
import useResponsiveLayout from '@hooks/useResponsiveLayout';
import useTheme from '@hooks/useTheme';
import useThemeStyles from '@hooks/useThemeStyles';
import {canUseTouchScreen} from '@libs/DeviceCapabilities';
import variables from '@styles/variables';
import CONST from '@src/CONST';
import Icon from './Icon';
import {PlusCircle} from './Icon/Expensicons';
import {PressableWithFeedback, PressableWithoutFeedback} from './Pressable';
import Text from './Text';
import {PressableWithoutFeedback} from './Pressable';

const FAB_PATH = 'M12,3c0-1.1-0.9-2-2-2C8.9,1,8,1.9,8,3v5H3c-1.1,0-2,0.9-2,2c0,1.1,0.9,2,2,2h5v5c0,1.1,0.9,2,2,2c1.1,0,2-0.9,2-2v-5h5c1.1,0,2-0.9,2-2c0-1.1-0.9-2-2-2h-5V3z';
const SMALL_FAB_PATH =
Expand All @@ -41,17 +35,16 @@ type FloatingActionButtonProps = {
role: Role;

/** Reference to the outer element */
ref?: ForwardedRef<HTMLDivElement | ViewType | TextType>;
ref?: ForwardedRef<HTMLDivElement | View | Text>;
};

function FloatingActionButton({onPress, onLongPress, isActive, accessibilityLabel, role, ref}: FloatingActionButtonProps) {
const {buttonDefaultBG, buttonHoveredBG, icon} = useTheme();
const {success, successHover, buttonDefaultBG, textLight} = useTheme();
const styles = useThemeStyles();
const borderRadius = styles.floatingActionButton.borderRadius;
const fabPressable = useRef<HTMLDivElement | ViewType | TextType | null>(null);
const fabPressable = useRef<HTMLDivElement | View | Text | null>(null);
const {shouldUseNarrowLayout} = useResponsiveLayout();
const isLHBVisible = !shouldUseNarrowLayout;
const {translate} = useLocalize();

const fabSize = isLHBVisible ? variables.iconSizeSmall : variables.iconSizeNormal;

Expand All @@ -68,7 +61,7 @@ function FloatingActionButton({onPress, onLongPress, isActive, accessibilityLabe
}, [isActive, sharedValue]);

const animatedStyle = useAnimatedStyle(() => {
const backgroundColor = interpolateColor(sharedValue.get(), [0, 1], [buttonDefaultBG, buttonHoveredBG]);
const backgroundColor = interpolateColor(sharedValue.get(), [0, 1], [success, buttonDefaultBG]);

return {
transform: [{rotate: `${sharedValue.get() * 135}deg`}],
Expand All @@ -92,84 +85,45 @@ function FloatingActionButton({onPress, onLongPress, isActive, accessibilityLabe
onLongPress?.(event);
};

if (isLHBVisible) {
return (
<PressableWithoutFeedback
ref={(el) => {
fabPressable.current = el ?? null;
if (buttonRef && 'current' in buttonRef) {
buttonRef.current = el ?? null;
}
}}
style={[
styles.navigationTabBarFABItem,

// Prevent text selection on touch devices (e.g. on long press)
canUseTouchScreen() && styles.userSelectNone,
styles.flex1,
]}
accessibilityLabel={accessibilityLabel}
onPress={toggleFabAction}
onLongPress={longPressFabAction}
role={role}
shouldUseHapticsOnLongPress
testID="floating-action-button"
>
{({hovered}) => (
<Animated.View
style={[styles.floatingActionButton, {borderRadius}, styles.floatingActionButtonSmall, animatedStyle, hovered && {backgroundColor: buttonHoveredBG}]}
testID="fab-animated-container"
>
<Svg
width={fabSize}
height={fabSize}
>
<AnimatedPath
d={isLHBVisible ? SMALL_FAB_PATH : FAB_PATH}
fill={icon}
/>
</Svg>
</Animated.View>
)}
</PressableWithoutFeedback>
);
}

return (
<PressableWithFeedback
onPress={onPress}
role={CONST.ROLE.BUTTON}
accessibilityLabel={translate('common.create')}
wrapperStyle={styles.flex1}
<PressableWithoutFeedback
ref={(el) => {
fabPressable.current = el ?? null;
if (buttonRef && 'current' in buttonRef) {
buttonRef.current = el ?? null;
}
}}
style={[
styles.navigationTabBarFABItem,
styles.h100,
styles.navigationTabBarItem,

// Prevent text selection on touch devices (e.g. on long press)
canUseTouchScreen() && styles.userSelectNone,
styles.flex1,
]}
testID="create-action-button"
accessibilityLabel={accessibilityLabel}
onPress={toggleFabAction}
onLongPress={longPressFabAction}
role={role}
shouldUseHapticsOnLongPress
testID="floating-action-button"
>
<View
testID="fab-container"
style={styles.navigationTabBarItem}
>
<View>
<Icon
src={PlusCircle}
fill={icon}
width={variables.iconBottomBar}
height={variables.iconBottomBar}
/>
</View>
<Text
numberOfLines={1}
style={[styles.textSmall, styles.textAlignCenter, styles.mt1Half, styles.textSupporting, styles.navigationTabBarLabel]}
{({hovered}) => (
<Animated.View
style={[styles.floatingActionButton, {borderRadius}, isLHBVisible && styles.floatingActionButtonSmall, animatedStyle, hovered && {backgroundColor: successHover}]}
testID="fab-animated-container"
>
{translate('common.create')}
</Text>
</View>
</PressableWithFeedback>
<Svg
width={fabSize}
height={fabSize}
>
<AnimatedPath
d={isLHBVisible ? SMALL_FAB_PATH : FAB_PATH}
fill={textLight}
/>
</Svg>
</Animated.View>
)}
</PressableWithoutFeedback>
);
}

Expand Down
91 changes: 0 additions & 91 deletions src/components/FloatingCameraButton.tsx

This file was deleted.

72 changes: 0 additions & 72 deletions src/components/FloatingReceiptButton.tsx

This file was deleted.

2 changes: 0 additions & 2 deletions src/components/Icon/Expensicons.ts
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,6 @@ import Phone from '@assets/images/phone.svg';
import Pin from '@assets/images/pin.svg';
import Plane from '@assets/images/plane.svg';
import Play from '@assets/images/play.svg';
import PlusCircle from '@assets/images/plus-circle.svg';
import PlusMinus from '@assets/images/plus-minus.svg';
import Plus from '@assets/images/plus.svg';
import Printer from '@assets/images/printer.svg';
Expand Down Expand Up @@ -453,5 +452,4 @@ export {
SageIntacctExport,
XeroExport,
ArrowCircleClockwise,
PlusCircle,
};
2 changes: 1 addition & 1 deletion src/components/Navigation/NavigationTabBar/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -324,7 +324,7 @@ function NavigationTabBar({selectedTab, isTopLevelBar = false}: NavigationTabBar
onPress={navigateToSettings}
/>
</View>
<View style={styles.leftNavigationTabBarFAB}>
<View style={styles.leftNavigationTabBarItem}>
<NavigationTabBarFloatingActionButton />
</View>
</View>
Expand Down
Loading