2019-06-10 16:22:35 +00:00
|
|
|
import React, { PureComponent } from 'react';
|
2021-09-13 20:41:05 +00:00
|
|
|
import { Animated, Easing, Switch, Text, TouchableWithoutFeedback, View } from 'react-native';
|
2019-06-10 16:22:35 +00:00
|
|
|
|
2022-08-17 13:32:21 +00:00
|
|
|
import Touch from '../../containers/Touch';
|
2022-05-02 19:21:15 +00:00
|
|
|
import { CustomIcon, TIconsName } from '../../containers/CustomIcon';
|
2019-06-10 16:22:35 +00:00
|
|
|
import Check from '../../containers/Check';
|
|
|
|
import I18n from '../../i18n';
|
2022-04-07 14:10:03 +00:00
|
|
|
import { SWITCH_TRACK_COLOR, themes } from '../../lib/constants';
|
2021-09-13 20:41:05 +00:00
|
|
|
import styles from './styles';
|
2022-04-12 16:27:05 +00:00
|
|
|
import { TSupportedThemes } from '../../theme';
|
2019-06-10 16:22:35 +00:00
|
|
|
|
|
|
|
const ANIMATION_DURATION = 200;
|
|
|
|
const ANIMATION_PROPS = {
|
|
|
|
duration: ANIMATION_DURATION,
|
|
|
|
easing: Easing.inOut(Easing.quad),
|
|
|
|
useNativeDriver: true
|
|
|
|
};
|
|
|
|
|
2021-09-15 20:37:21 +00:00
|
|
|
interface IDirectoryOptionsProps {
|
|
|
|
type: string;
|
|
|
|
globalUsers: boolean;
|
|
|
|
isFederationEnabled: boolean;
|
|
|
|
close: Function;
|
|
|
|
changeType: Function;
|
|
|
|
toggleWorkspace(): void;
|
2022-04-12 16:27:05 +00:00
|
|
|
theme: TSupportedThemes;
|
2021-09-15 20:37:21 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
export default class DirectoryOptions extends PureComponent<IDirectoryOptionsProps, any> {
|
|
|
|
private animatedValue: Animated.Value;
|
2019-06-10 16:22:35 +00:00
|
|
|
|
2021-09-15 20:37:21 +00:00
|
|
|
constructor(props: IDirectoryOptionsProps) {
|
2019-06-10 16:22:35 +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,
|
|
|
|
...ANIMATION_PROPS
|
|
|
|
}).start();
|
2019-06-10 16:22:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
close = () => {
|
|
|
|
const { close } = this.props;
|
2021-09-13 20:41:05 +00:00
|
|
|
Animated.timing(this.animatedValue, {
|
|
|
|
toValue: 0,
|
|
|
|
...ANIMATION_PROPS
|
|
|
|
}).start(() => close());
|
|
|
|
};
|
2019-06-10 16:22:35 +00:00
|
|
|
|
2021-09-15 20:37:21 +00:00
|
|
|
renderItem = (itemType: string) => {
|
2019-12-04 16:39:53 +00:00
|
|
|
const { changeType, type: propType, theme } = this.props;
|
2019-06-10 16:22:35 +00:00
|
|
|
let text = 'Users';
|
2022-05-02 19:21:15 +00:00
|
|
|
let icon: TIconsName = 'user';
|
2019-06-10 16:22:35 +00:00
|
|
|
if (itemType === 'channels') {
|
|
|
|
text = 'Channels';
|
2020-07-27 19:53:33 +00:00
|
|
|
icon = 'channel-public';
|
2019-06-10 16:22:35 +00:00
|
|
|
}
|
|
|
|
|
2021-06-04 18:07:26 +00:00
|
|
|
if (itemType === 'teams') {
|
|
|
|
text = 'Teams';
|
|
|
|
icon = 'teams';
|
|
|
|
}
|
|
|
|
|
2019-06-10 16:22:35 +00:00
|
|
|
return (
|
2022-08-17 13:32:21 +00:00
|
|
|
<Touch onPress={() => changeType(itemType)} style={styles.dropdownItemButton} accessibilityLabel={I18n.t(text)}>
|
2019-06-10 16:22:35 +00:00
|
|
|
<View style={styles.dropdownItemContainer}>
|
2022-05-02 19:21:15 +00:00
|
|
|
<CustomIcon name={icon} size={22} color={themes[theme].bodyText} style={styles.dropdownItemIcon} />
|
2019-12-04 16:39:53 +00:00
|
|
|
<Text style={[styles.dropdownItemText, { color: themes[theme].bodyText }]}>{I18n.t(text)}</Text>
|
2022-03-22 13:53:09 +00:00
|
|
|
{propType === itemType ? <Check /> : null}
|
2019-06-10 16:22:35 +00:00
|
|
|
</View>
|
|
|
|
</Touch>
|
|
|
|
);
|
2021-09-13 20:41:05 +00:00
|
|
|
};
|
2019-06-10 16:22:35 +00:00
|
|
|
|
|
|
|
render() {
|
|
|
|
const translateY = this.animatedValue.interpolate({
|
|
|
|
inputRange: [0, 1],
|
|
|
|
outputRange: [-326, 0]
|
|
|
|
});
|
2021-09-13 20:41:05 +00:00
|
|
|
const { globalUsers, toggleWorkspace, isFederationEnabled, theme } = this.props;
|
2021-02-19 18:05:47 +00:00
|
|
|
const backdropOpacity = this.animatedValue.interpolate({
|
|
|
|
inputRange: [0, 1],
|
|
|
|
outputRange: [0, themes[theme].backdropOpacity]
|
|
|
|
});
|
2019-06-10 16:22:35 +00:00
|
|
|
return (
|
2019-09-24 20:26:56 +00:00
|
|
|
<>
|
2019-06-10 16:22:35 +00:00
|
|
|
<TouchableWithoutFeedback onPress={this.close}>
|
2019-12-04 16:39:53 +00:00
|
|
|
<Animated.View style={[styles.backdrop, { backgroundColor: themes[theme].backdropColor, opacity: backdropOpacity }]} />
|
2019-06-10 16:22:35 +00:00
|
|
|
</TouchableWithoutFeedback>
|
2021-09-13 20:41:05 +00:00
|
|
|
<Animated.View
|
2022-08-08 21:02:08 +00:00
|
|
|
style={[styles.dropdownContainer, { transform: [{ translateY }], backgroundColor: themes[theme].backgroundColor }]}
|
|
|
|
>
|
2022-08-17 13:32:21 +00:00
|
|
|
<Touch onPress={this.close} accessibilityLabel={I18n.t('Search_by')}>
|
2021-09-13 20:41:05 +00:00
|
|
|
<View
|
|
|
|
style={[
|
|
|
|
styles.dropdownContainerHeader,
|
|
|
|
styles.dropdownItemContainer,
|
|
|
|
{ borderColor: themes[theme].separatorColor }
|
2022-08-08 21:02:08 +00:00
|
|
|
]}
|
|
|
|
>
|
2019-12-04 16:39:53 +00:00
|
|
|
<Text style={[styles.dropdownToggleText, { color: themes[theme].auxiliaryText }]}>{I18n.t('Search_by')}</Text>
|
2021-09-13 20:41:05 +00:00
|
|
|
<CustomIcon
|
2022-05-02 19:21:15 +00:00
|
|
|
style={[styles.dropdownItemIcon, styles.inverted]}
|
2021-09-13 20:41:05 +00:00
|
|
|
size={22}
|
|
|
|
name='chevron-down'
|
2022-05-02 19:21:15 +00:00
|
|
|
color={themes[theme].auxiliaryTintColor}
|
2021-09-13 20:41:05 +00:00
|
|
|
/>
|
2019-06-10 16:22:35 +00:00
|
|
|
</View>
|
|
|
|
</Touch>
|
|
|
|
{this.renderItem('channels')}
|
|
|
|
{this.renderItem('users')}
|
2021-06-04 18:07:26 +00:00
|
|
|
{this.renderItem('teams')}
|
2021-09-13 20:41:05 +00:00
|
|
|
{isFederationEnabled ? (
|
|
|
|
<>
|
|
|
|
<View style={[styles.dropdownSeparator, { backgroundColor: themes[theme].separatorColor }]} />
|
|
|
|
<View style={[styles.dropdownItemContainer, styles.globalUsersContainer]}>
|
|
|
|
<View style={styles.globalUsersTextContainer}>
|
|
|
|
<Text style={[styles.dropdownItemText, { color: themes[theme].infoText }]}>
|
|
|
|
{I18n.t('Search_global_users')}
|
|
|
|
</Text>
|
|
|
|
<Text style={[styles.dropdownItemDescription, { color: themes[theme].infoText }]}>
|
|
|
|
{I18n.t('Search_global_users_description')}
|
|
|
|
</Text>
|
2019-06-10 16:22:35 +00:00
|
|
|
</View>
|
2021-09-13 20:41:05 +00:00
|
|
|
<Switch value={globalUsers} onValueChange={toggleWorkspace} trackColor={SWITCH_TRACK_COLOR} />
|
|
|
|
</View>
|
|
|
|
</>
|
|
|
|
) : null}
|
2019-06-10 16:22:35 +00:00
|
|
|
</Animated.View>
|
2019-09-24 20:26:56 +00:00
|
|
|
</>
|
2019-06-10 16:22:35 +00:00
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|