React Native /如何解决屏幕向上滚动的问题?

时间:2018-10-29 15:27:10

标签: reactjs react-native react-native-router-flux

我正在研究React-Native项目。 在实现屏幕转换之后,特定的屏幕像bottom_img一样向上滚动。在原始屏幕上,文本输入位于底部。

image description

为解决该问题,我同时使用了react-native-router-fluxreact-navigation这两个库。但是,也会出现同样的问题。

有发生此问题的代码。 我该如何解决这个问题?

  render() {
const { chatLog } = this.props;
// console.log("In ChatRoom this.state:", this.state);
const contentsTopBottomMargin = 8;

return (
  <View style={styles.container}>
    <Header
      title={chatLog ? "ChatLog" : "MyHome"}
      left={this.renderChatRoomHeaderLeft()}
      right={this.renderChatRoomHeaderRight()}
    />
    <View style={styles.chatRoomContents}>
      <ScrollView
        style={{
          paddingBottom: contentsTopBottomMargin,
          paddingTop: contentsTopBottomMargin
        }}
        ref={ref => (this.scrollView = ref)}
        onContentSizeChange={(contentWidth, contentHeight) => {
          this.scrollView.scrollToEnd({ animated: true });
        }}
      >
        {this.state.currentDialog
          ? this.state.currentDialog.map((dialog, index) => (
              <ChatElement
                key={index} 
                speaker={dialog.speaker}
                text={dialog.text}
              />
            ))
          : null}
      </ScrollView>
      {this.state.isTextInput & !this.state.isFinished ? (
        <TextInputFooter onPress={this.handleTextInput} />
      ) : null}
      {this.state.isFinished ? <ButtonInputFooter onPress={this.routeToLogList} /> : null}
    </View>
  </View>
);

0 个答案:

没有答案