2019-07-15 16:54:28 +00:00
|
|
|
import React from 'react';
|
2021-09-13 20:41:05 +00:00
|
|
|
import { Animated, Text, View } from 'react-native';
|
2019-07-15 16:54:28 +00:00
|
|
|
import { RectButton } from 'react-native-gesture-handler';
|
|
|
|
|
2021-04-01 12:58:20 +00:00
|
|
|
import I18n, { isRTL } from '../../i18n';
|
2019-07-15 16:54:28 +00:00
|
|
|
import styles, { ACTION_WIDTH, LONG_SWIPE } from './styles';
|
|
|
|
import { CustomIcon } from '../../lib/Icons';
|
2019-12-04 16:39:53 +00:00
|
|
|
import { themes } from '../../constants/colors';
|
2019-07-15 16:54:28 +00:00
|
|
|
|
2021-09-13 20:41:05 +00:00
|
|
|
interface ILeftActions {
|
|
|
|
theme: string;
|
|
|
|
transX: any;
|
|
|
|
isRead: boolean;
|
|
|
|
width: number;
|
|
|
|
onToggleReadPress(): void;
|
|
|
|
}
|
|
|
|
|
|
|
|
interface IRightActions {
|
|
|
|
theme: string;
|
|
|
|
transX: any;
|
|
|
|
favorite: boolean;
|
|
|
|
width: number;
|
|
|
|
toggleFav(): void;
|
|
|
|
onHidePress(): void;
|
|
|
|
}
|
|
|
|
|
2021-04-01 12:58:20 +00:00
|
|
|
const reverse = new Animated.Value(isRTL() ? -1 : 1);
|
2020-11-30 21:47:05 +00:00
|
|
|
|
2021-09-13 20:41:05 +00:00
|
|
|
export const LeftActions = React.memo(({ theme, transX, isRead, width, onToggleReadPress }: ILeftActions) => {
|
2020-11-30 21:47:05 +00:00
|
|
|
const translateX = Animated.multiply(
|
|
|
|
transX.interpolate({
|
|
|
|
inputRange: [0, ACTION_WIDTH],
|
|
|
|
outputRange: [-ACTION_WIDTH, 0]
|
|
|
|
}),
|
|
|
|
reverse
|
|
|
|
);
|
2019-07-15 16:54:28 +00:00
|
|
|
return (
|
2021-09-13 20:41:05 +00:00
|
|
|
<View style={[styles.actionsContainer, styles.actionLeftContainer]} 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
|
2019-07-15 16:54:28 +00:00
|
|
|
}
|
2021-09-13 20:41:05 +00:00
|
|
|
]}>
|
2020-11-30 21:47:05 +00:00
|
|
|
<View style={styles.actionLeftButtonContainer}>
|
2019-07-15 16:54:28 +00:00
|
|
|
<RectButton style={styles.actionButton} onPress={onToggleReadPress}>
|
2019-09-24 20:26:56 +00:00
|
|
|
<>
|
2019-07-15 16:54:28 +00:00
|
|
|
<CustomIcon size={20} name={isRead ? 'flag' : 'check'} color='white' />
|
2019-12-04 16:39:53 +00:00
|
|
|
<Text style={[styles.actionText, { color: themes[theme].buttonText }]}>{I18n.t(isRead ? 'Unread' : 'Read')}</Text>
|
2019-09-24 20:26:56 +00:00
|
|
|
</>
|
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-09-13 20:41:05 +00:00
|
|
|
export const RightActions = React.memo(({ transX, favorite, width, toggleFav, onHidePress, theme }: IRightActions) => {
|
2020-11-30 21:47:05 +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
|
|
|
|
);
|
2019-07-15 16:54:28 +00:00
|
|
|
return (
|
|
|
|
<View
|
|
|
|
style={{
|
|
|
|
position: 'absolute',
|
|
|
|
left: 0,
|
|
|
|
right: 0,
|
|
|
|
height: 75,
|
|
|
|
flexDirection: 'row'
|
|
|
|
}}
|
2021-09-13 20:41:05 +00:00
|
|
|
pointerEvents='box-none'>
|
2019-07-15 16:54:28 +00:00
|
|
|
<Animated.View
|
|
|
|
style={[
|
|
|
|
styles.actionRightButtonContainer,
|
|
|
|
{
|
|
|
|
width,
|
2019-12-04 16:39:53 +00:00
|
|
|
transform: [{ translateX: translateXFav }],
|
|
|
|
backgroundColor: themes[theme].hideBackground
|
2019-07-15 16:54:28 +00:00
|
|
|
}
|
2021-09-13 20:41:05 +00:00
|
|
|
]}>
|
2019-12-04 16:39:53 +00:00
|
|
|
<RectButton style={[styles.actionButton, { backgroundColor: themes[theme].favoriteBackground }]} onPress={toggleFav}>
|
2019-09-24 20:26:56 +00:00
|
|
|
<>
|
2020-06-05 13:28:58 +00:00
|
|
|
<CustomIcon size={20} name={favorite ? 'star-filled' : 'star'} color={themes[theme].buttonText} />
|
2021-09-13 20:41:05 +00:00
|
|
|
<Text style={[styles.actionText, { color: themes[theme].buttonText }]}>
|
|
|
|
{I18n.t(favorite ? 'Unfavorite' : 'Favorite')}
|
|
|
|
</Text>
|
2019-09-24 20:26:56 +00:00
|
|
|
</>
|
2019-07-15 16:54:28 +00:00
|
|
|
</RectButton>
|
|
|
|
</Animated.View>
|
|
|
|
<Animated.View
|
|
|
|
style={[
|
|
|
|
styles.actionRightButtonContainer,
|
|
|
|
{
|
|
|
|
width,
|
|
|
|
transform: [{ translateX: translateXHide }]
|
|
|
|
}
|
2021-09-13 20:41:05 +00:00
|
|
|
]}>
|
2019-12-04 16:39:53 +00:00
|
|
|
<RectButton style={[styles.actionButton, { backgroundColor: themes[theme].hideBackground }]} onPress={onHidePress}>
|
2019-09-24 20:26:56 +00:00
|
|
|
<>
|
2020-07-27 19:53:33 +00:00
|
|
|
<CustomIcon size={20} name='unread-on-top-disabled' color={themes[theme].buttonText} />
|
2019-12-04 16:39:53 +00:00
|
|
|
<Text style={[styles.actionText, { color: themes[theme].buttonText }]}>{I18n.t('Hide')}</Text>
|
2019-09-24 20:26:56 +00:00
|
|
|
</>
|
2019-07-15 16:54:28 +00:00
|
|
|
</RectButton>
|
|
|
|
</Animated.View>
|
|
|
|
</View>
|
|
|
|
);
|
|
|
|
});
|