如何使用 Capacitor 而不是 Cordova 将 Ionic Native/Cordova 插件与 Ionic React(不是 Angular)一起使用?
我想将Screen Orientation Plugin与 Capacitor 和 Ionic React 结合使用。这是因为 Ionic React 项目不正式支持 Cordova。了解更多。
这是我尝试过的。
import { ScreenOrientation } from '@ionic-native/screen-orientation'
.
.
.
.
useEffect(() => {
ScreenOrientation.lock(ScreenOrientation.ORIENTATIONS.LANDSCAPE)
}, [])
Run Code Online (Sandbox Code Playgroud)
我的 package.json安装了以下相关依赖项。
"@ionic-native/core": "^5.13.0",
"@ionic-native/screen-orientation": "^5.13.0",
"cordova-plugin-screen-orientation": "^3.0.2"
Run Code Online (Sandbox Code Playgroud)
应用程序构建成功,但仍以纵向模式在我的 Android 设备上打开。如果我尝试显示以下内容,
console.log(ScreenOrientation.type)
Run Code Online (Sandbox Code Playgroud)
应用程序构建成功,但屏幕变为空白。
Capacitor 的原生 API 与 Ionic React 完美配合。例如,
import { Plugins } from '@capacitor/core'
const { StatusBar } = Plugins
.
. …Run Code Online (Sandbox Code Playgroud)