在我的ReactNative主页面中,我试图使用多行TextInput的ScrollView填充可用的最大高度,但没有成功。
这是我的页面代码
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;
这是我的Playground
答案 0 :(得分:0)
愚蠢的错误,实际上我忘了在textInput样式中添加“flex:1”。