简体   繁体   English

反应本机ScrollView的高度

[英]React Native ScrollView height

In my ReactNative main page I am trying to make a ScrollView with a multiline TextInput fill the maximum height available, without success. 在我的ReactNative主页中,我试图使具有多行TextInput的ScrollView填充可用的最大高度,但没有成功。

Here my page code 这是我的页面代码

import React, { Component } from 'react';
import { View, Text, TextInput, Button, ScrollView } from 'react-native';

class App extends Component {

  render() {
    const {
      mainContainerStyle,
      fileNameStyle,
      fileNameInputStyle,
      fileTextStyle,
      saveButtonStyle,
      fileTextScrollViewStyle,
      fileTextScrollViewContentContainerStyle,
      fileTextInputStyle
    } = styles;

    return (
      <View style={mainContainerStyle}>

        <View style={fileNameStyle}>
          <Text>File name :</Text>
          <TextInput
            style={fileNameInputStyle}
            placeholder="MyFileName.txt"
          />
        </View>

        <View style={fileTextStyle}>
          <Text>File text :</Text>
          <ScrollView
            style={fileTextScrollViewStyle}
            contentContainerStyle={fileTextScrollViewContentContainerStyle}
          >
            <TextInput multiline style={fileTextInputStyle} />
          </ScrollView>
        </View>

        <Button
          title="Save into DropBox"
          onPress={() => {}}
          style={saveButtonStyle}
        />

      </View>
    );
  }

}

const styles = {
  mainContainerStyle: {
    flex: 1,
    margin: 10
  },
  fileNameStyle: {
    marginBottom: 5
  },
  fileNameInputStyle: {
    height: 40,
    lineHeight: 20
  },
  fileTextStyle: {
    marginTop: 5,
    flex: 1
  },
  saveButtonStyle: {
  },
  fileTextScrollViewStyle: {
    flex: 1
  },
  fileTextScrollViewContentContainerStyle: {
    flex: 1
  },
  fileTextInputStyle: {
  }
};

export default App;

This is my Playground 这是我的游乐场

愚蠢的错误,实际上我忘记为textInput样式添加“ flex:1”。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM