import React from 'react'; import { SafeAreaView, ScrollView, StatusBar, StyleSheet, Text, Image, TouchableOpacity, View, TextInput } from 'react-native'; import { colors, filterEmoji, isEmpty, onePx, px2dp } from '../../utils'; interface Props { title?: string maxLength?: number placeholder?: string initContent?: string hasPermission?: boolean showLengthLimitPlaceHolder?: boolean contentHeight?: number isLast?: boolean onChangeText?: Function value?: string inlineLayout?: boolean miniLayout?: boolean } interface State { remark: string } export default class KitPureRemarkView extends React.Component { constructor(props: Props) { super(props); }; public contentInputRef = null; public readonly state: Readonly = { remark: "", }; componentDidMount() { const { initContent } = this.props; if (!isEmpty(initContent)) { this.setState({ remark: initContent + "" }) } } componentWillUnmount() { this.setState = (state, callback) => { return; } } public getRemark() { return this.state.remark } onChangeText(text) { const { onChangeText } = this.props; const newText = filterEmoji(text); onChangeText && onChangeText(text); this.setState({ remark: newText }) } render() { const { title, placeholder, maxLength = 300, hasPermission, showLengthLimitPlaceHolder = false, contentHeight = px2dp(96), isLast = false, value = "", inlineLayout = false, miniLayout } = this.props; const { remark } = this.state; return ( {title} this.contentInputRef.focus()} style={[styles.remarkContent, { height: contentHeight }]} > this.contentInputRef = c} defaultValue={value} value={value} style={styles.remarkContentInput} multiline maxLength={maxLength} editable={hasPermission} placeholder={showLengthLimitPlaceHolder ? placeholder + `,字数不超过${maxLength}字...` : placeholder} onChangeText={this.onChangeText.bind(this)} /> ) } } const styles = StyleSheet.create({ remarkContentBody: { width: px2dp(330), backgroundColor: '#fff', paddingTop: px2dp(6), marginHorizontal: px2dp(10), borderBottomLeftRadius: px2dp(6), borderBottomRightRadius: px2dp(6), borderBottomWidth: onePx, borderBottomColor: colors.borderColor, }, formGroupTitleContainer: { width: '100%', height: px2dp(24), justifyContent: 'center', alignItems: 'flex-start', marginBottom: px2dp(4) }, formRowTitle: { fontSize: 16, color: colors.blackColor, }, remarkContent: { width: '100%', height: px2dp(96), backgroundColor: '#f2f1f2', paddingVertical: px2dp(6), paddingHorizontal: px2dp(6), marginBottom: px2dp(12) }, remarkContentInput: { width: '100%', color: colors.blackColor, fontSize: 14, lineHeight: 19, paddingVertical: px2dp(0), }, })