2019-07-15 17:24:48 +00:00
|
|
|
import React from 'react';
|
|
|
|
import { Animated, View, Text } from 'react-native';
|
|
|
|
import { RectButton } from 'react-native-gesture-handler';
|
|
|
|
import PropTypes from 'prop-types';
|
|
|
|
|
|
|
|
import I18n from '../../i18n';
|
|
|
|
import styles, { ACTION_WIDTH, LONG_SWIPE } from './styles';
|
|
|
|
import { CustomIcon } from '../../lib/Icons';
|
2019-12-11 23:01:12 +00:00
|
|
|
import { themes } from '../../constants/colors';
|
2019-07-15 17:24:48 +00:00
|
|
|
|
|
|
|
export const LeftActions = React.memo(({
|
2019-12-11 23:01:12 +00:00
|
|
|
theme, transX, isRead, width, onToggleReadPress
|
2019-07-15 17:24:48 +00:00
|
|
|
}) => {
|
|
|
|
const translateX = transX.interpolate({
|
|
|
|
inputRange: [0, ACTION_WIDTH],
|
|
|
|
outputRange: [-ACTION_WIDTH, 0]
|
|
|
|
});
|
|
|
|
const translateXIcon = transX.interpolate({
|
|
|
|
inputRange: [0, ACTION_WIDTH, LONG_SWIPE - 2, LONG_SWIPE],
|
|
|
|
outputRange: [0, 0, -LONG_SWIPE + ACTION_WIDTH + 2, 0],
|
|
|
|
extrapolate: 'clamp'
|
|
|
|
});
|
|
|
|
return (
|
|
|
|
<View
|
2019-12-11 23:01:12 +00:00
|
|
|
style={[styles.actionsContainer, styles.actionLeftContainer]}
|
2019-07-15 17:24:48 +00:00
|
|
|
pointerEvents='box-none'
|
|
|
|
>
|
|
|
|
<Animated.View
|
|
|
|
style={[
|
|
|
|
styles.actionLeftButtonContainer,
|
|
|
|
{
|
|
|
|
right: width - ACTION_WIDTH,
|
|
|
|
width,
|
2019-12-11 23:01:12 +00:00
|
|
|
transform: [{ translateX }],
|
|
|
|
backgroundColor: themes[theme].tintColor
|
2019-07-15 17:24:48 +00:00
|
|
|
}
|
|
|
|
]}
|
|
|
|
>
|
|
|
|
<Animated.View
|
|
|
|
style={[
|
|
|
|
styles.actionLeftButtonContainer,
|
|
|
|
{
|
|
|
|
right: 0,
|
|
|
|
transform: [{ translateX: translateXIcon }]
|
|
|
|
}
|
|
|
|
]}
|
|
|
|
>
|
|
|
|
<RectButton style={styles.actionButton} onPress={onToggleReadPress}>
|
2019-10-07 20:56:30 +00:00
|
|
|
<>
|
2019-07-15 17:24:48 +00:00
|
|
|
<CustomIcon size={20} name={isRead ? 'flag' : 'check'} color='white' />
|
2019-12-11 23:01:12 +00:00
|
|
|
<Text style={[styles.actionText, { color: themes[theme].buttonText }]}>{I18n.t(isRead ? 'Unread' : 'Read')}</Text>
|
2019-10-07 20:56:30 +00:00
|
|
|
</>
|
2019-07-15 17:24:48 +00:00
|
|
|
</RectButton>
|
|
|
|
</Animated.View>
|
|
|
|
</Animated.View>
|
|
|
|
</View>
|
|
|
|
);
|
|
|
|
});
|
|
|
|
|
|
|
|
export const RightActions = React.memo(({
|
2019-12-11 23:01:12 +00:00
|
|
|
transX, favorite, width, toggleFav, onHidePress, theme
|
2019-07-15 17:24:48 +00:00
|
|
|
}) => {
|
|
|
|
const translateXFav = transX.interpolate({
|
|
|
|
inputRange: [-width / 2, -ACTION_WIDTH * 2, 0],
|
|
|
|
outputRange: [width / 2, width - ACTION_WIDTH * 2, width]
|
|
|
|
});
|
|
|
|
const translateXHide = transX.interpolate({
|
|
|
|
inputRange: [-width, -LONG_SWIPE, -ACTION_WIDTH * 2, 0],
|
|
|
|
outputRange: [0, width - LONG_SWIPE, width - ACTION_WIDTH, width]
|
|
|
|
});
|
|
|
|
return (
|
|
|
|
<View
|
|
|
|
style={{
|
|
|
|
position: 'absolute',
|
|
|
|
left: 0,
|
|
|
|
right: 0,
|
|
|
|
height: 75,
|
|
|
|
flexDirection: 'row'
|
|
|
|
}}
|
|
|
|
pointerEvents='box-none'
|
|
|
|
>
|
|
|
|
<Animated.View
|
|
|
|
style={[
|
|
|
|
styles.actionRightButtonContainer,
|
|
|
|
{
|
|
|
|
width,
|
2019-12-11 23:01:12 +00:00
|
|
|
transform: [{ translateX: translateXFav }],
|
|
|
|
backgroundColor: themes[theme].hideBackground
|
2019-07-15 17:24:48 +00:00
|
|
|
}
|
|
|
|
]}
|
|
|
|
>
|
2019-12-11 23:01:12 +00:00
|
|
|
<RectButton style={[styles.actionButton, { backgroundColor: themes[theme].favoriteBackground }]} onPress={toggleFav}>
|
2019-10-07 20:56:30 +00:00
|
|
|
<>
|
2019-12-11 23:01:12 +00:00
|
|
|
<CustomIcon size={20} name={favorite ? 'Star-filled' : 'star'} color={themes[theme].buttonText} />
|
|
|
|
<Text style={[styles.actionText, { color: themes[theme].buttonText }]}>{I18n.t(favorite ? 'Unfavorite' : 'Favorite')}</Text>
|
2019-10-07 20:56:30 +00:00
|
|
|
</>
|
2019-07-15 17:24:48 +00:00
|
|
|
</RectButton>
|
|
|
|
</Animated.View>
|
|
|
|
<Animated.View
|
|
|
|
style={[
|
|
|
|
styles.actionRightButtonContainer,
|
|
|
|
{
|
|
|
|
width,
|
|
|
|
transform: [{ translateX: translateXHide }]
|
|
|
|
}
|
|
|
|
]}
|
|
|
|
>
|
2019-12-11 23:01:12 +00:00
|
|
|
<RectButton style={[styles.actionButton, { backgroundColor: themes[theme].hideBackground }]} onPress={onHidePress}>
|
2019-10-07 20:56:30 +00:00
|
|
|
<>
|
2019-12-11 23:01:12 +00:00
|
|
|
<CustomIcon size={20} name='eye-off' color={themes[theme].buttonText} />
|
|
|
|
<Text style={[styles.actionText, { color: themes[theme].buttonText }]}>{I18n.t('Hide')}</Text>
|
2019-10-07 20:56:30 +00:00
|
|
|
</>
|
2019-07-15 17:24:48 +00:00
|
|
|
</RectButton>
|
|
|
|
</Animated.View>
|
|
|
|
</View>
|
|
|
|
);
|
|
|
|
});
|
|
|
|
|
|
|
|
LeftActions.propTypes = {
|
2019-12-11 23:01:12 +00:00
|
|
|
theme: PropTypes.string,
|
2019-07-15 17:24:48 +00:00
|
|
|
transX: PropTypes.object,
|
|
|
|
isRead: PropTypes.bool,
|
|
|
|
width: PropTypes.number,
|
|
|
|
onToggleReadPress: PropTypes.func
|
|
|
|
};
|
|
|
|
|
|
|
|
RightActions.propTypes = {
|
2019-12-11 23:01:12 +00:00
|
|
|
theme: PropTypes.string,
|
2019-07-15 17:24:48 +00:00
|
|
|
transX: PropTypes.object,
|
|
|
|
favorite: PropTypes.bool,
|
|
|
|
width: PropTypes.number,
|
|
|
|
toggleFav: PropTypes.func,
|
|
|
|
onHidePress: PropTypes.func
|
|
|
|
};
|