css - 多行 FormInput 元素离开屏幕

标签 css reactjs react-native jsx styling

我已经为带有 react-native-elements 的表单创建了一个简单的弹出窗口。问题是第二个表单输入是多行的,如果文本行太多,元素会溢出到弹出窗口底部之外,将提交按钮推离屏幕。一个好处是让提交按钮将自己定位在弹出窗口的底部。这是代码,为了方便起见,我还把它嵌入了零食中 https://snack.expo.io/HyZPSSj8m

import * as React from 'react';
import { Text, View, StyleSheet } from 'react-native';
import { Constants } from 'expo';

import { Card, FormLabel, FormInput, FormValidationMessage, Button } from 'react-native-elements';

export default class App extends React.Component {
  render() {
    return (
      <View style={styles.container}>
        <Card containerStyle={styles.popup} title="Add text">

              <FormLabel>Title</FormLabel>
              <FormInput inputStyle={{width: undefined}}/>

              <FormLabel>Text</FormLabel>
              <FormInput multiline numberOfLines={5} inputStyle={{width: undefined}} />
              <Button buttonStyle={styles.popupButton} title="Submit" />
          </Card>
      </View>
    );
  }
}

const styles = StyleSheet.create({
  container: {
    flex: 1,
    alignItems: 'stretch'
  },
  popup: {
    position: 'absolute',
    top: 0,
    bottom: 10,
    left: 0,
    right: 0,
    alignItems: 'stretch',
    flex: 1
  },
  popupButton: {
    borderRadius: 0, 
    marginLeft: 0, 
    marginRight: 0, 
    marginBottom: 10,
    marginTop: 10
  }
});

最佳答案

您可以用 ScrollView 替换您的 View 。

 export default class App extends React.Component {
  render() {
    return (
     <ScrollView style={styles.container}>
       <Card containerStyle={styles.popup} title="Add text">

          <FormLabel>Title</FormLabel>
          <FormInput inputStyle={{width: undefined}}/>

          <FormLabel>Text</FormLabel>
          <FormInput multiline numberOfLines={5} inputStyle={{width: undefined}} />
          <Button buttonStyle={styles.popupButton} title="Submit" />
      </Card>
     </ScrollView>
    );
   }
  }

关于css - 多行 FormInput 元素离开屏幕,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51974549/

相关文章:

javascript - 如何设置-webkit-print-color-adjust : exact from Javascript programmatically?

javascript - 数组映射到带有换行符的字符串 - React

javascript - 当我设置初始值时,React Input 不会改变

react-native - 在 Expo React Native 项目中使用 Detox 运行测试时出错

javascript - Possible Unhandled Promise Rejection undefined 不是函数

CSS 图像和文本不会随@media 查询缩放

html - 尝试使用@font-family

css - 键盘打开时, ionic 标签不会隐藏

javascript - 使用标记和群集创建自定义图像

android - 当文本输入聚焦在 React Native for Android 的底部工作表上时, View 移出屏幕