2019-06-10 16:22:35 +00:00
|
|
|
import React, { PureComponent } from 'react';
|
|
|
|
import {
|
|
|
|
View, Text, Animated, Easing, TouchableWithoutFeedback, Switch
|
|
|
|
} from 'react-native';
|
|
|
|
import PropTypes from 'prop-types';
|
|
|
|
|
|
|
|
import styles from './styles';
|
2019-12-04 16:39:53 +00:00
|
|
|
import Touch from '../../utils/touch';
|
2019-06-10 16:22:35 +00:00
|
|
|
import { CustomIcon } from '../../lib/Icons';
|
|
|
|
import Check from '../../containers/Check';
|
|
|
|
import I18n from '../../i18n';
|
2019-12-04 16:39:53 +00:00
|
|
|
import { SWITCH_TRACK_COLOR, themes } from '../../constants/colors';
|
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
|
|
|
|
};
|
|
|
|
|
|
|
|
export default class DirectoryOptions extends PureComponent {
|
|
|
|
static propTypes = {
|
|
|
|
type: PropTypes.string,
|
|
|
|
globalUsers: PropTypes.bool,
|
|
|
|
isFederationEnabled: PropTypes.bool,
|
|
|
|
close: PropTypes.func,
|
|
|
|
changeType: PropTypes.func,
|
2019-12-04 16:39:53 +00:00
|
|
|
toggleWorkspace: PropTypes.func,
|
|
|
|
theme: PropTypes.string
|
2019-06-10 16:22:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
constructor(props) {
|
|
|
|
super(props);
|
|
|
|
this.animatedValue = new Animated.Value(0);
|
|
|
|
}
|
|
|
|
|
|
|
|
componentDidMount() {
|
|
|
|
Animated.timing(
|
|
|
|
this.animatedValue,
|
|
|
|
{
|
|
|
|
toValue: 1,
|
|
|
|
...ANIMATION_PROPS
|
2019-10-31 16:21:59 +00:00
|
|
|
}
|
2019-06-10 16:22:35 +00:00
|
|
|
).start();
|
|
|
|
}
|
|
|
|
|
|
|
|
close = () => {
|
|
|
|
const { close } = this.props;
|
|
|
|
Animated.timing(
|
|
|
|
this.animatedValue,
|
|
|
|
{
|
|
|
|
toValue: 0,
|
|
|
|
...ANIMATION_PROPS
|
2019-10-31 16:21:59 +00:00
|
|
|
}
|
2019-06-10 16:22:35 +00:00
|
|
|
).start(() => close());
|
|
|
|
}
|
|
|
|
|
|
|
|
renderItem = (itemType) => {
|
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';
|
|
|
|
let icon = 'user';
|
|
|
|
if (itemType === 'channels') {
|
|
|
|
text = 'Channels';
|
2020-07-27 19:53:33 +00:00
|
|
|
icon = 'channel-public';
|
2019-06-10 16:22:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return (
|
2019-12-04 16:39:53 +00:00
|
|
|
<Touch
|
|
|
|
onPress={() => changeType(itemType)}
|
|
|
|
style={styles.dropdownItemButton}
|
|
|
|
theme={theme}
|
|
|
|
>
|
2019-06-10 16:22:35 +00:00
|
|
|
<View style={styles.dropdownItemContainer}>
|
2019-12-04 16:39:53 +00:00
|
|
|
<CustomIcon style={[styles.dropdownItemIcon, { color: themes[theme].bodyText }]} size={22} name={icon} />
|
|
|
|
<Text style={[styles.dropdownItemText, { color: themes[theme].bodyText }]}>{I18n.t(text)}</Text>
|
|
|
|
{propType === itemType ? <Check theme={theme} /> : null}
|
2019-06-10 16:22:35 +00:00
|
|
|
</View>
|
|
|
|
</Touch>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
render() {
|
|
|
|
const translateY = this.animatedValue.interpolate({
|
|
|
|
inputRange: [0, 1],
|
|
|
|
outputRange: [-326, 0]
|
|
|
|
});
|
2019-12-04 16:39:53 +00:00
|
|
|
const {
|
|
|
|
globalUsers, toggleWorkspace, isFederationEnabled, theme
|
|
|
|
} = this.props;
|
2021-03-15 20:16:34 +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>
|
2019-12-04 16:39:53 +00:00
|
|
|
<Animated.View style={[styles.dropdownContainer, { transform: [{ translateY }], backgroundColor: themes[theme].backgroundColor }]}>
|
|
|
|
<Touch onPress={this.close} theme={theme}>
|
|
|
|
<View style={[styles.dropdownContainerHeader, styles.dropdownItemContainer, { borderColor: themes[theme].separatorColor }]}>
|
|
|
|
<Text style={[styles.dropdownToggleText, { color: themes[theme].auxiliaryText }]}>{I18n.t('Search_by')}</Text>
|
2020-06-05 13:28:58 +00:00
|
|
|
<CustomIcon style={[styles.dropdownItemIcon, styles.inverted, { color: themes[theme].auxiliaryTintColor }]} size={22} name='chevron-down' />
|
2019-06-10 16:22:35 +00:00
|
|
|
</View>
|
|
|
|
</Touch>
|
|
|
|
{this.renderItem('channels')}
|
|
|
|
{this.renderItem('users')}
|
|
|
|
{isFederationEnabled
|
|
|
|
? (
|
2019-09-24 20:26:56 +00:00
|
|
|
<>
|
2019-12-04 16:39:53 +00:00
|
|
|
<View style={[styles.dropdownSeparator, { backgroundColor: themes[theme].separatorColor }]} />
|
2019-06-10 16:22:35 +00:00
|
|
|
<View style={[styles.dropdownItemContainer, styles.globalUsersContainer]}>
|
|
|
|
<View style={styles.globalUsersTextContainer}>
|
2020-08-26 14:10:26 +00:00
|
|
|
<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>
|
2019-06-28 17:02:30 +00:00
|
|
|
<Switch value={globalUsers} onValueChange={toggleWorkspace} trackColor={SWITCH_TRACK_COLOR} />
|
2019-06-10 16:22:35 +00:00
|
|
|
</View>
|
2019-09-24 20:26:56 +00:00
|
|
|
</>
|
2019-06-10 16:22:35 +00:00
|
|
|
)
|
|
|
|
: null}
|
|
|
|
</Animated.View>
|
2019-09-24 20:26:56 +00:00
|
|
|
</>
|
2019-06-10 16:22:35 +00:00
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|