Skip to content

Commit

Permalink
replace WithTheme and WithThemeStyles HOC with useTheme and useThemeS…
Browse files Browse the repository at this point in the history
…tyles hooks
  • Loading branch information
rayane-djouah committed Dec 15, 2023
1 parent 416229d commit 3648e1b
Showing 1 changed file with 9 additions and 11 deletions.
20 changes: 9 additions & 11 deletions src/components/FloatingActionButton/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,9 @@ import {View} from 'react-native';
import Animated, {Easing, interpolateColor, useAnimatedStyle, useSharedValue, withTiming} from 'react-native-reanimated';
import PressableWithFeedback from '@components/Pressable/PressableWithFeedback';
import Tooltip from '@components/Tooltip/PopoverAnchorTooltip';
import withTheme, {withThemePropTypes} from '@components/withTheme';
import withThemeStyles, {withThemeStylesPropTypes} from '@components/withThemeStyles';
import useLocalize from '@hooks/useLocalize';
import compose from '@libs/compose';
import useTheme from '@styles/themes/useTheme';
import useThemeStyles from '@styles/useThemeStyles';
import FabPlusIcon from './FabPlusIcon';

const AnimatedPressable = Animated.createAnimatedComponent(PressableWithFeedback);
Expand All @@ -25,12 +24,11 @@ const propTypes = {

/* An accessibility role for the button */
role: PropTypes.string.isRequired,

...withThemeStylesPropTypes,
...withThemePropTypes,
};

const FloatingActionButton = React.forwardRef(({onPress, isActive, accessibilityLabel, role, theme, themeStyles}, ref) => {
const FloatingActionButton = React.forwardRef(({onPress, isActive, accessibilityLabel, role}, ref) => {
const theme = useTheme();
const styles = useThemeStyles();
const {translate} = useLocalize();
const fabPressable = useRef(null);
const animatedValue = useSharedValue(isActive ? 1 : 0);
Expand All @@ -49,13 +47,13 @@ const FloatingActionButton = React.forwardRef(({onPress, isActive, accessibility
return {
transform: [{rotate: `${animatedValue.value * 135}deg`}],
backgroundColor,
borderRadius: themeStyles.floatingActionButton.borderRadius,
borderRadius: styles.floatingActionButton.borderRadius,
};
});

return (
<Tooltip text={translate('common.new')}>
<View style={themeStyles.floatingActionButtonContainer}>
<View style={styles.floatingActionButtonContainer}>
<AnimatedPressable
ref={(el) => {
fabPressable.current = el;
Expand All @@ -72,7 +70,7 @@ const FloatingActionButton = React.forwardRef(({onPress, isActive, accessibility
onPress(e);
}}
onLongPress={() => {}}
style={[themeStyles.floatingActionButton, animatedStyle]}
style={[styles.floatingActionButton, animatedStyle]}
>
<FabPlusIcon isActive={isActive} />
</AnimatedPressable>
Expand All @@ -84,4 +82,4 @@ const FloatingActionButton = React.forwardRef(({onPress, isActive, accessibility
FloatingActionButton.propTypes = propTypes;
FloatingActionButton.displayName = 'FloatingActionButton';

export default compose(withThemeStyles, withTheme)(FloatingActionButton);
export default FloatingActionButton;

0 comments on commit 3648e1b

Please sign in to comment.