gpt4 book ai didi

react-native - 收到此错误 : error: bundling failed: Error: Unable to resolve module `react-native-safe-area-context`

转载 作者:行者123 更新时间:2023-12-02 03:39:05 29 4
gpt4 key购买 nike

运行我的应用程序后出现此错误:

error: bundling failed: Error: Unable to resolve module react-native-safe-area-context from node_modules/react-navigation-stack/lib/module/vendor/views/Stack/StackView.js: react-native-safe-area-context could not be found within the project.


但是我为我的旧演示所做的同样的事情。它工作得很好。
我不知道我在这里做错了什么。请检查我的代码:
安装:
  • react 原生导航和手势处理程序:
  • npm install --save react-navigation npm install --save react-native-gesture-handler
  • react 原生堆栈:
  • npm install --save react-navigation-stack App.js
    import { createAppContainer } from "react-navigation";
    import { createStackNavigator } from "react-navigation-stack";
    import FirstOptionsPage from "./FirstOptionsPage";

    const MainNavigator = createStackNavigator(
    {
    FirstOptions: FirstOptionsPage
    },
    {
    defaultNavigationOptions: {
    headerStyle: {
    // backgroundColor: '#28F1A6',
    elevation: 0,
    shadowOpacity: 0
    },
    headerTintColor: "#ca375e",
    headerTitleStyle: {
    fontWeight: "bold",
    color: "#161616"
    }
    }
    }
    );

    const App = createAppContainer(MainNavigator); // For setting Navigation Stack
    export default App;
    FirstOptionsPage.js:
    import React from "react";
    import {
    SafeAreaView,
    StyleSheet,
    View,
    Text,
    ScrollView,
    Switch
    } from "react-native";

    export default class FirstOptionsPage extends React.Component {
    static navigationOptions = {
    title: "Preferences"
    };

    constructor(props) {
    super(props);
    this.state = {
    switch1Value: false
    };
    }

    toggleSwitch1 = value => {
    this.setState({ switch1Value: value });
    console.log("Switch 1 is: " + value);
    };

    render() {
    const { navigate } = this.props.navigation;
    return (
    <SafeAreaView style={styles.mainContainerStyle}>
    <View style={styles.subContainerStyle}>
    <Text style={styles.subtitleTextStyle}>Someone likes my post</Text>
    <View style={styles.switchStyle}>
    <Switch
    onValueChange={this.toggleSwitch1}
    value={this.state.switch1Value}
    thumbColor={MAGENTA_COLOR_CODE}
    trackColor={{
    false: GREY_COLOR_CODE,
    true: DARK_GREY_COLOR_CODE
    }}
    />
    </View>
    </View>
    </SafeAreaView>
    );
    }
    }
    我是 React-Native 的新手。我怎样才能解决这个问题?

    最佳答案

    我认为问题出在SafeAreaView ,对于新的 react-native 版本,它已经迁移到 react-native-community/react-native-safe-area-view .如果您想使用 SafeAreaView ,你应该先安装它。
    新用途是这样的:

    import SafeAreaView from 'react-native-safe-area-view';

    export default function MyAwesomeApp() {
    return (
    <SafeAreaView style={{ flex: 1 }}>
    <View style={{ flex: 1 }}>
    <Text>
    Look, I'm safe! Not under a status bar or notch or home indicator or
    anything! Very cool
    </Text>
    </View>
    </SafeAreaView>
    );
    }

    要安装它,您可以使用以下命令: yarn add react-native-safe-area-view react-native-safe-area-context .
    如果您不使用自动链接,则还必须链接它。有关详细信息,请参阅此 link

    关于react-native - 收到此错误 : error: bundling failed: Error: Unable to resolve module `react-native-safe-area-context` ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59560312/

    29 4 0
    Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
    广告合作:1813099741@qq.com 6ren.com