【问题标题】:How to fix this issue with React Native Navigation如何使用 React Native Navigation 解决此问题
【发布时间】:2021-07-18 04:51:19
【问题描述】:

我正在尝试创建一个新的 react-native 移动应用程序。但是,当我添加 react native 导航(堆栈,底部)时出现问题。

每当应用第一次加载或第一次打开屏幕时,堆栈导航的标题部分首先展开,然后恢复到正常大小。与底部导航相同,它会扩展并恢复到正常大小。不太确定用英语解释它,但我拍了一个视频并将其转换为 gif,让您清楚地了解这个问题。

安装了最新版本的包

"dependencies": {
    "@react-native-community/masked-view": "^0.1.10",
    "@react-navigation/native": "^5.9.4",
    "@react-navigation/stack": "^5.14.4",
    "react": "17.0.1",
    "react-native": "0.64.0",
    "react-native-gesture-handler": "^1.10.3",
    "react-native-reanimated": "^2.1.0",
    "react-native-safe-area-context": "^3.2.0",
    "react-native-screens": "^3.1.1"
  }

Index.js

/**
 * @format
 */
import 'react-native-gesture-handler';
import {AppRegistry} from 'react-native';
import App from './app/App';
import {name as appName} from './app.json';

AppRegistry.registerComponent(appName, () => App);

App.js

import React from 'react';
import { View, Text } from 'react-native';
import { NavigationContainer } from '@react-navigation/native';
import { createStackNavigator } from '@react-navigation/stack';

const Stack = createStackNavigator();

function HomeScreen() {
    return (
        <View style={{ flex: 1, alignItems: 'center', justifyContent: 'center' }}>
            <Text>Home Screen</Text>
        </View>
    );
}

export default function App() {
    return (
        <NavigationContainer>
            <Stack.Navigator>
                <Stack.Screen name="Home" component={HomeScreen} />
            </Stack.Navigator>
        </NavigationContainer>
    );
}

我什至尝试使用旧版本的软件包,但仍然是同样的问题。安卓物理设备和模拟器都试过了。

https://github.com/react-navigation/react-navigation/issues/8446https://github.com/react-navigation/react-navigation/issues/8620 的问题相同

【问题讨论】:

    标签: reactjs react-native react-navigation


    【解决方案1】:

    为什么不创建一个自定义的标题组件并将其直接添加到您的屏幕组件中。 react-navigation 标头很难处理。

    另外,使用react-native-cli 可以提供灵活性。

    【讨论】:

      【解决方案2】:

      我建议不要使用默认的屏幕标题并自己实现它,native-base for react 为您提供了一种很好的方法,并且要删除默认标题,请在反应导航中搜索它,因为我记得您应该通过删除它的道具

      【讨论】:

      • 这不仅仅是关于默认标题。即使我尝试使用底部标签导航,它也有同样的问题。它扩展,然后返回到原始大小。我尝试使用 expo 创建一个新项目,没有遇到任何问题。它渲染正确,但是当我弹出它时,问题就像在裸反应原生项目上发生的一样。
      • 那你为什么要弹出?
      • 我需要使用 appodeal sdk 并且不能与 expo 一起使用,所以我需要将其弹出。
      猜你喜欢
      • 2020-07-13
      • 1970-01-01
      • 1970-01-01
      • 2020-01-26
      • 1970-01-01
      • 2020-11-25
      • 2021-05-14
      • 2023-01-24
      • 2021-11-13
      相关资源
      最近更新 更多