已开启
chore(0.72): 同步分支修改 #68
action创建于 9月12日
chore(0.72): 同步分支修改 #68
已开启
共 2 个文件变更+28-5
| @@ -35,7 +35,8 @@ | |||
| 35 | "peerDependencies": { | 35 | "peerDependencies": { |
| 36 | "react": ">=16.13.1", | 36 | "react": ">=16.13.1", |
| 37 | "react-native": ">=0.63.2", | 37 | "react-native": ">=0.63.2", |
| 38 | - "react-native-windows": ">=0.63.3" | 38 | + "react-native-windows": ">=0.63.3", |
G | |||
| 39 | + "@react-native-ohos/native-stack": ">=7.4.0-rc.12" | ||
| 39 | }, | 40 | }, |
| 40 | "peerDependenciesMeta": { | 41 | "peerDependenciesMeta": { |
| 41 | "react-native-windows": { | 42 | "react-native-windows": { |
| @@ -9,9 +9,11 @@ | |||
| 9 | "use strict"; | 9 | "use strict"; |
| 10 | 10 | ||
| 11 | import { TurboModuleRegistry } from "react-native"; | 11 | import { TurboModuleRegistry } from "react-native"; |
| 12 | -var OrientationNative = TurboModuleRegistry ? | 12 | +import { setIsFullScreen } from '@react-native-ohos/native-stack'; |
| 13 | -TurboModuleRegistry.get('OreitationLockerNativeModule') : | 13 | + |
| 14 | -require('react-native').NativeModules.Orientation; | 14 | +var OrientationNative = TurboModuleRegistry ? |
| 15 | + TurboModuleRegistry.get('OreitationLockerNativeModule') : | ||
| 16 | + require('react-native').NativeModules.Orientation; | ||
| 15 | var deviceEventEmitter = require('react-native').DeviceEventEmitter; | 17 | var deviceEventEmitter = require('react-native').DeviceEventEmitter; |
| 16 | 18 | ||
| 17 | var listeners = {}; | 19 | var listeners = {}; |
| @@ -36,6 +38,20 @@ function getKey(listener) { | |||
| 36 | return listener[META]; | 38 | return listener[META]; |
| 37 | } | 39 | } |
| 38 | 40 | ||
| 41 | +function waitRedrawEnd() { | ||
GG | |||
| 42 | + return new Promise(resolve => { | ||
| 43 | + const start = Date.now(); | ||
| 44 | + const loop = () => { | ||
| 45 | + if (Date.now() - start >= 100) { | ||
| 46 | + resolve(); | ||
| 47 | + } else { | ||
| 48 | + requestAnimationFrame(loop); | ||
| 49 | + } | ||
| 50 | + }; | ||
| 51 | + requestAnimationFrame(loop); | ||
| 52 | + }); | ||
| 53 | +} | ||
| 54 | + | ||
| 39 | export default class Orientation { | 55 | export default class Orientation { |
| 40 | static _disableFaceUpDown = false; | 56 | static _disableFaceUpDown = false; |
| 41 | 57 | ||
| @@ -65,6 +81,8 @@ export default class Orientation { | |||
| 65 | static lockToPortrait = () => { | 81 | static lockToPortrait = () => { |
| 66 | locked = true; | 82 | locked = true; |
| 67 | OrientationNative.lockToPortrait(); | 83 | OrientationNative.lockToPortrait(); |
| 84 | + // 锁定竖屏 通知native-stack关闭全屏 | ||
| 85 | + setIsFullScreen(false); | ||
| 68 | }; | 86 | }; |
| 69 | 87 | ||
| 70 | static lockToPortraitUpsideDown = () => { | 88 | static lockToPortraitUpsideDown = () => { |
| @@ -74,7 +92,11 @@ export default class Orientation { | |||
| 74 | 92 | ||
| 75 | static lockToLandscape = () => { | 93 | static lockToLandscape = () => { |
| 76 | locked = true; | 94 | locked = true; |
| 77 | - OrientationNative.lockToLandscape(); | 95 | + // 锁定横屏 通知native-stack开启全屏 |
GG | |||
| 96 | + setIsFullScreen(true); | ||
GG | |||
| 97 | + waitRedrawEnd().then(() => { | ||
| 98 | + OrientationNative.lockToLandscape(); | ||
| 99 | + }); | ||
| 78 | }; | 100 | }; |
| 79 | 101 | ||
| 80 | static lockToLandscapeRight = () => { | 102 | static lockToLandscapeRight = () => { |


@react-native-ohos/native-stack 只在 OHOS 平台存在,但 peerDependencies 里没有对应 peerDependenciesMeta.optional 标记。非 OHOS 平台安装时 npm/yarn 会报 unmet peer dependency 警告。参照上面 react-native-windows 的做法,给它也加一个 optional: true?