我很难使用CSS将我的组件集中在屏幕上.

见我的App.js:

import { Container } from 'native-base';
import React from 'react';
import { StyleSheet } from 'react-native';

import Screen from './ScreenContainer';

const styles = StyleSheet.create({
  container: {
    backgroundColor: '#FF6666',
    flex: 1
  }
});

const App = () => (
  <Provider store={store}>
    <Container style={styles.container}>
      <Screen />
    </Container>
  </Provider>
);

export default App;

现在,看看我的ScreenContainer.js

import { Container, Content, Form, Input, Label, Item } from 'native-base';
import React from 'react';

import AppLogo from '../components/AppLogo';

const Screen = () => (
  <Container>
    <Content>
      <AppLogo />
      <Form>
        <Item floatingLabel last>
          <Label>Username</Label>
          <Input />
        </Item>
      </Form>
    </Content>
  </Container>
);

export default Screen;

此代码导致出现此屏幕:

enter image description here

但是,我希望屏幕保持这种格式:

enter image description here

当我更改代码时:

const styles = StyleSheet.create({
  container: {
    alignItems: 'center',
    backgroundColor: '#FF6666',
    flex: 1
  }
});

我的应用程序返回此屏幕:

enter image description here

推荐答案

完成了:

import { Container, Content, Form, Input, Label, Item } from 'native-base';
import React from 'react';
import { StyleSheet } from 'react-native';

import AppLogo from '../components/AppLogo';

const styles = StyleSheet.create({
  container: {},
  content: {
    alignItems: 'center',
    flex: 1,
    justifyContent: 'center'
  },
  form: {
    width: '100%'
  },
  item: {}
});

const Screen = () => (
  <Container style={styles.container}>
    <Content contentContainerStyle={styles.content}>
      <AppLogo />
      <Form style={styles.form}>
        <Item floatingLabel last>
          <Label>Username</Label>
          <Input />
        </Item>
      </Form>
    </Content>
  </Container>
);

export default Screen;

React-native相关问答推荐

没有给出相同价值观的时刻

Redux toolkit通过按钮操作进行查询

如何在底部标签导航中添加顶部标签

用图像 react native 动画进度条

如何在 react-native 中使用 Animated 制作 svg 动画

错误发生意外错误:https://registry.yarnpkg.com/react-native-template-react-native-template-typescript:未找到

在 TouchableOpacity 上创建 Raised凸起或Shadow阴影效果

react-native-snap-carousel 无法正确渲染

如何在 react-native 中设置 Onpress On Textinput

使用react native获取设备令牌

react Navigation 在标题中使用图像?

React native Refresh 有效,但下一次调用仍使用最后一个令牌

require() 必须有一个字符串文字参数 React Native

react-native run-android 构建错误':app:generateDebugBuildConfig'

如何在不使用 JSX 的情况下在 React Native 中制作组件?

如何在 Text 中围绕 Text 包裹 TouchableOpacity?

TypeError : props.navigation.getParam 不是函数. In(props.navigation.getParam('name')

更改按钮 colored颜色 onPress(切换功能)

React Native - 为什么执行这个函数?

WebStorm + ReactNative?