From f3c489ade3d0dacf8ccacf96ad99509d70b6a10a Mon Sep 17 00:00:00 2001 From: mx1700 Date: Sun, 25 Aug 2019 20:52:15 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E8=AF=84=E8=AE=BA=E6=A1=86?= =?UTF-8?q?=E6=8D=A2=E8=A1=8C=E5=90=8E=EF=BC=8C=E9=AB=98=E5=BA=A6=E4=B8=8D?= =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E7=9A=84=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/component/comment/commentInput.js | 40 +++++++++++++++++++++++---- 1 file changed, 35 insertions(+), 5 deletions(-) diff --git a/src/component/comment/commentInput.js b/src/component/comment/commentInput.js index b16cf11..2fee074 100644 --- a/src/component/comment/commentInput.js +++ b/src/component/comment/commentInput.js @@ -7,7 +7,8 @@ import { TextInput, TouchableOpacity, Alert, - DeviceEventEmitter + DeviceEventEmitter, + Platform, } from 'react-native'; import Icon from 'react-native-vector-icons/Ionicons'; import KeyboardSpacer from "react-native-keyboard-spacer"; @@ -17,6 +18,7 @@ import Color from '../../style/color'; import Api from '../../util/api'; import Event from '../../util/event'; +const DefaultInputHeight = 56; export default class CommentInput extends Component { @@ -31,7 +33,8 @@ export default class CommentInput extends Component { content: '', replyUserId: 0, - replyUserName: '' + replyUserName: '', + inputHeight: DefaultInputHeight, }; } @@ -93,8 +96,8 @@ export default class CommentInput extends Component { this.setState({ content: '', replyUserId: 0, - replyUserName: '' - + replyUserName: '', + inputHeight: DefaultInputHeight, }, () => { DeviceEventEmitter.emit(Event.updateComments); }); @@ -108,9 +111,34 @@ export default class CommentInput extends Component { }); } + resetInputHeight(event) { + let height = 0; + if(Platform.OS === "ios") { + //iOS 一开始是 29,只要一编辑就变成每行 18,36 + const h = event.nativeEvent.contentSize.height + 37; + const max = 74 + 37; + height = h > max ? max : h + } else { + //android 一开始是 41.5,57,75 + const h = event.nativeEvent.contentSize.height; + const max = 107; + if (h < DefaultInputHeight) { + height = DefaultInputHeight; + } else { + height = h + (DefaultInputHeight - 40); + height = height > max ? max : height; + } + } + if (this.state.inputHeight !== height) { + this.setState({ + inputHeight: height, + }); + } + } + render() { return ( - + @@ -166,6 +195,7 @@ const localStyle = StyleSheet.create({ borderTopWidth: StyleSheet.hairlineWidth }, input: { + flexGrow: 1, borderColor: '#bbb', backgroundColor: '#fff', borderWidth: StyleSheet.hairlineWidth,