如何在react native expo中使用styleSheet应用样式

irlmq6kh  于 2023-08-07  发布在  React
关注(0)|答案(1)|浏览(139)

我试图在我的react原生应用程序中应用一些样式,但它不适合我,我试图在浏览器中运行它,这是显示的输出:

的数据
但是当我在手机上运行它时,它显示了一个错误:


这是主App.js文件:

import { StatusBar } from 'expo-status-bar';
import React from 'react';
import { View } from 'react-native';
import HomeMenu from './src/screens/Home/index';

export default function App() {
  return (

    <View style={{ flex: 1 }}>
      <StatusBar style="auto" />
      <HomeMenu />
    </View>

  );
}

字符串
这是index.js文件(我想展示它的结果):

import React from 'react';
import { View, Text, StyleSheet, SafeAreaView } from 'react-native';

const HomeMenu = () => {
    return (
        <SafeAreaView style={{ flex: 1 }}>   //add flex:1 here
            <View style={styles.container}>
                <Text>Open up App.js to start working on your app!</Text>
            </View>
        </SafeAreaView>
    );
};
export default HomeMenu;

const styles = StyleSheet.create({
    container: {
        flex: 3,
        backgroundColor: '#21534A',
        alignItems: 'center',
        justifyContent: 'center',
    },
});

ttp71kqs

ttp71kqs1#

试试这样:

import React from 'react';
import { View, Text, StyleSheet, SafeAreaView } from 'react-native';

const HomeMenu = () => {
return (
    <SafeAreaView style={{ flex: 1 }}>  
  //add flex:1 here
        <View style={styles.container}>
            <Text>Open up App.js to start working on your app!</Text>
        </View>
    </SafeAreaView>
);
 };
 export default HomeMenu;

const styles = StyleSheet.create({
container: {
    flex: 3,
    backgroundColor: '#21534A',
    alignItems: 'center',
    justifyContent: 'center',
},
});

字符串

相关问题