react-native-orientation 库中的 lockToPortrait() 函数出错

Getting error in lockToPortrait() function in react-native-orientation library

我正在使用 react-native-orientation 库让我的应用程序仅在纵向模式下打开。 这是我的代码:

import React, {Component} from 'react';
import {
    View,
    Text,
} from 'react-native';
import AppContainer from './src/screens/Navigation';
import Orientation from 'react-native-orientation';

const App: () => React$Node = () => {

    useEffect(() => {
        Orientation.lockToPortrait();
    })

    return (
        <AppContainer />
    );
};


export default App;

我在 运行 这段代码中遇到错误。

NPM 中的 React Native Orientation 包的当前版本不是最新的。现在,只需直接从存储库中获取代码,例如:

npm install --save react-native-orientation@git+https://github.com/yamill/react-native-orientation.git

master 的当前版本应该有 lockToPortrait() 在 Android 上工作并且 iOS granted native linking/installing 是正确的。

对于 android,您只需将此行添加到 MainActivity 标记

中的 AndroidManifest.xml 即可设置方向 android
    <activity
    android:name=".MainActivity"
    android:label="@string/app_name"
    android:configChanges="keyboard|keyboardHidden|orientation|screenSize"
    android:screenOrientation="portrait" //add this line for portrait lock
    android:windowSoftInputMode="adjustPan">

在 ios 打开 xcode 文件后执行此操作