2020-10-30 17:35:07 +00:00
|
|
|
import React from 'react';
|
2021-09-13 20:41:05 +00:00
|
|
|
import { Animated, Easing, TouchableWithoutFeedback } from 'react-native';
|
2022-01-12 13:53:06 +00:00
|
|
|
import { EdgeInsets, withSafeAreaInsets } from 'react-native-safe-area-context';
|
2020-10-30 17:35:07 +00:00
|
|
|
|
|
|
|
import styles from '../styles';
|
2022-04-07 14:10:03 +00:00
|
|
|
import { themes } from '../../../lib/constants';
|
2022-04-12 16:27:05 +00:00
|
|
|
import { TSupportedThemes, withTheme } from '../../../theme';
|
2020-10-30 17:35:07 +00:00
|
|
|
import { headerHeight } from '../../../containers/Header';
|
|
|
|
import * as List from '../../../containers/List';
|
2022-01-12 13:53:06 +00:00
|
|
|
import { Filter } from '../filters';
|
2020-10-30 17:35:07 +00:00
|
|
|
import DropdownItemFilter from './DropdownItemFilter';
|
|
|
|
import DropdownItemHeader from './DropdownItemHeader';
|
|
|
|
|
|
|
|
const ANIMATION_DURATION = 200;
|
|
|
|
|
2022-01-12 13:53:06 +00:00
|
|
|
interface IDropdownProps {
|
2022-01-17 16:10:39 +00:00
|
|
|
isMasterDetail?: boolean;
|
2022-04-12 16:27:05 +00:00
|
|
|
theme?: TSupportedThemes;
|
2022-01-17 16:10:39 +00:00
|
|
|
insets?: EdgeInsets;
|
2022-01-12 13:53:06 +00:00
|
|
|
currentFilter: Filter;
|
|
|
|
onClose: () => void;
|
2022-01-17 16:10:39 +00:00
|
|
|
onFilterSelected: (value: Filter) => void;
|
2022-01-12 13:53:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
class Dropdown extends React.Component<IDropdownProps> {
|
|
|
|
private animatedValue: Animated.Value;
|
2020-10-30 17:35:07 +00:00
|
|
|
|
2022-01-12 13:53:06 +00:00
|
|
|
constructor(props: IDropdownProps) {
|
2020-10-30 17:35:07 +00:00
|
|
|
super(props);
|
|
|
|
this.animatedValue = new Animated.Value(0);
|
|
|
|
}
|
|
|
|
|
|
|
|
componentDidMount() {
|
2021-09-13 20:41:05 +00:00
|
|
|
Animated.timing(this.animatedValue, {
|
|
|
|
toValue: 1,
|
|
|
|
duration: ANIMATION_DURATION,
|
|
|
|
easing: Easing.inOut(Easing.quad),
|
|
|
|
useNativeDriver: true
|
|
|
|
}).start();
|
2020-10-30 17:35:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
close = () => {
|
|
|
|
const { onClose } = this.props;
|
2021-09-13 20:41:05 +00:00
|
|
|
Animated.timing(this.animatedValue, {
|
|
|
|
toValue: 0,
|
|
|
|
duration: ANIMATION_DURATION,
|
|
|
|
easing: Easing.inOut(Easing.quad),
|
|
|
|
useNativeDriver: true
|
|
|
|
}).start(() => onClose());
|
|
|
|
};
|
2020-10-30 17:35:07 +00:00
|
|
|
|
|
|
|
render() {
|
2021-09-13 20:41:05 +00:00
|
|
|
const { isMasterDetail, insets, theme, currentFilter, onFilterSelected } = this.props;
|
2020-10-30 17:35:07 +00:00
|
|
|
const statusBarHeight = insets?.top ?? 0;
|
|
|
|
const heightDestination = isMasterDetail ? headerHeight + statusBarHeight : 0;
|
|
|
|
const translateY = this.animatedValue.interpolate({
|
|
|
|
inputRange: [0, 1],
|
|
|
|
outputRange: [-300, heightDestination] // approximated height of the component when closed/open
|
|
|
|
});
|
|
|
|
const backdropOpacity = this.animatedValue.interpolate({
|
|
|
|
inputRange: [0, 1],
|
2022-01-17 16:10:39 +00:00
|
|
|
outputRange: [0, themes[theme!].backdropOpacity]
|
2020-10-30 17:35:07 +00:00
|
|
|
});
|
|
|
|
return (
|
|
|
|
<>
|
|
|
|
<TouchableWithoutFeedback onPress={this.close}>
|
2021-09-13 20:41:05 +00:00
|
|
|
<Animated.View
|
|
|
|
style={[
|
|
|
|
styles.backdrop,
|
|
|
|
{
|
2022-01-17 16:10:39 +00:00
|
|
|
backgroundColor: themes[theme!].backdropColor,
|
2021-09-13 20:41:05 +00:00
|
|
|
opacity: backdropOpacity,
|
|
|
|
top: heightDestination
|
|
|
|
}
|
|
|
|
]}
|
2020-10-30 17:35:07 +00:00
|
|
|
/>
|
|
|
|
</TouchableWithoutFeedback>
|
|
|
|
<Animated.View
|
|
|
|
style={[
|
|
|
|
styles.dropdownContainer,
|
|
|
|
{
|
|
|
|
transform: [{ translateY }],
|
2022-01-17 16:10:39 +00:00
|
|
|
backgroundColor: themes[theme!].backgroundColor,
|
|
|
|
borderColor: themes[theme!].separatorColor
|
2020-10-30 17:35:07 +00:00
|
|
|
}
|
2021-09-13 20:41:05 +00:00
|
|
|
]}>
|
2020-10-30 17:35:07 +00:00
|
|
|
<DropdownItemHeader currentFilter={currentFilter} onPress={this.close} />
|
|
|
|
<List.Separator />
|
2022-01-12 13:53:06 +00:00
|
|
|
<DropdownItemFilter currentFilter={currentFilter} value={Filter.All} onPress={onFilterSelected} />
|
|
|
|
<DropdownItemFilter currentFilter={currentFilter} value={Filter.Following} onPress={onFilterSelected} />
|
|
|
|
<DropdownItemFilter currentFilter={currentFilter} value={Filter.Unread} onPress={onFilterSelected} />
|
2020-10-30 17:35:07 +00:00
|
|
|
</Animated.View>
|
|
|
|
</>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
export default withTheme(withSafeAreaInsets(Dropdown));
|