2019-07-15 16:54:28 +00:00
|
|
|
import React from 'react';
|
2021-10-06 20:30:10 +00:00
|
|
|
import { Animated, View } from 'react-native';
|
2019-07-15 16:54:28 +00:00
|
|
|
import { RectButton } from 'react-native-gesture-handler';
|
|
|
|
|
2021-10-06 20:30:10 +00:00
|
|
|
import { isRTL } from '../../i18n';
|
2022-05-02 19:21:15 +00:00
|
|
|
import { CustomIcon } from '../CustomIcon';
|
2022-04-07 14:10:03 +00:00
|
|
|
import { DisplayMode, themes } from '../../lib/constants';
|
2021-10-06 20:30:10 +00:00
|
|
|
import styles, { ACTION_WIDTH, LONG_SWIPE, ROW_HEIGHT_CONDENSED } from './styles';
|
2022-04-20 21:37:54 +00:00
|
|
|
import { ILeftActionsProps, IRightActionsProps } from './interfaces';
|
2021-09-13 20:41:05 +00:00
|
|
|
|
2021-04-01 12:58:20 +00:00
|
|
|
const reverse = new Animated.Value(isRTL() ? -1 : 1);
|
2021-10-06 20:30:10 +00:00
|
|
|
const CONDENSED_ICON_SIZE = 24;
|
|
|
|
const EXPANDED_ICON_SIZE = 28;
|
2020-11-30 21:47:05 +00:00
|
|
|
|
2022-04-20 21:37:54 +00:00
|
|
|
export const LeftActions = React.memo(({ theme, transX, isRead, width, onToggleReadPress, displayMode }: ILeftActionsProps) => {
|
2020-11-30 21:47:05 +00:00
|
|
|
const translateX = Animated.multiply(
|
|
|
|
transX.interpolate({
|
|
|
|
inputRange: [0, ACTION_WIDTH],
|
|
|
|
outputRange: [-ACTION_WIDTH, 0]
|
|
|
|
}),
|
|
|
|
reverse
|
|
|
|
);
|
2021-10-06 20:30:10 +00:00
|
|
|
|
2022-01-11 14:47:23 +00:00
|
|
|
const isCondensed = displayMode === DisplayMode.Condensed;
|
2021-10-06 20:30:10 +00:00
|
|
|
const viewHeight = isCondensed ? { height: ROW_HEIGHT_CONDENSED } : null;
|
|
|
|
|
2019-07-15 16:54:28 +00:00
|
|
|
return (
|
2022-04-20 21:02:18 +00:00
|
|
|
<View style={[styles.actionsContainer, styles.actionsLeftContainer]} pointerEvents='box-none'>
|
2019-07-15 16:54:28 +00:00
|
|
|
<Animated.View
|
|
|
|
style={[
|
|
|
|
styles.actionLeftButtonContainer,
|
|
|
|
{
|
|
|
|
right: width - ACTION_WIDTH,
|
|
|
|
width,
|
2019-12-04 16:39:53 +00:00
|
|
|
transform: [{ translateX }],
|
|
|
|
backgroundColor: themes[theme].tintColor
|
2021-10-06 20:30:10 +00:00
|
|
|
},
|
|
|
|
viewHeight
|
2021-09-13 20:41:05 +00:00
|
|
|
]}>
|
2021-10-06 20:30:10 +00:00
|
|
|
<View style={[styles.actionLeftButtonContainer, viewHeight]}>
|
2019-07-15 16:54:28 +00:00
|
|
|
<RectButton style={styles.actionButton} onPress={onToggleReadPress}>
|
2021-10-06 20:30:10 +00:00
|
|
|
<CustomIcon
|
|
|
|
size={isCondensed ? CONDENSED_ICON_SIZE : EXPANDED_ICON_SIZE}
|
|
|
|
name={isRead ? 'flag' : 'check'}
|
|
|
|
color={themes[theme].buttonText}
|
|
|
|
/>
|
2019-07-15 16:54:28 +00:00
|
|
|
</RectButton>
|
2020-11-30 21:47:05 +00:00
|
|
|
</View>
|
2019-07-15 16:54:28 +00:00
|
|
|
</Animated.View>
|
|
|
|
</View>
|
|
|
|
);
|
|
|
|
});
|
|
|
|
|
2021-10-06 20:30:10 +00:00
|
|
|
export const RightActions = React.memo(
|
2022-04-20 21:37:54 +00:00
|
|
|
({ transX, favorite, width, toggleFav, onHidePress, theme, displayMode }: IRightActionsProps) => {
|
2021-10-06 20:30:10 +00:00
|
|
|
const translateXFav = Animated.multiply(
|
|
|
|
transX.interpolate({
|
|
|
|
inputRange: [-width / 2, -ACTION_WIDTH * 2, 0],
|
|
|
|
outputRange: [width / 2, width - ACTION_WIDTH * 2, width]
|
|
|
|
}),
|
|
|
|
reverse
|
|
|
|
);
|
|
|
|
const translateXHide = Animated.multiply(
|
|
|
|
transX.interpolate({
|
|
|
|
inputRange: [-width, -LONG_SWIPE, -ACTION_WIDTH * 2, 0],
|
|
|
|
outputRange: [0, width - LONG_SWIPE, width - ACTION_WIDTH, width]
|
|
|
|
}),
|
|
|
|
reverse
|
|
|
|
);
|
|
|
|
|
2022-01-11 14:47:23 +00:00
|
|
|
const isCondensed = displayMode === DisplayMode.Condensed;
|
2021-10-06 20:30:10 +00:00
|
|
|
const viewHeight = isCondensed ? { height: ROW_HEIGHT_CONDENSED } : null;
|
|
|
|
|
|
|
|
return (
|
|
|
|
<View style={[styles.actionsLeftContainer, viewHeight]} pointerEvents='box-none'>
|
|
|
|
<Animated.View
|
|
|
|
style={[
|
|
|
|
styles.actionRightButtonContainer,
|
|
|
|
{
|
|
|
|
width,
|
|
|
|
transform: [{ translateX: translateXFav }],
|
|
|
|
backgroundColor: themes[theme].hideBackground
|
|
|
|
},
|
|
|
|
viewHeight
|
|
|
|
]}>
|
|
|
|
<RectButton style={[styles.actionButton, { backgroundColor: themes[theme].favoriteBackground }]} onPress={toggleFav}>
|
|
|
|
<CustomIcon
|
|
|
|
size={isCondensed ? CONDENSED_ICON_SIZE : EXPANDED_ICON_SIZE}
|
|
|
|
name={favorite ? 'star-filled' : 'star'}
|
|
|
|
color={themes[theme].buttonText}
|
|
|
|
/>
|
|
|
|
</RectButton>
|
|
|
|
</Animated.View>
|
|
|
|
<Animated.View
|
|
|
|
style={[
|
|
|
|
styles.actionRightButtonContainer,
|
|
|
|
{
|
|
|
|
width,
|
|
|
|
transform: [{ translateX: translateXHide }]
|
|
|
|
},
|
|
|
|
isCondensed && { height: ROW_HEIGHT_CONDENSED }
|
|
|
|
]}>
|
|
|
|
<RectButton style={[styles.actionButton, { backgroundColor: themes[theme].hideBackground }]} onPress={onHidePress}>
|
|
|
|
<CustomIcon
|
|
|
|
size={isCondensed ? CONDENSED_ICON_SIZE : EXPANDED_ICON_SIZE}
|
|
|
|
name='unread-on-top-disabled'
|
|
|
|
color={themes[theme].buttonText}
|
|
|
|
/>
|
|
|
|
</RectButton>
|
|
|
|
</Animated.View>
|
|
|
|
</View>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
);
|