import React, { PureComponent } from 'react'; import { Animated, Easing, Switch, Text, TouchableWithoutFeedback, View } from 'react-native'; import Touch from '../../utils/touch'; import { CustomIcon } from '../../lib/Icons'; import Check from '../../containers/Check'; import I18n from '../../i18n'; import { SWITCH_TRACK_COLOR, themes } from '../../lib/constants'; import styles from './styles'; import { TSupportedThemes } from '../../theme'; const ANIMATION_DURATION = 200; const ANIMATION_PROPS = { duration: ANIMATION_DURATION, easing: Easing.inOut(Easing.quad), useNativeDriver: true }; interface IDirectoryOptionsProps { type: string; globalUsers: boolean; isFederationEnabled: boolean; close: Function; changeType: Function; toggleWorkspace(): void; theme: TSupportedThemes; } export default class DirectoryOptions extends PureComponent { private animatedValue: Animated.Value; constructor(props: IDirectoryOptionsProps) { super(props); this.animatedValue = new Animated.Value(0); } componentDidMount() { Animated.timing(this.animatedValue, { toValue: 1, ...ANIMATION_PROPS }).start(); } close = () => { const { close } = this.props; Animated.timing(this.animatedValue, { toValue: 0, ...ANIMATION_PROPS }).start(() => close()); }; renderItem = (itemType: string) => { const { changeType, type: propType, theme } = this.props; let text = 'Users'; let icon = 'user'; if (itemType === 'channels') { text = 'Channels'; icon = 'channel-public'; } if (itemType === 'teams') { text = 'Teams'; icon = 'teams'; } return ( changeType(itemType)} style={styles.dropdownItemButton} theme={theme} accessibilityLabel={I18n.t(text)}> {I18n.t(text)} {propType === itemType ? : null} ); }; render() { const translateY = this.animatedValue.interpolate({ inputRange: [0, 1], outputRange: [-326, 0] }); const { globalUsers, toggleWorkspace, isFederationEnabled, theme } = this.props; const backdropOpacity = this.animatedValue.interpolate({ inputRange: [0, 1], outputRange: [0, themes[theme].backdropOpacity] }); return ( <> {I18n.t('Search_by')} {this.renderItem('channels')} {this.renderItem('users')} {this.renderItem('teams')} {isFederationEnabled ? ( <> {I18n.t('Search_global_users')} {I18n.t('Search_global_users_description')} ) : null} ); } }