import React from 'react'; import { Text, View, StyleSheet, Platform, TouchableOpacity, Dimensions, TextInput } from 'react-native'; import Icon from 'react-native-vector-icons/Ionicons'; import PropTypes from 'prop-types'; import { connect } from 'react-redux'; import Modal from 'react-native-modal'; import { CachedImage } from 'react-native-img-cache'; import Avatar from '../../containers/Avatar'; import RocketChat from '../../lib/rocketchat'; import { STATUS_COLORS } from '../../constants/colors'; const TITLE_OFFSET = Platform.OS === 'ios' ? 70 : 56; const { width } = Dimensions.get('window'); const styles = StyleSheet.create({ header: { flexDirection: 'row', alignItems: 'center', flex: 1 }, titleContainer: { left: TITLE_OFFSET, right: TITLE_OFFSET, position: 'absolute', alignItems: 'center', justifyContent: Platform.OS === 'ios' ? 'center' : 'flex-start', flexDirection: 'row', height: 44 }, status: { borderRadius: 4, width: 8, height: 8, marginRight: 10 }, avatar: { marginRight: 10 }, title: { fontWeight: '500', color: '#292E35' }, left: { left: 0, position: 'absolute' }, right: { right: 0, position: 'absolute', flexDirection: 'row' }, modal: { width: width - 60, height: width - 60, backgroundColor: '#F7F7F7', borderRadius: 4, flexDirection: 'column' }, modalButton: { flex: 1, flexDirection: 'row', alignItems: 'center', justifyContent: 'center', backgroundColor: 'transparent', borderBottomWidth: StyleSheet.hairlineWidth, borderBottomColor: 'rgba(0, 0, 0, .3)', paddingHorizontal: 20 }, headerButton: { backgroundColor: 'transparent', height: 44, width: 44, alignItems: 'center', justifyContent: 'center' }, serverImage: { width: 24, height: 24, borderRadius: 4 } }); @connect(state => ({ user: state.login.user, baseUrl: state.settings.Site_Url })) export default class extends React.Component { static propTypes = { navigation: PropTypes.object.isRequired, user: PropTypes.object.isRequired, baseUrl: PropTypes.string } constructor(props) { super(props); this.state = { isModalVisible: false, searching: false }; } onPressModalButton(status) { RocketChat.setUserPresenceDefaultStatus(status); this.hideModal(); } showModal() { this.setState({ isModalVisible: true }); } hideModal() { this.setState({ isModalVisible: false }); } createChannel() { this.props.navigation.navigate('SelectUsers'); } renderLeft() { return ( this.props.navigation.navigate('DrawerOpen')} > ); } renderTitle() { if (!this.props.user.username) { return null; } return ( this.showModal()}> {this.props.user.username} ); } renderRight() { return ( {Platform.OS === 'android' ? this.setState({ searching: true })} > : null} {Platform.OS === 'ios' ? this.createChannel()} > : null} ); } renderModalButton = (status, text) => { const statusStyle = [styles.status, { backgroundColor: STATUS_COLORS[status] }]; const textStyle = { flex: 1, fontWeight: this.props.user.status === status ? 'bold' : 'normal' }; return ( this.onPressModalButton(status)} > {text || status.charAt(0).toUpperCase() + status.slice(1)} ); }; renderHeader() { if (this.state.searching) { return null; } return ( {this.renderLeft()} {this.renderTitle()} {this.renderRight()} ); } renderSearch() { if (!this.state.searching) { return null; } return ( this.setState({ searching: false })} > ); } render() { return ( {this.renderHeader()} {this.renderSearch()} this.hideModal()} onBackdropPress={() => this.hideModal()} > {this.renderModalButton('online')} {this.renderModalButton('busy')} {this.renderModalButton('away')} {this.renderModalButton('offline', 'Invisible')} ); } }