From fda846a880c6fc8ff33266d91e46caf60620da2d Mon Sep 17 00:00:00 2001 From: hezhengyi Date: Wed, 6 Dec 2023 19:20:30 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E6=A8=AA=E7=AB=96=E5=B1=8F?= =?UTF-8?q?=E5=88=87=E6=8D=A2=E6=97=A0=E6=95=88=E7=9A=84=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: hezhengyi --- .../engine/systemchannels/PlatformChannel.ets | 38 ++++++------------- 1 file changed, 12 insertions(+), 26 deletions(-) diff --git a/shell/platform/ohos/flutter_embedding/flutter/src/main/ets/embedding/engine/systemchannels/PlatformChannel.ets b/shell/platform/ohos/flutter_embedding/flutter/src/main/ets/embedding/engine/systemchannels/PlatformChannel.ets index 615dac78fb..d4892d51cd 100644 --- a/shell/platform/ohos/flutter_embedding/flutter/src/main/ets/embedding/engine/systemchannels/PlatformChannel.ets +++ b/shell/platform/ohos/flutter_embedding/flutter/src/main/ets/embedding/engine/systemchannels/PlatformChannel.ets @@ -129,21 +129,16 @@ export default class PlatformChannel { getClipboardContentFormatFromValue(encodedName: string): ClipboardContentFormat { let clipboardFormats : string[]= [ClipboardContentFormat.PLAIN_TEXT]; - for (let i = 0; i < clipboardFormats.length; i++) { - let format = clipboardFormats[i]; - if (ClipboardContentFormat[format] === encodedName) { - return ClipboardContentFormat[format]; - } + if (clipboardFormats.includes(encodedName as ClipboardContentFormat)) { + return encodedName as ClipboardContentFormat; } return ClipboardContentFormat.PLAIN_TEXT; } + getSystemUiOverlayFromValue(encodedName: string): SystemUiOverlay { let systemUiOverlays : string[] = [SystemUiOverlay.TOP_OVERLAYS, SystemUiOverlay.BOTTOM_OVERLAYS]; - for (let i = 0; i < systemUiOverlays.length; i++) { - let overlay = systemUiOverlays[i]; - if (SystemUiOverlay[overlay] === encodedName) { - return SystemUiOverlay[overlay]; - } + if (systemUiOverlays.includes(encodedName as SystemUiOverlay)) { + return encodedName as SystemUiOverlay; } throw new Error("No such SystemUiOverlay: " + encodedName); } @@ -153,36 +148,27 @@ export default class PlatformChannel { SystemUiMode.LEAN_BACK, SystemUiMode.IMMERSIVE, SystemUiMode.IMMERSIVE_STICKY, SystemUiMode.EDGE_TO_EDGE ]; - for (let i = 0; i < systemUiModes.length; i++) { - let mode = systemUiModes[i]; - if (SystemUiMode[mode] === encodedName) { - return SystemUiMode[mode]; - } + if (systemUiModes.includes(encodedName as SystemUiMode)) { + return encodedName as SystemUiMode; } throw new Error("No such SystemUiOverlay: " + encodedName); } getBrightnessFromValue(encodedName: string): Brightness { let brightnesses : string[] = [Brightness.LIGHT, Brightness.DARK]; - for (let i = 0; i < brightnesses.length; i++) { - let brightness = brightnesses[i]; - if (Brightness[brightness] === encodedName) { - return Brightness[brightness]; - } + if (brightnesses.includes(encodedName as Brightness)) { + return encodedName as Brightness; } throw new Error("No such Brightness: " + encodedName); } getDeviceOrientationFromValue(encodedName: string): DeviceOrientation { - let deviceOrientations: string[] = [ + let deviceOrientations: DeviceOrientation[] = [ DeviceOrientation.PORTRAIT_UP, DeviceOrientation.PORTRAIT_DOWN, DeviceOrientation.LANDSCAPE_LEFT, DeviceOrientation.LANDSCAPE_RIGHT ]; - for (let i = 0; i < deviceOrientations.length; i++) { - let orientation = deviceOrientations[i]; - if (DeviceOrientation[orientation] === encodedName) { - return DeviceOrientation[orientation]; - } + if (deviceOrientations.includes(encodedName as DeviceOrientation)) { + return encodedName as DeviceOrientation; } throw new Error("No such DeviceOrientation: " + encodedName); } -- Gitee