UNPKG

zl-react-native-gifted-chat

Version:

The most complete chat UI for React Native, based on 'react-native-gifted-chat'

106 lines (97 loc) 2.13 kB
import React from 'react'; import { StyleSheet, Text, TouchableOpacity, View, } from 'react-native'; export default class Actions extends React.Component { constructor(props) { super(props); this.onActionsPress = this.onActionsPress.bind(this); } onActionsPress() { const options = Object.keys(this.props.options); const cancelButtonIndex = Object.keys(this.props.options).length - 1; this.context.actionSheet().showActionSheetWithOptions({ options, cancelButtonIndex, }, (buttonIndex) => { let i = 0; for (let key in this.props.options) { if (this.props.options.hasOwnProperty(key)) { if (buttonIndex === i) { this.props.options[key](this.props); return; } i++; } } }); } renderIcon() { if (this.props.icon) { return this.props.icon(); } return ( <View style={[styles.wrapper, this.props.wrapperStyle]} > <Text style={[styles.iconText, this.props.iconTextStyle]} > + </Text> </View> ); } render() { return ( <TouchableOpacity style={[styles.container, this.props.containerStyle]} onPress={this.onActionsPress} > {this.renderIcon()} </TouchableOpacity> ); } } const styles = StyleSheet.create({ container: { width: 26, height: 26, marginLeft: 10, marginBottom: 10, }, wrapper: { borderRadius: 13, borderColor: '#b2b2b2', borderWidth: 2, flex: 1, }, iconText: { color: '#b2b2b2', fontWeight: 'bold', fontSize: 16, backgroundColor: 'transparent', textAlign: 'center', }, }); Actions.contextTypes = { actionSheet: React.PropTypes.func, }; Actions.defaultProps = { onSend: () => {}, containerStyle: {}, iconStyle: {}, options: {}, icon: null, }; Actions.propTypes = { onSend: React.PropTypes.func, containerStyle: React.PropTypes.object, iconStyle: React.PropTypes.object, options: React.PropTypes.object, icon: React.PropTypes.func, };