From 10f3fd5dc2cdec1a097def97ff425e8710eb18e2 Mon Sep 17 00:00:00 2001 From: fangzhiyuan Date: Tue, 1 Jul 2025 23:58:40 +0800 Subject: [PATCH 01/11] =?UTF-8?q?=E3=80=90ArkTS=E6=BC=94=E8=BF=9B=E3=80=91?= =?UTF-8?q?=E4=B8=BB=E9=A2=98=E8=83=BD=E5=8A=9B=E6=94=AF=E6=8C=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: fangzhiyuan Change-Id: I4d61c1f9cffbd72e8a393fad48534b7446b9d265 --- .../bridge/arkts_frontend/arkts_ani_utils.cpp | 41 +++ .../bridge/arkts_frontend/arkts_ani_utils.h | 15 +- .../arkoala-arkts/arktsconfig-gn.json | 3 + .../arkui-ohos/@ohos.arkui.theme.ts | 330 +++++++++++++++++ .../src/ani/arkts/ArkUIAniModule.ts | 8 +- .../src/ani/native/common/common_module.cpp | 97 +++++ .../src/ani/native/common/common_module.h | 5 + .../arkui-ohos/src/ani/native/module.cpp | 25 ++ .../handwritten/theme/ArkResourcesHelper.ts | 31 ++ .../src/handwritten/theme/ArkShapesImpl.ts | 279 ++++++++++++++ .../src/handwritten/theme/ArkThemeBase.ts | 206 +++++++++++ .../src/handwritten/theme/ArkThemeCache.ts | 167 +++++++++ .../src/handwritten/theme/ArkThemeImpl.ts | 40 ++ .../handwritten/theme/ArkThemeNativeHelper.ts | 108 ++++++ .../handwritten/theme/ArkThemeScopeManager.ts | 127 +++++++ .../handwritten/theme/ArkTypographyImpl.ts | 197 ++++++++++ .../arkui-ohos/src/handwritten/theme/index.ts | 317 ++++++++++++++++ .../theme/system/ArkSystemShapes.ts | 142 +++++++ .../theme/system/ArkSystemTheme.ts | 33 ++ .../theme/system/ArkSystemTypography.ts | 128 +++++++ .../arkui-ohos/ui2abcconfig-m3.json | 3 + .../arkoala-arkts/components.gni | 15 + .../arkoala-arkts/ui2abcconfig-m3.json | 3 + frameworks/core/interfaces/ani/ani_api.h | 7 + frameworks/core/interfaces/native/BUILD.gn | 11 +- .../core/interfaces/native/ani/ani_theme.cpp | 57 +++ .../core/interfaces/native/ani/ani_theme.h | 346 ++++++++++++++++++ .../native/ani/ani_theme_module.cpp | 78 ++++ .../interfaces/native/ani/ani_theme_module.h | 40 ++ .../native/ani/common_ani_modifier.cpp | 98 ++++- .../native/ani/resource_ani_modifier.cpp | 108 ++++++ .../native/ani/resource_ani_modifier.h | 31 ++ 32 files changed, 3089 insertions(+), 7 deletions(-) create mode 100644 frameworks/bridge/arkts_frontend/koala_projects/arkoala-arkts/arkui-ohos/@ohos.arkui.theme.ts create mode 100644 frameworks/bridge/arkts_frontend/koala_projects/arkoala-arkts/arkui-ohos/src/handwritten/theme/ArkResourcesHelper.ts create mode 100644 frameworks/bridge/arkts_frontend/koala_projects/arkoala-arkts/arkui-ohos/src/handwritten/theme/ArkShapesImpl.ts create mode 100644 frameworks/bridge/arkts_frontend/koala_projects/arkoala-arkts/arkui-ohos/src/handwritten/theme/ArkThemeBase.ts create mode 100644 frameworks/bridge/arkts_frontend/koala_projects/arkoala-arkts/arkui-ohos/src/handwritten/theme/ArkThemeCache.ts create mode 100644 frameworks/bridge/arkts_frontend/koala_projects/arkoala-arkts/arkui-ohos/src/handwritten/theme/ArkThemeImpl.ts create mode 100644 frameworks/bridge/arkts_frontend/koala_projects/arkoala-arkts/arkui-ohos/src/handwritten/theme/ArkThemeNativeHelper.ts create mode 100644 frameworks/bridge/arkts_frontend/koala_projects/arkoala-arkts/arkui-ohos/src/handwritten/theme/ArkThemeScopeManager.ts create mode 100644 frameworks/bridge/arkts_frontend/koala_projects/arkoala-arkts/arkui-ohos/src/handwritten/theme/ArkTypographyImpl.ts create mode 100644 frameworks/bridge/arkts_frontend/koala_projects/arkoala-arkts/arkui-ohos/src/handwritten/theme/index.ts create mode 100644 frameworks/bridge/arkts_frontend/koala_projects/arkoala-arkts/arkui-ohos/src/handwritten/theme/system/ArkSystemShapes.ts create mode 100644 frameworks/bridge/arkts_frontend/koala_projects/arkoala-arkts/arkui-ohos/src/handwritten/theme/system/ArkSystemTheme.ts create mode 100644 frameworks/bridge/arkts_frontend/koala_projects/arkoala-arkts/arkui-ohos/src/handwritten/theme/system/ArkSystemTypography.ts create mode 100644 frameworks/core/interfaces/native/ani/ani_theme.cpp create mode 100644 frameworks/core/interfaces/native/ani/ani_theme.h create mode 100644 frameworks/core/interfaces/native/ani/ani_theme_module.cpp create mode 100644 frameworks/core/interfaces/native/ani/ani_theme_module.h create mode 100644 frameworks/core/interfaces/native/ani/resource_ani_modifier.cpp create mode 100644 frameworks/core/interfaces/native/ani/resource_ani_modifier.h diff --git a/frameworks/bridge/arkts_frontend/arkts_ani_utils.cpp b/frameworks/bridge/arkts_frontend/arkts_ani_utils.cpp index b3f5c39b44a..4dccafe2a10 100644 --- a/frameworks/bridge/arkts_frontend/arkts_ani_utils.cpp +++ b/frameworks/bridge/arkts_frontend/arkts_ani_utils.cpp @@ -139,4 +139,45 @@ ani_object ArktsAniUtils::FloatToNumberObject(ani_env* env, const float& value) auto widthDoouble = ReplaceInfinity(value); return ArktsAniUtils::CreateDoubleObject(env, widthDoouble); } + +std::string ArktsAniUtils::ANIStringToStdString(ani_env* env, ani_string ani_str) +{ + ani_size strSize; + env->String_GetUTF8Size(ani_str, &strSize); + + std::vector buffer(strSize + 1); // +1 for null terminator + char* utf8_buffer = buffer.data(); + + ani_size bytes_written = 0; + env->String_GetUTF8(ani_str, utf8_buffer, strSize + 1, &bytes_written); + + utf8_buffer[bytes_written] = '\0'; + std::string content = std::string(utf8_buffer); + return content; +} + +std::string ArktsAniUtils::JsonStringify(ani_env* env, ani_object src) +{ + ani_status status; + ani_class json; + status = env->FindClass("Lescompat/JSON;", &json); + if (status != ANI_OK) { + ani_error aniError; + env->GetUnhandledError(&aniError); + env->ResetError(); + LOGW("Find JSON failed, status: %{public}d", status); + return ""; + } + ani_ref result; + status = + env->Class_CallStaticMethodByName_Ref(json, "stringify", "Lstd/core/Object;:Lstd/core/String;", &result, src); + if (status != ANI_OK) { + ani_error aniError; + env->GetUnhandledError(&aniError); + env->ResetError(); + LOGW("Call JSON.stringify failed, status: %{public}d", status); + return ""; + } + return ArktsAniUtils::ANIStringToStdString(env, static_cast(result)); +} } // namespace OHOS::Ace diff --git a/frameworks/bridge/arkts_frontend/arkts_ani_utils.h b/frameworks/bridge/arkts_frontend/arkts_ani_utils.h index 1a89131964c..d8e979888b5 100644 --- a/frameworks/bridge/arkts_frontend/arkts_ani_utils.h +++ b/frameworks/bridge/arkts_frontend/arkts_ani_utils.h @@ -18,6 +18,8 @@ #include #include +#include +#include "ui/base/macros.h" #define ANI_CALL(env, call, onFail...) \ if (env) { \ @@ -53,9 +55,10 @@ typedef struct __ani_env ani_env; typedef class __ani_object* ani_object; typedef class __ani_ref* ani_ref; typedef struct __ani_vm ani_vm; +typedef class __ani_string* ani_string; namespace OHOS::Ace { -class ArktsAniUtils final { +class ACE_FORCE_EXPORT ArktsAniUtils final { public: /** * Create std/core/Boolean. @@ -84,6 +87,16 @@ public: * Get std/core/Double by float. */ static ani_object FloatToNumberObject(ani_env* env, const float& value); + + /** + * Get std::string from std/core/String. + */ + static std::string ANIStringToStdString(ani_env* env, ani_string ani_str); + + /** + * Call JSON.stringify to generate the json string of ani_object. + */ + static std::string JsonStringify(ani_env* env, ani_object src); }; } // namespace OHOS::Ace diff --git a/frameworks/bridge/arkts_frontend/koala_projects/arkoala-arkts/arktsconfig-gn.json b/frameworks/bridge/arkts_frontend/koala_projects/arkoala-arkts/arktsconfig-gn.json index 4eb282ba3d5..31009d550de 100644 --- a/frameworks/bridge/arkts_frontend/koala_projects/arkoala-arkts/arktsconfig-gn.json +++ b/frameworks/bridge/arkts_frontend/koala_projects/arkoala-arkts/arktsconfig-gn.json @@ -117,6 +117,9 @@ ], "@ohos/arkui/Parallelize": [ "./@ohos.arkui.Parallelize.ets" + ], + "@ohos/arkui/theme": [ + "@ohos.arkui.theme.ets" ] } }, diff --git a/frameworks/bridge/arkts_frontend/koala_projects/arkoala-arkts/arkui-ohos/@ohos.arkui.theme.ts b/frameworks/bridge/arkts_frontend/koala_projects/arkoala-arkts/arkui-ohos/@ohos.arkui.theme.ts new file mode 100644 index 00000000000..6d0ac4bc9ec --- /dev/null +++ b/frameworks/bridge/arkts_frontend/koala_projects/arkoala-arkts/arkui-ohos/@ohos.arkui.theme.ts @@ -0,0 +1,330 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +import { ResourceColor, Color } from 'arkui/component'; +import { ArkThemeScopeManager } from 'arkui/handwritten/theme/ArkThemeScopeManager'; +import { ArkResourcesHelper } from 'arkui/handwritten/theme/ArkResourcesHelper'; +import { ArkSystemShapes } from 'arkui/handwritten/theme/system/ArkSystemShapes'; +import { ArkSystemTypography } from 'arkui/handwritten/theme/system/ArkSystemTypography'; +import { Shapes, Typography, CustomTypography, CustomShapes, BrandColors, ArkThemeResource } from 'arkui/handwritten/theme'; +import { Resource } from 'global.resource'; +import { ArkUIAniModule } from 'arkui.ani'; + +export class Colors { + brand: ResourceColor = ArkResourcesHelper.$r('sys.color.brand', 125830976); + warning: ResourceColor = ArkResourcesHelper.$r('sys.color.warning', 125830979); + alert: ResourceColor = ArkResourcesHelper.$r('sys.color.alert', 125830980); + confirm: ResourceColor = ArkResourcesHelper.$r('sys.color.confirm', 125830981); + + fontPrimary: ResourceColor = ArkResourcesHelper.$r('sys.color.font_primary', 125830982); + fontSecondary: ResourceColor = ArkResourcesHelper.$r('sys.color.font_secondary', 125830983); + fontTertiary: ResourceColor = ArkResourcesHelper.$r('sys.color.font_tertiary', 125830984); + fontFourth: ResourceColor = ArkResourcesHelper.$r('sys.color.font_fourth', 125830985); + fontEmphasize: ResourceColor = ArkResourcesHelper.$r('sys.color.font_emphasize', 125830986); + + fontOnPrimary: ResourceColor = ArkResourcesHelper.$r('sys.color.font_on_primary', 125830987); + fontOnSecondary: ResourceColor = ArkResourcesHelper.$r('sys.color.font_on_secondary', 125830988); + fontOnTertiary: ResourceColor = ArkResourcesHelper.$r('sys.color.font_on_tertiary', 125830989); + fontOnFourth: ResourceColor = ArkResourcesHelper.$r('sys.color.font_on_fourth', 125830990); + + iconPrimary: ResourceColor = ArkResourcesHelper.$r('sys.color.icon_primary', 125830991); + iconSecondary: ResourceColor = ArkResourcesHelper.$r('sys.color.icon_secondary', 125830992); + iconTertiary: ResourceColor = ArkResourcesHelper.$r('sys.color.icon_tertiary', 125830993); + iconFourth: ResourceColor = ArkResourcesHelper.$r('sys.color.icon_fourth', 125830994); + iconEmphasize: ResourceColor = ArkResourcesHelper.$r('sys.color.icon_emphasize', 125830995); + iconSubEmphasize: ResourceColor = ArkResourcesHelper.$r('sys.color.icon_sub_emphasize', 125830996); + + iconOnPrimary: ResourceColor = ArkResourcesHelper.$r('sys.color.icon_on_primary', 125831057); + iconOnSecondary: ResourceColor = ArkResourcesHelper.$r('sys.color.icon_on_secondary', 125831058); + iconOnTertiary: ResourceColor = ArkResourcesHelper.$r('sys.color.icon_on_tertiary', 125831059); + iconOnFourth: ResourceColor = ArkResourcesHelper.$r('sys.color.icon_on_fourth', 125831060); + + backgroundPrimary: ResourceColor = ArkResourcesHelper.$r('sys.color.background_primary', 125831061); + backgroundSecondary: ResourceColor = ArkResourcesHelper.$r('sys.color.background_secondary', 125831062); + backgroundTertiary: ResourceColor = ArkResourcesHelper.$r('sys.color.background_tertiary', 125831063); + backgroundFourth: ResourceColor = ArkResourcesHelper.$r('sys.color.background_fourth', 125831064); + backgroundEmphasize: ResourceColor = ArkResourcesHelper.$r('sys.color.background_emphasize', 125831065); + + compForegroundPrimary: ResourceColor = ArkResourcesHelper.$r('sys.color.comp_foreground_primary', 125831003); + compBackgroundPrimary: ResourceColor = ArkResourcesHelper.$r('sys.color.comp_background_primary', 125831004); + compBackgroundPrimaryTran: ResourceColor = ArkResourcesHelper.$r('sys.color.comp_background_primary_tran'); + compBackgroundPrimaryContrary: ResourceColor = ArkResourcesHelper.$r( + 'sys.color.comp_background_primary_contrary', + 125831005 + ); + compBackgroundGray: ResourceColor = ArkResourcesHelper.$r('sys.color.comp_background_gray', 125831006); + compBackgroundSecondary: ResourceColor = ArkResourcesHelper.$r('sys.color.comp_background_secondary', 125831007); + compBackgroundTertiary: ResourceColor = ArkResourcesHelper.$r('sys.color.comp_background_tertiary', 125831008); + compBackgroundEmphasize: ResourceColor = ArkResourcesHelper.$r('sys.color.comp_background_emphasize', 125831009); + compBackgroundNeutral: ResourceColor = ArkResourcesHelper.$r('sys.color.neutral', 125831066); + compEmphasizeSecondary: ResourceColor = ArkResourcesHelper.$r('sys.color.comp_emphasize_secondary', 125831011); + compEmphasizeTertiary: ResourceColor = ArkResourcesHelper.$r('sys.color.comp_emphasize_tertiary', 125831012); + compDivider: ResourceColor = ArkResourcesHelper.$r('sys.color.comp_divider', 125831013); + compCommonContrary: ResourceColor = ArkResourcesHelper.$r('sys.color.comp_common_contrary', 125831014); + compBackgroundFocus: ResourceColor = ArkResourcesHelper.$r('sys.color.comp_background_focus', 125831015); + compFocusedPrimary: ResourceColor = ArkResourcesHelper.$r('sys.color.comp_focused_primary', 125831016); + compFocusedSecondary: ResourceColor = ArkResourcesHelper.$r('sys.color.comp_focused_secondary', 125831017); + compFocusedTertiary: ResourceColor = ArkResourcesHelper.$r('sys.color.comp_focused_tertiary', 125831018); + + interactiveHover: ResourceColor = ArkResourcesHelper.$r('sys.color.interactive_hover', 125831019); + interactivePressed: ResourceColor = ArkResourcesHelper.$r('sys.color.interactive_pressed', 125831020); + interactiveFocus: ResourceColor = ArkResourcesHelper.$r('sys.color.interactive_focus', 125831021); + interactiveActive: ResourceColor = ArkResourcesHelper.$r('sys.color.interactive_active', 125831022); + interactiveSelect: ResourceColor = ArkResourcesHelper.$r('sys.color.interactive_select', 125831023); + interactiveClick: ResourceColor = ArkResourcesHelper.$r('sys.color.interactive_click', 125831024); + + constructor() { } + + constructor(colors: CustomColors | undefined, baselineColors: Colors) { + Colors.assign(this, baselineColors); + if (colors) { + Colors.assign(this, colors!); + } + } + + static assign(dst: Colors, src: Colors): void { + dst.brand = src.brand; + dst.warning = src.warning; + dst.alert = src.alert; + dst.confirm = src.confirm; + + dst.fontPrimary = src.fontPrimary; + dst.fontSecondary = src.fontSecondary; + dst.fontTertiary = src.fontTertiary; + dst.fontFourth = src.fontFourth; + dst.fontEmphasize = src.fontEmphasize; + + dst.fontOnPrimary = src.fontOnPrimary; + dst.fontOnSecondary = src.fontOnSecondary; + dst.fontOnTertiary = src.fontOnTertiary; + dst.fontOnFourth = src.fontOnFourth; + + dst.iconPrimary = src.iconPrimary; + dst.iconSecondary = src.iconSecondary; + dst.iconTertiary = src.iconTertiary; + dst.iconFourth = src.iconFourth; + dst.iconEmphasize = src.iconEmphasize; + dst.iconSubEmphasize = src.iconSubEmphasize; + + dst.iconOnPrimary = src.iconOnPrimary; + dst.iconOnSecondary = src.iconOnSecondary; + dst.iconOnTertiary = src.iconOnTertiary; + dst.iconOnFourth = src.iconOnFourth; + + dst.backgroundPrimary = src.backgroundPrimary; + dst.backgroundSecondary = src.backgroundSecondary; + dst.backgroundTertiary = src.backgroundTertiary; + dst.backgroundFourth = src.backgroundFourth; + dst.backgroundEmphasize = src.backgroundEmphasize; + + dst.compForegroundPrimary = src.compForegroundPrimary; + dst.compBackgroundPrimary = src.compBackgroundPrimary; + dst.compBackgroundPrimaryTran = src.compBackgroundPrimaryTran; + dst.compBackgroundPrimaryContrary = src.compBackgroundPrimaryContrary; + dst.compBackgroundGray = src.compBackgroundGray; + dst.compBackgroundSecondary = src.compBackgroundSecondary; + dst.compBackgroundTertiary = src.compBackgroundTertiary; + dst.compBackgroundEmphasize = src.compBackgroundEmphasize; + dst.compBackgroundNeutral = src.compBackgroundNeutral; + dst.compEmphasizeSecondary = src.compEmphasizeSecondary; + dst.compEmphasizeTertiary = src.compEmphasizeTertiary; + dst.compDivider = src.compDivider; + dst.compCommonContrary = src.compCommonContrary; + dst.compBackgroundFocus = src.compBackgroundFocus; + dst.compFocusedPrimary = src.compFocusedPrimary; + dst.compFocusedSecondary = src.compFocusedSecondary; + dst.compFocusedTertiary = src.compFocusedTertiary; + + dst.interactiveHover = src.interactiveHover; + dst.interactivePressed = src.interactivePressed; + dst.interactiveFocus = src.interactiveFocus; + dst.interactiveActive = src.interactiveActive; + dst.interactiveSelect = src.interactiveSelect; + dst.interactiveClick = src.interactiveClick; + } + + static expandByBrandColor(colors: CustomColors) { + if (colors.brand) { + const brandColors: BrandColors = Colors.makeBrandColors(colors.brand); + colors.fontEmphasize = colors.fontEmphasize ?? brandColors.primary!; + + colors.iconEmphasize = colors.iconEmphasize ?? brandColors.primary!; + colors.iconSubEmphasize = colors.iconSubEmphasize ?? brandColors.tertiary!; + + colors.backgroundEmphasize = colors.backgroundEmphasize ?? brandColors.primary!; + + colors.compBackgroundEmphasize = colors.compBackgroundEmphasize ?? brandColors.primary!; + + colors.compEmphasizeSecondary = colors.compEmphasizeSecondary ?? brandColors.fourth!; + colors.compEmphasizeTertiary = colors.compEmphasizeTertiary ?? brandColors.fifth!; + + colors.interactiveFocus = colors.interactiveFocus ?? brandColors.primary!; + colors.interactiveActive = colors.interactiveActive ?? brandColors.primary!; + } + } + + static makeBrandColors(brandColor: ResourceColor | undefined): BrandColors { + const result: BrandColors = { + primary: undefined, + secondary: undefined, + tertiary: undefined, + fourth: undefined, + fifth: undefined, + sixth: undefined, + }; + if (brandColor) { + if (brandColor instanceof Color) { + result.primary = Colors.convertColorEnumToValue(brandColor) as string; + result.secondary = Colors.convertColorEnumToValue(brandColor) as string; + result.tertiary = Colors.convertColorEnumToValue(brandColor) as string; + result.fourth = Colors.convertColorEnumToValue(brandColor) as string; + result.fifth = Colors.convertColorEnumToValue(brandColor) as string; + result.sixth = Colors.convertColorEnumToValue(brandColor) as string; + } else if (brandColor instanceof Resource) { + result.primary = brandColor as Resource; + result.secondary = Colors.makeResourceWithOpacity(brandColor as Resource, 0.6) as Resource; + result.tertiary = Colors.makeResourceWithOpacity(brandColor as Resource, 0.4) as Resource; + result.fourth = Colors.makeResourceWithOpacity(brandColor as Resource, 0.2) as Resource; + result.fifth = Colors.makeResourceWithOpacity(brandColor as Resource, 0.1) as Resource; + result.sixth = Colors.makeResourceWithOpacity(brandColor as Resource, 0.05) as Resource; + } else { + const brandColorValue = brandColor as number | string; + const argbColor = ArkUIAniModule._GetColorValue(brandColorValue); + result.primary = argbColor; + result.secondary = Colors.blendOpacity(argbColor, 0.6); + result.tertiary = Colors.blendOpacity(argbColor, 0.4); + result.fourth = Colors.blendOpacity(argbColor, 0.2); + result.fifth = Colors.blendOpacity(argbColor, 0.1); + result.sixth = Colors.blendOpacity(argbColor, 0.05); + } + } + return result; + } + + static makeResourceWithOpacity(resourceColor: Resource, opacityRatio: number): ArkThemeResource { + return { + id: resourceColor.id, + type: resourceColor.type, + params: [...resourceColor.params!], + bundleName: resourceColor.bundleName, + moduleName: resourceColor.moduleName, + opacityRatio: opacityRatio, + } as ArkThemeResource; + } + + static blendOpacity(argbColor: number, opacityRatio: number): number { + if (opacityRatio < 0 || opacityRatio > 1.0) { + return argbColor; + } + const alpha = (argbColor >> 24) & 0xff; + const outAlpha = (alpha * opacityRatio) & 0xff; + return ((argbColor & 0x00ffffff) | ((outAlpha & 0xff) << 24)) >>> 0; + } + + static convertColorEnumToValue(color: Color): string { + switch (color) { + case Color.WHITE: + case Color.White: + return '#ffffffff'; + case Color.BLACK: + case Color.Black: + return '#ff000000'; + case Color.BLUE: + case Color.Blue: + return '#ff0000ff'; + case Color.BROWN: + case Color.Brown: + return '#ffa52a2a'; + case Color.GRAY: + case Color.Gray: + return '#ff808080'; + case Color.GREEN: + case Color.Green: + return '#ff008000'; + case Color.GREY: + case Color.Grey: + return '#ff808080'; + case Color.ORANGE: + case Color.Orange: + return '#ffffa500'; + case Color.PINK: + case Color.Pink: + return '#ffffc0cb'; + case Color.RED: + case Color.Red: + return '#ffff0000'; + case Color.YELLOW: + case Color.Yellow: + return '#ffffff00'; + case Color.TRANSPARENT: + case Color.Transparent: + return '#00000000'; + } + // Do not match the color, return the default. + return '#ff000000'; + } + + static checkIsColor(value: ResourceColor): boolean { + return value instanceof Color; + } +} + +export type CustomColors = Colors; + +export class Theme { + colors: Colors; + shapes: Shapes; + typography: Typography; + + constructor() { + this.colors = new Colors(); + this.shapes = new ArkSystemShapes(); + this.typography = new ArkSystemTypography(); + } + + constructor(colors: Colors, shapes: Shapes, typography: Typography) { + this.colors = colors; + this.shapes = shapes; + this.typography = typography; + } +} + +export class CustomTheme { + colors?: CustomColors; + shapes?: CustomShapes; + typography?: CustomTypography; + + constructor() { + this.colors = undefined; + this.shapes = undefined; + this.typography = undefined; + } + + constructor(colors: CustomColors) { + this.colors = colors; + } + + constructor(colors: CustomColors, shapes: CustomShapes, typography: CustomTypography) { + this.colors = colors; + this.shapes = shapes; + this.typography = typography; + } +} + +export class ThemeControl { + static setDefaultTheme(customTheme: CustomTheme) { + ArkThemeScopeManager.getInstance().setDefaultTheme(customTheme); + } +} diff --git a/frameworks/bridge/arkts_frontend/koala_projects/arkoala-arkts/arkui-ohos/src/ani/arkts/ArkUIAniModule.ts b/frameworks/bridge/arkts_frontend/koala_projects/arkoala-arkts/arkui-ohos/src/ani/arkts/ArkUIAniModule.ts index f5bba43fea7..c12ad6a6a4d 100644 --- a/frameworks/bridge/arkts_frontend/koala_projects/arkoala-arkts/arkui-ohos/src/ani/arkts/ArkUIAniModule.ts +++ b/frameworks/bridge/arkts_frontend/koala_projects/arkoala-arkts/arkui-ohos/src/ani/arkts/ArkUIAniModule.ts @@ -13,7 +13,7 @@ * limitations under the License. */ -import { KPointer, KInt, KLong, KBoolean, KFloat } from "@koalaui/interop" +import { KPointer, KInt, KLong, KBoolean, KFloat, KUInt } from "@koalaui/interop" import { drawing } from "@ohos/graphics/drawing" import image from "@ohos.multimedia.image" import webview from "@ohos.web.webview" @@ -244,4 +244,10 @@ export class ArkUIAniModule { native static _CanvasRenderer_PutImageData0(peerPtr: KPointer, array: Uint8ClampedArray, dx: number, dy: number, width: KInt, height: KInt): void native static _CanvasRenderer_PutImageData1(peerPtr: KPointer, array: Uint8ClampedArray, dx: number, dy: number, width: KInt, height: KInt, dirtyX: number, dirtyY: number, dirtyWidth: number, dirtyHeight: number): void + + native static _GetColorValue(color: number | string): KUInt + native static _SendThemeToNative(colorArray: ResourceColor[], elmtId: KInt): void + native static _SetDefaultTheme(colorArray: ResourceColor[], isDark: boolean): void + native static _UpdateColorMode(colorMode: KInt): void + native static _RestoreColorMode(): void } diff --git a/frameworks/bridge/arkts_frontend/koala_projects/arkoala-arkts/arkui-ohos/src/ani/native/common/common_module.cpp b/frameworks/bridge/arkts_frontend/koala_projects/arkoala-arkts/arkui-ohos/src/ani/native/common/common_module.cpp index 2548629ac5a..9601da64edd 100644 --- a/frameworks/bridge/arkts_frontend/koala_projects/arkoala-arkts/arkui-ohos/src/ani/native/common/common_module.cpp +++ b/frameworks/bridge/arkts_frontend/koala_projects/arkoala-arkts/arkui-ohos/src/ani/native/common/common_module.cpp @@ -16,7 +16,10 @@ #include "common_module.h" #include +#include +#include +#include "ani.h" #include "load.h" #include "base/utils/utils.h" @@ -24,6 +27,24 @@ #include "utils/ani_utils.h" namespace OHOS::Ace::Ani { +namespace { +std::string ANIUtils_ANIStringToStdString(ani_env* env, ani_string ani_str) +{ + ani_size strSize; + env->String_GetUTF8Size(ani_str, &strSize); + + std::vector buffer(strSize + 1); // +1 for null terminator + char* utf8_buffer = buffer.data(); + + ani_size bytes_written = 0; + env->String_GetUTF8(ani_str, utf8_buffer, strSize + 1, &bytes_written); + + utf8_buffer[bytes_written] = '\0'; + std::string content = std::string(utf8_buffer); + return content; +} +} // namespace + ani_status GetAniEnv(ani_vm* vm, ani_env** env) { CHECK_NULL_RETURN(vm, ANI_ERROR); @@ -473,4 +494,80 @@ ani_double Px2lpx(ani_env* env, ani_object obj, ani_double value, ani_int instan } return modifier->getCommonAniModifier()->px2lpx(value, instanceId); } + + +ani_int GetColorValue(ani_env* env, ani_object aniClass, ani_object src) +{ + const auto* modifier = GetNodeAniModifier(); + if (!modifier) { + return 0; + } + + ani_status status; + ani_class stringClass; + if ((status = env->FindClass("Lstd/core/String;", &stringClass)) != ANI_OK) { + // LOGW("GetColorValue find string failed. %{public}d", status); + } + ani_boolean isString; + if ((status = env->Object_InstanceOf(src, stringClass, &isString)) != ANI_OK) { + // LOGW("GetColorValue call instanceof string failed. %{public}d", status); + } + if(isString){ + auto srcString = ANIUtils_ANIStringToStdString(env, static_cast(src)); + return modifier->getCommonAniModifier()->getColorValueByString(srcString); + } + + ani_class intClass; + if ((status = env->FindClass("Lstd/core/Int;", &intClass)) != ANI_OK) { + // LOGW("GetColorValue find int failed. %{public}d", status); + } + ani_boolean isInt; + if ((status = env->Object_InstanceOf(src, intClass, &isInt)) != ANI_OK) { + // LOGW("GetColorValue call instanceof int failed. %{public}d", status); + } + if (isInt) { + ani_int intSrc; + if ((status = env->Object_CallMethodByName_Int(src, "unboxed", ":I", &intSrc)) != ANI_OK) { + // LOGW("GetColorValue unboxed int failed. %{public}d", status); + } + return modifier->getCommonAniModifier()->getColorValueByNumber(static_cast(intSrc)); + } + return 0; +} + +void SendThemeToNative(ani_env* env, ani_object aniClass, ani_array colorArray, ani_int id) +{ + const auto* modifier = GetNodeAniModifier(); + if (!modifier) { + return; + } + modifier->getCommonAniModifier()->sendThemeToNative(env, colorArray, id); +} + +void SetDefaultTheme(ani_env* env, ani_object aniClass, ani_array colorArray, ani_boolean isDark) +{ + const auto* modifier = GetNodeAniModifier(); + if (!modifier) { + return; + } + modifier->getCommonAniModifier()->setDefaultTheme(env, colorArray, isDark); +} + +void UpdateColorMode(ani_env* env, ani_object aniClass, ani_int colorMode) +{ + const auto* modifier = GetNodeAniModifier(); + if (!modifier) { + return; + } + modifier->getCommonAniModifier()->updateColorMode(colorMode); +} + +void RestoreColorMode(ani_env* env, ani_object aniClass) +{ + const auto* modifier = GetNodeAniModifier(); + if (!modifier) { + return; + } + modifier->getCommonAniModifier()->restoreColorMode(); +} } // namespace OHOS::Ace::Ani diff --git a/frameworks/bridge/arkts_frontend/koala_projects/arkoala-arkts/arkui-ohos/src/ani/native/common/common_module.h b/frameworks/bridge/arkts_frontend/koala_projects/arkoala-arkts/arkui-ohos/src/ani/native/common/common_module.h index af41c02e7ca..e3aa2acdc89 100644 --- a/frameworks/bridge/arkts_frontend/koala_projects/arkoala-arkts/arkui-ohos/src/ani/native/common/common_module.h +++ b/frameworks/bridge/arkts_frontend/koala_projects/arkoala-arkts/arkui-ohos/src/ani/native/common/common_module.h @@ -52,6 +52,11 @@ ani_double Fp2px(ani_env* env, ani_object obj, ani_double value, ani_int instanc ani_double Px2fp(ani_env* env, ani_object obj, ani_double value, ani_int instanceId); ani_double Lpx2px(ani_env* env, ani_object obj, ani_double value, ani_int instanceId); ani_double Px2lpx(ani_env* env, ani_object obj, ani_double value, ani_int instanceId); +ani_int GetColorValue(ani_env* env, ani_object aniClass, ani_object src); +void SendThemeToNative(ani_env* env, ani_object aniClass, ani_array colorArray, ani_int id); +void SetDefaultTheme(ani_env* env, ani_object aniClass, ani_array colorArray, ani_boolean isDark); +void UpdateColorMode(ani_env* env, ani_object aniClass, ani_int colorMode); +void RestoreColorMode(ani_env* env, ani_object aniClass); } // namespace OHOS::Ace::Ani #endif // KOALA_PROJECTS_ARKOALA_ARKTS_ARKUI_OHOS_ANI_NATIVE_COMMON_MODULE diff --git a/frameworks/bridge/arkts_frontend/koala_projects/arkoala-arkts/arkui-ohos/src/ani/native/module.cpp b/frameworks/bridge/arkts_frontend/koala_projects/arkoala-arkts/arkui-ohos/src/ani/native/module.cpp index 424e2766f17..ec9a9abf6dc 100644 --- a/frameworks/bridge/arkts_frontend/koala_projects/arkoala-arkts/arkui-ohos/src/ani/native/module.cpp +++ b/frameworks/bridge/arkts_frontend/koala_projects/arkoala-arkts/arkui-ohos/src/ani/native/module.cpp @@ -826,6 +826,31 @@ ANI_EXPORT ani_status ANI_Constructor(ani_vm* vm, uint32_t* result) "JLescompat/Uint8ClampedArray;DDIIDDDD:V", reinterpret_cast(OHOS::Ace::Ani::CanvasModule::PutImageData1) }, + ani_native_function { + "_GetColorValue", + nullptr, + reinterpret_cast(OHOS::Ace::Ani::GetColorValue) + }, + ani_native_function { + "_SendThemeToNative", + nullptr, + reinterpret_cast(OHOS::Ace::Ani::SendThemeToNative) + }, + ani_native_function { + "_SetDefaultTheme", + nullptr, + reinterpret_cast(OHOS::Ace::Ani::SetDefaultTheme) + }, + ani_native_function { + "_UpdateColorMode", + nullptr, + reinterpret_cast(OHOS::Ace::Ani::UpdateColorMode) + }, + ani_native_function { + "_RestoreColorMode", + nullptr, + reinterpret_cast(OHOS::Ace::Ani::RestoreColorMode) + }, }; auto bindRst = env->Class_BindNativeMethods(cls, methods.data(), methods.size()); diff --git a/frameworks/bridge/arkts_frontend/koala_projects/arkoala-arkts/arkui-ohos/src/handwritten/theme/ArkResourcesHelper.ts b/frameworks/bridge/arkts_frontend/koala_projects/arkoala-arkts/arkui-ohos/src/handwritten/theme/ArkResourcesHelper.ts new file mode 100644 index 00000000000..9e99f811f02 --- /dev/null +++ b/frameworks/bridge/arkts_frontend/koala_projects/arkoala-arkts/arkui-ohos/src/handwritten/theme/ArkResourcesHelper.ts @@ -0,0 +1,31 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +import { Resource } from 'global.resource'; + +export class ArkResourcesHelper { + static COLOR: number = 10001; + static FLOAT: number = 10002; + + static $r(name: string, id?: number): Resource { + let splitted = name.split('.', 2); + let strType = splitted[1]; + let type: number = ArkResourcesHelper.COLOR; + if (strType === 'float') { + type = ArkResourcesHelper.FLOAT; + } + return { 'id': id ?? -1, 'type': type, 'params': [name], 'bundleName': '', 'moduleName': '' } as Resource; + } +} \ No newline at end of file diff --git a/frameworks/bridge/arkts_frontend/koala_projects/arkoala-arkts/arkui-ohos/src/handwritten/theme/ArkShapesImpl.ts b/frameworks/bridge/arkts_frontend/koala_projects/arkoala-arkts/arkui-ohos/src/handwritten/theme/ArkShapesImpl.ts new file mode 100644 index 00000000000..033a4fbbed2 --- /dev/null +++ b/frameworks/bridge/arkts_frontend/koala_projects/arkoala-arkts/arkui-ohos/src/handwritten/theme/ArkShapesImpl.ts @@ -0,0 +1,279 @@ +/* + * Copyright (c) 2024 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +import { + CornerRadius, CustomCornerRadius, Paddings, CustomPaddings, Outlines, Dimension, + CustomOutlines, Borders, CustomBorders, Shapes, CustomShapes +} from './index'; +import { Length } from 'arkui/component/units'; +import { ArkResourcesHelper } from './ArkResourcesHelper'; +import { + ArkSystemCornerRadius, + ArkSystemPaddings, + ArkSystemBorders, + ArkSystemOutlines, +} from './system/ArkSystemShapes'; + +export class ArkCornerRadiusImpl implements CornerRadius { + none: Length = 0; + level1: Length = 0; + level2: Length = 0; + level3: Length = 0; + level4: Length = 0; + level5: Length = 0; + level6: Length = 0; + level7: Length = 0; + level8: Length = 0; + level9: Length = 0; + level10: Length = 0; + level11: Length = 0; + level12: Length = 0; + level16: Length = 0; + + constructor(corners: CustomCornerRadius | undefined, baselineCorners: CornerRadius | undefined) { + if (baselineCorners) { + ArkCornerRadiusImpl.assign(this, baselineCorners!); + } + if (corners) { + ArkCornerRadiusImpl.assign(this, corners!); + } + } + + static assign(dst: CornerRadius, src: CornerRadius): void { + if (src.none !== undefined) dst.none = src.none!; + if (src.level1 !== undefined) dst.level1 = src.level1; + if (src.level2 !== undefined) dst.level2 = src.level2; + if (src.level3 !== undefined) dst.level3 = src.level3; + if (src.level4 !== undefined) dst.level4 = src.level4; + if (src.level5 !== undefined) dst.level5 = src.level5; + if (src.level6 !== undefined) dst.level6 = src.level6; + if (src.level7 !== undefined) dst.level7 = src.level7; + if (src.level8 !== undefined) dst.level8 = src.level8; + if (src.level9 !== undefined) dst.level9 = src.level9; + if (src.level10 !== undefined) dst.level10 = src.level10; + if (src.level11 !== undefined) dst.level11 = src.level11; + if (src.level12 !== undefined) dst.level12 = src.level12; + if (src.level16 !== undefined) dst.level16 = src.level16; + } + + static assign(dst: CornerRadius, src: CustomCornerRadius): void { + if (src.none !== undefined) dst.none = src.none!; + if (src.level1 !== undefined) dst.level1 = src.level1!; + if (src.level2 !== undefined) dst.level2 = src.level2!; + if (src.level3 !== undefined) dst.level3 = src.level3!; + if (src.level4 !== undefined) dst.level4 = src.level4!; + if (src.level5 !== undefined) dst.level5 = src.level5!; + if (src.level6 !== undefined) dst.level6 = src.level6!; + if (src.level7 !== undefined) dst.level7 = src.level7!; + if (src.level8 !== undefined) dst.level8 = src.level8!; + if (src.level9 !== undefined) dst.level9 = src.level9!; + if (src.level10 !== undefined) dst.level10 = src.level10!; + if (src.level11 !== undefined) dst.level11 = src.level11!; + if (src.level12 !== undefined) dst.level12 = src.level12!; + if (src.level16 !== undefined) dst.level16 = src.level16!; + } +} + +export class ArkPaddingsImpl implements Paddings { + level0: Length = 0; + level1: Length = 0; + level2: Length = 0; + level3: Length = 0; + level4: Length = 0; + level5: Length = 0; + level6: Length = 0; + level7: Length = 0; + level8: Length = 0; + level9: Length = 0; + level10: Length = 0; + level11: Length = 0; + level12: Length = 0; + level16: Length = 0; + level24: Length = 0; + level32: Length = 0; + level36: Length = 0; + + constructor( + paddings: CustomPaddings | undefined, + baselinePaddings: Paddings + ) { + ArkPaddingsImpl.assign(this, baselinePaddings); + if (paddings) { + ArkPaddingsImpl.assign(this, paddings!); + } + } + + static assign(dst: Paddings, src: Paddings): void { + if (src.level0 !== undefined) dst.level0 = src.level0; + if (src.level1 !== undefined) dst.level1 = src.level1; + if (src.level2 !== undefined) dst.level2 = src.level2; + if (src.level3 !== undefined) dst.level3 = src.level3; + if (src.level4 !== undefined) dst.level4 = src.level4; + if (src.level5 !== undefined) dst.level5 = src.level5; + if (src.level6 !== undefined) dst.level6 = src.level6; + if (src.level7 !== undefined) dst.level7 = src.level7; + if (src.level8 !== undefined) dst.level8 = src.level8; + if (src.level9 !== undefined) dst.level9 = src.level9; + if (src.level10 !== undefined) dst.level10 = src.level10; + if (src.level11 !== undefined) dst.level11 = src.level11; + if (src.level12 !== undefined) dst.level12 = src.level12; + if (src.level16 !== undefined) dst.level16 = src.level16; + if (src.level24 !== undefined) dst.level24 = src.level24; + if (src.level32 !== undefined) dst.level32 = src.level32; + if (src.level36 !== undefined) dst.level36 = src.level36; + } + + static assign(dst: Paddings, src: CustomPaddings): void { + if (src.level0 !== undefined) dst.level0 = src.level0!; + if (src.level1 !== undefined) dst.level1 = src.level1!; + if (src.level2 !== undefined) dst.level2 = src.level2!; + if (src.level3 !== undefined) dst.level3 = src.level3!; + if (src.level4 !== undefined) dst.level4 = src.level4!; + if (src.level5 !== undefined) dst.level5 = src.level5!; + if (src.level6 !== undefined) dst.level6 = src.level6!; + if (src.level7 !== undefined) dst.level7 = src.level7!; + if (src.level8 !== undefined) dst.level8 = src.level8!; + if (src.level9 !== undefined) dst.level9 = src.level9!; + if (src.level10 !== undefined) dst.level10 = src.level10!; + if (src.level11 !== undefined) dst.level11 = src.level11!; + if (src.level12 !== undefined) dst.level12 = src.level12!; + if (src.level16 !== undefined) dst.level16 = src.level16!; + if (src.level24 !== undefined) dst.level24 = src.level24!; + if (src.level32 !== undefined) dst.level32 = src.level32!; + if (src.level36 !== undefined) dst.level36 = src.level36!; + } +} + +export class ArkOutlinesImpl implements Outlines { + none: Dimension = ArkResourcesHelper.$r('sys.float.outline_none'); + xs: Dimension = ArkResourcesHelper.$r('sys.float.outline_extra_small'); + s: Dimension = ArkResourcesHelper.$r('sys.float.outline_small'); + m: Dimension = ArkResourcesHelper.$r('sys.float.outline_medium'); + l: Dimension = ArkResourcesHelper.$r('sys.float.outline_larger'); + xl: Dimension = ArkResourcesHelper.$r('sys.float.outline_extra_larger'); + + constructor(outlines: CustomOutlines | undefined, baselineOutlines: Outlines) { + ArkOutlinesImpl.assign(this, baselineOutlines); + if (outlines) { + ArkOutlinesImpl.assign(this, outlines!); + } + } + + static assign(dst: Outlines, src: Outlines): void { + if (src.none !== undefined) dst.none = src.none; + if (src.xs !== undefined) dst.xs = src.xs; + if (src.s !== undefined) dst.s = src.s; + if (src.m !== undefined) dst.m = src.m; + if (src.l !== undefined) dst.l = src.l; + if (src.xl !== undefined) dst.xl = src.xl; + } + + static assign(dst: Outlines, src: CustomOutlines): void { + if (src.none !== undefined) dst.none = src.none!; + if (src.xs !== undefined) dst.xs = src.xs!; + if (src.s !== undefined) dst.s = src.s!; + if (src.m !== undefined) dst.m = src.m!; + if (src.l !== undefined) dst.l = src.l!; + if (src.xl !== undefined) dst.xl = src.xl!; + } +} + +export class ArkBordersImpl implements Borders { + none: Length = 0; + xs: Length = 0; + s: Length = 0; + m: Length = 0; + l: Length = 0; + xl: Length = 0; + + constructor(borders: CustomBorders | undefined, baselineBorders: Borders) { + ArkBordersImpl.assign(this, baselineBorders); + if (borders) { + ArkBordersImpl.assign(this, borders!); + } + } + + static assign(dst: Borders, src: Borders): void { + if (src.none !== undefined) dst.none = src.none; + if (src.xs !== undefined) dst.xs = src.xs; + if (src.s !== undefined) dst.s = src.s; + if (src.m !== undefined) dst.m = src.m; + if (src.l !== undefined) dst.l = src.l; + if (src.xl !== undefined) dst.xl = src.xl; + } + + static assign(dst: Borders, src: CustomBorders): void { + if (src.none !== undefined) dst.none = src.none!; + if (src.xs !== undefined) dst.xs = src.xs!; + if (src.s !== undefined) dst.s = src.s!; + if (src.m !== undefined) dst.m = src.m!; + if (src.l !== undefined) dst.l = src.l!; + if (src.xl !== undefined) dst.xl = src.xl!; + } +} + +export class ArkShapesImpl implements Shapes { + cornerRadius: CornerRadius = new ArkSystemCornerRadius(); + paddings: Paddings = new ArkSystemPaddings(); + borders: Borders = new ArkSystemBorders(); + outlines: Outlines = new ArkSystemOutlines(); + + constructor( + shapes: CustomShapes | undefined, + baselineShapes: Shapes + ) { + if (!shapes) { + this.cornerRadius = new ArkCornerRadiusImpl(undefined, baselineShapes.cornerRadius); + this.paddings = new ArkPaddingsImpl(undefined, baselineShapes.paddings); + this.borders = new ArkBordersImpl(undefined, baselineShapes.borders); + this.outlines = new ArkOutlinesImpl(undefined, baselineShapes.outlines); + return; + } + this.cornerRadius = new ArkCornerRadiusImpl(shapes!.cornerRadius, baselineShapes.cornerRadius); + this.paddings = new ArkPaddingsImpl(shapes!.paddings, baselineShapes.paddings); + this.borders = new ArkBordersImpl(shapes!.borders, baselineShapes.borders); + this.outlines = new ArkOutlinesImpl(shapes!.outlines, baselineShapes.outlines); + } + + static assign(dst: Shapes, src: Shapes): void { + if (src.cornerRadius !== undefined) { + ArkCornerRadiusImpl.assign(dst.cornerRadius, src.cornerRadius); + } + if (src.paddings !== undefined) { + ArkPaddingsImpl.assign(dst.paddings, src.paddings); + } + if (src.borders !== undefined) { + ArkBordersImpl.assign(dst.borders, src.borders); + } + if (src.outlines !== undefined) { + ArkOutlinesImpl.assign(dst.outlines, src.outlines); + } + } + + static assign(dst: Shapes, src: CustomShapes): void { + if (src.cornerRadius !== undefined) { + ArkCornerRadiusImpl.assign(dst.cornerRadius, src.cornerRadius!); + } + if (src.paddings !== undefined) { + ArkPaddingsImpl.assign(dst.paddings, src.paddings!); + } + if (src.borders !== undefined) { + ArkBordersImpl.assign(dst.borders, src.borders!); + } + if (src.outlines !== undefined) { + ArkOutlinesImpl.assign(dst.outlines, src.outlines!); + } + } +} \ No newline at end of file diff --git a/frameworks/bridge/arkts_frontend/koala_projects/arkoala-arkts/arkui-ohos/src/handwritten/theme/ArkThemeBase.ts b/frameworks/bridge/arkts_frontend/koala_projects/arkoala-arkts/arkui-ohos/src/handwritten/theme/ArkThemeBase.ts new file mode 100644 index 00000000000..3013b949be3 --- /dev/null +++ b/frameworks/bridge/arkts_frontend/koala_projects/arkoala-arkts/arkui-ohos/src/handwritten/theme/ArkThemeBase.ts @@ -0,0 +1,206 @@ +/* + * Copyright (c) 2024 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +import { CustomTheme, Theme, Colors } from '@ohos/arkui/theme'; +import { ArkThemeCache } from './ArkThemeCache'; +import { Shapes, Typography } from './index'; +import { ThemeColorMode } from 'arkui/component/common'; +import { ArkShapesImpl } from './ArkShapesImpl'; +import { ArkTypographyImpl } from './ArkTypographyImpl'; + +/** + * Theme counter used to generate next theme id + */ +let themeCounter = 0; + +/** + * Base ArkTheme class + */ +export class ArkThemeBase extends Theme { + // Theme tokens + colors: Colors; + shapes: Shapes; + typography: Typography; + + /** + * Unique theme instance id + */ + id: number; + + /** + * Copy of CustomTheme used to create this theme instance + */ + private customTheme: CustomTheme | undefined; + + /** + * Color Mode used to create this theme instance + */ + private colorMode: ThemeColorMode; + + /** + * Binded theme scopes counter + */ + private scopesCounter: number = 0; + + /** + * Array of ids of binded theme scopes + */ + private bindedThemeScopesIds: number[] = []; + + /** + * Flag used to identify whether theme was just created or not + */ + private isJustCreated = true; + + /** + * Id of theme instance which was used as baseline theme for this theme instance + */ + private parentThemeId: number = -1; + + /** + * ArkThemeBase class constructor + * + * @param parentId id of theme instance which is used as baseline theme + * @param customTheme instance of CustomTheme used to create current theme + * @param colorMode local colorm mode used for current theme + * @param colors colors tokens + * @param shapes shapes tokens + * @param typography typography tokens + */ + constructor( + parentId: number, + customTheme: CustomTheme | undefined, + colorMode: ThemeColorMode, + colors: Colors, + shapes: Shapes, + typography: Typography + ) { + super(); + this.id = themeCounter++; + this.parentThemeId = parentId; + + this.customTheme = ArkThemeBase.copyCustomTheme(customTheme); + this.colorMode = colorMode; + + this.colors = colors; + this.shapes = shapes; + this.typography = typography; + } + + /** + * Binds current theme instance to theme scope + * + * @param themeScopeId binded theme scope id + */ + bindToScope(themeScopeId: number) { + if (this.bindedThemeScopesIds.includes(themeScopeId)) { + // do nothing if theme scope already binded + return; + } + // increment theme scopes counter + this.scopesCounter++; + // keep theme scope id + this.bindedThemeScopesIds.push(themeScopeId); + if (this.isJustCreated) { + // if theme instance is just created keep it to the cache + ArkThemeCache.getInstance().add(this); + // mark theme instance as not just created + this.isJustCreated = false; + } + } + + /** + * Unbinds current theme instance from theme scope + * + * @param themeScopeId binded theme scope id + */ + unbindFromScope(themeScopeId: number) { + const index = this.bindedThemeScopesIds.indexOf(themeScopeId); + if (index === -1) { + // do nothing if theme scope is not exist in binded scopes list + return; + } + // decrement theme scopes counter + this.scopesCounter--; + // remove theme scope id from the lisy of binded theme scopes + this.bindedThemeScopesIds.splice(index, 1); + if (this.canBeDestroyed()) { + // remove theme from cache if none theme scope binded to the current theme instance + ArkThemeCache.getInstance().remove(this); + } + } + + /** + * Checks whether we can destroy existing theme instance or not + * + * @returns true if theme instance can be destroyed; false otherwise + */ + canBeDestroyed(): boolean { + // checks whether theme is no just created and binded theme scopes counter is 0 + return !this.isJustCreated && this.scopesCounter === 0; + } + + /** + * Return id of theme instance which was used as baseline theme for current theme instance + * + * @returns parent theme id + */ + getParentThemeId(): number { + return this.parentThemeId; + } + + /** + * Returns copy of CustomTheme used to create current theme instance + * + * @returns CustomTheme instance + */ + getCustomTheme(): CustomTheme | undefined { + return this.customTheme; + } + + /** + * Returns color mode used by this theme instance + * + * @returns local color mode value + */ + getColorMode(): ThemeColorMode { + return this.colorMode; + } + + /** + * Makes a local copy of CustomTheme instance + * + * @param customTheme instance of CustomTheme used to create current theme + * @returns copy of custom theme instance + */ + static copyCustomTheme(customTheme: CustomTheme | undefined): CustomTheme | undefined { + if (!customTheme) { + // return undefined if original custom theme is undefined + return undefined; + } + const copyTheme: CustomTheme = new CustomTheme(); + if (customTheme.colors) { + copyTheme.colors = new Colors(); + Colors.assign(copyTheme.colors!, customTheme.colors!); + } + if (customTheme.shapes) { + copyTheme.shapes = customTheme.shapes; + } + if (customTheme.typography) { + copyTheme.typography = customTheme.typography!; + } + return copyTheme; + } +} diff --git a/frameworks/bridge/arkts_frontend/koala_projects/arkoala-arkts/arkui-ohos/src/handwritten/theme/ArkThemeCache.ts b/frameworks/bridge/arkts_frontend/koala_projects/arkoala-arkts/arkui-ohos/src/handwritten/theme/ArkThemeCache.ts new file mode 100644 index 00000000000..1d93686f9cf --- /dev/null +++ b/frameworks/bridge/arkts_frontend/koala_projects/arkoala-arkts/arkui-ohos/src/handwritten/theme/ArkThemeCache.ts @@ -0,0 +1,167 @@ +/* + * Copyright (c) 2024 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +import { ArkThemeBase } from './ArkThemeBase'; +import { CustomTheme } from '@ohos/arkui/theme'; +import { ThemeColorMode } from 'arkui/component/common'; +import { makeRecordfromObj } from './index'; + +/** + * Singleton class used to keep existing theme instances which are used by theme scopes right now + */ +export class ArkThemeCache { + // single instance + private static instance: ArkThemeCache | undefined = undefined; + + // array of theme instances + private cache: ArkThemeBase[] = []; + + private constructor() { } + + static getInstance() { + if (!ArkThemeCache.instance) { + ArkThemeCache.instance = new ArkThemeCache(); + } + return ArkThemeCache.instance!; + } + + /** + * Adds theme instance to the cache + * + * @param theme instance of theme + */ + add(theme: ArkThemeBase) { + if (this.contains(theme)) { + // do nothing if theme already contains in cache + return; + } + this.cache.push(theme); + } + + /** + * Removes theme instance from the cache + * + * @param theme instance of theme + */ + remove(theme: ArkThemeBase) { + const index = this.cache.indexOf(theme); + if (index === -1) { + // do nothing if cache doesn`t contain this theme instance + return; + } + // remove theme from TS side cache + this.cache.splice(index, 1); + // remove theme from native side cache + // TODO: Use ANI IMPL + // getUINativeModule().theme.removeFromCache(theme.id); + } + + /** + * Returns existing theme istance by CustomTheme and color mode + * + * @param baselineThemeId baseline theme id + * @param customTheme instance of CustomTheme used for theme + * @param colorMode local colorm mode used for theme + * @returns instance of theme if exists or undefined + */ + get(baselineThemeId: number, customTheme: CustomTheme | undefined, colorMode: ThemeColorMode): ArkThemeBase | undefined { + // check all cache items one by one + // return undefined if cache doesn`t contains theme instance with the same color mode and custom theme attributes + return this.cache.find((item) => { + return item.getParentThemeId() === baselineThemeId && + item.getColorMode() === colorMode && + this.isEqualsCustomThemes(item.getCustomTheme(), customTheme); + }); + } + + /** + * Checks whether cache contains theme instance or not + * + * @param theme instance of theme + * @returns true if theme instance contains in cache; false otherwise + */ + contains(theme: ArkThemeBase): boolean { + return this.containsByAttributes(theme.getParentThemeId(), theme.getCustomTheme(), theme.getColorMode()); + } + + /** + * Checks whether cache contains theme instance with the same color mode and custom theme attributes or not + * + * @param baselineThemeId baseline theme id + * @param customTheme instance of CustomTheme used for theme + * @param colorMode local colorm mode used for theme + * @returns true if theme instance contains in cache; false otherwise + */ + containsByAttributes(baselineThemeId: number, customTheme: CustomTheme | undefined, colorMode: ThemeColorMode): boolean { + return this.get(baselineThemeId, customTheme, colorMode) !== undefined; + } + + /** + * Checks equality of two custom themes + * + * @param theme1 first custom theme instance + * @param theme2 second custom theme instance + * @returns true if cutom themes are equals; false otherwise + */ + private isEqualsCustomThemes(theme1: CustomTheme | undefined, theme2: CustomTheme | undefined): boolean { + if (theme1 === theme2) { + // return true if references are the same + return true; + } + if (!theme1 || !theme2) { + // return false if one of instances is undefined + return false; + } + if (theme1.colors === theme2.colors) { + // return true if colors tokens references are the same + return true; + } + if (!theme1.colors || !theme2.colors) { + // return false if one of colors instances is undefined + return false; + } + + // take array of keys of color tokens used by both custom themes + let keys1 = Object.keys(theme1.colors!); + let keys2 = Object.keys(theme2.colors!); + + if (keys1.length !== keys2.length) { + // return false if the length of the keys arrays are different + return false; + } + + const theme1Colors = makeRecordfromObj(theme1!.colors!); + const theme2Colors = makeRecordfromObj(theme2!.colors!); + // go by color tokens attributes keys one by one + keys1.forEach((key: string) => { + if (!keys2.includes(key)) { + // return false if key of first custom theme colors dosn`t used by second custom theme colors + return; + } + + // take values of colors tokens by current attribute key + let value1 = theme1Colors[key]; + let value2 = theme2Colors[key]; + + if (value1 !== value2) { + // return false if color tokens values are different + return; + } + }); + + // return true because we achieved the end of the method that means that two instance of Custom Theme are the same + return true; + } +} \ No newline at end of file diff --git a/frameworks/bridge/arkts_frontend/koala_projects/arkoala-arkts/arkui-ohos/src/handwritten/theme/ArkThemeImpl.ts b/frameworks/bridge/arkts_frontend/koala_projects/arkoala-arkts/arkui-ohos/src/handwritten/theme/ArkThemeImpl.ts new file mode 100644 index 00000000000..d1a4e23b6ae --- /dev/null +++ b/frameworks/bridge/arkts_frontend/koala_projects/arkoala-arkts/arkui-ohos/src/handwritten/theme/ArkThemeImpl.ts @@ -0,0 +1,40 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +import { ArkThemeBase } from './ArkThemeBase'; +import { CustomTheme, Colors } from '@ohos/arkui/theme'; +import { ThemeColorMode } from 'arkui/component/common'; +import { ArkShapesImpl } from './ArkShapesImpl'; +import { ArkTypographyImpl } from './ArkTypographyImpl'; + +export class ArkThemeImpl extends ArkThemeBase { + constructor( + customTheme: CustomTheme, + colorMode: ThemeColorMode, + baselineTheme: ArkThemeBase, + ) { + // if (!customTheme) { + // super(baselineTheme.id, undefined, colorMode, + // new Colors(undefined, baselineTheme.colors), + // new ArkShapesImpl(undefined, baselineTheme.shapes), + // new ArkTypographyImpl(undefined, baselineTheme.typography)); + // return; + // } + super(baselineTheme.id, customTheme, colorMode, + new Colors(customTheme.colors, baselineTheme.colors), + new ArkShapesImpl(customTheme.shapes, baselineTheme.shapes), + new ArkTypographyImpl(customTheme.typography, baselineTheme.typography)); + } +} diff --git a/frameworks/bridge/arkts_frontend/koala_projects/arkoala-arkts/arkui-ohos/src/handwritten/theme/ArkThemeNativeHelper.ts b/frameworks/bridge/arkts_frontend/koala_projects/arkoala-arkts/arkui-ohos/src/handwritten/theme/ArkThemeNativeHelper.ts new file mode 100644 index 00000000000..eef754f899c --- /dev/null +++ b/frameworks/bridge/arkts_frontend/koala_projects/arkoala-arkts/arkui-ohos/src/handwritten/theme/ArkThemeNativeHelper.ts @@ -0,0 +1,108 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +import { Theme, CustomTheme } from '@ohos/arkui/theme'; +import { ResourceColor, Color } from 'arkui/component'; +import { ThemeColorMode } from 'arkui/component/common'; +import { ArkUIAniModule } from 'arkui.ani'; +import { CustomColors } from '@ohos/arkui/theme'; +import { ArkThemeScopeManager } from './ArkThemeScopeManager'; +import { int32 } from "@koalaui/common" +import { Colors } from '@ohos/arkui/theme'; + +export class ArkThemeNativeHelper { + static sendThemeToNative(theme: Theme, elmtId: int32): void { + ArkUIAniModule._SendThemeToNative(ArkThemeNativeHelper.convertThemeToColorArray(theme), elmtId); + } + static setDefaultTheme(theme: CustomTheme): void { + const colorArray = ArkThemeNativeHelper.convertColorsToArray(theme?.colors); + ArkThemeScopeManager.getInstance().onEnterLocalColorMode(ThemeColorMode.LIGHT); + ArkUIAniModule._SetDefaultTheme(colorArray, false); + ArkThemeScopeManager.getInstance().onEnterLocalColorMode(ThemeColorMode.DARK); + ArkUIAniModule._SetDefaultTheme(colorArray, true); + ArkThemeScopeManager.getInstance().onExitLocalColorMode(); + } + private static convertThemeToColorArray(theme: Theme): ResourceColor[] { + return [ + theme.colors.brand, + theme.colors.warning, + theme.colors.alert, + theme.colors.confirm, + theme.colors.fontPrimary, + theme.colors.fontSecondary, + theme.colors.fontTertiary, + theme.colors.fontFourth, + theme.colors.fontEmphasize, + theme.colors.fontOnPrimary, + theme.colors.fontOnSecondary, + theme.colors.fontOnTertiary, + theme.colors.fontOnFourth, + theme.colors.iconPrimary, + theme.colors.iconSecondary, + theme.colors.iconTertiary, + theme.colors.iconFourth, + theme.colors.iconEmphasize, + theme.colors.iconSubEmphasize, + theme.colors.iconOnPrimary, + theme.colors.iconOnSecondary, + theme.colors.iconOnTertiary, + theme.colors.iconOnFourth, + theme.colors.backgroundPrimary, + theme.colors.backgroundSecondary, + theme.colors.backgroundTertiary, + theme.colors.backgroundFourth, + theme.colors.backgroundEmphasize, + theme.colors.compForegroundPrimary, + theme.colors.compBackgroundPrimary, + theme.colors.compBackgroundPrimaryTran, + theme.colors.compBackgroundPrimaryContrary, + theme.colors.compBackgroundGray, + theme.colors.compBackgroundSecondary, + theme.colors.compBackgroundTertiary, + theme.colors.compBackgroundEmphasize, + theme.colors.compBackgroundNeutral, + theme.colors.compEmphasizeSecondary, + theme.colors.compEmphasizeTertiary, + theme.colors.compDivider, + theme.colors.compCommonContrary, + theme.colors.compBackgroundFocus, + theme.colors.compFocusedPrimary, + theme.colors.compFocusedSecondary, + theme.colors.compFocusedTertiary, + theme.colors.interactiveHover, + theme.colors.interactivePressed, + theme.colors.interactiveFocus, + theme.colors.interactiveActive, + theme.colors.interactiveSelect, + theme.colors.interactiveClick, + ]; + } + private static convertColorsToArray(colors: CustomColors | undefined): ResourceColor[] { + const basisColors = ArkThemeScopeManager.getSystemColors(); + if (!colors) { + return new Array(Object.keys(basisColors).length); + } + const colorArray: ResourceColor[] = []; + for (let attr of Object.values(colors)) { + const value: ResourceColor = attr as ResourceColor; + if (Colors.checkIsColor(value)) { + colorArray.push(Colors.convertColorEnumToValue(value as Color)); + continue; + } + colorArray.push(value); + } + return colorArray; + } +} diff --git a/frameworks/bridge/arkts_frontend/koala_projects/arkoala-arkts/arkui-ohos/src/handwritten/theme/ArkThemeScopeManager.ts b/frameworks/bridge/arkts_frontend/koala_projects/arkoala-arkts/arkui-ohos/src/handwritten/theme/ArkThemeScopeManager.ts new file mode 100644 index 00000000000..a23f57f5101 --- /dev/null +++ b/frameworks/bridge/arkts_frontend/koala_projects/arkoala-arkts/arkui-ohos/src/handwritten/theme/ArkThemeScopeManager.ts @@ -0,0 +1,127 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +import { CustomTheme, Theme, Colors } from '@ohos/arkui/theme'; +import { ThemeColorMode } from 'arkui/component/common'; +import { InteropNativeModule } from '@koalaui/interop'; +import { ArkThemeBase } from './ArkThemeBase'; +import { ArkSystemTheme } from './system/ArkSystemTheme'; +import { ArkThemeCache } from './ArkThemeCache'; +import { ArkThemeImpl } from './ArkThemeImpl'; +import { ArkThemeNativeHelper } from './ArkThemeNativeHelper'; + +type ViewPuInternal = Object; + +export class ArkThemeScopeManager { + private static instance: ArkThemeScopeManager | undefined = undefined; + private static systemTheme = new ArkSystemTheme(); + /** + * Theme update listeners + */ + private listeners: ViewPuInternal[] = []; + /** + * The default Theme + */ + private defaultTheme: ArkThemeBase | undefined = undefined; + + /** + * Obtain System Colors + * + * @returns System Colors + */ + static getSystemColors(): Colors { + return ArkThemeScopeManager.systemTheme.colors; + } + + /** + * Enter to the local color mode scope + * + * @param colorMode local color mode + */ + onEnterLocalColorMode(colorMode: ThemeColorMode) { + // getUINativeModule().resource.updateColorMode(colorMode); + } + + /** + * Exit from the local color mode scope + */ + onExitLocalColorMode() { + // getUINativeModule().resource.restore(); + } + + /** + * Create CustomTheme instance based on given Custom theme with the additional expands + * + * @param customTheme instance of CustomTheme used to create theme + * @returns theme instance + */ + static cloneCustomThemeWithExpand(customTheme: CustomTheme): CustomTheme { + const theme = ArkThemeBase.copyCustomTheme(customTheme); + if (theme?.colors) { + Colors.expandByBrandColor(theme!.colors!); + } + return theme!; + } + + /** + * Create Theme instance + * + * @param customTheme instance of CustomTheme used to create theme + * @param colorMode local colorm mode used for theme + * @returns theme instance + */ + makeTheme(customTheme: CustomTheme, colorMode: ThemeColorMode): ArkThemeBase { + const baselineTheme = this.defaultTheme ?? ArkThemeScopeManager.systemTheme; + // try to take theme from the cache + const theme = ArkThemeCache.getInstance().get(baselineTheme.id, customTheme, colorMode); + + // return theme instance from cache or create new theme instance + return theme ? theme : new ArkThemeImpl(customTheme, colorMode, baselineTheme); + } + + /** + * Notifies listeners about app Theme change + */ + private notifyGlobalThemeChanged() { + this.listeners.forEach((listener) => { + // if (listener.parent_ === undefined) { + // listener.onGlobalThemeChanged(); + // } + }); + } + + setDefaultTheme(customTheme: CustomTheme) { + // unbind previous default theme from 0 theme scope + this.defaultTheme?.unbindFromScope(0); + this.defaultTheme = ArkThemeScopeManager.systemTheme; + const cloneTheme = ArkThemeScopeManager.cloneCustomThemeWithExpand(customTheme); + this.defaultTheme = this.makeTheme(customTheme, ThemeColorMode.SYSTEM); + // bind new default theme to 0 theme scope + this.defaultTheme?.bindToScope(0); + + // keep for backward compatibility + ArkThemeNativeHelper.sendThemeToNative(this.defaultTheme!, 0); // 0 means default Theme scope id + // new approach to apply theme in native side + ArkThemeNativeHelper.setDefaultTheme(cloneTheme); + + this.notifyGlobalThemeChanged(); + } + static getInstance(): ArkThemeScopeManager { + if (!ArkThemeScopeManager.instance) { + ArkThemeScopeManager.instance = new ArkThemeScopeManager(); + } + return ArkThemeScopeManager.instance!; + } +} diff --git a/frameworks/bridge/arkts_frontend/koala_projects/arkoala-arkts/arkui-ohos/src/handwritten/theme/ArkTypographyImpl.ts b/frameworks/bridge/arkts_frontend/koala_projects/arkoala-arkts/arkui-ohos/src/handwritten/theme/ArkTypographyImpl.ts new file mode 100644 index 00000000000..abe89975dfa --- /dev/null +++ b/frameworks/bridge/arkts_frontend/koala_projects/arkoala-arkts/arkui-ohos/src/handwritten/theme/ArkTypographyImpl.ts @@ -0,0 +1,197 @@ +/* + * Copyright (c) 2024 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +import { Typography, TypographyStyle, CustomTypography } from 'arkui/handwritten/theme'; +import { ArkTypographyWeights } from './system/ArkSystemTypography'; + +export class ArkTypographyImpl implements Typography { + // Display + displayLarge: TypographyStyle; + displayMiddle: TypographyStyle; + displaySmall: TypographyStyle; + + // Title + titleLarge: TypographyStyle; + titleMiddle: TypographyStyle; + titleSmall: TypographyStyle; + + // Subtitle + subtitleLarge: TypographyStyle; + subtitleMiddle: TypographyStyle; + subtitleSmall: TypographyStyle; + + // Body + bodyLarge: TypographyStyle; + bodyMiddle: TypographyStyle; + bodySmall: TypographyStyle; + + // Caption + captionLarge: TypographyStyle; + captionMiddle: TypographyStyle; + captionSmall: TypographyStyle; + + constructor( + typography: CustomTypography | undefined, + baselineTypography: Typography) { + // Display + this.displayLarge = { + weight: typography?.displayLarge?.weight ?? ArkTypographyWeights.light, + size: typography?.displayLarge?.size ?? baselineTypography.displayLarge.size + }; + this.displayMiddle = { + weight: typography?.displayMiddle?.weight ?? ArkTypographyWeights.light, + size: typography?.displayMiddle?.size ?? baselineTypography.displayMiddle.size + }; + this.displaySmall = { + weight: typography?.displaySmall?.weight ?? ArkTypographyWeights.light, + size: typography?.displaySmall?.size ?? baselineTypography.displaySmall.size + }; + + // Title + this.titleLarge = { + weight: typography?.titleLarge?.weight ?? ArkTypographyWeights.bold, + size: typography?.titleLarge?.size ?? baselineTypography.titleLarge.size + }; + this.titleMiddle = { + weight: typography?.titleMiddle?.weight ?? ArkTypographyWeights.bold, + size: typography?.titleMiddle?.size ?? baselineTypography.titleMiddle.size + }; + this.titleSmall = { + weight: typography?.titleSmall?.weight ?? ArkTypographyWeights.bold, + size: typography?.titleSmall?.size ?? baselineTypography.titleSmall.size + }; + + // Subtitle + this.subtitleLarge = { + weight: typography?.subtitleLarge?.weight ?? ArkTypographyWeights.medium, + size: typography?.subtitleLarge?.size ?? baselineTypography.subtitleLarge.size + }; + this.subtitleMiddle = { + weight: typography?.subtitleMiddle?.weight ?? ArkTypographyWeights.medium, + size: typography?.subtitleMiddle?.size ?? baselineTypography.subtitleMiddle.size + }; + this.subtitleSmall = { + weight: typography?.subtitleSmall?.weight ?? ArkTypographyWeights.medium, + size: typography?.subtitleSmall?.size ?? baselineTypography.subtitleSmall.size + }; + + // Body + this.bodyLarge = { + weight: typography?.bodyLarge?.weight ?? ArkTypographyWeights.medium, + size: typography?.bodyLarge?.size ?? baselineTypography.bodyLarge.size + }; + this.bodyMiddle = { + weight: typography?.bodyMiddle?.weight ?? ArkTypographyWeights.regular, + size: typography?.bodyMiddle?.size ?? baselineTypography.bodyMiddle.size + }; + this.bodySmall = { + weight: typography?.bodySmall?.weight ?? ArkTypographyWeights.regular, + size: typography?.bodySmall?.size ?? baselineTypography.bodySmall.size + }; + + // Caption + this.captionLarge = { + weight: typography?.captionLarge?.weight ?? ArkTypographyWeights.medium, + size: typography?.captionLarge?.size ?? baselineTypography.captionLarge.size + }; + this.captionMiddle = { + weight: typography?.captionMiddle?.weight ?? ArkTypographyWeights.medium, + size: typography?.captionMiddle?.size ?? baselineTypography.captionMiddle.size + }; + this.captionSmall = { + weight: typography?.captionSmall?.weight ?? ArkTypographyWeights.medium, + size: typography?.captionSmall?.size ?? baselineTypography.captionSmall.size + }; + } + + static assign(dst: Typography, src: Typography): void { + // Display + if (src.displayLarge !== undefined) dst.displayLarge = src.displayLarge; + if (src.displayMiddle !== undefined) dst.displayMiddle = src.displayMiddle; + if (src.displaySmall !== undefined) dst.displaySmall = src.displaySmall; + + // Title + if (src.titleLarge !== undefined) dst.titleLarge = src.titleLarge; + if (src.titleMiddle !== undefined) dst.titleMiddle = src.titleMiddle; + if (src.titleSmall !== undefined) dst.titleSmall = src.titleSmall; + + // Subtitle + if (src.subtitleLarge !== undefined) dst.subtitleLarge = src.subtitleLarge; + if (src.subtitleMiddle !== undefined) dst.subtitleMiddle = src.subtitleMiddle; + if (src.subtitleSmall !== undefined) dst.subtitleSmall = src.subtitleSmall; + + // Body + if (src.bodyLarge !== undefined) dst.bodyLarge = src.bodyLarge; + if (src.bodyMiddle !== undefined) dst.bodyMiddle = src.bodyMiddle; + if (src.bodySmall !== undefined) dst.bodySmall = src.bodySmall; + + // Caption + if (src.captionLarge !== undefined) dst.captionLarge = src.captionLarge; + if (src.captionMiddle !== undefined) dst.captionMiddle = src.captionMiddle; + if (src.captionSmall !== undefined) dst.captionSmall = src.captionSmall; + } + + static assign(dst: Typography, src: CustomTypography): void { + // Display + if (src.displayLarge?.weight !== undefined) dst.displayLarge.weight = src.displayLarge!.weight!; + if (src.displayLarge?.size !== undefined) dst.displayLarge.size = src.displayLarge!.size!; + + if (src.displayMiddle?.weight !== undefined) dst.displayMiddle.weight = src.displayMiddle!.weight!; + if (src.displayMiddle?.size !== undefined) dst.displayMiddle.size = src.displayMiddle!.size!; + + if (src.displaySmall?.weight !== undefined) dst.displaySmall.weight = src.displaySmall!.weight!; + if (src.displaySmall?.size !== undefined) dst.displaySmall.size = src.displaySmall!.size!; + + // Title + if (src.titleLarge?.weight !== undefined) dst.titleLarge.weight = src.titleLarge!.weight!; + if (src.titleLarge?.size !== undefined) dst.titleLarge.size = src.titleLarge!.size!; + + if (src.titleMiddle?.weight !== undefined) dst.titleMiddle.weight = src.titleMiddle!.weight!; + if (src.titleMiddle?.size !== undefined) dst.titleMiddle.size = src.titleMiddle!.size!; + + if (src.titleSmall?.weight !== undefined) dst.titleSmall.weight = src.titleSmall!.weight!; + if (src.titleSmall?.size !== undefined) dst.titleSmall.size = src.titleSmall!.size!; + + // Subtitle + if (src.subtitleLarge?.weight !== undefined) dst.subtitleLarge.weight = src.subtitleLarge!.weight!; + if (src.subtitleLarge?.size !== undefined) dst.subtitleLarge.size = src.subtitleLarge!.size!; + + if (src.subtitleMiddle?.weight !== undefined) dst.subtitleMiddle.weight = src.subtitleMiddle!.weight!; + if (src.subtitleMiddle?.size !== undefined) dst.subtitleMiddle.size = src.subtitleMiddle!.size!; + + if (src.subtitleSmall?.weight !== undefined) dst.subtitleSmall.weight = src.subtitleSmall!.weight!; + if (src.subtitleSmall?.size !== undefined) dst.subtitleSmall.size = src.subtitleSmall!.size!; + + // Body + if (src.bodyLarge?.weight !== undefined) dst.bodyLarge.weight = src.bodyLarge!.weight!; + if (src.bodyLarge?.size !== undefined) dst.bodyLarge.size = src.bodyLarge!.size!; + + if (src.bodyMiddle?.weight !== undefined) dst.bodyMiddle.weight = src.bodyMiddle!.weight!; + if (src.bodyMiddle?.size !== undefined) dst.bodyMiddle.size = src.bodyMiddle!.size!; + + if (src.bodySmall?.weight !== undefined) dst.bodySmall.weight = src.bodySmall!.weight!; + if (src.bodySmall?.size !== undefined) dst.bodySmall.size = src.bodySmall!.size!; + + // Caption + if (src.captionLarge?.weight !== undefined) dst.captionLarge.weight = src.captionLarge!.weight!; + if (src.captionLarge?.size !== undefined) dst.captionLarge.size = src.captionLarge!.size!; + + if (src.captionMiddle?.weight !== undefined) dst.captionMiddle.weight = src.captionMiddle!.weight!; + if (src.captionMiddle?.size !== undefined) dst.captionMiddle.size = src.captionMiddle!.size!; + + if (src.captionSmall?.weight !== undefined) dst.captionSmall.weight = src.captionSmall!.weight!; + if (src.captionSmall?.size !== undefined) dst.captionSmall.size = src.captionSmall!.size!; + } +} \ No newline at end of file diff --git a/frameworks/bridge/arkts_frontend/koala_projects/arkoala-arkts/arkui-ohos/src/handwritten/theme/index.ts b/frameworks/bridge/arkts_frontend/koala_projects/arkoala-arkts/arkui-ohos/src/handwritten/theme/index.ts new file mode 100644 index 00000000000..73232a9772a --- /dev/null +++ b/frameworks/bridge/arkts_frontend/koala_projects/arkoala-arkts/arkui-ohos/src/handwritten/theme/index.ts @@ -0,0 +1,317 @@ +/* + * Copyright (c) 2024 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +import { FontWeight } from 'arkui/component/enums'; +import { Length, ResourceColor } from 'arkui/component/units'; +import { Resource } from 'global.resource'; +import { CustomTheme, Theme } from '@ohos/arkui/theme'; +import { int32 } from "@koalaui/common" + +export type Dimension = Resource; + +export interface CornerRadius { + none: Length; + level1: Length; + level2: Length; + level3: Length; + level4: Length; + level5: Length; + level6: Length; + level7: Length; + level8: Length; + level9: Length; + level10: Length; + level11: Length; + level12: Length; + level16: Length; +} + +/** + * Defines the struct of Paddings. + * + * @interface Paddings + * @syscap SystemCapability.ArkUI.ArkUI.Full + * @crossplatform + * @atomicservice + * @since 12 + */ +export interface Paddings { + level0: Length; + level1: Length; + level2: Length; + level3: Length; + level4: Length; + level5: Length; + level6: Length; + level7: Length; + level8: Length; + level9: Length; + level10: Length; + level11: Length; + level12: Length; + level16: Length; + level24: Length; + level32: Length; + level36: Length; +} + +/** + * Defines the struct of Borders. + * + * @interface Borders + * @syscap SystemCapability.ArkUI.ArkUI.Full + * @crossplatform + * @atomicservice + * @since 12 + */ +export interface Borders { + none: Length; + xs: Length; + s: Length; + m: Length; + l: Length; + xl: Length; +} + +/** + * Defines the struct of Outlines. + * + * @interface Outlines + * @syscap SystemCapability.ArkUI.ArkUI.Full + * @crossplatform + * @atomicservice + * @since 12 + */ +export interface Outlines { + none: Dimension; + xs: Dimension; + s: Dimension; + m: Dimension; + l: Dimension; + xl: Dimension; +} + +/** + * Defines the struct of Shapes. + * + * @interface Shapes + * @syscap SystemCapability.ArkUI.ArkUI.Full + * @crossplatform + * @atomicservice + * @since 12 + */ +export interface Shapes { + + /** + * CornerRadius Value Set. + * + * @type { CornerRadius } + * @syscap SystemCapability.ArkUI.ArkUI.Full + * @crossplatform + * @atomicservice + * @since 12 + */ + cornerRadius: CornerRadius; + + /** + * Paddings Value Set. + * + * @type { Paddings } + * @syscap SystemCapability.ArkUI.ArkUI.Full + * @crossplatform + * @atomicservice + * @since 12 + */ + paddings: Paddings; + + /** + * Borders Value Set. + * + * @type { Borders } + * @syscap SystemCapability.ArkUI.ArkUI.Full + * @crossplatform + * @atomicservice + * @since 12 + */ + borders: Borders; + + /** + * Outlines Value Set. + * + * @type { Outlines } + * @syscap SystemCapability.ArkUI.ArkUI.Full + * @crossplatform + * @atomicservice + * @since 12 + */ + outlines: Outlines; +} + +/** + * Defines the struct of TypographyStyle. + * + * @interface TypographyStyle + * @syscap SystemCapability.ArkUI.ArkUI.Full + * @crossplatform + * @atomicservice + * @since 12 + */ +export interface TypographyStyle { + weight: FontWeight | number | string | int32; + size: Length; +} + +/** + * Defines the struct of Typography. + * + * @interface Typography + * @syscap SystemCapability.ArkUI.ArkUI.Full + * @crossplatform + * @atomicservice + * @since 12 + */ +export interface Typography { + + //display + displayLarge: TypographyStyle; + displayMiddle: TypographyStyle; + displaySmall: TypographyStyle; + + // Title + titleLarge: TypographyStyle; + titleMiddle: TypographyStyle; + titleSmall: TypographyStyle; + + // Subtitle + subtitleLarge: TypographyStyle; + subtitleMiddle: TypographyStyle; + subtitleSmall: TypographyStyle; + + // Body + bodyLarge: TypographyStyle; + bodyMiddle: TypographyStyle; + bodySmall: TypographyStyle; + + // Caption + captionLarge: TypographyStyle; + captionMiddle: TypographyStyle; + captionSmall: TypographyStyle; +} +export interface CustomCornerRadius { + none?: Length; + level1?: Length; + level2?: Length; + level3?: Length; + level4?: Length; + level5?: Length; + level6?: Length; + level7?: Length; + level8?: Length; + level9?: Length; + level10?: Length; + level11?: Length; + level12?: Length; + level16?: Length; +} +export interface CustomPaddings { + level0?: Length; + level1?: Length; + level2?: Length; + level3?: Length; + level4?: Length; + level5?: Length; + level6?: Length; + level7?: Length; + level8?: Length; + level9?: Length; + level10?: Length; + level11?: Length; + level12?: Length; + level16?: Length; + level24?: Length; + level32?: Length; + level36?: Length; +} +export interface CustomBorders { + none?: Length; + xs?: Length; + s?: Length; + m?: Length; + l?: Length; + xl?: Length; +} +export interface CustomOutlines { + none?: Dimension; + xs?: Dimension; + s?: Dimension; + m?: Dimension; + l?: Dimension; + xl?: Dimension; +} +export interface CustomShapes { + cornerRadius?: CustomCornerRadius; + paddings?: CustomPaddings; + borders?: CustomBorders; + outlines?: CustomOutlines; +} +export interface CustomTypographyStyle { + weight?: FontWeight | number | string | int32; + size?: Length; +} +export interface CustomTypography { + displayLarge?: CustomTypographyStyle; + displayMiddle?: CustomTypographyStyle; + displaySmall?: CustomTypographyStyle; + titleLarge?: CustomTypographyStyle; + titleMiddle?: CustomTypographyStyle; + titleSmall?: CustomTypographyStyle; + subtitleLarge?: CustomTypographyStyle; + subtitleMiddle?: CustomTypographyStyle; + subtitleSmall?: CustomTypographyStyle; + bodyLarge?: CustomTypographyStyle; + bodyMiddle?: CustomTypographyStyle; + bodySmall?: CustomTypographyStyle; + captionLarge?: CustomTypographyStyle; + captionMiddle?: CustomTypographyStyle; + captionSmall?: CustomTypographyStyle; +} + +export class BrandColors { + primary: ResourceColor | undefined; + secondary: ResourceColor | undefined; + tertiary: ResourceColor | undefined; + fourth: ResourceColor | undefined; + fifth: ResourceColor | undefined; + sixth: ResourceColor | undefined; +} + +export function makeRecordfromObj(obj: Object): Record { + let record: Record = {}; + const keys = Object.keys(obj); + const values = Object.values(obj); + keys.forEach((key: string, index: number) => { + record[key] = values[index]; + }) + return record; +} + +export interface ArkThemeResource extends Resource { + bundleName: string; + moduleName: string; + id: number; + params?: Array; + type?: number; + opacityRatio: number; +} diff --git a/frameworks/bridge/arkts_frontend/koala_projects/arkoala-arkts/arkui-ohos/src/handwritten/theme/system/ArkSystemShapes.ts b/frameworks/bridge/arkts_frontend/koala_projects/arkoala-arkts/arkui-ohos/src/handwritten/theme/system/ArkSystemShapes.ts new file mode 100644 index 00000000000..363f4973534 --- /dev/null +++ b/frameworks/bridge/arkts_frontend/koala_projects/arkoala-arkts/arkui-ohos/src/handwritten/theme/system/ArkSystemShapes.ts @@ -0,0 +1,142 @@ +/* + * Copyright (c) 2024 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +import { CornerRadius, Paddings, Outlines, Dimension, Borders, Shapes } from '../index'; +import { ArkResourcesHelper } from '../ArkResourcesHelper'; +import { Length } from 'arkui/component/units'; + +export class ArkSystemCornerRadius implements CornerRadius { + none: Length; + level1: Length; + level2: Length; + level3: Length; + level4: Length; + level5: Length; + level6: Length; + level7: Length; + level8: Length; + level9: Length; + level10: Length; + level11: Length; + level12: Length; + level16: Length; + + constructor() { + this.none = ArkResourcesHelper.$r('sys.float.corner_radius_none'); + this.level1 = ArkResourcesHelper.$r('sys.float.corner_radius_level1'); + this.level2 = ArkResourcesHelper.$r('sys.float.corner_radius_level2'); + this.level3 = ArkResourcesHelper.$r('sys.float.corner_radius_level3'); + this.level4 = ArkResourcesHelper.$r('sys.float.corner_radius_level4'); + this.level5 = ArkResourcesHelper.$r('sys.float.corner_radius_level5'); + this.level6 = ArkResourcesHelper.$r('sys.float.corner_radius_level6'); + this.level7 = ArkResourcesHelper.$r('sys.float.corner_radius_level7'); + this.level8 = ArkResourcesHelper.$r('sys.float.corner_radius_level8'); + this.level9 = ArkResourcesHelper.$r('sys.float.corner_radius_level9'); + this.level10 = ArkResourcesHelper.$r('sys.float.corner_radius_level10'); + this.level11 = ArkResourcesHelper.$r('sys.float.corner_radius_level11'); + this.level12 = ArkResourcesHelper.$r('sys.float.corner_radius_level12'); + this.level16 = ArkResourcesHelper.$r('sys.float.corner_radius_level16'); + } +} + +export class ArkSystemPaddings implements Paddings { + level0: Length; + level1: Length; + level2: Length; + level3: Length; + level4: Length; + level5: Length; + level6: Length; + level7: Length; + level8: Length; + level9: Length; + level10: Length; + level11: Length; + level12: Length; + level16: Length; + level24: Length; + level32: Length; + level36: Length; + + constructor() { + this.level0 = ArkResourcesHelper.$r('sys.float.padding_level0'); + this.level1 = ArkResourcesHelper.$r('sys.float.padding_level1'); + this.level2 = ArkResourcesHelper.$r('sys.float.padding_level2'); + this.level3 = ArkResourcesHelper.$r('sys.float.padding_level3'); + this.level4 = ArkResourcesHelper.$r('sys.float.padding_level4'); + this.level5 = ArkResourcesHelper.$r('sys.float.padding_level5'); + this.level6 = ArkResourcesHelper.$r('sys.float.padding_level6'); + this.level7 = ArkResourcesHelper.$r('sys.float.padding_level7'); + this.level8 = ArkResourcesHelper.$r('sys.float.padding_level8'); + this.level9 = ArkResourcesHelper.$r('sys.float.padding_level9'); + this.level10 = ArkResourcesHelper.$r('sys.float.padding_level10'); + this.level11 = ArkResourcesHelper.$r('sys.float.padding_level11'); + this.level12 = ArkResourcesHelper.$r('sys.float.padding_level12'); + this.level16 = ArkResourcesHelper.$r('sys.float.padding_level16'); + this.level24 = ArkResourcesHelper.$r('sys.float.padding_level24'); + this.level32 = ArkResourcesHelper.$r('sys.float.padding_level32'); + this.level36 = ArkResourcesHelper.$r('sys.float.padding_level36'); + } +} + +export class ArkSystemOutlines implements Outlines { + none: Dimension; + xs: Dimension; + s: Dimension; + m: Dimension; + l: Dimension; + xl: Dimension; + + constructor() { + this.none = ArkResourcesHelper.$r('sys.float.outline_none'); + this.xs = ArkResourcesHelper.$r('sys.float.outline_extra_small'); + this.s = ArkResourcesHelper.$r('sys.float.outline_small'); + this.m = ArkResourcesHelper.$r('sys.float.outline_medium'); + this.l = ArkResourcesHelper.$r('sys.float.outline_larger'); + this.xl = ArkResourcesHelper.$r('sys.float.outline_extra_larger'); + } +} + +export class ArkSystemBorders implements Borders { + none: Length; + xs: Length; + s: Length; + m: Length; + l: Length; + xl: Length; + + constructor() { + this.none = ArkResourcesHelper.$r('sys.float.border_none'); + this.xs = ArkResourcesHelper.$r('sys.float.border_extra_small'); + this.s = ArkResourcesHelper.$r('sys.float.border_small'); + this.m = ArkResourcesHelper.$r('sys.float.border_medium'); + this.l = ArkResourcesHelper.$r('sys.float.border_larger'); + this.xl = ArkResourcesHelper.$r('sys.float.border_extra_larger'); + } +} + +export class ArkSystemShapes implements Shapes { + cornerRadius: CornerRadius; + paddings: Paddings; + borders: Borders; + outlines: Outlines; + + constructor() { + this.cornerRadius = new ArkSystemCornerRadius(); + this.paddings = new ArkSystemPaddings(); + this.borders = new ArkSystemBorders(); + this.outlines = new ArkSystemOutlines(); + } +} \ No newline at end of file diff --git a/frameworks/bridge/arkts_frontend/koala_projects/arkoala-arkts/arkui-ohos/src/handwritten/theme/system/ArkSystemTheme.ts b/frameworks/bridge/arkts_frontend/koala_projects/arkoala-arkts/arkui-ohos/src/handwritten/theme/system/ArkSystemTheme.ts new file mode 100644 index 00000000000..4519c04917f --- /dev/null +++ b/frameworks/bridge/arkts_frontend/koala_projects/arkoala-arkts/arkui-ohos/src/handwritten/theme/system/ArkSystemTheme.ts @@ -0,0 +1,33 @@ +/* + * Copyright (c) 2024 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +import { Colors } from '@ohos/arkui/theme'; +import { ArkThemeBase } from '../ArkThemeBase'; +import { ThemeColorMode } from 'arkui/component/common'; +import { ArkSystemShapes } from './ArkSystemShapes'; +import { ArkSystemTypography } from './ArkSystemTypography'; + +export class ArkSystemTheme extends ArkThemeBase { + constructor() { + super( + -1, // no parent theme + undefined, + ThemeColorMode.SYSTEM, + new Colors(), + new ArkSystemShapes(), + new ArkSystemTypography() + ); + } +} \ No newline at end of file diff --git a/frameworks/bridge/arkts_frontend/koala_projects/arkoala-arkts/arkui-ohos/src/handwritten/theme/system/ArkSystemTypography.ts b/frameworks/bridge/arkts_frontend/koala_projects/arkoala-arkts/arkui-ohos/src/handwritten/theme/system/ArkSystemTypography.ts new file mode 100644 index 00000000000..560357864c8 --- /dev/null +++ b/frameworks/bridge/arkts_frontend/koala_projects/arkoala-arkts/arkui-ohos/src/handwritten/theme/system/ArkSystemTypography.ts @@ -0,0 +1,128 @@ +/* + * Copyright (c) 2024 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +import { Typography, TypographyStyle } from '../index'; +import { ArkResourcesHelper } from '../ArkResourcesHelper'; + +export class ArkTypographyWeights { + public static thin = 100; + public static ultralight = 200; + public static light = 300; + public static regular = 400; + public static medium = 500; + public static semibold = 600; + public static bold = 700; + public static heavy = 800; + public static black = 900; +} + +export class ArkSystemTypography implements Typography { + // Display + displayLarge: TypographyStyle; + displayMiddle: TypographyStyle; + displaySmall: TypographyStyle; + + // Title + titleLarge: TypographyStyle; + titleMiddle: TypographyStyle; + titleSmall: TypographyStyle; + + // Subtitle + subtitleLarge: TypographyStyle; + subtitleMiddle: TypographyStyle; + subtitleSmall: TypographyStyle; + + // Body + bodyLarge: TypographyStyle; + bodyMiddle: TypographyStyle; + bodySmall: TypographyStyle; + + // Caption + captionLarge: TypographyStyle; + captionMiddle: TypographyStyle; + captionSmall: TypographyStyle; + + constructor() { + // Display + this.displayLarge = { + weight: ArkTypographyWeights.light, + size: ArkResourcesHelper.$r('sys.float.Display_L') + }; + this.displayMiddle = { + weight: ArkTypographyWeights.light, + size: ArkResourcesHelper.$r('sys.float.Display_M') + }; + this.displaySmall = { + weight: ArkTypographyWeights.light, + size: ArkResourcesHelper.$r('sys.float.Display_S') + }; + + // Title + this.titleLarge = { + weight: ArkTypographyWeights.bold, + size: ArkResourcesHelper.$r('sys.float.Title_L') + }; + this.titleMiddle = { + weight: ArkTypographyWeights.bold, + size: ArkResourcesHelper.$r('sys.float.Title_M') + }; + this.titleSmall = { + weight: ArkTypographyWeights.bold, + size: ArkResourcesHelper.$r('sys.float.Title_S') + }; + + // Subtitle + this.subtitleLarge = { + weight: ArkTypographyWeights.medium, + size: ArkResourcesHelper.$r('sys.float.Subtitle_L') + }; + this.subtitleMiddle = { + weight: ArkTypographyWeights.medium, + size: ArkResourcesHelper.$r('sys.float.Subtitle_M') + }; + this.subtitleSmall = { + weight: ArkTypographyWeights.medium, + size: ArkResourcesHelper.$r('sys.float.Subtitle_S') + }; + + // Body + this.bodyLarge = { + weight: ArkTypographyWeights.medium, + size: ArkResourcesHelper.$r('sys.float.Body_L') + }; + this.bodyMiddle = { + weight: ArkTypographyWeights.regular, + size: ArkResourcesHelper.$r('sys.float.Body_M') + }; + this.bodySmall = { + weight: ArkTypographyWeights.regular, + size: ArkResourcesHelper.$r('sys.float.Body_S') + }; + + // Caption + this.captionLarge = { + weight: ArkTypographyWeights.medium, + size: ArkResourcesHelper.$r('sys.float.Caption_L') + }; + this.captionMiddle = { + weight: ArkTypographyWeights.medium, + size: ArkResourcesHelper.$r('sys.float.Caption_M') + }; + this.captionSmall = { + weight: ArkTypographyWeights.medium, + size: ArkResourcesHelper.$r('sys.float.Caption_S') + }; + } +} \ No newline at end of file diff --git a/frameworks/bridge/arkts_frontend/koala_projects/arkoala-arkts/arkui-ohos/ui2abcconfig-m3.json b/frameworks/bridge/arkts_frontend/koala_projects/arkoala-arkts/arkui-ohos/ui2abcconfig-m3.json index e3a18073568..3642ef80b7c 100644 --- a/frameworks/bridge/arkts_frontend/koala_projects/arkoala-arkts/arkui-ohos/ui2abcconfig-m3.json +++ b/frameworks/bridge/arkts_frontend/koala_projects/arkoala-arkts/arkui-ohos/ui2abcconfig-m3.json @@ -93,6 +93,9 @@ ], "#stateMgmtTool": [ "arkui/stateManagement/tools/arkts" + ], + "@ohos/arkui/theme": [ + "./@ohos.arkui.theme" ] }, "plugins": [ diff --git a/frameworks/bridge/arkts_frontend/koala_projects/arkoala-arkts/components.gni b/frameworks/bridge/arkts_frontend/koala_projects/arkoala-arkts/components.gni index b8439533057..e31435fc64e 100644 --- a/frameworks/bridge/arkts_frontend/koala_projects/arkoala-arkts/components.gni +++ b/frameworks/bridge/arkts_frontend/koala_projects/arkoala-arkts/components.gni @@ -27,6 +27,7 @@ arkui_files = [ "arkui-preprocessed/@ohos.arkui.graphics.ets", "arkui-preprocessed/@ohos.arkui.inspector.ets", "arkui-preprocessed/@ohos.arkui.observer.ets", + "arkui-preprocessed/@ohos.arkui.theme.ets", "arkui-preprocessed/@ohos.font.ets", "arkui-preprocessed/@ohos.graphics.common2D.ets", "arkui-preprocessed/@ohos.graphics.drawing.ets", @@ -384,6 +385,18 @@ arkui_files = [ "arkui-preprocessed/arkui/handwritten/modifiers/ArkTextInputNode.ets", "arkui-preprocessed/arkui/handwritten/modifiers/ArkTextNode.ets", "arkui-preprocessed/arkui/handwritten/modifiers/ArkXComponentNode.ets", + "arkui-preprocessed/arkui/handwritten/theme/ArkResourcesHelper.ets", + "arkui-preprocessed/arkui/handwritten/theme/ArkShapesImpl.ets", + "arkui-preprocessed/arkui/handwritten/theme/ArkThemeBase.ets", + "arkui-preprocessed/arkui/handwritten/theme/ArkThemeCache.ets", + "arkui-preprocessed/arkui/handwritten/theme/ArkThemeImpl.ets", + "arkui-preprocessed/arkui/handwritten/theme/ArkThemeNativeHelper.ets", + "arkui-preprocessed/arkui/handwritten/theme/ArkThemeScopeManager.ets", + "arkui-preprocessed/arkui/handwritten/theme/ArkTypographyImpl.ets", + "arkui-preprocessed/arkui/handwritten/theme/index.ets", + "arkui-preprocessed/arkui/handwritten/theme/system/ArkSystemShapes.ets", + "arkui-preprocessed/arkui/handwritten/theme/system/ArkSystemTheme.ets", + "arkui-preprocessed/arkui/handwritten/theme/system/ArkSystemTypography.ets", "arkui-preprocessed/arkui/index.ets", "arkui-preprocessed/arkui/ohos.arkui.modifier.ets", "arkui-preprocessed/arkui/ohos.arkui.node.ets", @@ -479,6 +492,7 @@ arkui_path_keys = [ "@ohos/arkui/dragController", "#stateMgmtTool", "@ohos/arkui/Parallelize", + "@ohos/arkui/theme", ] arkui_path_values = [ @@ -520,4 +534,5 @@ arkui_path_values = [ "arkui-preprocessed/@ohos.arkui.dragController.ets", "arkui-preprocessed/arkui/stateManagement/tools/arkts", "arkui-preprocessed/@ohos.arkui.Parallelize.ets", + "arkui-preprocessed/@ohos.arkui.theme.ets", ] diff --git a/frameworks/bridge/arkts_frontend/koala_projects/arkoala-arkts/ui2abcconfig-m3.json b/frameworks/bridge/arkts_frontend/koala_projects/arkoala-arkts/ui2abcconfig-m3.json index 9e34be92684..73853bfd475 100644 --- a/frameworks/bridge/arkts_frontend/koala_projects/arkoala-arkts/ui2abcconfig-m3.json +++ b/frameworks/bridge/arkts_frontend/koala_projects/arkoala-arkts/ui2abcconfig-m3.json @@ -109,6 +109,9 @@ ], "#stateMgmtTool": [ "./arkui/stateManagement/tools/arkts" + ], + "@ohos/arkui/theme": [ + "./@ohos.arkui.theme.ets" ] }, "plugins": [ diff --git a/frameworks/core/interfaces/ani/ani_api.h b/frameworks/core/interfaces/ani/ani_api.h index 89774f48398..95451a9ddfe 100644 --- a/frameworks/core/interfaces/ani/ani_api.h +++ b/frameworks/core/interfaces/ani/ani_api.h @@ -53,6 +53,7 @@ typedef class __ani_error* ani_error; typedef struct __ani_resolver *ani_resolver; typedef struct napi_env__* napi_env; typedef struct napi_value__* napi_value; +typedef class __ani_array* ani_array; typedef _ArkUINode* ArkUINodeHandle; typedef int ArkUI_Int32; typedef size_t ani_size; @@ -285,6 +286,12 @@ struct ArkUIAniCommonModifier { ani_double (*px2fp)(ani_double value, ani_int instanceId); ani_double (*lpx2px)(ani_double value, ani_int instanceId); ani_double (*px2lpx)(ani_double value, ani_int instanceId); + ArkUI_Uint32 (*getColorValueByString)(const std::string& src); + ArkUI_Uint32 (*getColorValueByNumber)(ArkUI_Uint32 src); + void (*sendThemeToNative)(ani_env* env, ani_array colors, ani_int id); + void (*setDefaultTheme)(ani_env* env, ani_array colors, ani_boolean isDark); + void (*updateColorMode)(ani_int colorMode); + void (*restoreColorMode)(); }; struct ArkUIAniCustomNodeModifier { ani_long (*constructCustomNode)(ani_int, std::function&& onPageShow, std::function&& onPageHide, diff --git a/frameworks/core/interfaces/native/BUILD.gn b/frameworks/core/interfaces/native/BUILD.gn index a766b0533aa..11024a155bb 100644 --- a/frameworks/core/interfaces/native/BUILD.gn +++ b/frameworks/core/interfaces/native/BUILD.gn @@ -144,6 +144,8 @@ template("ace_core_interfaces_native_node") { sources += [ + "ani/ani_theme.cpp", + "ani/ani_theme_module.cpp", "ani/ani_utils.cpp", "ani/animation_ani_modifier.cpp", "ani/canvas_ani_modifier.cpp", @@ -161,6 +163,7 @@ template("ace_core_interfaces_native_node") { "ani/node_ani_modifier.cpp", "ani/styled_string_ani_modifier.cpp", "ani/web_ani_modifier.cpp", + "ani/resource_ani_modifier.cpp", "ani/waterflow_ani_modifier.cpp", "ani/video_ani_modifier.cpp", "ani/rich_editor_ani_modifier.cpp", @@ -172,16 +175,20 @@ template("ace_core_interfaces_native_node") { ] if (build_ohos_sdk) { sources -= [ + "ani/ani_theme.cpp", + "ani/ani_theme_module.cpp", "ani/ani_utils.cpp", "ani/animation_ani_modifier.cpp", "ani/common_ani_modifier.cpp", "ani/custom_node_ani_modifier.cpp", "ani/node_ani_modifier.cpp", + "ani/resource_ani_modifier.cpp", "ani/waterflow_ani_modifier.cpp", "ani/interop_ani_modifier.cpp", "ani/list_ani_modifier.cpp", "ani/drag_controller_ani_modifier.cpp", "ani/drag_controller_utils.cpp", + "ani/web_ani_modifier.cpp", ] } @@ -268,9 +275,7 @@ template("ace_core_interfaces_native_node") { } } if (build_ohos_sdk) { - external_deps -= [ - "runtime_core:ani", - ] + external_deps -= [ "runtime_core:ani" ] } if (defined(config.model_component_support) && diff --git a/frameworks/core/interfaces/native/ani/ani_theme.cpp b/frameworks/core/interfaces/native/ani/ani_theme.cpp new file mode 100644 index 00000000000..51bb02e97b9 --- /dev/null +++ b/frameworks/core/interfaces/native/ani/ani_theme.cpp @@ -0,0 +1,57 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "core/interfaces/native/ani/ani_theme.h" + +#include + +#include "ani.h" + +#include "base/log/log_wrapper.h" +#include "bridge/arkts_frontend/arkts_ani_utils.h" +#include "core/interfaces/native/ani/resource_ani_modifier.h" + +namespace OHOS::Ace::NG { +std::map AniThemeScope::aniThemes = {}; + +void AniThemeColors::SetColors(ani_env* env, ani_array colors) +{ + ani_size length; + env->Array_GetLength(colors, &length); + for (int i = 0; i < length; i++) { + // type ResourceColor = number | string | Resource + ani_ref value; + env->Array_Get_Ref((ani_array_ref)colors, i, &value); + colors_.push_back((ani_object)value); + } + env->GetVM(&vm_); +} + +Color AniThemeColors::ConvertAniValueToColor(ani_object aniValue) const +{ + if (!vm_) { + LOGW("Invalid vm when ConvertAniValueToColor"); + return Color(); + } + auto* env = ArktsAniUtils::GetAniEnv(vm_); + if (!env) { + LOGW("Invalid env when ConvertAniValueToColor"); + return Color(); + } + Color color; + ResourceAniModifier::ParseAniColor(env, aniValue, color); + return color; +} +} // namespace OHOS::Ace::NG diff --git a/frameworks/core/interfaces/native/ani/ani_theme.h b/frameworks/core/interfaces/native/ani/ani_theme.h new file mode 100644 index 00000000000..0c36888a90c --- /dev/null +++ b/frameworks/core/interfaces/native/ani/ani_theme.h @@ -0,0 +1,346 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef FRAMEWORKS_CORE_INTERFACES_NATIVE_ANI_ANI_THEME_H +#define FRAMEWORKS_CORE_INTERFACES_NATIVE_ANI_ANI_THEME_H + +#include +#include +#include +#include + +#include "ui/properties/color.h" + +#define COLORS_NUMBER (51) + +#define BRAND (0) +#define WARNING (1) +#define ALERT (2) +#define CONFIRM (3) + +#define FONT_PRIMARY (4) +#define FONT_SECONDARY (5) +#define FONT_TERTIARY (6) +#define FONT_FOURTH (7) +#define FONT_EMPHASIZE (8) + +#define FONT_ON_PRIMARY (9) +#define FONT_ON_SECONDARY (10) +#define FONT_ON_TERTIARY (11) +#define FONT_ON_FOURTH (12) + +#define ICON_PRIMARY (13) +#define ICON_SECONDARY (14) +#define ICON_TERTIARY (15) +#define ICON_FOURTH (16) +#define ICON_EMPHASIZE (17) +#define ICON_SUB_EMPHASIZE (18) + +#define ICON_ON_PRIMARY (19) +#define ICON_ON_SECONDARY (20) +#define ICON_ON_TERTIARY (21) +#define ICON_ON_FOURTH (22) + +#define BACKGROUND_PRIMARY (23) +#define BACKGROUND_SECONDARY (24) +#define BACKGROUND_TERTIARY (25) +#define BACKGROUND_FOURTH (26) +#define BACKGROUND_EMPHASIZE (27) + +#define COMP_FOREGROUND_PRIMARY (28) +#define COMP_BACKGROUND_PRIMARY (29) +#define COMP_BACKGROUND_PRIMARY_TRAN (30) +#define COMP_BACKGROUND_PRIMARY_CONTRARY (31) +#define COMP_BACKGROUND_GRAY (32) +#define COMP_BACKGROUND_SECONDARY (33) +#define COMP_BACKGROUND_TERTIARY (34) +#define COMP_BACKGROUND_EMPHASIZE (35) +#define COMP_BACKGROUND_NEUTRAL (36) +#define COMP_EMPHASIZE_SECONDARY (37) +#define COMP_EMPHASIZE_TERTIARY (38) +#define COMP_DIVIDER (39) +#define COMP_COMMON_CONTRARY (40) +#define COMP_BACKGROUND_FOCUS (41) +#define COMP_FOCUSED_PRIMARY (42) +#define COMP_FOCUSED_SECONDARY (43) +#define COMP_FOCUSED_TERTIARY (44) + +#define INTERACTIVE_HOVER (45) +#define INTERACTIVE_PRESSED (46) +#define INTERACTIVE_FOCUS (47) +#define INTERACTIVE_ACTIVE (48) +#define INTERACTIVE_SELECT (49) +#define INTERACTIVE_CLICK (50) + +typedef class __ani_array* ani_array; +typedef class __ani_object* ani_object; +typedef struct __ani_env ani_env; +typedef struct __ani_vm ani_vm; + +namespace OHOS::Ace::NG { +class AniThemeColors { +public: + AniThemeColors() = default; + virtual ~AniThemeColors() = default; + + void SetColors(ani_env* env, ani_array colors); + + Color Brand() const + { + return ConvertAniValueToColor(colors_[BRAND]); + } + Color Warning() const + { + return ConvertAniValueToColor(colors_[WARNING]); + } + Color Alert() const + { + return ConvertAniValueToColor(colors_[ALERT]); + } + Color Confirm() const + { + return ConvertAniValueToColor(colors_[CONFIRM]); + } + + Color FontPrimary() const + { + return ConvertAniValueToColor(colors_[FONT_PRIMARY]); + } + Color FontSecondary() const + { + return ConvertAniValueToColor(colors_[FONT_SECONDARY]); + } + Color FontTertiary() const + { + return ConvertAniValueToColor(colors_[FONT_TERTIARY]); + } + Color FontFourth() const + { + return ConvertAniValueToColor(colors_[FONT_FOURTH]); + } + Color FontEmphasize() const + { + return ConvertAniValueToColor(colors_[FONT_EMPHASIZE]); + } + + Color FontOnPrimary() const + { + return ConvertAniValueToColor(colors_[FONT_ON_PRIMARY]); + } + Color FontOnSecondary() const + { + return ConvertAniValueToColor(colors_[FONT_ON_SECONDARY]); + } + Color FontOnTertiary() const + { + return ConvertAniValueToColor(colors_[FONT_ON_TERTIARY]); + } + Color FontOnFourth() const + { + return ConvertAniValueToColor(colors_[FONT_ON_FOURTH]); + } + + Color IconPrimary() const + { + return ConvertAniValueToColor(colors_[ICON_PRIMARY]); + } + Color IconSecondary() const + { + return ConvertAniValueToColor(colors_[ICON_SECONDARY]); + } + Color IconTertiary() const + { + return ConvertAniValueToColor(colors_[ICON_TERTIARY]); + } + Color IconFourth() const + { + return ConvertAniValueToColor(colors_[ICON_FOURTH]); + } + Color IconEmphasize() const + { + return ConvertAniValueToColor(colors_[ICON_EMPHASIZE]); + } + Color IconSubEmphasize() const + { + return ConvertAniValueToColor(colors_[ICON_SUB_EMPHASIZE]); + } + + Color IconOnPrimary() const + { + return ConvertAniValueToColor(colors_[ICON_ON_PRIMARY]); + } + Color IconOnSecondary() const + { + return ConvertAniValueToColor(colors_[ICON_ON_SECONDARY]); + } + Color IconOnTertiary() const + { + return ConvertAniValueToColor(colors_[ICON_ON_TERTIARY]); + } + Color IconOnFourth() const + { + return ConvertAniValueToColor(colors_[ICON_ON_FOURTH]); + } + + Color BackgroundPrimary() const + { + return ConvertAniValueToColor(colors_[BACKGROUND_PRIMARY]); + } + Color BackgroundSecondary() const + { + return ConvertAniValueToColor(colors_[BACKGROUND_SECONDARY]); + } + Color BackgroundTertiary() const + { + return ConvertAniValueToColor(colors_[BACKGROUND_TERTIARY]); + } + Color BackgroundFourth() const + { + return ConvertAniValueToColor(colors_[BACKGROUND_FOURTH]); + } + Color BackgroundEmphasize() const + { + return ConvertAniValueToColor(colors_[BACKGROUND_EMPHASIZE]); + } + + Color CompForegroundPrimary() const + { + return ConvertAniValueToColor(colors_[COMP_FOREGROUND_PRIMARY]); + } + Color CompBackgroundPrimary() const + { + return ConvertAniValueToColor(colors_[COMP_BACKGROUND_PRIMARY]); + } + Color CompBackgroundPrimaryTran() const + { + return ConvertAniValueToColor(colors_[COMP_BACKGROUND_PRIMARY_TRAN]); + } + Color CompBackgroundPrimaryContrary() const + { + return ConvertAniValueToColor(colors_[COMP_BACKGROUND_PRIMARY_CONTRARY]); + } + Color CompBackgroundGray() const + { + return ConvertAniValueToColor(colors_[COMP_BACKGROUND_GRAY]); + } + Color CompBackgroundSecondary() const + { + return ConvertAniValueToColor(colors_[COMP_BACKGROUND_SECONDARY]); + } + Color CompBackgroundTertiary() const + { + return ConvertAniValueToColor(colors_[COMP_BACKGROUND_TERTIARY]); + } + Color CompBackgroundEmphasize() const + { + return ConvertAniValueToColor(colors_[COMP_BACKGROUND_EMPHASIZE]); + } + Color CompBackgroundNeutral() const + { + return ConvertAniValueToColor(colors_[COMP_BACKGROUND_NEUTRAL]); + } + Color CompEmphasizeSecondary() const + { + return ConvertAniValueToColor(colors_[COMP_EMPHASIZE_SECONDARY]); + } + Color CompEmphasizeTertiary() const + { + return ConvertAniValueToColor(colors_[COMP_EMPHASIZE_TERTIARY]); + } + Color CompDivider() const + { + return ConvertAniValueToColor(colors_[COMP_DIVIDER]); + } + Color CompCommonContrary() const + { + return ConvertAniValueToColor(colors_[COMP_COMMON_CONTRARY]); + } + Color CompBackgroundFocus() const + { + return ConvertAniValueToColor(colors_[COMP_BACKGROUND_FOCUS]); + } + Color CompFocusedPrimary() const + { + return ConvertAniValueToColor(colors_[COMP_FOCUSED_PRIMARY]); + } + Color CompFocusedSecondary() const + { + return ConvertAniValueToColor(colors_[COMP_FOCUSED_SECONDARY]); + } + Color CompFocusedTertiary() const + { + return ConvertAniValueToColor(colors_[COMP_FOCUSED_TERTIARY]); + } + + Color InteractiveHover() const + { + return ConvertAniValueToColor(colors_[INTERACTIVE_HOVER]); + } + Color InteractivePressed() const + { + return ConvertAniValueToColor(colors_[INTERACTIVE_PRESSED]); + } + Color InteractiveFocus() const + { + return ConvertAniValueToColor(colors_[INTERACTIVE_FOCUS]); + } + Color InteractiveActive() const + { + return ConvertAniValueToColor(colors_[INTERACTIVE_ACTIVE]); + } + Color InteractiveSelect() const + { + return ConvertAniValueToColor(colors_[INTERACTIVE_SELECT]); + } + Color InteractiveClick() const + { + return ConvertAniValueToColor(colors_[INTERACTIVE_CLICK]); + } + +private: + Color ConvertAniValueToColor(ani_object aniValue) const; + + std::vector colors_; + ani_vm* vm_ = nullptr; +}; + +class AniTheme { +public: + AniTheme() = default; + virtual ~AniTheme() = default; + + void SetColors(const AniThemeColors& colors) + { + colors_ = colors; + } + + const AniThemeColors& Colors() const + { + return colors_; + } + +private: + AniThemeColors colors_; +}; + +class AniThemeScope { +public: + static std::map aniThemes; + // keeps the current theme in static optional object + inline static std::optional aniCurrentTheme = std::nullopt; + inline static bool isCurrentThemeDefault = true; +}; +} // namespace OHOS::Ace::NG +#endif // FRAMEWORKS_CORE_INTERFACES_NATIVE_ANI_ANI_THEME_H \ No newline at end of file diff --git a/frameworks/core/interfaces/native/ani/ani_theme_module.cpp b/frameworks/core/interfaces/native/ani/ani_theme_module.cpp new file mode 100644 index 00000000000..9891e4716d4 --- /dev/null +++ b/frameworks/core/interfaces/native/ani/ani_theme_module.cpp @@ -0,0 +1,78 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "core/interfaces/native/ani/ani_theme_module.h" + +#include "core/common/resource/resource_manager.h" +#include "core/pipeline_ng/pipeline_context.h" + +namespace OHOS::Ace::NG { +void AniThemeModule::UpdateColorMode(int32_t colorMode) +{ + ColorMode colorModeValue = MapAniColorModeToColorMode(colorMode); + if (colorModeValue != ColorMode::COLOR_MODE_UNDEFINED) { +#if defined(ANDROID_PLATFORM) || defined(IOS_PLATFORM) + UpdateColorModeForThemeConstants(colorModeValue); +#else + ResourceManager::GetInstance().UpdateColorMode(colorModeValue); +#endif + auto pipelineContext = NG::PipelineContext::GetCurrentContext(); + pipelineContext->SetLocalColorMode(colorModeValue); + } +} + +void AniThemeModule::RestoreColorMode() +{ + auto pipelineContext = NG::PipelineContext::GetCurrentContext(); + CHECK_NULL_VOID(pipelineContext); + pipelineContext->SetLocalColorMode(ColorMode::COLOR_MODE_UNDEFINED); + + auto colorModeValue = pipelineContext->GetColorMode(); +#if defined(ANDROID_PLATFORM) || defined(IOS_PLATFORM) + UpdateColorModeForThemeConstants(colorModeValue); +#else + ResourceManager::GetInstance().UpdateColorMode(colorModeValue); +#endif +} + +#if defined(ANDROID_PLATFORM) || defined(IOS_PLATFORM) +void AniThemeModule::UpdateColorModeForThemeConstants(const ColorMode& colorMode) +{ + auto container = Container::Current(); + CHECK_NULL_VOID(container); + auto resConfig = container->GetResourceConfiguration(); + resConfig.SetColorMode(colorMode); + + auto themeManager = PipelineBase::CurrentThemeManager(); + CHECK_NULL_VOID(themeManager); + auto themeConstants = themeManager->GetThemeConstants(); + CHECK_NULL_VOID(themeConstants); + themeConstants->UpdateConfig(resConfig); +} +#endif + +ColorMode AniThemeModule::MapAniColorModeToColorMode(int32_t aniColorMode) +{ + switch (aniColorMode) { + case 1: // 1 is the ThemeColorMode.LIGHT + return ColorMode::LIGHT; + case 2: // 2 is the ThemeColorMode.DARK + return ColorMode::DARK; + default: + return ColorMode::COLOR_MODE_UNDEFINED; + } + return ColorMode::COLOR_MODE_UNDEFINED; +} +} // namespace OHOS::Ace::NG diff --git a/frameworks/core/interfaces/native/ani/ani_theme_module.h b/frameworks/core/interfaces/native/ani/ani_theme_module.h new file mode 100644 index 00000000000..3b4bbe5c751 --- /dev/null +++ b/frameworks/core/interfaces/native/ani/ani_theme_module.h @@ -0,0 +1,40 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef FOUNDATION_ACE_FRAMEWORKS_CORE_INTERFACES_NATIVE_ANI_ANI_THEME_MODULE_H +#define FOUNDATION_ACE_FRAMEWORKS_CORE_INTERFACES_NATIVE_ANI_ANI_THEME_MODULE_H + +#include +#include + +#include "ui/properties/color.h" + +#include "base/utils/device_config.h" + +namespace OHOS::Ace::NG { +class AniThemeModule final { +public: + static void UpdateColorMode(int32_t colorMode); + static void RestoreColorMode(); + +private: + static ColorMode MapAniColorModeToColorMode(int32_t aniColorMode); +#if defined(ANDROID_PLATFORM) || defined(IOS_PLATFORM) + static void UpdateColorModeForThemeConstants(const ColorMode& colorMode); +#endif +}; +} // namespace OHOS::Ace::NG + +#endif diff --git a/frameworks/core/interfaces/native/ani/common_ani_modifier.cpp b/frameworks/core/interfaces/native/ani/common_ani_modifier.cpp index 6e273ab3008..e17991a32f3 100644 --- a/frameworks/core/interfaces/native/ani/common_ani_modifier.cpp +++ b/frameworks/core/interfaces/native/ani/common_ani_modifier.cpp @@ -23,7 +23,12 @@ #include "core/components_ng/base/frame_node.h" #include "core/components_ng/base/view_abstract.h" #include "core/components_ng/pattern/stack/stack_pattern.h" +#include "core/components_ng/token_theme/token_theme_storage.h" +#include "core/interfaces/native/ani/ani_theme.h" +#include "core/interfaces/native/ani/ani_theme_module.h" +#include "core/interfaces/native/ani/resource_ani_modifier.h" #include "core/interfaces/native/implementation/frame_node_peer_impl.h" +#include "core/interfaces/native/node/theme_modifier.h" #include "core/pipeline/base/element_register.h" #include "core/pipeline_ng/pipeline_context.h" #include "bridge/arkts_frontend/ani_graphics_module.h" @@ -31,6 +36,7 @@ #include "bridge/arkts_frontend/ani_context_module.h" #include "core/components/container_modal/container_modal_constants.h" +#include #include #include @@ -45,7 +51,20 @@ constexpr int NUM_5 = 5; constexpr int NUM_6 = 6; constexpr int NUM_7 = 7; constexpr int NUM_8 = 8; + +constexpr uint32_t COLOR_ALPHA_OFFSET = 24; +constexpr uint32_t COLOR_ALPHA_VALUE = 0xFF000000; + +uint32_t ColorAlphaAdapt(uint32_t origin) +{ + uint32_t result = origin; + if ((origin >> COLOR_ALPHA_OFFSET) == 0) { + result = origin | COLOR_ALPHA_VALUE; + } + return result; } +} // namespace + static thread_local std::vector restoreInstanceIds_; ani_ref* GetHostContext() @@ -403,6 +422,77 @@ ani_double Px2lpx(ani_double value, ani_int instanceId) return value / windowConfig.designWidthScale; } +ArkUI_Uint32 GetColorValueByString(const std::string& src) +{ + Color color; + Color::ParseColorString(src, color); + return color.GetValue(); +} + +ArkUI_Uint32 GetColorValueByNumber(ArkUI_Uint32 src) +{ + Color color(ColorAlphaAdapt(src)); + return color.GetValue(); +} + +void SendThemeToNative(ani_env* env, ani_array colorArray, ani_int id) +{ + auto colors = AniThemeColors(); + colors.SetColors(env, colorArray); + + auto themeScopeId = static_cast(id); + AniThemeScope::aniThemes[themeScopeId].SetColors(colors); + // save the current theme when Theme was created by WithTheme container + if (AniThemeScope::isCurrentThemeDefault || themeScopeId > 0) { + std::optional themeOpt = std::make_optional(AniThemeScope::aniThemes[themeScopeId]); + AniThemeScope::aniCurrentTheme.swap(themeOpt); + } +} + +void SetDefaultTheme(ani_env* env, ani_array colorArray, ani_boolean isDark) +{ + auto isDarkValue = static_cast(isDark); + ani_size length; + env->Array_GetLength(colorArray, &length); + if (length < TokenColors::TOTAL_NUMBER) { + LOGW("colorArray incorrect in SetDefaultTheme"); + } + std::vector colors; + auto basisTheme = TokenThemeStorage::GetInstance()->ObtainSystemTheme(); + for (size_t i = 0; i < TokenColors::TOTAL_NUMBER; i++) { + // type ResourceColor = number | string | Resource + ani_ref value; + auto status = env->Array_Get(colorArray, i, &value); + if (status != ANI_OK) { + LOGW("SetDefaultTheme colorArray get index: %{public}d failed", i); + continue; + } + Color color; + bool isColorAvailable = false; + if (!ResourceAniModifier::ParseAniColor(env, static_cast(value), color)) { + if (basisTheme) { + color = basisTheme->Colors()->GetByIndex(i); + isColorAvailable = true; + } + } else { + isColorAvailable = true; + } + colors.push_back(color.GetValue()); + } + NodeModifier::GetThemeModifier()->setDefaultTheme(colors.data(), isDarkValue); +} + +void UpdateColorMode(ani_int colorMode) +{ + auto colorModeValue = static_cast(colorMode); + AniThemeModule::UpdateColorMode(colorModeValue); +} + +void RestoreColorMode() +{ + AniThemeModule::RestoreColorMode(); +} + const ArkUIAniCommonModifier* GetCommonAniModifier() { static const ArkUIAniCommonModifier impl = { @@ -430,8 +520,12 @@ const ArkUIAniCommonModifier* GetCommonAniModifier() .fp2px = OHOS::Ace::NG::Fp2px, .px2fp = OHOS::Ace::NG::Px2fp, .lpx2px = OHOS::Ace::NG::Lpx2px, - .px2lpx = OHOS::Ace::NG::Px2lpx - }; + .px2lpx = OHOS::Ace::NG::Px2lpx, + .getColorValueByNumber = OHOS::Ace::NG::GetColorValueByNumber, + .sendThemeToNative = OHOS::Ace::NG::SendThemeToNative, + .setDefaultTheme = OHOS::Ace::NG::SetDefaultTheme, + .updateColorMode = OHOS::Ace::NG::UpdateColorMode, + .restoreColorMode = OHOS::Ace::NG::RestoreColorMode }; return &impl; } diff --git a/frameworks/core/interfaces/native/ani/resource_ani_modifier.cpp b/frameworks/core/interfaces/native/ani/resource_ani_modifier.cpp new file mode 100644 index 00000000000..870bfb4f899 --- /dev/null +++ b/frameworks/core/interfaces/native/ani/resource_ani_modifier.cpp @@ -0,0 +1,108 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "core/interfaces/native/ani/resource_ani_modifier.h" + +#include + +#include "ani.h" + +#include "base/log/log.h" +#include "base/log/log_wrapper.h" +#include "bridge/arkts_frontend/arkts_ani_utils.h" +#include "core/common/container.h" +#include "core/common/resource/resource_manager.h" +#include "core/common/resource/resource_object.h" + +namespace OHOS::Ace::NG { +namespace { +constexpr uint32_t COLOR_ALPHA_OFFSET = 24; +constexpr uint32_t COLOR_ALPHA_VALUE = 0xFF000000; +uint32_t ColorAlphaAdapt(uint32_t origin) +{ + uint32_t result = origin; + if ((origin >> COLOR_ALPHA_OFFSET) == 0) { + result = origin | COLOR_ALPHA_VALUE; + } + return result; +} +} // namespace +bool ResourceAniModifier::ParseAniColor(ani_env* env, ani_object aniValue, Color& color) +{ + ani_status status; + ani_class stringClass; + if ((status = env->FindClass("Lstd/core/String;", &stringClass)) != ANI_OK) { + LOGW("ParseAniColor find string failed. %{public}d", status); + return false; + } + ani_boolean isString; + if ((status = env->Object_InstanceOf(aniValue, stringClass, &isString)) != ANI_OK) { + LOGW("ParseAniColor call instanceof string failed. %{public}d", status); + return false; + } + if (isString) { + auto srcString = ArktsAniUtils::ANIStringToStdString(env, static_cast(aniValue)); + Color::ParseColorString(srcString, color); + return true; + } + + ani_class doubleClass; + if ((status = env->FindClass("Lstd/core/Double;", &doubleClass)) != ANI_OK) { + LOGW("ParseAniColor find int failed. %{public}d", status); + return false; + } + ani_boolean isDouble; + if ((status = env->Object_InstanceOf(aniValue, doubleClass, &isDouble)) != ANI_OK) { + LOGW("ParseAniColor call instanceof double failed. %{public}d", status); + return false; + } + if (isDouble) { + ani_double doubleSrc; + if ((status = env->Object_CallMethodByName_Double(aniValue, "unboxed", ":d", &doubleSrc)) != ANI_OK) { + LOGW("GetColorValue unboxed double failed. %{public}d", status); + return false; + } + color = Color(ColorAlphaAdapt(static_cast(doubleSrc))); + return true; + } + + ani_class resourceClass; + if ((status = env->FindClass("Lglobal/resource/Resource;", &resourceClass)) != ANI_OK) { + LOGW("ParseAniColor find Resource failed. %{public}d", status); + return false; + } + ani_boolean isResource; + if ((status = env->Object_InstanceOf(aniValue, resourceClass, &isResource)) != ANI_OK) { + LOGW("ParseAniColor call instanceof Resource failed. %{public}d", status); + return false; + } + if (isResource) { + ani_double resId; + env->Object_GetPropertyByName_Double(aniValue, "id", &resId); + ani_ref bundleName; + env->Object_GetPropertyByName_Ref(aniValue, "bundleName", &bundleName); + ani_ref moduleName; + env->Object_GetPropertyByName_Ref(aniValue, "moduleName", &moduleName); + auto resObj = AceType::MakeRefPtr( + ArktsAniUtils::ANIStringToStdString(env, static_cast(bundleName)), + ArktsAniUtils::ANIStringToStdString(env, static_cast(moduleName)), + Container::CurrentIdSafely()); + auto resAdapter = ResourceManager::GetInstance().GetOrCreateResourceAdapter(resObj); + color = resAdapter->GetColor(static_cast(resId)); + return true; + } + return false; +} +} // namespace OHOS::Ace::NG diff --git a/frameworks/core/interfaces/native/ani/resource_ani_modifier.h b/frameworks/core/interfaces/native/ani/resource_ani_modifier.h new file mode 100644 index 00000000000..5343e9ae8c7 --- /dev/null +++ b/frameworks/core/interfaces/native/ani/resource_ani_modifier.h @@ -0,0 +1,31 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef FRAMEWORKS_CORE_INTERFACES_NATIVE_ANI_RESOURCE_ANI_MODIFIER_H +#define FRAMEWORKS_CORE_INTERFACES_NATIVE_ANI_RESOURCE_ANI_MODIFIER_H + +#include "ui/properties/color.h" + +typedef struct __ani_env ani_env; +typedef class __ani_object* ani_object; + +namespace OHOS::Ace::NG { +class ResourceAniModifier final { +public: + static bool ParseAniColor(ani_env* env, ani_object aniValue, Color& color); +}; +} // namespace OHOS::Ace::NG + +#endif -- Gitee From 43efe6582da4d9b27fc6975d1ef97feedb34458a Mon Sep 17 00:00:00 2001 From: fangzhiyuan Date: Sun, 13 Jul 2025 21:58:38 +0800 Subject: [PATCH 02/11] Add withTheme adapter Signed-off-by: fangzhiyuan Change-Id: I6f1af30ff089fd8b246c01315a3937898c4ab2ed --- .../arkui-ohos/src/ComponentBase.ts | 2 +- .../src/ani/arkts/ArkUIAniModule.ts | 10 + .../src/ani/native/common/common_module.cpp | 38 + .../src/ani/native/common/common_module.h | 5 + .../arkui-ohos/src/ani/native/module.cpp | 20 + .../arkts/ArkUIGeneratedNativeModule.ts | 4 + .../peers/CallbackDeserializeCall.ts | 14 +- .../src/component/peers/Deserializer.ts | 2559 +++++++++-------- .../src/component/peers/Serializer.ts | 5 +- .../arkui-ohos/src/component/text.ts | 18 +- .../arkui-ohos/src/component/withTheme.ts | 159 +- .../src/handwritten/theme/ArkThemeBase.ts | 11 +- .../src/handwritten/theme/ArkThemeImpl.ts | 15 +- .../handwritten/theme/ArkThemeNativeHelper.ts | 26 +- .../src/handwritten/theme/ArkThemeScope.ts | 254 ++ .../handwritten/theme/ArkThemeScopeManager.ts | 258 +- .../arkoala-arkts/components.gni | 15 +- .../src/generated/arkoala_api_generated.h | 27 +- .../native/src/generated/bridge_generated.cc | 11 + .../incremental/runtime/src/states/State.ts | 2 + .../ark_theme/theme_apply/js_theme_utils.h | 2 + frameworks/core/interfaces/ani/ani_api.h | 5 + .../core/interfaces/native/ani/ani_theme.cpp | 25 +- .../core/interfaces/native/ani/ani_theme.h | 44 +- .../native/ani/ani_theme_module.cpp | 46 + .../interfaces/native/ani/ani_theme_module.h | 8 + .../native/ani/common_ani_modifier.cpp | 107 +- .../native/ani/resource_ani_modifier.cpp | 7 +- .../native/ani/resource_ani_modifier.h | 4 +- .../interface/arkoala_api_generated.h | 10 + .../generated/interface/node_interface.gni | 2 +- .../native/implementation/all_modifiers.cpp | 2 + .../native/implementation/button_modifier.cpp | 3 + .../implementation/theme/ani_button_theme.h | 103 + .../implementation/theme/ani_theme_utils.h | 45 + .../implementation/with_theme_modifier.cpp | 53 + 36 files changed, 2563 insertions(+), 1356 deletions(-) create mode 100644 frameworks/bridge/arkts_frontend/koala_projects/arkoala-arkts/arkui-ohos/src/handwritten/theme/ArkThemeScope.ts create mode 100644 frameworks/core/interfaces/native/implementation/theme/ani_button_theme.h create mode 100644 frameworks/core/interfaces/native/implementation/theme/ani_theme_utils.h create mode 100644 frameworks/core/interfaces/native/implementation/with_theme_modifier.cpp diff --git a/frameworks/bridge/arkts_frontend/koala_projects/arkoala-arkts/arkui-ohos/src/ComponentBase.ts b/frameworks/bridge/arkts_frontend/koala_projects/arkoala-arkts/arkui-ohos/src/ComponentBase.ts index e37cfa7f769..c0774b106da 100644 --- a/frameworks/bridge/arkts_frontend/koala_projects/arkoala-arkts/arkui-ohos/src/ComponentBase.ts +++ b/frameworks/bridge/arkts_frontend/koala_projects/arkoala-arkts/arkui-ohos/src/ComponentBase.ts @@ -21,7 +21,7 @@ import { unsafeCast } from "@koalaui/common" export class ComponentBase { protected peer?: PeerNode - protected isFirstBuild: boolean = true + public isFirstBuild: boolean = true protected gestureEvent: UIGestureEvent | undefined = undefined setPeer(peer: PeerNode) { this.peer = peer diff --git a/frameworks/bridge/arkts_frontend/koala_projects/arkoala-arkts/arkui-ohos/src/ani/arkts/ArkUIAniModule.ts b/frameworks/bridge/arkts_frontend/koala_projects/arkoala-arkts/arkui-ohos/src/ani/arkts/ArkUIAniModule.ts index c12ad6a6a4d..a10edd8bb78 100644 --- a/frameworks/bridge/arkts_frontend/koala_projects/arkoala-arkts/arkui-ohos/src/ani/arkts/ArkUIAniModule.ts +++ b/frameworks/bridge/arkts_frontend/koala_projects/arkoala-arkts/arkui-ohos/src/ani/arkts/ArkUIAniModule.ts @@ -247,7 +247,17 @@ export class ArkUIAniModule { native static _GetColorValue(color: number | string): KUInt native static _SendThemeToNative(colorArray: ResourceColor[], elmtId: KInt): void + native static _RemoveThemeInNative(withThemeId: number): void native static _SetDefaultTheme(colorArray: ResourceColor[], isDark: boolean): void native static _UpdateColorMode(colorMode: KInt): void native static _RestoreColorMode(): void + native static _SetThemeScopeId(themeScopeId: number): void + native static _CreateAndBindTheme( + themeScopeId: KInt, + themeId: KInt, + colors: ResourceColor[], + colorMode: KInt, + onThemeScopeDestroy: () => void + ): void; + native static _ApplyParentThemeScopeId(self: KPointer, parent: KPointer): void } diff --git a/frameworks/bridge/arkts_frontend/koala_projects/arkoala-arkts/arkui-ohos/src/ani/native/common/common_module.cpp b/frameworks/bridge/arkts_frontend/koala_projects/arkoala-arkts/arkui-ohos/src/ani/native/common/common_module.cpp index 9601da64edd..04e9eaf5684 100644 --- a/frameworks/bridge/arkts_frontend/koala_projects/arkoala-arkts/arkui-ohos/src/ani/native/common/common_module.cpp +++ b/frameworks/bridge/arkts_frontend/koala_projects/arkoala-arkts/arkui-ohos/src/ani/native/common/common_module.cpp @@ -544,6 +544,15 @@ void SendThemeToNative(ani_env* env, ani_object aniClass, ani_array colorArray, modifier->getCommonAniModifier()->sendThemeToNative(env, colorArray, id); } +void RemoveThemeInNative(ani_env* env, ani_object aniClass, ani_int withThemeId) +{ + const auto* modifier = GetNodeAniModifier(); + if (!modifier) { + return; + } + modifier->getCommonAniModifier()->removeThemeInNative(env, withThemeId); +} + void SetDefaultTheme(ani_env* env, ani_object aniClass, ani_array colorArray, ani_boolean isDark) { const auto* modifier = GetNodeAniModifier(); @@ -570,4 +579,33 @@ void RestoreColorMode(ani_env* env, ani_object aniClass) } modifier->getCommonAniModifier()->restoreColorMode(); } + +void SetThemeScopeId(ani_env* env, ani_object aniClass, ani_int themeScopeId) +{ + const auto* modifier = GetNodeAniModifier(); + if (!modifier) { + return; + } + modifier->getCommonAniModifier()->setThemeScopeId(env, themeScopeId); +} + +void CreateAndBindTheme(ani_env* env, ani_object aniClass, ani_int themeScopeId, ani_int themeId, ani_array colors, + ani_int colorMode, ani_fn_object onThemeScopeDestroy) +{ + const auto* modifier = GetNodeAniModifier(); + if (!modifier) { + return; + } + modifier->getCommonAniModifier()->createAndBindTheme( + env, themeScopeId, themeId, colors, colorMode, onThemeScopeDestroy); +} + +void ApplyParentThemeScopeId(ani_env* env, ani_object aniClass, ani_long self, ani_long parent) +{ + const auto* modifier = GetNodeAniModifier(); + if (!modifier) { + return; + } + modifier->getCommonAniModifier()->applyParentThemeScopeId(env, self, parent); +} } // namespace OHOS::Ace::Ani diff --git a/frameworks/bridge/arkts_frontend/koala_projects/arkoala-arkts/arkui-ohos/src/ani/native/common/common_module.h b/frameworks/bridge/arkts_frontend/koala_projects/arkoala-arkts/arkui-ohos/src/ani/native/common/common_module.h index e3aa2acdc89..6c5e3222905 100644 --- a/frameworks/bridge/arkts_frontend/koala_projects/arkoala-arkts/arkui-ohos/src/ani/native/common/common_module.h +++ b/frameworks/bridge/arkts_frontend/koala_projects/arkoala-arkts/arkui-ohos/src/ani/native/common/common_module.h @@ -54,9 +54,14 @@ ani_double Lpx2px(ani_env* env, ani_object obj, ani_double value, ani_int instan ani_double Px2lpx(ani_env* env, ani_object obj, ani_double value, ani_int instanceId); ani_int GetColorValue(ani_env* env, ani_object aniClass, ani_object src); void SendThemeToNative(ani_env* env, ani_object aniClass, ani_array colorArray, ani_int id); +void RemoveThemeInNative(ani_env* env, ani_object aniClass, ani_int withThemeId); void SetDefaultTheme(ani_env* env, ani_object aniClass, ani_array colorArray, ani_boolean isDark); void UpdateColorMode(ani_env* env, ani_object aniClass, ani_int colorMode); void RestoreColorMode(ani_env* env, ani_object aniClass); +void SetThemeScopeId(ani_env* env, ani_object aniClass, ani_int themeScopeId); +void CreateAndBindTheme(ani_env* env, ani_object aniClass, ani_int themeScopeId, ani_int themeId, ani_array colors, + ani_int colorMode, ani_fn_object onThemeScopeDestroy); +void ApplyParentThemeScopeId(ani_env* env, ani_object aniClass, ani_long self, ani_long parent); } // namespace OHOS::Ace::Ani #endif // KOALA_PROJECTS_ARKOALA_ARKTS_ARKUI_OHOS_ANI_NATIVE_COMMON_MODULE diff --git a/frameworks/bridge/arkts_frontend/koala_projects/arkoala-arkts/arkui-ohos/src/ani/native/module.cpp b/frameworks/bridge/arkts_frontend/koala_projects/arkoala-arkts/arkui-ohos/src/ani/native/module.cpp index ec9a9abf6dc..d29c3659f76 100644 --- a/frameworks/bridge/arkts_frontend/koala_projects/arkoala-arkts/arkui-ohos/src/ani/native/module.cpp +++ b/frameworks/bridge/arkts_frontend/koala_projects/arkoala-arkts/arkui-ohos/src/ani/native/module.cpp @@ -836,6 +836,11 @@ ANI_EXPORT ani_status ANI_Constructor(ani_vm* vm, uint32_t* result) nullptr, reinterpret_cast(OHOS::Ace::Ani::SendThemeToNative) }, + ani_native_function { + "_RemoveThemeInNative", + nullptr, + reinterpret_cast(OHOS::Ace::Ani::RemoveThemeInNative) + }, ani_native_function { "_SetDefaultTheme", nullptr, @@ -851,6 +856,21 @@ ANI_EXPORT ani_status ANI_Constructor(ani_vm* vm, uint32_t* result) nullptr, reinterpret_cast(OHOS::Ace::Ani::RestoreColorMode) }, + ani_native_function { + "_SetThemeScopeId", + nullptr, + reinterpret_cast(OHOS::Ace::Ani::SetThemeScopeId) + }, + ani_native_function { + "_CreateAndBindTheme", + nullptr, + reinterpret_cast(OHOS::Ace::Ani::CreateAndBindTheme) + }, + ani_native_function { + "_ApplyParentThemeScopeId", + nullptr, + reinterpret_cast(OHOS::Ace::Ani::ApplyParentThemeScopeId) + }, }; auto bindRst = env->Class_BindNativeMethods(cls, methods.data(), methods.size()); diff --git a/frameworks/bridge/arkts_frontend/koala_projects/arkoala-arkts/arkui-ohos/src/component/arkts/ArkUIGeneratedNativeModule.ts b/frameworks/bridge/arkts_frontend/koala_projects/arkoala-arkts/arkui-ohos/src/component/arkts/ArkUIGeneratedNativeModule.ts index b6446d0effb..e7f262e18f4 100644 --- a/frameworks/bridge/arkts_frontend/koala_projects/arkoala-arkts/arkui-ohos/src/component/arkts/ArkUIGeneratedNativeModule.ts +++ b/frameworks/bridge/arkts_frontend/koala_projects/arkoala-arkts/arkui-ohos/src/component/arkts/ArkUIGeneratedNativeModule.ts @@ -3590,6 +3590,10 @@ export class ArkUIGeneratedNativeModule { @ani.unsafe.Direct native static _WindowSceneAttribute_attractionEffect(ptr: KPointer, thisArray: KSerializerBuffer, thisLength: int32): void @ani.unsafe.Direct + native static _WithTheme_construct(id: KInt, flags: KInt): KPointer + @ani.unsafe.Direct + native static _WithThemeInterface_setWithThemeOptions(ptr: KPointer, thisArray: KSerializerBuffer, thisLength: int32): void + @ani.unsafe.Direct native static _XComponent_construct(id: KInt, flags: KInt): KPointer @ani.unsafe.Direct native static _XComponentInterface_setXComponentOptions0(ptr: KPointer, thisArray: KSerializerBuffer, thisLength: int32): void diff --git a/frameworks/bridge/arkts_frontend/koala_projects/arkoala-arkts/arkui-ohos/src/component/peers/CallbackDeserializeCall.ts b/frameworks/bridge/arkts_frontend/koala_projects/arkoala-arkts/arkui-ohos/src/component/peers/CallbackDeserializeCall.ts index 302b7d1d4ba..9ff343fe795 100644 --- a/frameworks/bridge/arkts_frontend/koala_projects/arkoala-arkts/arkui-ohos/src/component/peers/CallbackDeserializeCall.ts +++ b/frameworks/bridge/arkts_frontend/koala_projects/arkoala-arkts/arkui-ohos/src/component/peers/CallbackDeserializeCall.ts @@ -70,7 +70,7 @@ import { Callback_SwiperContentTransitionProxy_Void, SwiperContentTransitionProx import { Callback_TerminationInfo_Void, TerminationInfo } from "./../embeddedComponent" import { Callback_TimePickerResult_Void, TimePickerResult, OnTimePickerChangeCallback } from "./../timePicker" import { ImageOnCompleteCallback, ImageCompleteEvent, ImageErrorCallback, ImageError } from "./../image" -import { WithThemeAttribute, WithThemeInterface, WithThemeOptions } from "./../withTheme" +import { WithThemeAttribute, WithThemeOptions } from "./../withTheme" import { Callback_WrappedBuilder_Args_Void, CommonConfiguration } from "./../arkui-wrapper-builder" import { CheckedCallback } from "./../radioops" import { CustomNodeBuilder } from "./../customBuilder" @@ -2739,12 +2739,12 @@ export function deserializeAndCallWebKeyboardCallback(thisDeserializer: Deserial _continuation(_callResult) } export function deserializeAndCallWithThemeInterface(thisDeserializer: Deserializer): void { - const _resourceId : int32 = thisDeserializer.readInt32() - const _call = (ResourceHolder.instance().get(_resourceId) as WithThemeInterface) - let options : WithThemeOptions = thisDeserializer.readWithThemeOptions() - let _continuation : ((value: WithThemeAttribute) => void) = thisDeserializer.readCallback_WithThemeAttribute_Void(true) - const _callResult = _call(options) - _continuation(_callResult) + // const _resourceId : int32 = thisDeserializer.readInt32() + // const _call = (ResourceHolder.instance().get(_resourceId) as WithThemeInterface) + // let options : WithThemeOptions = thisDeserializer.readWithThemeOptions() + // let _continuation : ((value: WithThemeAttribute) => void) = thisDeserializer.readCallback_WithThemeAttribute_Void(true) + // const _callResult = _call(options) + // _continuation(_callResult) } export function deserializeAndCallCallback_String_SurfaceRect_Void(thisDeserializer: Deserializer): void { const _resourceId : int32 = thisDeserializer.readInt32() diff --git a/frameworks/bridge/arkts_frontend/koala_projects/arkoala-arkts/arkui-ohos/src/component/peers/Deserializer.ts b/frameworks/bridge/arkts_frontend/koala_projects/arkoala-arkts/arkui-ohos/src/component/peers/Deserializer.ts index bf011f12e90..0d1f7fc8ab3 100644 --- a/frameworks/bridge/arkts_frontend/koala_projects/arkoala-arkts/arkui-ohos/src/component/peers/Deserializer.ts +++ b/frameworks/bridge/arkts_frontend/koala_projects/arkoala-arkts/arkui-ohos/src/component/peers/Deserializer.ts @@ -25,8 +25,9 @@ import { CallbackTransformer } from "./CallbackTransformer" import { AccessibilityCallback, AccessibilityFocusCallback, GestureRecognizerJudgeBeginCallback, HoverCallback, OnDragEventCallback, OnMoveHandler, OnScrollCallback, PopupStateChangeCallback, ReuseIdCallback, ShouldBuiltInRecognizerParallelWithCallback, SizeChangeCallback, TransitionFinishCallback, VisibleAreaChangeCallback, AccessibilityHoverEvent, AccessibilityHoverEventInternal, AccessibilityRoleType, AccessibilitySamePageMode, AdaptiveColor, CommonMethod, BlurStyle, BlendApplyType, BlurStyleActivePolicy, PickerTextStyle, ChainStyle, ContentClipMode, DismissReason, DragBehavior, DragEvent, DragEventInternal, DragResult, Rectangle, DraggingSizeChangeEffect, DragPreviewMode, DrawModifier, EffectEdge, EffectType, FinishCallbackType, GestureModifier, GestureModifierInternal, UIGestureEvent, ScrollableCommonMethod, ItemDragInfo, CustomBuilder, NestedScrollOptions, EdgeEffectOptions, HapticFeedbackMode, HoverModeAreaType, ICurve, ICurveInternal, KeyboardAvoidMode, LayoutPolicy, LayoutSafeAreaEdge, LayoutSafeAreaType, ChildrenMainSize, ChildrenMainSizeInternal, RectResult, MenuPolicy, MenuPreviewMode, ModalTransition, OutlineStyle, PixelMapMock, PixelMapMockInternal, PopupStateChangeParam, PreDragStatus, ProgressMask, ProgressMaskInternal, RepeatMode, SelectionOptions, SafeAreaEdge, SafeAreaType, ScrollSizeMode, TextDecorationOptions, TextContentControllerBase, TextContentControllerBaseInternal, ShadowStyle, ShadowType, SheetKeyboardAvoidMode, SheetMode, SheetSize, SheetType, SourceTool, SourceType, BackgroundEffectOptions, BackgroundBlurStyleOptions, TranslateOptions, InputCounterOptions, ShadowOptions, CaretOffset, TextContentControllerOptions, ThemeColorMode, TouchTestInfo, TouchTestStrategy, TransitionEdge, TransitionEffect, TransitionEffectInternal, TransitionEffects, RotateOptions, ScaleOptions, AnimateParam, TransitionHierarchyStrategy, UICommonEvent, UICommonEventInternal, Callback_ClickEvent_Void, ClickEvent, ClickEventInternal, Callback_TouchEvent_Void, TouchEvent, TouchEventInternal, Callback_KeyEvent_Void, KeyEvent, KeyEventInternal, HoverEvent, HoverEventInternal, Callback_MouseEvent_Void, MouseEvent, MouseEventInternal, VisibleAreaEventOptions, SheetOptions, View, ViewInternal, Callback_KeyEvent_Boolean, Callback_Area_Area_Void, Callback_Array_TouchTestInfo_TouchResult, TouchResult, Callback_AxisEvent_Void, AxisEvent, AxisEventInternal, Callback_Boolean_HoverEvent_Void, Callback_CrownEvent_Void, CrownEvent, Callback_DismissContentCoverAction_Void, DismissContentCoverAction, Callback_DismissPopupAction_Void, DismissPopupAction, Callback_DismissSheetAction_Void, DismissSheetAction, Callback_DragEvent_String_Union_CustomBuilder_DragItemInfo, DragItemInfo, Callback_DragEvent_String_Void, Callback_FocusAxisEvent_Void, FocusAxisEvent, FocusAxisEventInternal, Callback_GestureInfo_BaseGestureEvent_GestureJudgeResult, Callback_HoverEvent_Void, Callback_Literal_Boolean_isVisible_Void, Literal_Boolean_isVisible, Callback_PreDragStatus_Void, Callback_SheetDismiss_Void, SheetDismiss, Callback_SheetType_Void, Callback_SpringBackAction_Void, SpringBackAction, Callback_TouchEvent_HitTestMode, BackgroundBrightnessOptions, BackgroundImageOptions, BlurOptions, ClickEffect, DateRange, DragInteractionOptions, DropOptions, ExpectedFrameRateRange, FocusMovement, ForegroundEffectOptions, GeometryTransitionOptions, InvertOptions, LinearGradient_common, Tuple_ResourceColor_Number, LinearGradientBlurOptions, FractionStop, LinearGradientOptions, LocalizedHorizontalAlignParam, LocalizedVerticalAlignParam, Measurable, MeasurableInternal, MeasureResult, SizeResult, MotionBlurAnchor, MotionBlurOptions, MotionPathOptions, OverlayOffset, PixelRoundPolicy, PixelStretchEffectOptions, PreviewConfiguration, RadialGradientOptions, Tuple_Length_Length, StateStyles, SweepGradientOptions, SystemAdaptiveOptions, TipsOptions, TouchObject, AlignRuleOption, HorizontalAlignOptions, VerticalAlignOptions, BlurStyleOptions, ContentCoverOptions, BindOptions, ContextMenuAnimationOptions, MultiShadowOptions, DragPreviewOptions, EventTarget, FadingEdgeOptions, BaseEvent, BaseEventInternal, ForegroundBlurStyleOptions, HistoricalPoint, LightSource, LocalizedAlignRuleOptions, MenuElement, OverlayOptions, PickerDialogButtonStyle, ReuseOptions, sharedTransitionOptions, SheetTitleOptions, TransitionOptions, BorderImageOption, CustomPopupOptions, Literal_ResourceColor_color, PointLightStyle, PopupMessageOptions, Type_SheetOptions_detents, ContextMenuOptions, BorderRadiusType, MenuOptions, PopupOptions, PopupButton, OnWillScrollCallback, ScrollResult, PopupMaskType, SelectedCallback, IndexCallback, IndexerSelectedCallback, RefreshingCallback, DividerStyle, BlendMode, PopupCommonOptions, DismissPopupActionInternal, ContentModifier } from "./../common" import { ButtonTriggerClickCallback, ButtonRole, ButtonStyleMode, ButtonType, ControlSize, ButtonOptions, ButtonConfiguration } from "./../button" import { Callback_Extender_OnFinish, Callback_Extender_OnProgress, DoubleAnimationParam } from "./../animationExtender" -import { Callback_RangeUpdate, Context_getGroupDir_Callback, RestrictedWorker_onerror_Callback, RestrictedWorker_onexit_Callback, RestrictedWorker_onmessage_Callback, BuilderNodeOps, BuilderNodeOpsInternal, BuilderNodeOptions, ComponentContent, ComponentContentInternal, UnifiedData, UnifiedDataInternal, SystemBarStyle, Scene, SceneInternal, Context, ContextInternal, WorkerEventListener, WorkerEventListenerInternal, Event, ErrorEvent, MessageEvents, BaseContext, BaseContextInternal, PostMessageOptions, WorkerOptions, CustomColors, RestrictedWorker, RestrictedWorkerInternal, CustomTheme, Callback_CreateItem, LengthMetricsCustom } from "./../arkui-custom" +import { Callback_RangeUpdate, Context_getGroupDir_Callback, RestrictedWorker_onerror_Callback, RestrictedWorker_onexit_Callback, RestrictedWorker_onmessage_Callback, BuilderNodeOps, BuilderNodeOpsInternal, BuilderNodeOptions, ComponentContent, ComponentContentInternal, UnifiedData, UnifiedDataInternal, SystemBarStyle, Scene, SceneInternal, Context, ContextInternal, WorkerEventListener, WorkerEventListenerInternal, Event, ErrorEvent, MessageEvents, BaseContext, BaseContextInternal, PostMessageOptions, WorkerOptions, RestrictedWorker, RestrictedWorkerInternal, Callback_CreateItem, LengthMetricsCustom } from "./../arkui-custom" import { UIContext, TargetInfo } from "@ohos/arkui/UIContext" +import { CustomTheme, CustomColors } from '@ohos/arkui/theme'; import { ContentDidScrollCallback, ContentWillScrollCallback, OnSwiperAnimationEndCallback, OnSwiperAnimationStartCallback, OnSwiperGestureSwipeCallback, SwiperAnimationEvent, SwiperAnimationMode, SwiperAttribute, DotIndicator, DigitIndicator, SwiperDisplayMode, SwiperNestedScrollMode, SwiperContentAnimatedTransition, SwiperContentWillScrollResult, AutoPlayOptions, ArrowStyle, SwiperAutoFill, SwiperContentTransitionProxy, SwiperContentTransitionProxyInternal, SwiperController, SwiperControllerInternal, Callback_SwiperContentTransitionProxy_Void, Indicator } from "./../swiper" import { CustomNodeBuilder } from "./../customBuilder" import { DatePickerSelectedCallback } from "./../datepickerselectedops" @@ -90,7 +91,7 @@ import { TextPickerSelectedCallback } from "./../textpickerselectedops" import { TextPickerValueCallback } from "./../textpickervalueops" import { TimePickerSelectedCallback } from "./../timepickerselectedops" import { VoidCallback, ResourceColor, Font, Position, Length, SizeOptions, Offset, ColorFilter, ColorFilterInternal, ResourceStr, Dimension, PX, VP, FP, LPX, Percentage, LengthConstrain, DividerStyleOptions, ConstraintSizeOptions, Area, AccessibilityOptions, Bias, BorderRadiuses, ChainWeightOptions, DirectionalEdgesT, EdgeOutlineStyles, EdgeOutlineWidths, EdgeWidths, OutlineRadiuses, Padding, EdgeColors, LocalizedBorderRadiuses, LocalizedEdgeColors, LocalizedEdges, LocalizedEdgeWidths, LocalizedPadding, LocalizedPosition, MarkStyle, BorderOptions, OutlineOptions, EdgeStyles, Edges } from "./../units" -import { WithThemeInterface, WithThemeAttribute, WithThemeOptions } from "./../withTheme" +import { WithThemeAttribute, WithThemeOptions } from "./../withTheme" import { AccessibilityHoverType, Alignment, Color, AnimationStatus, AppRotation, ArrowPointPosition, Axis, AxisAction, AxisModel, BarState, BorderStyle, CheckBoxShape, ClickEffectLevel, ColoringStrategy, CopyOptions, CrownAction, CrownSensitivity, Curve, DialogButtonStyle, Direction, DividerMode, Edge, EdgeEffect, EllipsisMode, EmbeddedType, FillMode, FlexAlign, FlexDirection, FlexWrap, FocusDrawLevel, FoldStatus, FontStyle, FontWeight, FunctionKey, GradientDirection, HeightBreakpoint, HitTestMode, HorizontalAlign, HoverEffect, IlluminatedType, ImageFit, ImageRepeat, ImageSize, ImageSpanAlignment, InteractionHand, ItemAlign, KeySource, KeyType, LineBreakStrategy, LineCapStyle, LineJoinStyle, MarqueeUpdateStrategy, ModifierKey, MouseAction, MouseButton, NestedScrollMode, ObscuredReasons, OptionWidthMode, PageFlipMode, PixelRoundCalcPolicy, PixelRoundMode, Placement, PlayMode, RelateType, RenderFit, ResponseType, ScrollSource, TextAlign, SharedTransitionEffectType, TextOverflow, TextContentStyle, TextHeightAdaptivePolicy, WordBreak, TextCase, TextSelectableMode, TextDecorationStyle, TextDecorationType, TitleHeight, TouchType, TransitionType, VerticalAlign, Visibility, Week, WidthBreakpoint, XComponentType } from "./../enums" import { Affinity, LineMetrics, TextBox, RunMetrics, TextDirection } from "./../arkui-graphics-text" import { Resource } from "global.resource" @@ -6391,23 +6392,23 @@ export class Deserializer extends DeserializerBase { _argsSerializer.release(); return (_continuationValue as WebKeyboardOptions); } } - readWithThemeInterface(isSync: boolean = false): WithThemeInterface { - const _resource : CallbackResource = this.readCallbackResource() - const _call : KPointer = this.readPointer() - const _callSync : KPointer = this.readPointer() - return (options: WithThemeOptions):WithThemeAttribute => { - const _argsSerializer : Serializer = Serializer.hold(); - _argsSerializer.writeInt32(_resource.resourceId); - _argsSerializer.writePointer(_call); - _argsSerializer.writePointer(_callSync); - _argsSerializer.writeWithThemeOptions(options); - let _continuationValue : WithThemeAttribute | undefined; - const _continuationCallback : ((value: WithThemeAttribute) => void) = (value: WithThemeAttribute):void => { _continuationValue = value; } - _argsSerializer.holdAndWriteCallback(_continuationCallback); - (isSync) ? (InteropNativeModule._CallCallbackSync(219587748, _argsSerializer.asBuffer(), _argsSerializer.length())) : (InteropNativeModule._CallCallback(219587748, _argsSerializer.asBuffer(), _argsSerializer.length())); - _argsSerializer.release(); - return (_continuationValue as WithThemeAttribute); } - } + // readWithThemeInterface(isSync: boolean = false): WithThemeInterface { + // const _resource : CallbackResource = this.readCallbackResource() + // const _call : KPointer = this.readPointer() + // const _callSync : KPointer = this.readPointer() + // return (options: WithThemeOptions):WithThemeAttribute => { + // const _argsSerializer : Serializer = Serializer.hold(); + // _argsSerializer.writeInt32(_resource.resourceId); + // _argsSerializer.writePointer(_call); + // _argsSerializer.writePointer(_callSync); + // _argsSerializer.writeWithThemeOptions(options); + // let _continuationValue : WithThemeAttribute | undefined; + // const _continuationCallback : ((value: WithThemeAttribute) => void) = (value: WithThemeAttribute):void => { _continuationValue = value; } + // _argsSerializer.holdAndWriteCallback(_continuationCallback); + // (isSync) ? (InteropNativeModule._CallCallbackSync(219587748, _argsSerializer.asBuffer(), _argsSerializer.length())) : (InteropNativeModule._CallCallback(219587748, _argsSerializer.asBuffer(), _argsSerializer.length())); + // _argsSerializer.release(); + // return (_continuationValue as WithThemeAttribute); } + // } readAccessibilityOptions(): AccessibilityOptions { let valueDeserializer : Deserializer = this const accessibilityPreferred_buf_runtimeType = (valueDeserializer.readInt8() as int32) @@ -14481,1235 +14482,1235 @@ export class Deserializer extends DeserializerBase { let value : CurrentDayStyle = ({dayColor: dayColor_result, lunarColor: lunarColor_result, markLunarColor: markLunarColor_result, dayFontSize: dayFontSize_result, lunarDayFontSize: lunarDayFontSize_result, dayHeight: dayHeight_result, dayWidth: dayWidth_result, gregorianCalendarHeight: gregorianCalendarHeight_result, dayYAxisOffset: dayYAxisOffset_result, lunarDayYAxisOffset: lunarDayYAxisOffset_result, underscoreXAxisOffset: underscoreXAxisOffset_result, underscoreYAxisOffset: underscoreYAxisOffset_result, scheduleMarkerXAxisOffset: scheduleMarkerXAxisOffset_result, scheduleMarkerYAxisOffset: scheduleMarkerYAxisOffset_result, colSpace: colSpace_result, dailyFiveRowSpace: dailyFiveRowSpace_result, dailySixRowSpace: dailySixRowSpace_result, lunarHeight: lunarHeight_result, underscoreWidth: underscoreWidth_result, underscoreLength: underscoreLength_result, scheduleMarkerRadius: scheduleMarkerRadius_result, boundaryRowOffset: boundaryRowOffset_result, boundaryColOffset: boundaryColOffset_result} as CurrentDayStyle) return value } - readCustomColors(): CustomColors { - let valueDeserializer : Deserializer = this - const brand_buf_runtimeType = (valueDeserializer.readInt8() as int32) - let brand_buf : ResourceColor | undefined - if ((RuntimeType.UNDEFINED) != (brand_buf_runtimeType)) - { - const brand_buf__selector : int32 = valueDeserializer.readInt8() - let brand_buf_ : Color | number | string | Resource | undefined - if (brand_buf__selector == 0) { - brand_buf_ = TypeChecker.Color_FromNumeric(valueDeserializer.readInt32()) - } - else if (brand_buf__selector == 1) { - brand_buf_ = (valueDeserializer.readNumber() as number) - } - else if (brand_buf__selector == 2) { - brand_buf_ = (valueDeserializer.readString() as string) - } - else if (brand_buf__selector == 3) { - brand_buf_ = valueDeserializer.readResource() - } - else { - throw new Error("One of the branches for brand_buf_ has to be chosen through deserialisation.") - } - brand_buf = (brand_buf_ as Color | number | string | Resource) - } - const brand_result : ResourceColor | undefined = brand_buf - const warning_buf_runtimeType = (valueDeserializer.readInt8() as int32) - let warning_buf : ResourceColor | undefined - if ((RuntimeType.UNDEFINED) != (warning_buf_runtimeType)) - { - const warning_buf__selector : int32 = valueDeserializer.readInt8() - let warning_buf_ : Color | number | string | Resource | undefined - if (warning_buf__selector == 0) { - warning_buf_ = TypeChecker.Color_FromNumeric(valueDeserializer.readInt32()) - } - else if (warning_buf__selector == 1) { - warning_buf_ = (valueDeserializer.readNumber() as number) - } - else if (warning_buf__selector == 2) { - warning_buf_ = (valueDeserializer.readString() as string) - } - else if (warning_buf__selector == 3) { - warning_buf_ = valueDeserializer.readResource() - } - else { - throw new Error("One of the branches for warning_buf_ has to be chosen through deserialisation.") - } - warning_buf = (warning_buf_ as Color | number | string | Resource) - } - const warning_result : ResourceColor | undefined = warning_buf - const alert_buf_runtimeType = (valueDeserializer.readInt8() as int32) - let alert_buf : ResourceColor | undefined - if ((RuntimeType.UNDEFINED) != (alert_buf_runtimeType)) - { - const alert_buf__selector : int32 = valueDeserializer.readInt8() - let alert_buf_ : Color | number | string | Resource | undefined - if (alert_buf__selector == 0) { - alert_buf_ = TypeChecker.Color_FromNumeric(valueDeserializer.readInt32()) - } - else if (alert_buf__selector == 1) { - alert_buf_ = (valueDeserializer.readNumber() as number) - } - else if (alert_buf__selector == 2) { - alert_buf_ = (valueDeserializer.readString() as string) - } - else if (alert_buf__selector == 3) { - alert_buf_ = valueDeserializer.readResource() - } - else { - throw new Error("One of the branches for alert_buf_ has to be chosen through deserialisation.") - } - alert_buf = (alert_buf_ as Color | number | string | Resource) - } - const alert_result : ResourceColor | undefined = alert_buf - const confirm_buf_runtimeType = (valueDeserializer.readInt8() as int32) - let confirm_buf : ResourceColor | undefined - if ((RuntimeType.UNDEFINED) != (confirm_buf_runtimeType)) - { - const confirm_buf__selector : int32 = valueDeserializer.readInt8() - let confirm_buf_ : Color | number | string | Resource | undefined - if (confirm_buf__selector == 0) { - confirm_buf_ = TypeChecker.Color_FromNumeric(valueDeserializer.readInt32()) - } - else if (confirm_buf__selector == 1) { - confirm_buf_ = (valueDeserializer.readNumber() as number) - } - else if (confirm_buf__selector == 2) { - confirm_buf_ = (valueDeserializer.readString() as string) - } - else if (confirm_buf__selector == 3) { - confirm_buf_ = valueDeserializer.readResource() - } - else { - throw new Error("One of the branches for confirm_buf_ has to be chosen through deserialisation.") - } - confirm_buf = (confirm_buf_ as Color | number | string | Resource) - } - const confirm_result : ResourceColor | undefined = confirm_buf - const fontPrimary_buf_runtimeType = (valueDeserializer.readInt8() as int32) - let fontPrimary_buf : ResourceColor | undefined - if ((RuntimeType.UNDEFINED) != (fontPrimary_buf_runtimeType)) - { - const fontPrimary_buf__selector : int32 = valueDeserializer.readInt8() - let fontPrimary_buf_ : Color | number | string | Resource | undefined - if (fontPrimary_buf__selector == 0) { - fontPrimary_buf_ = TypeChecker.Color_FromNumeric(valueDeserializer.readInt32()) - } - else if (fontPrimary_buf__selector == 1) { - fontPrimary_buf_ = (valueDeserializer.readNumber() as number) - } - else if (fontPrimary_buf__selector == 2) { - fontPrimary_buf_ = (valueDeserializer.readString() as string) - } - else if (fontPrimary_buf__selector == 3) { - fontPrimary_buf_ = valueDeserializer.readResource() - } - else { - throw new Error("One of the branches for fontPrimary_buf_ has to be chosen through deserialisation.") - } - fontPrimary_buf = (fontPrimary_buf_ as Color | number | string | Resource) - } - const fontPrimary_result : ResourceColor | undefined = fontPrimary_buf - const fontSecondary_buf_runtimeType = (valueDeserializer.readInt8() as int32) - let fontSecondary_buf : ResourceColor | undefined - if ((RuntimeType.UNDEFINED) != (fontSecondary_buf_runtimeType)) - { - const fontSecondary_buf__selector : int32 = valueDeserializer.readInt8() - let fontSecondary_buf_ : Color | number | string | Resource | undefined - if (fontSecondary_buf__selector == 0) { - fontSecondary_buf_ = TypeChecker.Color_FromNumeric(valueDeserializer.readInt32()) - } - else if (fontSecondary_buf__selector == 1) { - fontSecondary_buf_ = (valueDeserializer.readNumber() as number) - } - else if (fontSecondary_buf__selector == 2) { - fontSecondary_buf_ = (valueDeserializer.readString() as string) - } - else if (fontSecondary_buf__selector == 3) { - fontSecondary_buf_ = valueDeserializer.readResource() - } - else { - throw new Error("One of the branches for fontSecondary_buf_ has to be chosen through deserialisation.") - } - fontSecondary_buf = (fontSecondary_buf_ as Color | number | string | Resource) - } - const fontSecondary_result : ResourceColor | undefined = fontSecondary_buf - const fontTertiary_buf_runtimeType = (valueDeserializer.readInt8() as int32) - let fontTertiary_buf : ResourceColor | undefined - if ((RuntimeType.UNDEFINED) != (fontTertiary_buf_runtimeType)) - { - const fontTertiary_buf__selector : int32 = valueDeserializer.readInt8() - let fontTertiary_buf_ : Color | number | string | Resource | undefined - if (fontTertiary_buf__selector == 0) { - fontTertiary_buf_ = TypeChecker.Color_FromNumeric(valueDeserializer.readInt32()) - } - else if (fontTertiary_buf__selector == 1) { - fontTertiary_buf_ = (valueDeserializer.readNumber() as number) - } - else if (fontTertiary_buf__selector == 2) { - fontTertiary_buf_ = (valueDeserializer.readString() as string) - } - else if (fontTertiary_buf__selector == 3) { - fontTertiary_buf_ = valueDeserializer.readResource() - } - else { - throw new Error("One of the branches for fontTertiary_buf_ has to be chosen through deserialisation.") - } - fontTertiary_buf = (fontTertiary_buf_ as Color | number | string | Resource) - } - const fontTertiary_result : ResourceColor | undefined = fontTertiary_buf - const fontFourth_buf_runtimeType = (valueDeserializer.readInt8() as int32) - let fontFourth_buf : ResourceColor | undefined - if ((RuntimeType.UNDEFINED) != (fontFourth_buf_runtimeType)) - { - const fontFourth_buf__selector : int32 = valueDeserializer.readInt8() - let fontFourth_buf_ : Color | number | string | Resource | undefined - if (fontFourth_buf__selector == 0) { - fontFourth_buf_ = TypeChecker.Color_FromNumeric(valueDeserializer.readInt32()) - } - else if (fontFourth_buf__selector == 1) { - fontFourth_buf_ = (valueDeserializer.readNumber() as number) - } - else if (fontFourth_buf__selector == 2) { - fontFourth_buf_ = (valueDeserializer.readString() as string) - } - else if (fontFourth_buf__selector == 3) { - fontFourth_buf_ = valueDeserializer.readResource() - } - else { - throw new Error("One of the branches for fontFourth_buf_ has to be chosen through deserialisation.") - } - fontFourth_buf = (fontFourth_buf_ as Color | number | string | Resource) - } - const fontFourth_result : ResourceColor | undefined = fontFourth_buf - const fontEmphasize_buf_runtimeType = (valueDeserializer.readInt8() as int32) - let fontEmphasize_buf : ResourceColor | undefined - if ((RuntimeType.UNDEFINED) != (fontEmphasize_buf_runtimeType)) - { - const fontEmphasize_buf__selector : int32 = valueDeserializer.readInt8() - let fontEmphasize_buf_ : Color | number | string | Resource | undefined - if (fontEmphasize_buf__selector == 0) { - fontEmphasize_buf_ = TypeChecker.Color_FromNumeric(valueDeserializer.readInt32()) - } - else if (fontEmphasize_buf__selector == 1) { - fontEmphasize_buf_ = (valueDeserializer.readNumber() as number) - } - else if (fontEmphasize_buf__selector == 2) { - fontEmphasize_buf_ = (valueDeserializer.readString() as string) - } - else if (fontEmphasize_buf__selector == 3) { - fontEmphasize_buf_ = valueDeserializer.readResource() - } - else { - throw new Error("One of the branches for fontEmphasize_buf_ has to be chosen through deserialisation.") - } - fontEmphasize_buf = (fontEmphasize_buf_ as Color | number | string | Resource) - } - const fontEmphasize_result : ResourceColor | undefined = fontEmphasize_buf - const fontOnPrimary_buf_runtimeType = (valueDeserializer.readInt8() as int32) - let fontOnPrimary_buf : ResourceColor | undefined - if ((RuntimeType.UNDEFINED) != (fontOnPrimary_buf_runtimeType)) - { - const fontOnPrimary_buf__selector : int32 = valueDeserializer.readInt8() - let fontOnPrimary_buf_ : Color | number | string | Resource | undefined - if (fontOnPrimary_buf__selector == 0) { - fontOnPrimary_buf_ = TypeChecker.Color_FromNumeric(valueDeserializer.readInt32()) - } - else if (fontOnPrimary_buf__selector == 1) { - fontOnPrimary_buf_ = (valueDeserializer.readNumber() as number) - } - else if (fontOnPrimary_buf__selector == 2) { - fontOnPrimary_buf_ = (valueDeserializer.readString() as string) - } - else if (fontOnPrimary_buf__selector == 3) { - fontOnPrimary_buf_ = valueDeserializer.readResource() - } - else { - throw new Error("One of the branches for fontOnPrimary_buf_ has to be chosen through deserialisation.") - } - fontOnPrimary_buf = (fontOnPrimary_buf_ as Color | number | string | Resource) - } - const fontOnPrimary_result : ResourceColor | undefined = fontOnPrimary_buf - const fontOnSecondary_buf_runtimeType = (valueDeserializer.readInt8() as int32) - let fontOnSecondary_buf : ResourceColor | undefined - if ((RuntimeType.UNDEFINED) != (fontOnSecondary_buf_runtimeType)) - { - const fontOnSecondary_buf__selector : int32 = valueDeserializer.readInt8() - let fontOnSecondary_buf_ : Color | number | string | Resource | undefined - if (fontOnSecondary_buf__selector == 0) { - fontOnSecondary_buf_ = TypeChecker.Color_FromNumeric(valueDeserializer.readInt32()) - } - else if (fontOnSecondary_buf__selector == 1) { - fontOnSecondary_buf_ = (valueDeserializer.readNumber() as number) - } - else if (fontOnSecondary_buf__selector == 2) { - fontOnSecondary_buf_ = (valueDeserializer.readString() as string) - } - else if (fontOnSecondary_buf__selector == 3) { - fontOnSecondary_buf_ = valueDeserializer.readResource() - } - else { - throw new Error("One of the branches for fontOnSecondary_buf_ has to be chosen through deserialisation.") - } - fontOnSecondary_buf = (fontOnSecondary_buf_ as Color | number | string | Resource) - } - const fontOnSecondary_result : ResourceColor | undefined = fontOnSecondary_buf - const fontOnTertiary_buf_runtimeType = (valueDeserializer.readInt8() as int32) - let fontOnTertiary_buf : ResourceColor | undefined - if ((RuntimeType.UNDEFINED) != (fontOnTertiary_buf_runtimeType)) - { - const fontOnTertiary_buf__selector : int32 = valueDeserializer.readInt8() - let fontOnTertiary_buf_ : Color | number | string | Resource | undefined - if (fontOnTertiary_buf__selector == 0) { - fontOnTertiary_buf_ = TypeChecker.Color_FromNumeric(valueDeserializer.readInt32()) - } - else if (fontOnTertiary_buf__selector == 1) { - fontOnTertiary_buf_ = (valueDeserializer.readNumber() as number) - } - else if (fontOnTertiary_buf__selector == 2) { - fontOnTertiary_buf_ = (valueDeserializer.readString() as string) - } - else if (fontOnTertiary_buf__selector == 3) { - fontOnTertiary_buf_ = valueDeserializer.readResource() - } - else { - throw new Error("One of the branches for fontOnTertiary_buf_ has to be chosen through deserialisation.") - } - fontOnTertiary_buf = (fontOnTertiary_buf_ as Color | number | string | Resource) - } - const fontOnTertiary_result : ResourceColor | undefined = fontOnTertiary_buf - const fontOnFourth_buf_runtimeType = (valueDeserializer.readInt8() as int32) - let fontOnFourth_buf : ResourceColor | undefined - if ((RuntimeType.UNDEFINED) != (fontOnFourth_buf_runtimeType)) - { - const fontOnFourth_buf__selector : int32 = valueDeserializer.readInt8() - let fontOnFourth_buf_ : Color | number | string | Resource | undefined - if (fontOnFourth_buf__selector == 0) { - fontOnFourth_buf_ = TypeChecker.Color_FromNumeric(valueDeserializer.readInt32()) - } - else if (fontOnFourth_buf__selector == 1) { - fontOnFourth_buf_ = (valueDeserializer.readNumber() as number) - } - else if (fontOnFourth_buf__selector == 2) { - fontOnFourth_buf_ = (valueDeserializer.readString() as string) - } - else if (fontOnFourth_buf__selector == 3) { - fontOnFourth_buf_ = valueDeserializer.readResource() - } - else { - throw new Error("One of the branches for fontOnFourth_buf_ has to be chosen through deserialisation.") - } - fontOnFourth_buf = (fontOnFourth_buf_ as Color | number | string | Resource) - } - const fontOnFourth_result : ResourceColor | undefined = fontOnFourth_buf - const iconPrimary_buf_runtimeType = (valueDeserializer.readInt8() as int32) - let iconPrimary_buf : ResourceColor | undefined - if ((RuntimeType.UNDEFINED) != (iconPrimary_buf_runtimeType)) - { - const iconPrimary_buf__selector : int32 = valueDeserializer.readInt8() - let iconPrimary_buf_ : Color | number | string | Resource | undefined - if (iconPrimary_buf__selector == 0) { - iconPrimary_buf_ = TypeChecker.Color_FromNumeric(valueDeserializer.readInt32()) - } - else if (iconPrimary_buf__selector == 1) { - iconPrimary_buf_ = (valueDeserializer.readNumber() as number) - } - else if (iconPrimary_buf__selector == 2) { - iconPrimary_buf_ = (valueDeserializer.readString() as string) - } - else if (iconPrimary_buf__selector == 3) { - iconPrimary_buf_ = valueDeserializer.readResource() - } - else { - throw new Error("One of the branches for iconPrimary_buf_ has to be chosen through deserialisation.") - } - iconPrimary_buf = (iconPrimary_buf_ as Color | number | string | Resource) - } - const iconPrimary_result : ResourceColor | undefined = iconPrimary_buf - const iconSecondary_buf_runtimeType = (valueDeserializer.readInt8() as int32) - let iconSecondary_buf : ResourceColor | undefined - if ((RuntimeType.UNDEFINED) != (iconSecondary_buf_runtimeType)) - { - const iconSecondary_buf__selector : int32 = valueDeserializer.readInt8() - let iconSecondary_buf_ : Color | number | string | Resource | undefined - if (iconSecondary_buf__selector == 0) { - iconSecondary_buf_ = TypeChecker.Color_FromNumeric(valueDeserializer.readInt32()) - } - else if (iconSecondary_buf__selector == 1) { - iconSecondary_buf_ = (valueDeserializer.readNumber() as number) - } - else if (iconSecondary_buf__selector == 2) { - iconSecondary_buf_ = (valueDeserializer.readString() as string) - } - else if (iconSecondary_buf__selector == 3) { - iconSecondary_buf_ = valueDeserializer.readResource() - } - else { - throw new Error("One of the branches for iconSecondary_buf_ has to be chosen through deserialisation.") - } - iconSecondary_buf = (iconSecondary_buf_ as Color | number | string | Resource) - } - const iconSecondary_result : ResourceColor | undefined = iconSecondary_buf - const iconTertiary_buf_runtimeType = (valueDeserializer.readInt8() as int32) - let iconTertiary_buf : ResourceColor | undefined - if ((RuntimeType.UNDEFINED) != (iconTertiary_buf_runtimeType)) - { - const iconTertiary_buf__selector : int32 = valueDeserializer.readInt8() - let iconTertiary_buf_ : Color | number | string | Resource | undefined - if (iconTertiary_buf__selector == 0) { - iconTertiary_buf_ = TypeChecker.Color_FromNumeric(valueDeserializer.readInt32()) - } - else if (iconTertiary_buf__selector == 1) { - iconTertiary_buf_ = (valueDeserializer.readNumber() as number) - } - else if (iconTertiary_buf__selector == 2) { - iconTertiary_buf_ = (valueDeserializer.readString() as string) - } - else if (iconTertiary_buf__selector == 3) { - iconTertiary_buf_ = valueDeserializer.readResource() - } - else { - throw new Error("One of the branches for iconTertiary_buf_ has to be chosen through deserialisation.") - } - iconTertiary_buf = (iconTertiary_buf_ as Color | number | string | Resource) - } - const iconTertiary_result : ResourceColor | undefined = iconTertiary_buf - const iconFourth_buf_runtimeType = (valueDeserializer.readInt8() as int32) - let iconFourth_buf : ResourceColor | undefined - if ((RuntimeType.UNDEFINED) != (iconFourth_buf_runtimeType)) - { - const iconFourth_buf__selector : int32 = valueDeserializer.readInt8() - let iconFourth_buf_ : Color | number | string | Resource | undefined - if (iconFourth_buf__selector == 0) { - iconFourth_buf_ = TypeChecker.Color_FromNumeric(valueDeserializer.readInt32()) - } - else if (iconFourth_buf__selector == 1) { - iconFourth_buf_ = (valueDeserializer.readNumber() as number) - } - else if (iconFourth_buf__selector == 2) { - iconFourth_buf_ = (valueDeserializer.readString() as string) - } - else if (iconFourth_buf__selector == 3) { - iconFourth_buf_ = valueDeserializer.readResource() - } - else { - throw new Error("One of the branches for iconFourth_buf_ has to be chosen through deserialisation.") - } - iconFourth_buf = (iconFourth_buf_ as Color | number | string | Resource) - } - const iconFourth_result : ResourceColor | undefined = iconFourth_buf - const iconEmphasize_buf_runtimeType = (valueDeserializer.readInt8() as int32) - let iconEmphasize_buf : ResourceColor | undefined - if ((RuntimeType.UNDEFINED) != (iconEmphasize_buf_runtimeType)) - { - const iconEmphasize_buf__selector : int32 = valueDeserializer.readInt8() - let iconEmphasize_buf_ : Color | number | string | Resource | undefined - if (iconEmphasize_buf__selector == 0) { - iconEmphasize_buf_ = TypeChecker.Color_FromNumeric(valueDeserializer.readInt32()) - } - else if (iconEmphasize_buf__selector == 1) { - iconEmphasize_buf_ = (valueDeserializer.readNumber() as number) - } - else if (iconEmphasize_buf__selector == 2) { - iconEmphasize_buf_ = (valueDeserializer.readString() as string) - } - else if (iconEmphasize_buf__selector == 3) { - iconEmphasize_buf_ = valueDeserializer.readResource() - } - else { - throw new Error("One of the branches for iconEmphasize_buf_ has to be chosen through deserialisation.") - } - iconEmphasize_buf = (iconEmphasize_buf_ as Color | number | string | Resource) - } - const iconEmphasize_result : ResourceColor | undefined = iconEmphasize_buf - const iconSubEmphasize_buf_runtimeType = (valueDeserializer.readInt8() as int32) - let iconSubEmphasize_buf : ResourceColor | undefined - if ((RuntimeType.UNDEFINED) != (iconSubEmphasize_buf_runtimeType)) - { - const iconSubEmphasize_buf__selector : int32 = valueDeserializer.readInt8() - let iconSubEmphasize_buf_ : Color | number | string | Resource | undefined - if (iconSubEmphasize_buf__selector == 0) { - iconSubEmphasize_buf_ = TypeChecker.Color_FromNumeric(valueDeserializer.readInt32()) - } - else if (iconSubEmphasize_buf__selector == 1) { - iconSubEmphasize_buf_ = (valueDeserializer.readNumber() as number) - } - else if (iconSubEmphasize_buf__selector == 2) { - iconSubEmphasize_buf_ = (valueDeserializer.readString() as string) - } - else if (iconSubEmphasize_buf__selector == 3) { - iconSubEmphasize_buf_ = valueDeserializer.readResource() - } - else { - throw new Error("One of the branches for iconSubEmphasize_buf_ has to be chosen through deserialisation.") - } - iconSubEmphasize_buf = (iconSubEmphasize_buf_ as Color | number | string | Resource) - } - const iconSubEmphasize_result : ResourceColor | undefined = iconSubEmphasize_buf - const iconOnPrimary_buf_runtimeType = (valueDeserializer.readInt8() as int32) - let iconOnPrimary_buf : ResourceColor | undefined - if ((RuntimeType.UNDEFINED) != (iconOnPrimary_buf_runtimeType)) - { - const iconOnPrimary_buf__selector : int32 = valueDeserializer.readInt8() - let iconOnPrimary_buf_ : Color | number | string | Resource | undefined - if (iconOnPrimary_buf__selector == 0) { - iconOnPrimary_buf_ = TypeChecker.Color_FromNumeric(valueDeserializer.readInt32()) - } - else if (iconOnPrimary_buf__selector == 1) { - iconOnPrimary_buf_ = (valueDeserializer.readNumber() as number) - } - else if (iconOnPrimary_buf__selector == 2) { - iconOnPrimary_buf_ = (valueDeserializer.readString() as string) - } - else if (iconOnPrimary_buf__selector == 3) { - iconOnPrimary_buf_ = valueDeserializer.readResource() - } - else { - throw new Error("One of the branches for iconOnPrimary_buf_ has to be chosen through deserialisation.") - } - iconOnPrimary_buf = (iconOnPrimary_buf_ as Color | number | string | Resource) - } - const iconOnPrimary_result : ResourceColor | undefined = iconOnPrimary_buf - const iconOnSecondary_buf_runtimeType = (valueDeserializer.readInt8() as int32) - let iconOnSecondary_buf : ResourceColor | undefined - if ((RuntimeType.UNDEFINED) != (iconOnSecondary_buf_runtimeType)) - { - const iconOnSecondary_buf__selector : int32 = valueDeserializer.readInt8() - let iconOnSecondary_buf_ : Color | number | string | Resource | undefined - if (iconOnSecondary_buf__selector == 0) { - iconOnSecondary_buf_ = TypeChecker.Color_FromNumeric(valueDeserializer.readInt32()) - } - else if (iconOnSecondary_buf__selector == 1) { - iconOnSecondary_buf_ = (valueDeserializer.readNumber() as number) - } - else if (iconOnSecondary_buf__selector == 2) { - iconOnSecondary_buf_ = (valueDeserializer.readString() as string) - } - else if (iconOnSecondary_buf__selector == 3) { - iconOnSecondary_buf_ = valueDeserializer.readResource() - } - else { - throw new Error("One of the branches for iconOnSecondary_buf_ has to be chosen through deserialisation.") - } - iconOnSecondary_buf = (iconOnSecondary_buf_ as Color | number | string | Resource) - } - const iconOnSecondary_result : ResourceColor | undefined = iconOnSecondary_buf - const iconOnTertiary_buf_runtimeType = (valueDeserializer.readInt8() as int32) - let iconOnTertiary_buf : ResourceColor | undefined - if ((RuntimeType.UNDEFINED) != (iconOnTertiary_buf_runtimeType)) - { - const iconOnTertiary_buf__selector : int32 = valueDeserializer.readInt8() - let iconOnTertiary_buf_ : Color | number | string | Resource | undefined - if (iconOnTertiary_buf__selector == 0) { - iconOnTertiary_buf_ = TypeChecker.Color_FromNumeric(valueDeserializer.readInt32()) - } - else if (iconOnTertiary_buf__selector == 1) { - iconOnTertiary_buf_ = (valueDeserializer.readNumber() as number) - } - else if (iconOnTertiary_buf__selector == 2) { - iconOnTertiary_buf_ = (valueDeserializer.readString() as string) - } - else if (iconOnTertiary_buf__selector == 3) { - iconOnTertiary_buf_ = valueDeserializer.readResource() - } - else { - throw new Error("One of the branches for iconOnTertiary_buf_ has to be chosen through deserialisation.") - } - iconOnTertiary_buf = (iconOnTertiary_buf_ as Color | number | string | Resource) - } - const iconOnTertiary_result : ResourceColor | undefined = iconOnTertiary_buf - const iconOnFourth_buf_runtimeType = (valueDeserializer.readInt8() as int32) - let iconOnFourth_buf : ResourceColor | undefined - if ((RuntimeType.UNDEFINED) != (iconOnFourth_buf_runtimeType)) - { - const iconOnFourth_buf__selector : int32 = valueDeserializer.readInt8() - let iconOnFourth_buf_ : Color | number | string | Resource | undefined - if (iconOnFourth_buf__selector == 0) { - iconOnFourth_buf_ = TypeChecker.Color_FromNumeric(valueDeserializer.readInt32()) - } - else if (iconOnFourth_buf__selector == 1) { - iconOnFourth_buf_ = (valueDeserializer.readNumber() as number) - } - else if (iconOnFourth_buf__selector == 2) { - iconOnFourth_buf_ = (valueDeserializer.readString() as string) - } - else if (iconOnFourth_buf__selector == 3) { - iconOnFourth_buf_ = valueDeserializer.readResource() - } - else { - throw new Error("One of the branches for iconOnFourth_buf_ has to be chosen through deserialisation.") - } - iconOnFourth_buf = (iconOnFourth_buf_ as Color | number | string | Resource) - } - const iconOnFourth_result : ResourceColor | undefined = iconOnFourth_buf - const backgroundPrimary_buf_runtimeType = (valueDeserializer.readInt8() as int32) - let backgroundPrimary_buf : ResourceColor | undefined - if ((RuntimeType.UNDEFINED) != (backgroundPrimary_buf_runtimeType)) - { - const backgroundPrimary_buf__selector : int32 = valueDeserializer.readInt8() - let backgroundPrimary_buf_ : Color | number | string | Resource | undefined - if (backgroundPrimary_buf__selector == 0) { - backgroundPrimary_buf_ = TypeChecker.Color_FromNumeric(valueDeserializer.readInt32()) - } - else if (backgroundPrimary_buf__selector == 1) { - backgroundPrimary_buf_ = (valueDeserializer.readNumber() as number) - } - else if (backgroundPrimary_buf__selector == 2) { - backgroundPrimary_buf_ = (valueDeserializer.readString() as string) - } - else if (backgroundPrimary_buf__selector == 3) { - backgroundPrimary_buf_ = valueDeserializer.readResource() - } - else { - throw new Error("One of the branches for backgroundPrimary_buf_ has to be chosen through deserialisation.") - } - backgroundPrimary_buf = (backgroundPrimary_buf_ as Color | number | string | Resource) - } - const backgroundPrimary_result : ResourceColor | undefined = backgroundPrimary_buf - const backgroundSecondary_buf_runtimeType = (valueDeserializer.readInt8() as int32) - let backgroundSecondary_buf : ResourceColor | undefined - if ((RuntimeType.UNDEFINED) != (backgroundSecondary_buf_runtimeType)) - { - const backgroundSecondary_buf__selector : int32 = valueDeserializer.readInt8() - let backgroundSecondary_buf_ : Color | number | string | Resource | undefined - if (backgroundSecondary_buf__selector == 0) { - backgroundSecondary_buf_ = TypeChecker.Color_FromNumeric(valueDeserializer.readInt32()) - } - else if (backgroundSecondary_buf__selector == 1) { - backgroundSecondary_buf_ = (valueDeserializer.readNumber() as number) - } - else if (backgroundSecondary_buf__selector == 2) { - backgroundSecondary_buf_ = (valueDeserializer.readString() as string) - } - else if (backgroundSecondary_buf__selector == 3) { - backgroundSecondary_buf_ = valueDeserializer.readResource() - } - else { - throw new Error("One of the branches for backgroundSecondary_buf_ has to be chosen through deserialisation.") - } - backgroundSecondary_buf = (backgroundSecondary_buf_ as Color | number | string | Resource) - } - const backgroundSecondary_result : ResourceColor | undefined = backgroundSecondary_buf - const backgroundTertiary_buf_runtimeType = (valueDeserializer.readInt8() as int32) - let backgroundTertiary_buf : ResourceColor | undefined - if ((RuntimeType.UNDEFINED) != (backgroundTertiary_buf_runtimeType)) - { - const backgroundTertiary_buf__selector : int32 = valueDeserializer.readInt8() - let backgroundTertiary_buf_ : Color | number | string | Resource | undefined - if (backgroundTertiary_buf__selector == 0) { - backgroundTertiary_buf_ = TypeChecker.Color_FromNumeric(valueDeserializer.readInt32()) - } - else if (backgroundTertiary_buf__selector == 1) { - backgroundTertiary_buf_ = (valueDeserializer.readNumber() as number) - } - else if (backgroundTertiary_buf__selector == 2) { - backgroundTertiary_buf_ = (valueDeserializer.readString() as string) - } - else if (backgroundTertiary_buf__selector == 3) { - backgroundTertiary_buf_ = valueDeserializer.readResource() - } - else { - throw new Error("One of the branches for backgroundTertiary_buf_ has to be chosen through deserialisation.") - } - backgroundTertiary_buf = (backgroundTertiary_buf_ as Color | number | string | Resource) - } - const backgroundTertiary_result : ResourceColor | undefined = backgroundTertiary_buf - const backgroundFourth_buf_runtimeType = (valueDeserializer.readInt8() as int32) - let backgroundFourth_buf : ResourceColor | undefined - if ((RuntimeType.UNDEFINED) != (backgroundFourth_buf_runtimeType)) - { - const backgroundFourth_buf__selector : int32 = valueDeserializer.readInt8() - let backgroundFourth_buf_ : Color | number | string | Resource | undefined - if (backgroundFourth_buf__selector == 0) { - backgroundFourth_buf_ = TypeChecker.Color_FromNumeric(valueDeserializer.readInt32()) - } - else if (backgroundFourth_buf__selector == 1) { - backgroundFourth_buf_ = (valueDeserializer.readNumber() as number) - } - else if (backgroundFourth_buf__selector == 2) { - backgroundFourth_buf_ = (valueDeserializer.readString() as string) - } - else if (backgroundFourth_buf__selector == 3) { - backgroundFourth_buf_ = valueDeserializer.readResource() - } - else { - throw new Error("One of the branches for backgroundFourth_buf_ has to be chosen through deserialisation.") - } - backgroundFourth_buf = (backgroundFourth_buf_ as Color | number | string | Resource) - } - const backgroundFourth_result : ResourceColor | undefined = backgroundFourth_buf - const backgroundEmphasize_buf_runtimeType = (valueDeserializer.readInt8() as int32) - let backgroundEmphasize_buf : ResourceColor | undefined - if ((RuntimeType.UNDEFINED) != (backgroundEmphasize_buf_runtimeType)) - { - const backgroundEmphasize_buf__selector : int32 = valueDeserializer.readInt8() - let backgroundEmphasize_buf_ : Color | number | string | Resource | undefined - if (backgroundEmphasize_buf__selector == 0) { - backgroundEmphasize_buf_ = TypeChecker.Color_FromNumeric(valueDeserializer.readInt32()) - } - else if (backgroundEmphasize_buf__selector == 1) { - backgroundEmphasize_buf_ = (valueDeserializer.readNumber() as number) - } - else if (backgroundEmphasize_buf__selector == 2) { - backgroundEmphasize_buf_ = (valueDeserializer.readString() as string) - } - else if (backgroundEmphasize_buf__selector == 3) { - backgroundEmphasize_buf_ = valueDeserializer.readResource() - } - else { - throw new Error("One of the branches for backgroundEmphasize_buf_ has to be chosen through deserialisation.") - } - backgroundEmphasize_buf = (backgroundEmphasize_buf_ as Color | number | string | Resource) - } - const backgroundEmphasize_result : ResourceColor | undefined = backgroundEmphasize_buf - const compForegroundPrimary_buf_runtimeType = (valueDeserializer.readInt8() as int32) - let compForegroundPrimary_buf : ResourceColor | undefined - if ((RuntimeType.UNDEFINED) != (compForegroundPrimary_buf_runtimeType)) - { - const compForegroundPrimary_buf__selector : int32 = valueDeserializer.readInt8() - let compForegroundPrimary_buf_ : Color | number | string | Resource | undefined - if (compForegroundPrimary_buf__selector == 0) { - compForegroundPrimary_buf_ = TypeChecker.Color_FromNumeric(valueDeserializer.readInt32()) - } - else if (compForegroundPrimary_buf__selector == 1) { - compForegroundPrimary_buf_ = (valueDeserializer.readNumber() as number) - } - else if (compForegroundPrimary_buf__selector == 2) { - compForegroundPrimary_buf_ = (valueDeserializer.readString() as string) - } - else if (compForegroundPrimary_buf__selector == 3) { - compForegroundPrimary_buf_ = valueDeserializer.readResource() - } - else { - throw new Error("One of the branches for compForegroundPrimary_buf_ has to be chosen through deserialisation.") - } - compForegroundPrimary_buf = (compForegroundPrimary_buf_ as Color | number | string | Resource) - } - const compForegroundPrimary_result : ResourceColor | undefined = compForegroundPrimary_buf - const compBackgroundPrimary_buf_runtimeType = (valueDeserializer.readInt8() as int32) - let compBackgroundPrimary_buf : ResourceColor | undefined - if ((RuntimeType.UNDEFINED) != (compBackgroundPrimary_buf_runtimeType)) - { - const compBackgroundPrimary_buf__selector : int32 = valueDeserializer.readInt8() - let compBackgroundPrimary_buf_ : Color | number | string | Resource | undefined - if (compBackgroundPrimary_buf__selector == 0) { - compBackgroundPrimary_buf_ = TypeChecker.Color_FromNumeric(valueDeserializer.readInt32()) - } - else if (compBackgroundPrimary_buf__selector == 1) { - compBackgroundPrimary_buf_ = (valueDeserializer.readNumber() as number) - } - else if (compBackgroundPrimary_buf__selector == 2) { - compBackgroundPrimary_buf_ = (valueDeserializer.readString() as string) - } - else if (compBackgroundPrimary_buf__selector == 3) { - compBackgroundPrimary_buf_ = valueDeserializer.readResource() - } - else { - throw new Error("One of the branches for compBackgroundPrimary_buf_ has to be chosen through deserialisation.") - } - compBackgroundPrimary_buf = (compBackgroundPrimary_buf_ as Color | number | string | Resource) - } - const compBackgroundPrimary_result : ResourceColor | undefined = compBackgroundPrimary_buf - const compBackgroundPrimaryTran_buf_runtimeType = (valueDeserializer.readInt8() as int32) - let compBackgroundPrimaryTran_buf : ResourceColor | undefined - if ((RuntimeType.UNDEFINED) != (compBackgroundPrimaryTran_buf_runtimeType)) - { - const compBackgroundPrimaryTran_buf__selector : int32 = valueDeserializer.readInt8() - let compBackgroundPrimaryTran_buf_ : Color | number | string | Resource | undefined - if (compBackgroundPrimaryTran_buf__selector == 0) { - compBackgroundPrimaryTran_buf_ = TypeChecker.Color_FromNumeric(valueDeserializer.readInt32()) - } - else if (compBackgroundPrimaryTran_buf__selector == 1) { - compBackgroundPrimaryTran_buf_ = (valueDeserializer.readNumber() as number) - } - else if (compBackgroundPrimaryTran_buf__selector == 2) { - compBackgroundPrimaryTran_buf_ = (valueDeserializer.readString() as string) - } - else if (compBackgroundPrimaryTran_buf__selector == 3) { - compBackgroundPrimaryTran_buf_ = valueDeserializer.readResource() - } - else { - throw new Error("One of the branches for compBackgroundPrimaryTran_buf_ has to be chosen through deserialisation.") - } - compBackgroundPrimaryTran_buf = (compBackgroundPrimaryTran_buf_ as Color | number | string | Resource) - } - const compBackgroundPrimaryTran_result : ResourceColor | undefined = compBackgroundPrimaryTran_buf - const compBackgroundPrimaryContrary_buf_runtimeType = (valueDeserializer.readInt8() as int32) - let compBackgroundPrimaryContrary_buf : ResourceColor | undefined - if ((RuntimeType.UNDEFINED) != (compBackgroundPrimaryContrary_buf_runtimeType)) - { - const compBackgroundPrimaryContrary_buf__selector : int32 = valueDeserializer.readInt8() - let compBackgroundPrimaryContrary_buf_ : Color | number | string | Resource | undefined - if (compBackgroundPrimaryContrary_buf__selector == 0) { - compBackgroundPrimaryContrary_buf_ = TypeChecker.Color_FromNumeric(valueDeserializer.readInt32()) - } - else if (compBackgroundPrimaryContrary_buf__selector == 1) { - compBackgroundPrimaryContrary_buf_ = (valueDeserializer.readNumber() as number) - } - else if (compBackgroundPrimaryContrary_buf__selector == 2) { - compBackgroundPrimaryContrary_buf_ = (valueDeserializer.readString() as string) - } - else if (compBackgroundPrimaryContrary_buf__selector == 3) { - compBackgroundPrimaryContrary_buf_ = valueDeserializer.readResource() - } - else { - throw new Error("One of the branches for compBackgroundPrimaryContrary_buf_ has to be chosen through deserialisation.") - } - compBackgroundPrimaryContrary_buf = (compBackgroundPrimaryContrary_buf_ as Color | number | string | Resource) - } - const compBackgroundPrimaryContrary_result : ResourceColor | undefined = compBackgroundPrimaryContrary_buf - const compBackgroundGray_buf_runtimeType = (valueDeserializer.readInt8() as int32) - let compBackgroundGray_buf : ResourceColor | undefined - if ((RuntimeType.UNDEFINED) != (compBackgroundGray_buf_runtimeType)) - { - const compBackgroundGray_buf__selector : int32 = valueDeserializer.readInt8() - let compBackgroundGray_buf_ : Color | number | string | Resource | undefined - if (compBackgroundGray_buf__selector == 0) { - compBackgroundGray_buf_ = TypeChecker.Color_FromNumeric(valueDeserializer.readInt32()) - } - else if (compBackgroundGray_buf__selector == 1) { - compBackgroundGray_buf_ = (valueDeserializer.readNumber() as number) - } - else if (compBackgroundGray_buf__selector == 2) { - compBackgroundGray_buf_ = (valueDeserializer.readString() as string) - } - else if (compBackgroundGray_buf__selector == 3) { - compBackgroundGray_buf_ = valueDeserializer.readResource() - } - else { - throw new Error("One of the branches for compBackgroundGray_buf_ has to be chosen through deserialisation.") - } - compBackgroundGray_buf = (compBackgroundGray_buf_ as Color | number | string | Resource) - } - const compBackgroundGray_result : ResourceColor | undefined = compBackgroundGray_buf - const compBackgroundSecondary_buf_runtimeType = (valueDeserializer.readInt8() as int32) - let compBackgroundSecondary_buf : ResourceColor | undefined - if ((RuntimeType.UNDEFINED) != (compBackgroundSecondary_buf_runtimeType)) - { - const compBackgroundSecondary_buf__selector : int32 = valueDeserializer.readInt8() - let compBackgroundSecondary_buf_ : Color | number | string | Resource | undefined - if (compBackgroundSecondary_buf__selector == 0) { - compBackgroundSecondary_buf_ = TypeChecker.Color_FromNumeric(valueDeserializer.readInt32()) - } - else if (compBackgroundSecondary_buf__selector == 1) { - compBackgroundSecondary_buf_ = (valueDeserializer.readNumber() as number) - } - else if (compBackgroundSecondary_buf__selector == 2) { - compBackgroundSecondary_buf_ = (valueDeserializer.readString() as string) - } - else if (compBackgroundSecondary_buf__selector == 3) { - compBackgroundSecondary_buf_ = valueDeserializer.readResource() - } - else { - throw new Error("One of the branches for compBackgroundSecondary_buf_ has to be chosen through deserialisation.") - } - compBackgroundSecondary_buf = (compBackgroundSecondary_buf_ as Color | number | string | Resource) - } - const compBackgroundSecondary_result : ResourceColor | undefined = compBackgroundSecondary_buf - const compBackgroundTertiary_buf_runtimeType = (valueDeserializer.readInt8() as int32) - let compBackgroundTertiary_buf : ResourceColor | undefined - if ((RuntimeType.UNDEFINED) != (compBackgroundTertiary_buf_runtimeType)) - { - const compBackgroundTertiary_buf__selector : int32 = valueDeserializer.readInt8() - let compBackgroundTertiary_buf_ : Color | number | string | Resource | undefined - if (compBackgroundTertiary_buf__selector == 0) { - compBackgroundTertiary_buf_ = TypeChecker.Color_FromNumeric(valueDeserializer.readInt32()) - } - else if (compBackgroundTertiary_buf__selector == 1) { - compBackgroundTertiary_buf_ = (valueDeserializer.readNumber() as number) - } - else if (compBackgroundTertiary_buf__selector == 2) { - compBackgroundTertiary_buf_ = (valueDeserializer.readString() as string) - } - else if (compBackgroundTertiary_buf__selector == 3) { - compBackgroundTertiary_buf_ = valueDeserializer.readResource() - } - else { - throw new Error("One of the branches for compBackgroundTertiary_buf_ has to be chosen through deserialisation.") - } - compBackgroundTertiary_buf = (compBackgroundTertiary_buf_ as Color | number | string | Resource) - } - const compBackgroundTertiary_result : ResourceColor | undefined = compBackgroundTertiary_buf - const compBackgroundEmphasize_buf_runtimeType = (valueDeserializer.readInt8() as int32) - let compBackgroundEmphasize_buf : ResourceColor | undefined - if ((RuntimeType.UNDEFINED) != (compBackgroundEmphasize_buf_runtimeType)) - { - const compBackgroundEmphasize_buf__selector : int32 = valueDeserializer.readInt8() - let compBackgroundEmphasize_buf_ : Color | number | string | Resource | undefined - if (compBackgroundEmphasize_buf__selector == 0) { - compBackgroundEmphasize_buf_ = TypeChecker.Color_FromNumeric(valueDeserializer.readInt32()) - } - else if (compBackgroundEmphasize_buf__selector == 1) { - compBackgroundEmphasize_buf_ = (valueDeserializer.readNumber() as number) - } - else if (compBackgroundEmphasize_buf__selector == 2) { - compBackgroundEmphasize_buf_ = (valueDeserializer.readString() as string) - } - else if (compBackgroundEmphasize_buf__selector == 3) { - compBackgroundEmphasize_buf_ = valueDeserializer.readResource() - } - else { - throw new Error("One of the branches for compBackgroundEmphasize_buf_ has to be chosen through deserialisation.") - } - compBackgroundEmphasize_buf = (compBackgroundEmphasize_buf_ as Color | number | string | Resource) - } - const compBackgroundEmphasize_result : ResourceColor | undefined = compBackgroundEmphasize_buf - const compBackgroundNeutral_buf_runtimeType = (valueDeserializer.readInt8() as int32) - let compBackgroundNeutral_buf : ResourceColor | undefined - if ((RuntimeType.UNDEFINED) != (compBackgroundNeutral_buf_runtimeType)) - { - const compBackgroundNeutral_buf__selector : int32 = valueDeserializer.readInt8() - let compBackgroundNeutral_buf_ : Color | number | string | Resource | undefined - if (compBackgroundNeutral_buf__selector == 0) { - compBackgroundNeutral_buf_ = TypeChecker.Color_FromNumeric(valueDeserializer.readInt32()) - } - else if (compBackgroundNeutral_buf__selector == 1) { - compBackgroundNeutral_buf_ = (valueDeserializer.readNumber() as number) - } - else if (compBackgroundNeutral_buf__selector == 2) { - compBackgroundNeutral_buf_ = (valueDeserializer.readString() as string) - } - else if (compBackgroundNeutral_buf__selector == 3) { - compBackgroundNeutral_buf_ = valueDeserializer.readResource() - } - else { - throw new Error("One of the branches for compBackgroundNeutral_buf_ has to be chosen through deserialisation.") - } - compBackgroundNeutral_buf = (compBackgroundNeutral_buf_ as Color | number | string | Resource) - } - const compBackgroundNeutral_result : ResourceColor | undefined = compBackgroundNeutral_buf - const compEmphasizeSecondary_buf_runtimeType = (valueDeserializer.readInt8() as int32) - let compEmphasizeSecondary_buf : ResourceColor | undefined - if ((RuntimeType.UNDEFINED) != (compEmphasizeSecondary_buf_runtimeType)) - { - const compEmphasizeSecondary_buf__selector : int32 = valueDeserializer.readInt8() - let compEmphasizeSecondary_buf_ : Color | number | string | Resource | undefined - if (compEmphasizeSecondary_buf__selector == 0) { - compEmphasizeSecondary_buf_ = TypeChecker.Color_FromNumeric(valueDeserializer.readInt32()) - } - else if (compEmphasizeSecondary_buf__selector == 1) { - compEmphasizeSecondary_buf_ = (valueDeserializer.readNumber() as number) - } - else if (compEmphasizeSecondary_buf__selector == 2) { - compEmphasizeSecondary_buf_ = (valueDeserializer.readString() as string) - } - else if (compEmphasizeSecondary_buf__selector == 3) { - compEmphasizeSecondary_buf_ = valueDeserializer.readResource() - } - else { - throw new Error("One of the branches for compEmphasizeSecondary_buf_ has to be chosen through deserialisation.") - } - compEmphasizeSecondary_buf = (compEmphasizeSecondary_buf_ as Color | number | string | Resource) - } - const compEmphasizeSecondary_result : ResourceColor | undefined = compEmphasizeSecondary_buf - const compEmphasizeTertiary_buf_runtimeType = (valueDeserializer.readInt8() as int32) - let compEmphasizeTertiary_buf : ResourceColor | undefined - if ((RuntimeType.UNDEFINED) != (compEmphasizeTertiary_buf_runtimeType)) - { - const compEmphasizeTertiary_buf__selector : int32 = valueDeserializer.readInt8() - let compEmphasizeTertiary_buf_ : Color | number | string | Resource | undefined - if (compEmphasizeTertiary_buf__selector == 0) { - compEmphasizeTertiary_buf_ = TypeChecker.Color_FromNumeric(valueDeserializer.readInt32()) - } - else if (compEmphasizeTertiary_buf__selector == 1) { - compEmphasizeTertiary_buf_ = (valueDeserializer.readNumber() as number) - } - else if (compEmphasizeTertiary_buf__selector == 2) { - compEmphasizeTertiary_buf_ = (valueDeserializer.readString() as string) - } - else if (compEmphasizeTertiary_buf__selector == 3) { - compEmphasizeTertiary_buf_ = valueDeserializer.readResource() - } - else { - throw new Error("One of the branches for compEmphasizeTertiary_buf_ has to be chosen through deserialisation.") - } - compEmphasizeTertiary_buf = (compEmphasizeTertiary_buf_ as Color | number | string | Resource) - } - const compEmphasizeTertiary_result : ResourceColor | undefined = compEmphasizeTertiary_buf - const compDivider_buf_runtimeType = (valueDeserializer.readInt8() as int32) - let compDivider_buf : ResourceColor | undefined - if ((RuntimeType.UNDEFINED) != (compDivider_buf_runtimeType)) - { - const compDivider_buf__selector : int32 = valueDeserializer.readInt8() - let compDivider_buf_ : Color | number | string | Resource | undefined - if (compDivider_buf__selector == 0) { - compDivider_buf_ = TypeChecker.Color_FromNumeric(valueDeserializer.readInt32()) - } - else if (compDivider_buf__selector == 1) { - compDivider_buf_ = (valueDeserializer.readNumber() as number) - } - else if (compDivider_buf__selector == 2) { - compDivider_buf_ = (valueDeserializer.readString() as string) - } - else if (compDivider_buf__selector == 3) { - compDivider_buf_ = valueDeserializer.readResource() - } - else { - throw new Error("One of the branches for compDivider_buf_ has to be chosen through deserialisation.") - } - compDivider_buf = (compDivider_buf_ as Color | number | string | Resource) - } - const compDivider_result : ResourceColor | undefined = compDivider_buf - const compCommonContrary_buf_runtimeType = (valueDeserializer.readInt8() as int32) - let compCommonContrary_buf : ResourceColor | undefined - if ((RuntimeType.UNDEFINED) != (compCommonContrary_buf_runtimeType)) - { - const compCommonContrary_buf__selector : int32 = valueDeserializer.readInt8() - let compCommonContrary_buf_ : Color | number | string | Resource | undefined - if (compCommonContrary_buf__selector == 0) { - compCommonContrary_buf_ = TypeChecker.Color_FromNumeric(valueDeserializer.readInt32()) - } - else if (compCommonContrary_buf__selector == 1) { - compCommonContrary_buf_ = (valueDeserializer.readNumber() as number) - } - else if (compCommonContrary_buf__selector == 2) { - compCommonContrary_buf_ = (valueDeserializer.readString() as string) - } - else if (compCommonContrary_buf__selector == 3) { - compCommonContrary_buf_ = valueDeserializer.readResource() - } - else { - throw new Error("One of the branches for compCommonContrary_buf_ has to be chosen through deserialisation.") - } - compCommonContrary_buf = (compCommonContrary_buf_ as Color | number | string | Resource) - } - const compCommonContrary_result : ResourceColor | undefined = compCommonContrary_buf - const compBackgroundFocus_buf_runtimeType = (valueDeserializer.readInt8() as int32) - let compBackgroundFocus_buf : ResourceColor | undefined - if ((RuntimeType.UNDEFINED) != (compBackgroundFocus_buf_runtimeType)) - { - const compBackgroundFocus_buf__selector : int32 = valueDeserializer.readInt8() - let compBackgroundFocus_buf_ : Color | number | string | Resource | undefined - if (compBackgroundFocus_buf__selector == 0) { - compBackgroundFocus_buf_ = TypeChecker.Color_FromNumeric(valueDeserializer.readInt32()) - } - else if (compBackgroundFocus_buf__selector == 1) { - compBackgroundFocus_buf_ = (valueDeserializer.readNumber() as number) - } - else if (compBackgroundFocus_buf__selector == 2) { - compBackgroundFocus_buf_ = (valueDeserializer.readString() as string) - } - else if (compBackgroundFocus_buf__selector == 3) { - compBackgroundFocus_buf_ = valueDeserializer.readResource() - } - else { - throw new Error("One of the branches for compBackgroundFocus_buf_ has to be chosen through deserialisation.") - } - compBackgroundFocus_buf = (compBackgroundFocus_buf_ as Color | number | string | Resource) - } - const compBackgroundFocus_result : ResourceColor | undefined = compBackgroundFocus_buf - const compFocusedPrimary_buf_runtimeType = (valueDeserializer.readInt8() as int32) - let compFocusedPrimary_buf : ResourceColor | undefined - if ((RuntimeType.UNDEFINED) != (compFocusedPrimary_buf_runtimeType)) - { - const compFocusedPrimary_buf__selector : int32 = valueDeserializer.readInt8() - let compFocusedPrimary_buf_ : Color | number | string | Resource | undefined - if (compFocusedPrimary_buf__selector == 0) { - compFocusedPrimary_buf_ = TypeChecker.Color_FromNumeric(valueDeserializer.readInt32()) - } - else if (compFocusedPrimary_buf__selector == 1) { - compFocusedPrimary_buf_ = (valueDeserializer.readNumber() as number) - } - else if (compFocusedPrimary_buf__selector == 2) { - compFocusedPrimary_buf_ = (valueDeserializer.readString() as string) - } - else if (compFocusedPrimary_buf__selector == 3) { - compFocusedPrimary_buf_ = valueDeserializer.readResource() - } - else { - throw new Error("One of the branches for compFocusedPrimary_buf_ has to be chosen through deserialisation.") - } - compFocusedPrimary_buf = (compFocusedPrimary_buf_ as Color | number | string | Resource) - } - const compFocusedPrimary_result : ResourceColor | undefined = compFocusedPrimary_buf - const compFocusedSecondary_buf_runtimeType = (valueDeserializer.readInt8() as int32) - let compFocusedSecondary_buf : ResourceColor | undefined - if ((RuntimeType.UNDEFINED) != (compFocusedSecondary_buf_runtimeType)) - { - const compFocusedSecondary_buf__selector : int32 = valueDeserializer.readInt8() - let compFocusedSecondary_buf_ : Color | number | string | Resource | undefined - if (compFocusedSecondary_buf__selector == 0) { - compFocusedSecondary_buf_ = TypeChecker.Color_FromNumeric(valueDeserializer.readInt32()) - } - else if (compFocusedSecondary_buf__selector == 1) { - compFocusedSecondary_buf_ = (valueDeserializer.readNumber() as number) - } - else if (compFocusedSecondary_buf__selector == 2) { - compFocusedSecondary_buf_ = (valueDeserializer.readString() as string) - } - else if (compFocusedSecondary_buf__selector == 3) { - compFocusedSecondary_buf_ = valueDeserializer.readResource() - } - else { - throw new Error("One of the branches for compFocusedSecondary_buf_ has to be chosen through deserialisation.") - } - compFocusedSecondary_buf = (compFocusedSecondary_buf_ as Color | number | string | Resource) - } - const compFocusedSecondary_result : ResourceColor | undefined = compFocusedSecondary_buf - const compFocusedTertiary_buf_runtimeType = (valueDeserializer.readInt8() as int32) - let compFocusedTertiary_buf : ResourceColor | undefined - if ((RuntimeType.UNDEFINED) != (compFocusedTertiary_buf_runtimeType)) - { - const compFocusedTertiary_buf__selector : int32 = valueDeserializer.readInt8() - let compFocusedTertiary_buf_ : Color | number | string | Resource | undefined - if (compFocusedTertiary_buf__selector == 0) { - compFocusedTertiary_buf_ = TypeChecker.Color_FromNumeric(valueDeserializer.readInt32()) - } - else if (compFocusedTertiary_buf__selector == 1) { - compFocusedTertiary_buf_ = (valueDeserializer.readNumber() as number) - } - else if (compFocusedTertiary_buf__selector == 2) { - compFocusedTertiary_buf_ = (valueDeserializer.readString() as string) - } - else if (compFocusedTertiary_buf__selector == 3) { - compFocusedTertiary_buf_ = valueDeserializer.readResource() - } - else { - throw new Error("One of the branches for compFocusedTertiary_buf_ has to be chosen through deserialisation.") - } - compFocusedTertiary_buf = (compFocusedTertiary_buf_ as Color | number | string | Resource) - } - const compFocusedTertiary_result : ResourceColor | undefined = compFocusedTertiary_buf - const interactiveHover_buf_runtimeType = (valueDeserializer.readInt8() as int32) - let interactiveHover_buf : ResourceColor | undefined - if ((RuntimeType.UNDEFINED) != (interactiveHover_buf_runtimeType)) - { - const interactiveHover_buf__selector : int32 = valueDeserializer.readInt8() - let interactiveHover_buf_ : Color | number | string | Resource | undefined - if (interactiveHover_buf__selector == 0) { - interactiveHover_buf_ = TypeChecker.Color_FromNumeric(valueDeserializer.readInt32()) - } - else if (interactiveHover_buf__selector == 1) { - interactiveHover_buf_ = (valueDeserializer.readNumber() as number) - } - else if (interactiveHover_buf__selector == 2) { - interactiveHover_buf_ = (valueDeserializer.readString() as string) - } - else if (interactiveHover_buf__selector == 3) { - interactiveHover_buf_ = valueDeserializer.readResource() - } - else { - throw new Error("One of the branches for interactiveHover_buf_ has to be chosen through deserialisation.") - } - interactiveHover_buf = (interactiveHover_buf_ as Color | number | string | Resource) - } - const interactiveHover_result : ResourceColor | undefined = interactiveHover_buf - const interactivePressed_buf_runtimeType = (valueDeserializer.readInt8() as int32) - let interactivePressed_buf : ResourceColor | undefined - if ((RuntimeType.UNDEFINED) != (interactivePressed_buf_runtimeType)) - { - const interactivePressed_buf__selector : int32 = valueDeserializer.readInt8() - let interactivePressed_buf_ : Color | number | string | Resource | undefined - if (interactivePressed_buf__selector == 0) { - interactivePressed_buf_ = TypeChecker.Color_FromNumeric(valueDeserializer.readInt32()) - } - else if (interactivePressed_buf__selector == 1) { - interactivePressed_buf_ = (valueDeserializer.readNumber() as number) - } - else if (interactivePressed_buf__selector == 2) { - interactivePressed_buf_ = (valueDeserializer.readString() as string) - } - else if (interactivePressed_buf__selector == 3) { - interactivePressed_buf_ = valueDeserializer.readResource() - } - else { - throw new Error("One of the branches for interactivePressed_buf_ has to be chosen through deserialisation.") - } - interactivePressed_buf = (interactivePressed_buf_ as Color | number | string | Resource) - } - const interactivePressed_result : ResourceColor | undefined = interactivePressed_buf - const interactiveFocus_buf_runtimeType = (valueDeserializer.readInt8() as int32) - let interactiveFocus_buf : ResourceColor | undefined - if ((RuntimeType.UNDEFINED) != (interactiveFocus_buf_runtimeType)) - { - const interactiveFocus_buf__selector : int32 = valueDeserializer.readInt8() - let interactiveFocus_buf_ : Color | number | string | Resource | undefined - if (interactiveFocus_buf__selector == 0) { - interactiveFocus_buf_ = TypeChecker.Color_FromNumeric(valueDeserializer.readInt32()) - } - else if (interactiveFocus_buf__selector == 1) { - interactiveFocus_buf_ = (valueDeserializer.readNumber() as number) - } - else if (interactiveFocus_buf__selector == 2) { - interactiveFocus_buf_ = (valueDeserializer.readString() as string) - } - else if (interactiveFocus_buf__selector == 3) { - interactiveFocus_buf_ = valueDeserializer.readResource() - } - else { - throw new Error("One of the branches for interactiveFocus_buf_ has to be chosen through deserialisation.") - } - interactiveFocus_buf = (interactiveFocus_buf_ as Color | number | string | Resource) - } - const interactiveFocus_result : ResourceColor | undefined = interactiveFocus_buf - const interactiveActive_buf_runtimeType = (valueDeserializer.readInt8() as int32) - let interactiveActive_buf : ResourceColor | undefined - if ((RuntimeType.UNDEFINED) != (interactiveActive_buf_runtimeType)) - { - const interactiveActive_buf__selector : int32 = valueDeserializer.readInt8() - let interactiveActive_buf_ : Color | number | string | Resource | undefined - if (interactiveActive_buf__selector == 0) { - interactiveActive_buf_ = TypeChecker.Color_FromNumeric(valueDeserializer.readInt32()) - } - else if (interactiveActive_buf__selector == 1) { - interactiveActive_buf_ = (valueDeserializer.readNumber() as number) - } - else if (interactiveActive_buf__selector == 2) { - interactiveActive_buf_ = (valueDeserializer.readString() as string) - } - else if (interactiveActive_buf__selector == 3) { - interactiveActive_buf_ = valueDeserializer.readResource() - } - else { - throw new Error("One of the branches for interactiveActive_buf_ has to be chosen through deserialisation.") - } - interactiveActive_buf = (interactiveActive_buf_ as Color | number | string | Resource) - } - const interactiveActive_result : ResourceColor | undefined = interactiveActive_buf - const interactiveSelect_buf_runtimeType = (valueDeserializer.readInt8() as int32) - let interactiveSelect_buf : ResourceColor | undefined - if ((RuntimeType.UNDEFINED) != (interactiveSelect_buf_runtimeType)) - { - const interactiveSelect_buf__selector : int32 = valueDeserializer.readInt8() - let interactiveSelect_buf_ : Color | number | string | Resource | undefined - if (interactiveSelect_buf__selector == 0) { - interactiveSelect_buf_ = TypeChecker.Color_FromNumeric(valueDeserializer.readInt32()) - } - else if (interactiveSelect_buf__selector == 1) { - interactiveSelect_buf_ = (valueDeserializer.readNumber() as number) - } - else if (interactiveSelect_buf__selector == 2) { - interactiveSelect_buf_ = (valueDeserializer.readString() as string) - } - else if (interactiveSelect_buf__selector == 3) { - interactiveSelect_buf_ = valueDeserializer.readResource() - } - else { - throw new Error("One of the branches for interactiveSelect_buf_ has to be chosen through deserialisation.") - } - interactiveSelect_buf = (interactiveSelect_buf_ as Color | number | string | Resource) - } - const interactiveSelect_result : ResourceColor | undefined = interactiveSelect_buf - const interactiveClick_buf_runtimeType = (valueDeserializer.readInt8() as int32) - let interactiveClick_buf : ResourceColor | undefined - if ((RuntimeType.UNDEFINED) != (interactiveClick_buf_runtimeType)) - { - const interactiveClick_buf__selector : int32 = valueDeserializer.readInt8() - let interactiveClick_buf_ : Color | number | string | Resource | undefined - if (interactiveClick_buf__selector == 0) { - interactiveClick_buf_ = TypeChecker.Color_FromNumeric(valueDeserializer.readInt32()) - } - else if (interactiveClick_buf__selector == 1) { - interactiveClick_buf_ = (valueDeserializer.readNumber() as number) - } - else if (interactiveClick_buf__selector == 2) { - interactiveClick_buf_ = (valueDeserializer.readString() as string) - } - else if (interactiveClick_buf__selector == 3) { - interactiveClick_buf_ = valueDeserializer.readResource() - } - else { - throw new Error("One of the branches for interactiveClick_buf_ has to be chosen through deserialisation.") - } - interactiveClick_buf = (interactiveClick_buf_ as Color | number | string | Resource) - } - const interactiveClick_result : ResourceColor | undefined = interactiveClick_buf - let value : CustomColors = ({brand: brand_result, warning: warning_result, alert: alert_result, confirm: confirm_result, fontPrimary: fontPrimary_result, fontSecondary: fontSecondary_result, fontTertiary: fontTertiary_result, fontFourth: fontFourth_result, fontEmphasize: fontEmphasize_result, fontOnPrimary: fontOnPrimary_result, fontOnSecondary: fontOnSecondary_result, fontOnTertiary: fontOnTertiary_result, fontOnFourth: fontOnFourth_result, iconPrimary: iconPrimary_result, iconSecondary: iconSecondary_result, iconTertiary: iconTertiary_result, iconFourth: iconFourth_result, iconEmphasize: iconEmphasize_result, iconSubEmphasize: iconSubEmphasize_result, iconOnPrimary: iconOnPrimary_result, iconOnSecondary: iconOnSecondary_result, iconOnTertiary: iconOnTertiary_result, iconOnFourth: iconOnFourth_result, backgroundPrimary: backgroundPrimary_result, backgroundSecondary: backgroundSecondary_result, backgroundTertiary: backgroundTertiary_result, backgroundFourth: backgroundFourth_result, backgroundEmphasize: backgroundEmphasize_result, compForegroundPrimary: compForegroundPrimary_result, compBackgroundPrimary: compBackgroundPrimary_result, compBackgroundPrimaryTran: compBackgroundPrimaryTran_result, compBackgroundPrimaryContrary: compBackgroundPrimaryContrary_result, compBackgroundGray: compBackgroundGray_result, compBackgroundSecondary: compBackgroundSecondary_result, compBackgroundTertiary: compBackgroundTertiary_result, compBackgroundEmphasize: compBackgroundEmphasize_result, compBackgroundNeutral: compBackgroundNeutral_result, compEmphasizeSecondary: compEmphasizeSecondary_result, compEmphasizeTertiary: compEmphasizeTertiary_result, compDivider: compDivider_result, compCommonContrary: compCommonContrary_result, compBackgroundFocus: compBackgroundFocus_result, compFocusedPrimary: compFocusedPrimary_result, compFocusedSecondary: compFocusedSecondary_result, compFocusedTertiary: compFocusedTertiary_result, interactiveHover: interactiveHover_result, interactivePressed: interactivePressed_result, interactiveFocus: interactiveFocus_result, interactiveActive: interactiveActive_result, interactiveSelect: interactiveSelect_result, interactiveClick: interactiveClick_result} as CustomColors) - return value - } + // readCustomColors(): CustomColors { + // let valueDeserializer : Deserializer = this + // const brand_buf_runtimeType = (valueDeserializer.readInt8() as int32) + // let brand_buf : ResourceColor | undefined + // if ((RuntimeType.UNDEFINED) != (brand_buf_runtimeType)) + // { + // const brand_buf__selector : int32 = valueDeserializer.readInt8() + // let brand_buf_ : Color | number | string | Resource | undefined + // if (brand_buf__selector == 0) { + // brand_buf_ = TypeChecker.Color_FromNumeric(valueDeserializer.readInt32()) + // } + // else if (brand_buf__selector == 1) { + // brand_buf_ = (valueDeserializer.readNumber() as number) + // } + // else if (brand_buf__selector == 2) { + // brand_buf_ = (valueDeserializer.readString() as string) + // } + // else if (brand_buf__selector == 3) { + // brand_buf_ = valueDeserializer.readResource() + // } + // else { + // throw new Error("One of the branches for brand_buf_ has to be chosen through deserialisation.") + // } + // brand_buf = (brand_buf_ as Color | number | string | Resource) + // } + // const brand_result : ResourceColor | undefined = brand_buf + // const warning_buf_runtimeType = (valueDeserializer.readInt8() as int32) + // let warning_buf : ResourceColor | undefined + // if ((RuntimeType.UNDEFINED) != (warning_buf_runtimeType)) + // { + // const warning_buf__selector : int32 = valueDeserializer.readInt8() + // let warning_buf_ : Color | number | string | Resource | undefined + // if (warning_buf__selector == 0) { + // warning_buf_ = TypeChecker.Color_FromNumeric(valueDeserializer.readInt32()) + // } + // else if (warning_buf__selector == 1) { + // warning_buf_ = (valueDeserializer.readNumber() as number) + // } + // else if (warning_buf__selector == 2) { + // warning_buf_ = (valueDeserializer.readString() as string) + // } + // else if (warning_buf__selector == 3) { + // warning_buf_ = valueDeserializer.readResource() + // } + // else { + // throw new Error("One of the branches for warning_buf_ has to be chosen through deserialisation.") + // } + // warning_buf = (warning_buf_ as Color | number | string | Resource) + // } + // const warning_result : ResourceColor | undefined = warning_buf + // const alert_buf_runtimeType = (valueDeserializer.readInt8() as int32) + // let alert_buf : ResourceColor | undefined + // if ((RuntimeType.UNDEFINED) != (alert_buf_runtimeType)) + // { + // const alert_buf__selector : int32 = valueDeserializer.readInt8() + // let alert_buf_ : Color | number | string | Resource | undefined + // if (alert_buf__selector == 0) { + // alert_buf_ = TypeChecker.Color_FromNumeric(valueDeserializer.readInt32()) + // } + // else if (alert_buf__selector == 1) { + // alert_buf_ = (valueDeserializer.readNumber() as number) + // } + // else if (alert_buf__selector == 2) { + // alert_buf_ = (valueDeserializer.readString() as string) + // } + // else if (alert_buf__selector == 3) { + // alert_buf_ = valueDeserializer.readResource() + // } + // else { + // throw new Error("One of the branches for alert_buf_ has to be chosen through deserialisation.") + // } + // alert_buf = (alert_buf_ as Color | number | string | Resource) + // } + // const alert_result : ResourceColor | undefined = alert_buf + // const confirm_buf_runtimeType = (valueDeserializer.readInt8() as int32) + // let confirm_buf : ResourceColor | undefined + // if ((RuntimeType.UNDEFINED) != (confirm_buf_runtimeType)) + // { + // const confirm_buf__selector : int32 = valueDeserializer.readInt8() + // let confirm_buf_ : Color | number | string | Resource | undefined + // if (confirm_buf__selector == 0) { + // confirm_buf_ = TypeChecker.Color_FromNumeric(valueDeserializer.readInt32()) + // } + // else if (confirm_buf__selector == 1) { + // confirm_buf_ = (valueDeserializer.readNumber() as number) + // } + // else if (confirm_buf__selector == 2) { + // confirm_buf_ = (valueDeserializer.readString() as string) + // } + // else if (confirm_buf__selector == 3) { + // confirm_buf_ = valueDeserializer.readResource() + // } + // else { + // throw new Error("One of the branches for confirm_buf_ has to be chosen through deserialisation.") + // } + // confirm_buf = (confirm_buf_ as Color | number | string | Resource) + // } + // const confirm_result : ResourceColor | undefined = confirm_buf + // const fontPrimary_buf_runtimeType = (valueDeserializer.readInt8() as int32) + // let fontPrimary_buf : ResourceColor | undefined + // if ((RuntimeType.UNDEFINED) != (fontPrimary_buf_runtimeType)) + // { + // const fontPrimary_buf__selector : int32 = valueDeserializer.readInt8() + // let fontPrimary_buf_ : Color | number | string | Resource | undefined + // if (fontPrimary_buf__selector == 0) { + // fontPrimary_buf_ = TypeChecker.Color_FromNumeric(valueDeserializer.readInt32()) + // } + // else if (fontPrimary_buf__selector == 1) { + // fontPrimary_buf_ = (valueDeserializer.readNumber() as number) + // } + // else if (fontPrimary_buf__selector == 2) { + // fontPrimary_buf_ = (valueDeserializer.readString() as string) + // } + // else if (fontPrimary_buf__selector == 3) { + // fontPrimary_buf_ = valueDeserializer.readResource() + // } + // else { + // throw new Error("One of the branches for fontPrimary_buf_ has to be chosen through deserialisation.") + // } + // fontPrimary_buf = (fontPrimary_buf_ as Color | number | string | Resource) + // } + // const fontPrimary_result : ResourceColor | undefined = fontPrimary_buf + // const fontSecondary_buf_runtimeType = (valueDeserializer.readInt8() as int32) + // let fontSecondary_buf : ResourceColor | undefined + // if ((RuntimeType.UNDEFINED) != (fontSecondary_buf_runtimeType)) + // { + // const fontSecondary_buf__selector : int32 = valueDeserializer.readInt8() + // let fontSecondary_buf_ : Color | number | string | Resource | undefined + // if (fontSecondary_buf__selector == 0) { + // fontSecondary_buf_ = TypeChecker.Color_FromNumeric(valueDeserializer.readInt32()) + // } + // else if (fontSecondary_buf__selector == 1) { + // fontSecondary_buf_ = (valueDeserializer.readNumber() as number) + // } + // else if (fontSecondary_buf__selector == 2) { + // fontSecondary_buf_ = (valueDeserializer.readString() as string) + // } + // else if (fontSecondary_buf__selector == 3) { + // fontSecondary_buf_ = valueDeserializer.readResource() + // } + // else { + // throw new Error("One of the branches for fontSecondary_buf_ has to be chosen through deserialisation.") + // } + // fontSecondary_buf = (fontSecondary_buf_ as Color | number | string | Resource) + // } + // const fontSecondary_result : ResourceColor | undefined = fontSecondary_buf + // const fontTertiary_buf_runtimeType = (valueDeserializer.readInt8() as int32) + // let fontTertiary_buf : ResourceColor | undefined + // if ((RuntimeType.UNDEFINED) != (fontTertiary_buf_runtimeType)) + // { + // const fontTertiary_buf__selector : int32 = valueDeserializer.readInt8() + // let fontTertiary_buf_ : Color | number | string | Resource | undefined + // if (fontTertiary_buf__selector == 0) { + // fontTertiary_buf_ = TypeChecker.Color_FromNumeric(valueDeserializer.readInt32()) + // } + // else if (fontTertiary_buf__selector == 1) { + // fontTertiary_buf_ = (valueDeserializer.readNumber() as number) + // } + // else if (fontTertiary_buf__selector == 2) { + // fontTertiary_buf_ = (valueDeserializer.readString() as string) + // } + // else if (fontTertiary_buf__selector == 3) { + // fontTertiary_buf_ = valueDeserializer.readResource() + // } + // else { + // throw new Error("One of the branches for fontTertiary_buf_ has to be chosen through deserialisation.") + // } + // fontTertiary_buf = (fontTertiary_buf_ as Color | number | string | Resource) + // } + // const fontTertiary_result : ResourceColor | undefined = fontTertiary_buf + // const fontFourth_buf_runtimeType = (valueDeserializer.readInt8() as int32) + // let fontFourth_buf : ResourceColor | undefined + // if ((RuntimeType.UNDEFINED) != (fontFourth_buf_runtimeType)) + // { + // const fontFourth_buf__selector : int32 = valueDeserializer.readInt8() + // let fontFourth_buf_ : Color | number | string | Resource | undefined + // if (fontFourth_buf__selector == 0) { + // fontFourth_buf_ = TypeChecker.Color_FromNumeric(valueDeserializer.readInt32()) + // } + // else if (fontFourth_buf__selector == 1) { + // fontFourth_buf_ = (valueDeserializer.readNumber() as number) + // } + // else if (fontFourth_buf__selector == 2) { + // fontFourth_buf_ = (valueDeserializer.readString() as string) + // } + // else if (fontFourth_buf__selector == 3) { + // fontFourth_buf_ = valueDeserializer.readResource() + // } + // else { + // throw new Error("One of the branches for fontFourth_buf_ has to be chosen through deserialisation.") + // } + // fontFourth_buf = (fontFourth_buf_ as Color | number | string | Resource) + // } + // const fontFourth_result : ResourceColor | undefined = fontFourth_buf + // const fontEmphasize_buf_runtimeType = (valueDeserializer.readInt8() as int32) + // let fontEmphasize_buf : ResourceColor | undefined + // if ((RuntimeType.UNDEFINED) != (fontEmphasize_buf_runtimeType)) + // { + // const fontEmphasize_buf__selector : int32 = valueDeserializer.readInt8() + // let fontEmphasize_buf_ : Color | number | string | Resource | undefined + // if (fontEmphasize_buf__selector == 0) { + // fontEmphasize_buf_ = TypeChecker.Color_FromNumeric(valueDeserializer.readInt32()) + // } + // else if (fontEmphasize_buf__selector == 1) { + // fontEmphasize_buf_ = (valueDeserializer.readNumber() as number) + // } + // else if (fontEmphasize_buf__selector == 2) { + // fontEmphasize_buf_ = (valueDeserializer.readString() as string) + // } + // else if (fontEmphasize_buf__selector == 3) { + // fontEmphasize_buf_ = valueDeserializer.readResource() + // } + // else { + // throw new Error("One of the branches for fontEmphasize_buf_ has to be chosen through deserialisation.") + // } + // fontEmphasize_buf = (fontEmphasize_buf_ as Color | number | string | Resource) + // } + // const fontEmphasize_result : ResourceColor | undefined = fontEmphasize_buf + // const fontOnPrimary_buf_runtimeType = (valueDeserializer.readInt8() as int32) + // let fontOnPrimary_buf : ResourceColor | undefined + // if ((RuntimeType.UNDEFINED) != (fontOnPrimary_buf_runtimeType)) + // { + // const fontOnPrimary_buf__selector : int32 = valueDeserializer.readInt8() + // let fontOnPrimary_buf_ : Color | number | string | Resource | undefined + // if (fontOnPrimary_buf__selector == 0) { + // fontOnPrimary_buf_ = TypeChecker.Color_FromNumeric(valueDeserializer.readInt32()) + // } + // else if (fontOnPrimary_buf__selector == 1) { + // fontOnPrimary_buf_ = (valueDeserializer.readNumber() as number) + // } + // else if (fontOnPrimary_buf__selector == 2) { + // fontOnPrimary_buf_ = (valueDeserializer.readString() as string) + // } + // else if (fontOnPrimary_buf__selector == 3) { + // fontOnPrimary_buf_ = valueDeserializer.readResource() + // } + // else { + // throw new Error("One of the branches for fontOnPrimary_buf_ has to be chosen through deserialisation.") + // } + // fontOnPrimary_buf = (fontOnPrimary_buf_ as Color | number | string | Resource) + // } + // const fontOnPrimary_result : ResourceColor | undefined = fontOnPrimary_buf + // const fontOnSecondary_buf_runtimeType = (valueDeserializer.readInt8() as int32) + // let fontOnSecondary_buf : ResourceColor | undefined + // if ((RuntimeType.UNDEFINED) != (fontOnSecondary_buf_runtimeType)) + // { + // const fontOnSecondary_buf__selector : int32 = valueDeserializer.readInt8() + // let fontOnSecondary_buf_ : Color | number | string | Resource | undefined + // if (fontOnSecondary_buf__selector == 0) { + // fontOnSecondary_buf_ = TypeChecker.Color_FromNumeric(valueDeserializer.readInt32()) + // } + // else if (fontOnSecondary_buf__selector == 1) { + // fontOnSecondary_buf_ = (valueDeserializer.readNumber() as number) + // } + // else if (fontOnSecondary_buf__selector == 2) { + // fontOnSecondary_buf_ = (valueDeserializer.readString() as string) + // } + // else if (fontOnSecondary_buf__selector == 3) { + // fontOnSecondary_buf_ = valueDeserializer.readResource() + // } + // else { + // throw new Error("One of the branches for fontOnSecondary_buf_ has to be chosen through deserialisation.") + // } + // fontOnSecondary_buf = (fontOnSecondary_buf_ as Color | number | string | Resource) + // } + // const fontOnSecondary_result : ResourceColor | undefined = fontOnSecondary_buf + // const fontOnTertiary_buf_runtimeType = (valueDeserializer.readInt8() as int32) + // let fontOnTertiary_buf : ResourceColor | undefined + // if ((RuntimeType.UNDEFINED) != (fontOnTertiary_buf_runtimeType)) + // { + // const fontOnTertiary_buf__selector : int32 = valueDeserializer.readInt8() + // let fontOnTertiary_buf_ : Color | number | string | Resource | undefined + // if (fontOnTertiary_buf__selector == 0) { + // fontOnTertiary_buf_ = TypeChecker.Color_FromNumeric(valueDeserializer.readInt32()) + // } + // else if (fontOnTertiary_buf__selector == 1) { + // fontOnTertiary_buf_ = (valueDeserializer.readNumber() as number) + // } + // else if (fontOnTertiary_buf__selector == 2) { + // fontOnTertiary_buf_ = (valueDeserializer.readString() as string) + // } + // else if (fontOnTertiary_buf__selector == 3) { + // fontOnTertiary_buf_ = valueDeserializer.readResource() + // } + // else { + // throw new Error("One of the branches for fontOnTertiary_buf_ has to be chosen through deserialisation.") + // } + // fontOnTertiary_buf = (fontOnTertiary_buf_ as Color | number | string | Resource) + // } + // const fontOnTertiary_result : ResourceColor | undefined = fontOnTertiary_buf + // const fontOnFourth_buf_runtimeType = (valueDeserializer.readInt8() as int32) + // let fontOnFourth_buf : ResourceColor | undefined + // if ((RuntimeType.UNDEFINED) != (fontOnFourth_buf_runtimeType)) + // { + // const fontOnFourth_buf__selector : int32 = valueDeserializer.readInt8() + // let fontOnFourth_buf_ : Color | number | string | Resource | undefined + // if (fontOnFourth_buf__selector == 0) { + // fontOnFourth_buf_ = TypeChecker.Color_FromNumeric(valueDeserializer.readInt32()) + // } + // else if (fontOnFourth_buf__selector == 1) { + // fontOnFourth_buf_ = (valueDeserializer.readNumber() as number) + // } + // else if (fontOnFourth_buf__selector == 2) { + // fontOnFourth_buf_ = (valueDeserializer.readString() as string) + // } + // else if (fontOnFourth_buf__selector == 3) { + // fontOnFourth_buf_ = valueDeserializer.readResource() + // } + // else { + // throw new Error("One of the branches for fontOnFourth_buf_ has to be chosen through deserialisation.") + // } + // fontOnFourth_buf = (fontOnFourth_buf_ as Color | number | string | Resource) + // } + // const fontOnFourth_result : ResourceColor | undefined = fontOnFourth_buf + // const iconPrimary_buf_runtimeType = (valueDeserializer.readInt8() as int32) + // let iconPrimary_buf : ResourceColor | undefined + // if ((RuntimeType.UNDEFINED) != (iconPrimary_buf_runtimeType)) + // { + // const iconPrimary_buf__selector : int32 = valueDeserializer.readInt8() + // let iconPrimary_buf_ : Color | number | string | Resource | undefined + // if (iconPrimary_buf__selector == 0) { + // iconPrimary_buf_ = TypeChecker.Color_FromNumeric(valueDeserializer.readInt32()) + // } + // else if (iconPrimary_buf__selector == 1) { + // iconPrimary_buf_ = (valueDeserializer.readNumber() as number) + // } + // else if (iconPrimary_buf__selector == 2) { + // iconPrimary_buf_ = (valueDeserializer.readString() as string) + // } + // else if (iconPrimary_buf__selector == 3) { + // iconPrimary_buf_ = valueDeserializer.readResource() + // } + // else { + // throw new Error("One of the branches for iconPrimary_buf_ has to be chosen through deserialisation.") + // } + // iconPrimary_buf = (iconPrimary_buf_ as Color | number | string | Resource) + // } + // const iconPrimary_result : ResourceColor | undefined = iconPrimary_buf + // const iconSecondary_buf_runtimeType = (valueDeserializer.readInt8() as int32) + // let iconSecondary_buf : ResourceColor | undefined + // if ((RuntimeType.UNDEFINED) != (iconSecondary_buf_runtimeType)) + // { + // const iconSecondary_buf__selector : int32 = valueDeserializer.readInt8() + // let iconSecondary_buf_ : Color | number | string | Resource | undefined + // if (iconSecondary_buf__selector == 0) { + // iconSecondary_buf_ = TypeChecker.Color_FromNumeric(valueDeserializer.readInt32()) + // } + // else if (iconSecondary_buf__selector == 1) { + // iconSecondary_buf_ = (valueDeserializer.readNumber() as number) + // } + // else if (iconSecondary_buf__selector == 2) { + // iconSecondary_buf_ = (valueDeserializer.readString() as string) + // } + // else if (iconSecondary_buf__selector == 3) { + // iconSecondary_buf_ = valueDeserializer.readResource() + // } + // else { + // throw new Error("One of the branches for iconSecondary_buf_ has to be chosen through deserialisation.") + // } + // iconSecondary_buf = (iconSecondary_buf_ as Color | number | string | Resource) + // } + // const iconSecondary_result : ResourceColor | undefined = iconSecondary_buf + // const iconTertiary_buf_runtimeType = (valueDeserializer.readInt8() as int32) + // let iconTertiary_buf : ResourceColor | undefined + // if ((RuntimeType.UNDEFINED) != (iconTertiary_buf_runtimeType)) + // { + // const iconTertiary_buf__selector : int32 = valueDeserializer.readInt8() + // let iconTertiary_buf_ : Color | number | string | Resource | undefined + // if (iconTertiary_buf__selector == 0) { + // iconTertiary_buf_ = TypeChecker.Color_FromNumeric(valueDeserializer.readInt32()) + // } + // else if (iconTertiary_buf__selector == 1) { + // iconTertiary_buf_ = (valueDeserializer.readNumber() as number) + // } + // else if (iconTertiary_buf__selector == 2) { + // iconTertiary_buf_ = (valueDeserializer.readString() as string) + // } + // else if (iconTertiary_buf__selector == 3) { + // iconTertiary_buf_ = valueDeserializer.readResource() + // } + // else { + // throw new Error("One of the branches for iconTertiary_buf_ has to be chosen through deserialisation.") + // } + // iconTertiary_buf = (iconTertiary_buf_ as Color | number | string | Resource) + // } + // const iconTertiary_result : ResourceColor | undefined = iconTertiary_buf + // const iconFourth_buf_runtimeType = (valueDeserializer.readInt8() as int32) + // let iconFourth_buf : ResourceColor | undefined + // if ((RuntimeType.UNDEFINED) != (iconFourth_buf_runtimeType)) + // { + // const iconFourth_buf__selector : int32 = valueDeserializer.readInt8() + // let iconFourth_buf_ : Color | number | string | Resource | undefined + // if (iconFourth_buf__selector == 0) { + // iconFourth_buf_ = TypeChecker.Color_FromNumeric(valueDeserializer.readInt32()) + // } + // else if (iconFourth_buf__selector == 1) { + // iconFourth_buf_ = (valueDeserializer.readNumber() as number) + // } + // else if (iconFourth_buf__selector == 2) { + // iconFourth_buf_ = (valueDeserializer.readString() as string) + // } + // else if (iconFourth_buf__selector == 3) { + // iconFourth_buf_ = valueDeserializer.readResource() + // } + // else { + // throw new Error("One of the branches for iconFourth_buf_ has to be chosen through deserialisation.") + // } + // iconFourth_buf = (iconFourth_buf_ as Color | number | string | Resource) + // } + // const iconFourth_result : ResourceColor | undefined = iconFourth_buf + // const iconEmphasize_buf_runtimeType = (valueDeserializer.readInt8() as int32) + // let iconEmphasize_buf : ResourceColor | undefined + // if ((RuntimeType.UNDEFINED) != (iconEmphasize_buf_runtimeType)) + // { + // const iconEmphasize_buf__selector : int32 = valueDeserializer.readInt8() + // let iconEmphasize_buf_ : Color | number | string | Resource | undefined + // if (iconEmphasize_buf__selector == 0) { + // iconEmphasize_buf_ = TypeChecker.Color_FromNumeric(valueDeserializer.readInt32()) + // } + // else if (iconEmphasize_buf__selector == 1) { + // iconEmphasize_buf_ = (valueDeserializer.readNumber() as number) + // } + // else if (iconEmphasize_buf__selector == 2) { + // iconEmphasize_buf_ = (valueDeserializer.readString() as string) + // } + // else if (iconEmphasize_buf__selector == 3) { + // iconEmphasize_buf_ = valueDeserializer.readResource() + // } + // else { + // throw new Error("One of the branches for iconEmphasize_buf_ has to be chosen through deserialisation.") + // } + // iconEmphasize_buf = (iconEmphasize_buf_ as Color | number | string | Resource) + // } + // const iconEmphasize_result : ResourceColor | undefined = iconEmphasize_buf + // const iconSubEmphasize_buf_runtimeType = (valueDeserializer.readInt8() as int32) + // let iconSubEmphasize_buf : ResourceColor | undefined + // if ((RuntimeType.UNDEFINED) != (iconSubEmphasize_buf_runtimeType)) + // { + // const iconSubEmphasize_buf__selector : int32 = valueDeserializer.readInt8() + // let iconSubEmphasize_buf_ : Color | number | string | Resource | undefined + // if (iconSubEmphasize_buf__selector == 0) { + // iconSubEmphasize_buf_ = TypeChecker.Color_FromNumeric(valueDeserializer.readInt32()) + // } + // else if (iconSubEmphasize_buf__selector == 1) { + // iconSubEmphasize_buf_ = (valueDeserializer.readNumber() as number) + // } + // else if (iconSubEmphasize_buf__selector == 2) { + // iconSubEmphasize_buf_ = (valueDeserializer.readString() as string) + // } + // else if (iconSubEmphasize_buf__selector == 3) { + // iconSubEmphasize_buf_ = valueDeserializer.readResource() + // } + // else { + // throw new Error("One of the branches for iconSubEmphasize_buf_ has to be chosen through deserialisation.") + // } + // iconSubEmphasize_buf = (iconSubEmphasize_buf_ as Color | number | string | Resource) + // } + // const iconSubEmphasize_result : ResourceColor | undefined = iconSubEmphasize_buf + // const iconOnPrimary_buf_runtimeType = (valueDeserializer.readInt8() as int32) + // let iconOnPrimary_buf : ResourceColor | undefined + // if ((RuntimeType.UNDEFINED) != (iconOnPrimary_buf_runtimeType)) + // { + // const iconOnPrimary_buf__selector : int32 = valueDeserializer.readInt8() + // let iconOnPrimary_buf_ : Color | number | string | Resource | undefined + // if (iconOnPrimary_buf__selector == 0) { + // iconOnPrimary_buf_ = TypeChecker.Color_FromNumeric(valueDeserializer.readInt32()) + // } + // else if (iconOnPrimary_buf__selector == 1) { + // iconOnPrimary_buf_ = (valueDeserializer.readNumber() as number) + // } + // else if (iconOnPrimary_buf__selector == 2) { + // iconOnPrimary_buf_ = (valueDeserializer.readString() as string) + // } + // else if (iconOnPrimary_buf__selector == 3) { + // iconOnPrimary_buf_ = valueDeserializer.readResource() + // } + // else { + // throw new Error("One of the branches for iconOnPrimary_buf_ has to be chosen through deserialisation.") + // } + // iconOnPrimary_buf = (iconOnPrimary_buf_ as Color | number | string | Resource) + // } + // const iconOnPrimary_result : ResourceColor | undefined = iconOnPrimary_buf + // const iconOnSecondary_buf_runtimeType = (valueDeserializer.readInt8() as int32) + // let iconOnSecondary_buf : ResourceColor | undefined + // if ((RuntimeType.UNDEFINED) != (iconOnSecondary_buf_runtimeType)) + // { + // const iconOnSecondary_buf__selector : int32 = valueDeserializer.readInt8() + // let iconOnSecondary_buf_ : Color | number | string | Resource | undefined + // if (iconOnSecondary_buf__selector == 0) { + // iconOnSecondary_buf_ = TypeChecker.Color_FromNumeric(valueDeserializer.readInt32()) + // } + // else if (iconOnSecondary_buf__selector == 1) { + // iconOnSecondary_buf_ = (valueDeserializer.readNumber() as number) + // } + // else if (iconOnSecondary_buf__selector == 2) { + // iconOnSecondary_buf_ = (valueDeserializer.readString() as string) + // } + // else if (iconOnSecondary_buf__selector == 3) { + // iconOnSecondary_buf_ = valueDeserializer.readResource() + // } + // else { + // throw new Error("One of the branches for iconOnSecondary_buf_ has to be chosen through deserialisation.") + // } + // iconOnSecondary_buf = (iconOnSecondary_buf_ as Color | number | string | Resource) + // } + // const iconOnSecondary_result : ResourceColor | undefined = iconOnSecondary_buf + // const iconOnTertiary_buf_runtimeType = (valueDeserializer.readInt8() as int32) + // let iconOnTertiary_buf : ResourceColor | undefined + // if ((RuntimeType.UNDEFINED) != (iconOnTertiary_buf_runtimeType)) + // { + // const iconOnTertiary_buf__selector : int32 = valueDeserializer.readInt8() + // let iconOnTertiary_buf_ : Color | number | string | Resource | undefined + // if (iconOnTertiary_buf__selector == 0) { + // iconOnTertiary_buf_ = TypeChecker.Color_FromNumeric(valueDeserializer.readInt32()) + // } + // else if (iconOnTertiary_buf__selector == 1) { + // iconOnTertiary_buf_ = (valueDeserializer.readNumber() as number) + // } + // else if (iconOnTertiary_buf__selector == 2) { + // iconOnTertiary_buf_ = (valueDeserializer.readString() as string) + // } + // else if (iconOnTertiary_buf__selector == 3) { + // iconOnTertiary_buf_ = valueDeserializer.readResource() + // } + // else { + // throw new Error("One of the branches for iconOnTertiary_buf_ has to be chosen through deserialisation.") + // } + // iconOnTertiary_buf = (iconOnTertiary_buf_ as Color | number | string | Resource) + // } + // const iconOnTertiary_result : ResourceColor | undefined = iconOnTertiary_buf + // const iconOnFourth_buf_runtimeType = (valueDeserializer.readInt8() as int32) + // let iconOnFourth_buf : ResourceColor | undefined + // if ((RuntimeType.UNDEFINED) != (iconOnFourth_buf_runtimeType)) + // { + // const iconOnFourth_buf__selector : int32 = valueDeserializer.readInt8() + // let iconOnFourth_buf_ : Color | number | string | Resource | undefined + // if (iconOnFourth_buf__selector == 0) { + // iconOnFourth_buf_ = TypeChecker.Color_FromNumeric(valueDeserializer.readInt32()) + // } + // else if (iconOnFourth_buf__selector == 1) { + // iconOnFourth_buf_ = (valueDeserializer.readNumber() as number) + // } + // else if (iconOnFourth_buf__selector == 2) { + // iconOnFourth_buf_ = (valueDeserializer.readString() as string) + // } + // else if (iconOnFourth_buf__selector == 3) { + // iconOnFourth_buf_ = valueDeserializer.readResource() + // } + // else { + // throw new Error("One of the branches for iconOnFourth_buf_ has to be chosen through deserialisation.") + // } + // iconOnFourth_buf = (iconOnFourth_buf_ as Color | number | string | Resource) + // } + // const iconOnFourth_result : ResourceColor | undefined = iconOnFourth_buf + // const backgroundPrimary_buf_runtimeType = (valueDeserializer.readInt8() as int32) + // let backgroundPrimary_buf : ResourceColor | undefined + // if ((RuntimeType.UNDEFINED) != (backgroundPrimary_buf_runtimeType)) + // { + // const backgroundPrimary_buf__selector : int32 = valueDeserializer.readInt8() + // let backgroundPrimary_buf_ : Color | number | string | Resource | undefined + // if (backgroundPrimary_buf__selector == 0) { + // backgroundPrimary_buf_ = TypeChecker.Color_FromNumeric(valueDeserializer.readInt32()) + // } + // else if (backgroundPrimary_buf__selector == 1) { + // backgroundPrimary_buf_ = (valueDeserializer.readNumber() as number) + // } + // else if (backgroundPrimary_buf__selector == 2) { + // backgroundPrimary_buf_ = (valueDeserializer.readString() as string) + // } + // else if (backgroundPrimary_buf__selector == 3) { + // backgroundPrimary_buf_ = valueDeserializer.readResource() + // } + // else { + // throw new Error("One of the branches for backgroundPrimary_buf_ has to be chosen through deserialisation.") + // } + // backgroundPrimary_buf = (backgroundPrimary_buf_ as Color | number | string | Resource) + // } + // const backgroundPrimary_result : ResourceColor | undefined = backgroundPrimary_buf + // const backgroundSecondary_buf_runtimeType = (valueDeserializer.readInt8() as int32) + // let backgroundSecondary_buf : ResourceColor | undefined + // if ((RuntimeType.UNDEFINED) != (backgroundSecondary_buf_runtimeType)) + // { + // const backgroundSecondary_buf__selector : int32 = valueDeserializer.readInt8() + // let backgroundSecondary_buf_ : Color | number | string | Resource | undefined + // if (backgroundSecondary_buf__selector == 0) { + // backgroundSecondary_buf_ = TypeChecker.Color_FromNumeric(valueDeserializer.readInt32()) + // } + // else if (backgroundSecondary_buf__selector == 1) { + // backgroundSecondary_buf_ = (valueDeserializer.readNumber() as number) + // } + // else if (backgroundSecondary_buf__selector == 2) { + // backgroundSecondary_buf_ = (valueDeserializer.readString() as string) + // } + // else if (backgroundSecondary_buf__selector == 3) { + // backgroundSecondary_buf_ = valueDeserializer.readResource() + // } + // else { + // throw new Error("One of the branches for backgroundSecondary_buf_ has to be chosen through deserialisation.") + // } + // backgroundSecondary_buf = (backgroundSecondary_buf_ as Color | number | string | Resource) + // } + // const backgroundSecondary_result : ResourceColor | undefined = backgroundSecondary_buf + // const backgroundTertiary_buf_runtimeType = (valueDeserializer.readInt8() as int32) + // let backgroundTertiary_buf : ResourceColor | undefined + // if ((RuntimeType.UNDEFINED) != (backgroundTertiary_buf_runtimeType)) + // { + // const backgroundTertiary_buf__selector : int32 = valueDeserializer.readInt8() + // let backgroundTertiary_buf_ : Color | number | string | Resource | undefined + // if (backgroundTertiary_buf__selector == 0) { + // backgroundTertiary_buf_ = TypeChecker.Color_FromNumeric(valueDeserializer.readInt32()) + // } + // else if (backgroundTertiary_buf__selector == 1) { + // backgroundTertiary_buf_ = (valueDeserializer.readNumber() as number) + // } + // else if (backgroundTertiary_buf__selector == 2) { + // backgroundTertiary_buf_ = (valueDeserializer.readString() as string) + // } + // else if (backgroundTertiary_buf__selector == 3) { + // backgroundTertiary_buf_ = valueDeserializer.readResource() + // } + // else { + // throw new Error("One of the branches for backgroundTertiary_buf_ has to be chosen through deserialisation.") + // } + // backgroundTertiary_buf = (backgroundTertiary_buf_ as Color | number | string | Resource) + // } + // const backgroundTertiary_result : ResourceColor | undefined = backgroundTertiary_buf + // const backgroundFourth_buf_runtimeType = (valueDeserializer.readInt8() as int32) + // let backgroundFourth_buf : ResourceColor | undefined + // if ((RuntimeType.UNDEFINED) != (backgroundFourth_buf_runtimeType)) + // { + // const backgroundFourth_buf__selector : int32 = valueDeserializer.readInt8() + // let backgroundFourth_buf_ : Color | number | string | Resource | undefined + // if (backgroundFourth_buf__selector == 0) { + // backgroundFourth_buf_ = TypeChecker.Color_FromNumeric(valueDeserializer.readInt32()) + // } + // else if (backgroundFourth_buf__selector == 1) { + // backgroundFourth_buf_ = (valueDeserializer.readNumber() as number) + // } + // else if (backgroundFourth_buf__selector == 2) { + // backgroundFourth_buf_ = (valueDeserializer.readString() as string) + // } + // else if (backgroundFourth_buf__selector == 3) { + // backgroundFourth_buf_ = valueDeserializer.readResource() + // } + // else { + // throw new Error("One of the branches for backgroundFourth_buf_ has to be chosen through deserialisation.") + // } + // backgroundFourth_buf = (backgroundFourth_buf_ as Color | number | string | Resource) + // } + // const backgroundFourth_result : ResourceColor | undefined = backgroundFourth_buf + // const backgroundEmphasize_buf_runtimeType = (valueDeserializer.readInt8() as int32) + // let backgroundEmphasize_buf : ResourceColor | undefined + // if ((RuntimeType.UNDEFINED) != (backgroundEmphasize_buf_runtimeType)) + // { + // const backgroundEmphasize_buf__selector : int32 = valueDeserializer.readInt8() + // let backgroundEmphasize_buf_ : Color | number | string | Resource | undefined + // if (backgroundEmphasize_buf__selector == 0) { + // backgroundEmphasize_buf_ = TypeChecker.Color_FromNumeric(valueDeserializer.readInt32()) + // } + // else if (backgroundEmphasize_buf__selector == 1) { + // backgroundEmphasize_buf_ = (valueDeserializer.readNumber() as number) + // } + // else if (backgroundEmphasize_buf__selector == 2) { + // backgroundEmphasize_buf_ = (valueDeserializer.readString() as string) + // } + // else if (backgroundEmphasize_buf__selector == 3) { + // backgroundEmphasize_buf_ = valueDeserializer.readResource() + // } + // else { + // throw new Error("One of the branches for backgroundEmphasize_buf_ has to be chosen through deserialisation.") + // } + // backgroundEmphasize_buf = (backgroundEmphasize_buf_ as Color | number | string | Resource) + // } + // const backgroundEmphasize_result : ResourceColor | undefined = backgroundEmphasize_buf + // const compForegroundPrimary_buf_runtimeType = (valueDeserializer.readInt8() as int32) + // let compForegroundPrimary_buf : ResourceColor | undefined + // if ((RuntimeType.UNDEFINED) != (compForegroundPrimary_buf_runtimeType)) + // { + // const compForegroundPrimary_buf__selector : int32 = valueDeserializer.readInt8() + // let compForegroundPrimary_buf_ : Color | number | string | Resource | undefined + // if (compForegroundPrimary_buf__selector == 0) { + // compForegroundPrimary_buf_ = TypeChecker.Color_FromNumeric(valueDeserializer.readInt32()) + // } + // else if (compForegroundPrimary_buf__selector == 1) { + // compForegroundPrimary_buf_ = (valueDeserializer.readNumber() as number) + // } + // else if (compForegroundPrimary_buf__selector == 2) { + // compForegroundPrimary_buf_ = (valueDeserializer.readString() as string) + // } + // else if (compForegroundPrimary_buf__selector == 3) { + // compForegroundPrimary_buf_ = valueDeserializer.readResource() + // } + // else { + // throw new Error("One of the branches for compForegroundPrimary_buf_ has to be chosen through deserialisation.") + // } + // compForegroundPrimary_buf = (compForegroundPrimary_buf_ as Color | number | string | Resource) + // } + // const compForegroundPrimary_result : ResourceColor | undefined = compForegroundPrimary_buf + // const compBackgroundPrimary_buf_runtimeType = (valueDeserializer.readInt8() as int32) + // let compBackgroundPrimary_buf : ResourceColor | undefined + // if ((RuntimeType.UNDEFINED) != (compBackgroundPrimary_buf_runtimeType)) + // { + // const compBackgroundPrimary_buf__selector : int32 = valueDeserializer.readInt8() + // let compBackgroundPrimary_buf_ : Color | number | string | Resource | undefined + // if (compBackgroundPrimary_buf__selector == 0) { + // compBackgroundPrimary_buf_ = TypeChecker.Color_FromNumeric(valueDeserializer.readInt32()) + // } + // else if (compBackgroundPrimary_buf__selector == 1) { + // compBackgroundPrimary_buf_ = (valueDeserializer.readNumber() as number) + // } + // else if (compBackgroundPrimary_buf__selector == 2) { + // compBackgroundPrimary_buf_ = (valueDeserializer.readString() as string) + // } + // else if (compBackgroundPrimary_buf__selector == 3) { + // compBackgroundPrimary_buf_ = valueDeserializer.readResource() + // } + // else { + // throw new Error("One of the branches for compBackgroundPrimary_buf_ has to be chosen through deserialisation.") + // } + // compBackgroundPrimary_buf = (compBackgroundPrimary_buf_ as Color | number | string | Resource) + // } + // const compBackgroundPrimary_result : ResourceColor | undefined = compBackgroundPrimary_buf + // const compBackgroundPrimaryTran_buf_runtimeType = (valueDeserializer.readInt8() as int32) + // let compBackgroundPrimaryTran_buf : ResourceColor | undefined + // if ((RuntimeType.UNDEFINED) != (compBackgroundPrimaryTran_buf_runtimeType)) + // { + // const compBackgroundPrimaryTran_buf__selector : int32 = valueDeserializer.readInt8() + // let compBackgroundPrimaryTran_buf_ : Color | number | string | Resource | undefined + // if (compBackgroundPrimaryTran_buf__selector == 0) { + // compBackgroundPrimaryTran_buf_ = TypeChecker.Color_FromNumeric(valueDeserializer.readInt32()) + // } + // else if (compBackgroundPrimaryTran_buf__selector == 1) { + // compBackgroundPrimaryTran_buf_ = (valueDeserializer.readNumber() as number) + // } + // else if (compBackgroundPrimaryTran_buf__selector == 2) { + // compBackgroundPrimaryTran_buf_ = (valueDeserializer.readString() as string) + // } + // else if (compBackgroundPrimaryTran_buf__selector == 3) { + // compBackgroundPrimaryTran_buf_ = valueDeserializer.readResource() + // } + // else { + // throw new Error("One of the branches for compBackgroundPrimaryTran_buf_ has to be chosen through deserialisation.") + // } + // compBackgroundPrimaryTran_buf = (compBackgroundPrimaryTran_buf_ as Color | number | string | Resource) + // } + // const compBackgroundPrimaryTran_result : ResourceColor | undefined = compBackgroundPrimaryTran_buf + // const compBackgroundPrimaryContrary_buf_runtimeType = (valueDeserializer.readInt8() as int32) + // let compBackgroundPrimaryContrary_buf : ResourceColor | undefined + // if ((RuntimeType.UNDEFINED) != (compBackgroundPrimaryContrary_buf_runtimeType)) + // { + // const compBackgroundPrimaryContrary_buf__selector : int32 = valueDeserializer.readInt8() + // let compBackgroundPrimaryContrary_buf_ : Color | number | string | Resource | undefined + // if (compBackgroundPrimaryContrary_buf__selector == 0) { + // compBackgroundPrimaryContrary_buf_ = TypeChecker.Color_FromNumeric(valueDeserializer.readInt32()) + // } + // else if (compBackgroundPrimaryContrary_buf__selector == 1) { + // compBackgroundPrimaryContrary_buf_ = (valueDeserializer.readNumber() as number) + // } + // else if (compBackgroundPrimaryContrary_buf__selector == 2) { + // compBackgroundPrimaryContrary_buf_ = (valueDeserializer.readString() as string) + // } + // else if (compBackgroundPrimaryContrary_buf__selector == 3) { + // compBackgroundPrimaryContrary_buf_ = valueDeserializer.readResource() + // } + // else { + // throw new Error("One of the branches for compBackgroundPrimaryContrary_buf_ has to be chosen through deserialisation.") + // } + // compBackgroundPrimaryContrary_buf = (compBackgroundPrimaryContrary_buf_ as Color | number | string | Resource) + // } + // const compBackgroundPrimaryContrary_result : ResourceColor | undefined = compBackgroundPrimaryContrary_buf + // const compBackgroundGray_buf_runtimeType = (valueDeserializer.readInt8() as int32) + // let compBackgroundGray_buf : ResourceColor | undefined + // if ((RuntimeType.UNDEFINED) != (compBackgroundGray_buf_runtimeType)) + // { + // const compBackgroundGray_buf__selector : int32 = valueDeserializer.readInt8() + // let compBackgroundGray_buf_ : Color | number | string | Resource | undefined + // if (compBackgroundGray_buf__selector == 0) { + // compBackgroundGray_buf_ = TypeChecker.Color_FromNumeric(valueDeserializer.readInt32()) + // } + // else if (compBackgroundGray_buf__selector == 1) { + // compBackgroundGray_buf_ = (valueDeserializer.readNumber() as number) + // } + // else if (compBackgroundGray_buf__selector == 2) { + // compBackgroundGray_buf_ = (valueDeserializer.readString() as string) + // } + // else if (compBackgroundGray_buf__selector == 3) { + // compBackgroundGray_buf_ = valueDeserializer.readResource() + // } + // else { + // throw new Error("One of the branches for compBackgroundGray_buf_ has to be chosen through deserialisation.") + // } + // compBackgroundGray_buf = (compBackgroundGray_buf_ as Color | number | string | Resource) + // } + // const compBackgroundGray_result : ResourceColor | undefined = compBackgroundGray_buf + // const compBackgroundSecondary_buf_runtimeType = (valueDeserializer.readInt8() as int32) + // let compBackgroundSecondary_buf : ResourceColor | undefined + // if ((RuntimeType.UNDEFINED) != (compBackgroundSecondary_buf_runtimeType)) + // { + // const compBackgroundSecondary_buf__selector : int32 = valueDeserializer.readInt8() + // let compBackgroundSecondary_buf_ : Color | number | string | Resource | undefined + // if (compBackgroundSecondary_buf__selector == 0) { + // compBackgroundSecondary_buf_ = TypeChecker.Color_FromNumeric(valueDeserializer.readInt32()) + // } + // else if (compBackgroundSecondary_buf__selector == 1) { + // compBackgroundSecondary_buf_ = (valueDeserializer.readNumber() as number) + // } + // else if (compBackgroundSecondary_buf__selector == 2) { + // compBackgroundSecondary_buf_ = (valueDeserializer.readString() as string) + // } + // else if (compBackgroundSecondary_buf__selector == 3) { + // compBackgroundSecondary_buf_ = valueDeserializer.readResource() + // } + // else { + // throw new Error("One of the branches for compBackgroundSecondary_buf_ has to be chosen through deserialisation.") + // } + // compBackgroundSecondary_buf = (compBackgroundSecondary_buf_ as Color | number | string | Resource) + // } + // const compBackgroundSecondary_result : ResourceColor | undefined = compBackgroundSecondary_buf + // const compBackgroundTertiary_buf_runtimeType = (valueDeserializer.readInt8() as int32) + // let compBackgroundTertiary_buf : ResourceColor | undefined + // if ((RuntimeType.UNDEFINED) != (compBackgroundTertiary_buf_runtimeType)) + // { + // const compBackgroundTertiary_buf__selector : int32 = valueDeserializer.readInt8() + // let compBackgroundTertiary_buf_ : Color | number | string | Resource | undefined + // if (compBackgroundTertiary_buf__selector == 0) { + // compBackgroundTertiary_buf_ = TypeChecker.Color_FromNumeric(valueDeserializer.readInt32()) + // } + // else if (compBackgroundTertiary_buf__selector == 1) { + // compBackgroundTertiary_buf_ = (valueDeserializer.readNumber() as number) + // } + // else if (compBackgroundTertiary_buf__selector == 2) { + // compBackgroundTertiary_buf_ = (valueDeserializer.readString() as string) + // } + // else if (compBackgroundTertiary_buf__selector == 3) { + // compBackgroundTertiary_buf_ = valueDeserializer.readResource() + // } + // else { + // throw new Error("One of the branches for compBackgroundTertiary_buf_ has to be chosen through deserialisation.") + // } + // compBackgroundTertiary_buf = (compBackgroundTertiary_buf_ as Color | number | string | Resource) + // } + // const compBackgroundTertiary_result : ResourceColor | undefined = compBackgroundTertiary_buf + // const compBackgroundEmphasize_buf_runtimeType = (valueDeserializer.readInt8() as int32) + // let compBackgroundEmphasize_buf : ResourceColor | undefined + // if ((RuntimeType.UNDEFINED) != (compBackgroundEmphasize_buf_runtimeType)) + // { + // const compBackgroundEmphasize_buf__selector : int32 = valueDeserializer.readInt8() + // let compBackgroundEmphasize_buf_ : Color | number | string | Resource | undefined + // if (compBackgroundEmphasize_buf__selector == 0) { + // compBackgroundEmphasize_buf_ = TypeChecker.Color_FromNumeric(valueDeserializer.readInt32()) + // } + // else if (compBackgroundEmphasize_buf__selector == 1) { + // compBackgroundEmphasize_buf_ = (valueDeserializer.readNumber() as number) + // } + // else if (compBackgroundEmphasize_buf__selector == 2) { + // compBackgroundEmphasize_buf_ = (valueDeserializer.readString() as string) + // } + // else if (compBackgroundEmphasize_buf__selector == 3) { + // compBackgroundEmphasize_buf_ = valueDeserializer.readResource() + // } + // else { + // throw new Error("One of the branches for compBackgroundEmphasize_buf_ has to be chosen through deserialisation.") + // } + // compBackgroundEmphasize_buf = (compBackgroundEmphasize_buf_ as Color | number | string | Resource) + // } + // const compBackgroundEmphasize_result : ResourceColor | undefined = compBackgroundEmphasize_buf + // const compBackgroundNeutral_buf_runtimeType = (valueDeserializer.readInt8() as int32) + // let compBackgroundNeutral_buf : ResourceColor | undefined + // if ((RuntimeType.UNDEFINED) != (compBackgroundNeutral_buf_runtimeType)) + // { + // const compBackgroundNeutral_buf__selector : int32 = valueDeserializer.readInt8() + // let compBackgroundNeutral_buf_ : Color | number | string | Resource | undefined + // if (compBackgroundNeutral_buf__selector == 0) { + // compBackgroundNeutral_buf_ = TypeChecker.Color_FromNumeric(valueDeserializer.readInt32()) + // } + // else if (compBackgroundNeutral_buf__selector == 1) { + // compBackgroundNeutral_buf_ = (valueDeserializer.readNumber() as number) + // } + // else if (compBackgroundNeutral_buf__selector == 2) { + // compBackgroundNeutral_buf_ = (valueDeserializer.readString() as string) + // } + // else if (compBackgroundNeutral_buf__selector == 3) { + // compBackgroundNeutral_buf_ = valueDeserializer.readResource() + // } + // else { + // throw new Error("One of the branches for compBackgroundNeutral_buf_ has to be chosen through deserialisation.") + // } + // compBackgroundNeutral_buf = (compBackgroundNeutral_buf_ as Color | number | string | Resource) + // } + // const compBackgroundNeutral_result : ResourceColor | undefined = compBackgroundNeutral_buf + // const compEmphasizeSecondary_buf_runtimeType = (valueDeserializer.readInt8() as int32) + // let compEmphasizeSecondary_buf : ResourceColor | undefined + // if ((RuntimeType.UNDEFINED) != (compEmphasizeSecondary_buf_runtimeType)) + // { + // const compEmphasizeSecondary_buf__selector : int32 = valueDeserializer.readInt8() + // let compEmphasizeSecondary_buf_ : Color | number | string | Resource | undefined + // if (compEmphasizeSecondary_buf__selector == 0) { + // compEmphasizeSecondary_buf_ = TypeChecker.Color_FromNumeric(valueDeserializer.readInt32()) + // } + // else if (compEmphasizeSecondary_buf__selector == 1) { + // compEmphasizeSecondary_buf_ = (valueDeserializer.readNumber() as number) + // } + // else if (compEmphasizeSecondary_buf__selector == 2) { + // compEmphasizeSecondary_buf_ = (valueDeserializer.readString() as string) + // } + // else if (compEmphasizeSecondary_buf__selector == 3) { + // compEmphasizeSecondary_buf_ = valueDeserializer.readResource() + // } + // else { + // throw new Error("One of the branches for compEmphasizeSecondary_buf_ has to be chosen through deserialisation.") + // } + // compEmphasizeSecondary_buf = (compEmphasizeSecondary_buf_ as Color | number | string | Resource) + // } + // const compEmphasizeSecondary_result : ResourceColor | undefined = compEmphasizeSecondary_buf + // const compEmphasizeTertiary_buf_runtimeType = (valueDeserializer.readInt8() as int32) + // let compEmphasizeTertiary_buf : ResourceColor | undefined + // if ((RuntimeType.UNDEFINED) != (compEmphasizeTertiary_buf_runtimeType)) + // { + // const compEmphasizeTertiary_buf__selector : int32 = valueDeserializer.readInt8() + // let compEmphasizeTertiary_buf_ : Color | number | string | Resource | undefined + // if (compEmphasizeTertiary_buf__selector == 0) { + // compEmphasizeTertiary_buf_ = TypeChecker.Color_FromNumeric(valueDeserializer.readInt32()) + // } + // else if (compEmphasizeTertiary_buf__selector == 1) { + // compEmphasizeTertiary_buf_ = (valueDeserializer.readNumber() as number) + // } + // else if (compEmphasizeTertiary_buf__selector == 2) { + // compEmphasizeTertiary_buf_ = (valueDeserializer.readString() as string) + // } + // else if (compEmphasizeTertiary_buf__selector == 3) { + // compEmphasizeTertiary_buf_ = valueDeserializer.readResource() + // } + // else { + // throw new Error("One of the branches for compEmphasizeTertiary_buf_ has to be chosen through deserialisation.") + // } + // compEmphasizeTertiary_buf = (compEmphasizeTertiary_buf_ as Color | number | string | Resource) + // } + // const compEmphasizeTertiary_result : ResourceColor | undefined = compEmphasizeTertiary_buf + // const compDivider_buf_runtimeType = (valueDeserializer.readInt8() as int32) + // let compDivider_buf : ResourceColor | undefined + // if ((RuntimeType.UNDEFINED) != (compDivider_buf_runtimeType)) + // { + // const compDivider_buf__selector : int32 = valueDeserializer.readInt8() + // let compDivider_buf_ : Color | number | string | Resource | undefined + // if (compDivider_buf__selector == 0) { + // compDivider_buf_ = TypeChecker.Color_FromNumeric(valueDeserializer.readInt32()) + // } + // else if (compDivider_buf__selector == 1) { + // compDivider_buf_ = (valueDeserializer.readNumber() as number) + // } + // else if (compDivider_buf__selector == 2) { + // compDivider_buf_ = (valueDeserializer.readString() as string) + // } + // else if (compDivider_buf__selector == 3) { + // compDivider_buf_ = valueDeserializer.readResource() + // } + // else { + // throw new Error("One of the branches for compDivider_buf_ has to be chosen through deserialisation.") + // } + // compDivider_buf = (compDivider_buf_ as Color | number | string | Resource) + // } + // const compDivider_result : ResourceColor | undefined = compDivider_buf + // const compCommonContrary_buf_runtimeType = (valueDeserializer.readInt8() as int32) + // let compCommonContrary_buf : ResourceColor | undefined + // if ((RuntimeType.UNDEFINED) != (compCommonContrary_buf_runtimeType)) + // { + // const compCommonContrary_buf__selector : int32 = valueDeserializer.readInt8() + // let compCommonContrary_buf_ : Color | number | string | Resource | undefined + // if (compCommonContrary_buf__selector == 0) { + // compCommonContrary_buf_ = TypeChecker.Color_FromNumeric(valueDeserializer.readInt32()) + // } + // else if (compCommonContrary_buf__selector == 1) { + // compCommonContrary_buf_ = (valueDeserializer.readNumber() as number) + // } + // else if (compCommonContrary_buf__selector == 2) { + // compCommonContrary_buf_ = (valueDeserializer.readString() as string) + // } + // else if (compCommonContrary_buf__selector == 3) { + // compCommonContrary_buf_ = valueDeserializer.readResource() + // } + // else { + // throw new Error("One of the branches for compCommonContrary_buf_ has to be chosen through deserialisation.") + // } + // compCommonContrary_buf = (compCommonContrary_buf_ as Color | number | string | Resource) + // } + // const compCommonContrary_result : ResourceColor | undefined = compCommonContrary_buf + // const compBackgroundFocus_buf_runtimeType = (valueDeserializer.readInt8() as int32) + // let compBackgroundFocus_buf : ResourceColor | undefined + // if ((RuntimeType.UNDEFINED) != (compBackgroundFocus_buf_runtimeType)) + // { + // const compBackgroundFocus_buf__selector : int32 = valueDeserializer.readInt8() + // let compBackgroundFocus_buf_ : Color | number | string | Resource | undefined + // if (compBackgroundFocus_buf__selector == 0) { + // compBackgroundFocus_buf_ = TypeChecker.Color_FromNumeric(valueDeserializer.readInt32()) + // } + // else if (compBackgroundFocus_buf__selector == 1) { + // compBackgroundFocus_buf_ = (valueDeserializer.readNumber() as number) + // } + // else if (compBackgroundFocus_buf__selector == 2) { + // compBackgroundFocus_buf_ = (valueDeserializer.readString() as string) + // } + // else if (compBackgroundFocus_buf__selector == 3) { + // compBackgroundFocus_buf_ = valueDeserializer.readResource() + // } + // else { + // throw new Error("One of the branches for compBackgroundFocus_buf_ has to be chosen through deserialisation.") + // } + // compBackgroundFocus_buf = (compBackgroundFocus_buf_ as Color | number | string | Resource) + // } + // const compBackgroundFocus_result : ResourceColor | undefined = compBackgroundFocus_buf + // const compFocusedPrimary_buf_runtimeType = (valueDeserializer.readInt8() as int32) + // let compFocusedPrimary_buf : ResourceColor | undefined + // if ((RuntimeType.UNDEFINED) != (compFocusedPrimary_buf_runtimeType)) + // { + // const compFocusedPrimary_buf__selector : int32 = valueDeserializer.readInt8() + // let compFocusedPrimary_buf_ : Color | number | string | Resource | undefined + // if (compFocusedPrimary_buf__selector == 0) { + // compFocusedPrimary_buf_ = TypeChecker.Color_FromNumeric(valueDeserializer.readInt32()) + // } + // else if (compFocusedPrimary_buf__selector == 1) { + // compFocusedPrimary_buf_ = (valueDeserializer.readNumber() as number) + // } + // else if (compFocusedPrimary_buf__selector == 2) { + // compFocusedPrimary_buf_ = (valueDeserializer.readString() as string) + // } + // else if (compFocusedPrimary_buf__selector == 3) { + // compFocusedPrimary_buf_ = valueDeserializer.readResource() + // } + // else { + // throw new Error("One of the branches for compFocusedPrimary_buf_ has to be chosen through deserialisation.") + // } + // compFocusedPrimary_buf = (compFocusedPrimary_buf_ as Color | number | string | Resource) + // } + // const compFocusedPrimary_result : ResourceColor | undefined = compFocusedPrimary_buf + // const compFocusedSecondary_buf_runtimeType = (valueDeserializer.readInt8() as int32) + // let compFocusedSecondary_buf : ResourceColor | undefined + // if ((RuntimeType.UNDEFINED) != (compFocusedSecondary_buf_runtimeType)) + // { + // const compFocusedSecondary_buf__selector : int32 = valueDeserializer.readInt8() + // let compFocusedSecondary_buf_ : Color | number | string | Resource | undefined + // if (compFocusedSecondary_buf__selector == 0) { + // compFocusedSecondary_buf_ = TypeChecker.Color_FromNumeric(valueDeserializer.readInt32()) + // } + // else if (compFocusedSecondary_buf__selector == 1) { + // compFocusedSecondary_buf_ = (valueDeserializer.readNumber() as number) + // } + // else if (compFocusedSecondary_buf__selector == 2) { + // compFocusedSecondary_buf_ = (valueDeserializer.readString() as string) + // } + // else if (compFocusedSecondary_buf__selector == 3) { + // compFocusedSecondary_buf_ = valueDeserializer.readResource() + // } + // else { + // throw new Error("One of the branches for compFocusedSecondary_buf_ has to be chosen through deserialisation.") + // } + // compFocusedSecondary_buf = (compFocusedSecondary_buf_ as Color | number | string | Resource) + // } + // const compFocusedSecondary_result : ResourceColor | undefined = compFocusedSecondary_buf + // const compFocusedTertiary_buf_runtimeType = (valueDeserializer.readInt8() as int32) + // let compFocusedTertiary_buf : ResourceColor | undefined + // if ((RuntimeType.UNDEFINED) != (compFocusedTertiary_buf_runtimeType)) + // { + // const compFocusedTertiary_buf__selector : int32 = valueDeserializer.readInt8() + // let compFocusedTertiary_buf_ : Color | number | string | Resource | undefined + // if (compFocusedTertiary_buf__selector == 0) { + // compFocusedTertiary_buf_ = TypeChecker.Color_FromNumeric(valueDeserializer.readInt32()) + // } + // else if (compFocusedTertiary_buf__selector == 1) { + // compFocusedTertiary_buf_ = (valueDeserializer.readNumber() as number) + // } + // else if (compFocusedTertiary_buf__selector == 2) { + // compFocusedTertiary_buf_ = (valueDeserializer.readString() as string) + // } + // else if (compFocusedTertiary_buf__selector == 3) { + // compFocusedTertiary_buf_ = valueDeserializer.readResource() + // } + // else { + // throw new Error("One of the branches for compFocusedTertiary_buf_ has to be chosen through deserialisation.") + // } + // compFocusedTertiary_buf = (compFocusedTertiary_buf_ as Color | number | string | Resource) + // } + // const compFocusedTertiary_result : ResourceColor | undefined = compFocusedTertiary_buf + // const interactiveHover_buf_runtimeType = (valueDeserializer.readInt8() as int32) + // let interactiveHover_buf : ResourceColor | undefined + // if ((RuntimeType.UNDEFINED) != (interactiveHover_buf_runtimeType)) + // { + // const interactiveHover_buf__selector : int32 = valueDeserializer.readInt8() + // let interactiveHover_buf_ : Color | number | string | Resource | undefined + // if (interactiveHover_buf__selector == 0) { + // interactiveHover_buf_ = TypeChecker.Color_FromNumeric(valueDeserializer.readInt32()) + // } + // else if (interactiveHover_buf__selector == 1) { + // interactiveHover_buf_ = (valueDeserializer.readNumber() as number) + // } + // else if (interactiveHover_buf__selector == 2) { + // interactiveHover_buf_ = (valueDeserializer.readString() as string) + // } + // else if (interactiveHover_buf__selector == 3) { + // interactiveHover_buf_ = valueDeserializer.readResource() + // } + // else { + // throw new Error("One of the branches for interactiveHover_buf_ has to be chosen through deserialisation.") + // } + // interactiveHover_buf = (interactiveHover_buf_ as Color | number | string | Resource) + // } + // const interactiveHover_result : ResourceColor | undefined = interactiveHover_buf + // const interactivePressed_buf_runtimeType = (valueDeserializer.readInt8() as int32) + // let interactivePressed_buf : ResourceColor | undefined + // if ((RuntimeType.UNDEFINED) != (interactivePressed_buf_runtimeType)) + // { + // const interactivePressed_buf__selector : int32 = valueDeserializer.readInt8() + // let interactivePressed_buf_ : Color | number | string | Resource | undefined + // if (interactivePressed_buf__selector == 0) { + // interactivePressed_buf_ = TypeChecker.Color_FromNumeric(valueDeserializer.readInt32()) + // } + // else if (interactivePressed_buf__selector == 1) { + // interactivePressed_buf_ = (valueDeserializer.readNumber() as number) + // } + // else if (interactivePressed_buf__selector == 2) { + // interactivePressed_buf_ = (valueDeserializer.readString() as string) + // } + // else if (interactivePressed_buf__selector == 3) { + // interactivePressed_buf_ = valueDeserializer.readResource() + // } + // else { + // throw new Error("One of the branches for interactivePressed_buf_ has to be chosen through deserialisation.") + // } + // interactivePressed_buf = (interactivePressed_buf_ as Color | number | string | Resource) + // } + // const interactivePressed_result : ResourceColor | undefined = interactivePressed_buf + // const interactiveFocus_buf_runtimeType = (valueDeserializer.readInt8() as int32) + // let interactiveFocus_buf : ResourceColor | undefined + // if ((RuntimeType.UNDEFINED) != (interactiveFocus_buf_runtimeType)) + // { + // const interactiveFocus_buf__selector : int32 = valueDeserializer.readInt8() + // let interactiveFocus_buf_ : Color | number | string | Resource | undefined + // if (interactiveFocus_buf__selector == 0) { + // interactiveFocus_buf_ = TypeChecker.Color_FromNumeric(valueDeserializer.readInt32()) + // } + // else if (interactiveFocus_buf__selector == 1) { + // interactiveFocus_buf_ = (valueDeserializer.readNumber() as number) + // } + // else if (interactiveFocus_buf__selector == 2) { + // interactiveFocus_buf_ = (valueDeserializer.readString() as string) + // } + // else if (interactiveFocus_buf__selector == 3) { + // interactiveFocus_buf_ = valueDeserializer.readResource() + // } + // else { + // throw new Error("One of the branches for interactiveFocus_buf_ has to be chosen through deserialisation.") + // } + // interactiveFocus_buf = (interactiveFocus_buf_ as Color | number | string | Resource) + // } + // const interactiveFocus_result : ResourceColor | undefined = interactiveFocus_buf + // const interactiveActive_buf_runtimeType = (valueDeserializer.readInt8() as int32) + // let interactiveActive_buf : ResourceColor | undefined + // if ((RuntimeType.UNDEFINED) != (interactiveActive_buf_runtimeType)) + // { + // const interactiveActive_buf__selector : int32 = valueDeserializer.readInt8() + // let interactiveActive_buf_ : Color | number | string | Resource | undefined + // if (interactiveActive_buf__selector == 0) { + // interactiveActive_buf_ = TypeChecker.Color_FromNumeric(valueDeserializer.readInt32()) + // } + // else if (interactiveActive_buf__selector == 1) { + // interactiveActive_buf_ = (valueDeserializer.readNumber() as number) + // } + // else if (interactiveActive_buf__selector == 2) { + // interactiveActive_buf_ = (valueDeserializer.readString() as string) + // } + // else if (interactiveActive_buf__selector == 3) { + // interactiveActive_buf_ = valueDeserializer.readResource() + // } + // else { + // throw new Error("One of the branches for interactiveActive_buf_ has to be chosen through deserialisation.") + // } + // interactiveActive_buf = (interactiveActive_buf_ as Color | number | string | Resource) + // } + // const interactiveActive_result : ResourceColor | undefined = interactiveActive_buf + // const interactiveSelect_buf_runtimeType = (valueDeserializer.readInt8() as int32) + // let interactiveSelect_buf : ResourceColor | undefined + // if ((RuntimeType.UNDEFINED) != (interactiveSelect_buf_runtimeType)) + // { + // const interactiveSelect_buf__selector : int32 = valueDeserializer.readInt8() + // let interactiveSelect_buf_ : Color | number | string | Resource | undefined + // if (interactiveSelect_buf__selector == 0) { + // interactiveSelect_buf_ = TypeChecker.Color_FromNumeric(valueDeserializer.readInt32()) + // } + // else if (interactiveSelect_buf__selector == 1) { + // interactiveSelect_buf_ = (valueDeserializer.readNumber() as number) + // } + // else if (interactiveSelect_buf__selector == 2) { + // interactiveSelect_buf_ = (valueDeserializer.readString() as string) + // } + // else if (interactiveSelect_buf__selector == 3) { + // interactiveSelect_buf_ = valueDeserializer.readResource() + // } + // else { + // throw new Error("One of the branches for interactiveSelect_buf_ has to be chosen through deserialisation.") + // } + // interactiveSelect_buf = (interactiveSelect_buf_ as Color | number | string | Resource) + // } + // const interactiveSelect_result : ResourceColor | undefined = interactiveSelect_buf + // const interactiveClick_buf_runtimeType = (valueDeserializer.readInt8() as int32) + // let interactiveClick_buf : ResourceColor | undefined + // if ((RuntimeType.UNDEFINED) != (interactiveClick_buf_runtimeType)) + // { + // const interactiveClick_buf__selector : int32 = valueDeserializer.readInt8() + // let interactiveClick_buf_ : Color | number | string | Resource | undefined + // if (interactiveClick_buf__selector == 0) { + // interactiveClick_buf_ = TypeChecker.Color_FromNumeric(valueDeserializer.readInt32()) + // } + // else if (interactiveClick_buf__selector == 1) { + // interactiveClick_buf_ = (valueDeserializer.readNumber() as number) + // } + // else if (interactiveClick_buf__selector == 2) { + // interactiveClick_buf_ = (valueDeserializer.readString() as string) + // } + // else if (interactiveClick_buf__selector == 3) { + // interactiveClick_buf_ = valueDeserializer.readResource() + // } + // else { + // throw new Error("One of the branches for interactiveClick_buf_ has to be chosen through deserialisation.") + // } + // interactiveClick_buf = (interactiveClick_buf_ as Color | number | string | Resource) + // } + // const interactiveClick_result : ResourceColor | undefined = interactiveClick_buf + // let value : CustomColors = ({brand: brand_result, warning: warning_result, alert: alert_result, confirm: confirm_result, fontPrimary: fontPrimary_result, fontSecondary: fontSecondary_result, fontTertiary: fontTertiary_result, fontFourth: fontFourth_result, fontEmphasize: fontEmphasize_result, fontOnPrimary: fontOnPrimary_result, fontOnSecondary: fontOnSecondary_result, fontOnTertiary: fontOnTertiary_result, fontOnFourth: fontOnFourth_result, iconPrimary: iconPrimary_result, iconSecondary: iconSecondary_result, iconTertiary: iconTertiary_result, iconFourth: iconFourth_result, iconEmphasize: iconEmphasize_result, iconSubEmphasize: iconSubEmphasize_result, iconOnPrimary: iconOnPrimary_result, iconOnSecondary: iconOnSecondary_result, iconOnTertiary: iconOnTertiary_result, iconOnFourth: iconOnFourth_result, backgroundPrimary: backgroundPrimary_result, backgroundSecondary: backgroundSecondary_result, backgroundTertiary: backgroundTertiary_result, backgroundFourth: backgroundFourth_result, backgroundEmphasize: backgroundEmphasize_result, compForegroundPrimary: compForegroundPrimary_result, compBackgroundPrimary: compBackgroundPrimary_result, compBackgroundPrimaryTran: compBackgroundPrimaryTran_result, compBackgroundPrimaryContrary: compBackgroundPrimaryContrary_result, compBackgroundGray: compBackgroundGray_result, compBackgroundSecondary: compBackgroundSecondary_result, compBackgroundTertiary: compBackgroundTertiary_result, compBackgroundEmphasize: compBackgroundEmphasize_result, compBackgroundNeutral: compBackgroundNeutral_result, compEmphasizeSecondary: compEmphasizeSecondary_result, compEmphasizeTertiary: compEmphasizeTertiary_result, compDivider: compDivider_result, compCommonContrary: compCommonContrary_result, compBackgroundFocus: compBackgroundFocus_result, compFocusedPrimary: compFocusedPrimary_result, compFocusedSecondary: compFocusedSecondary_result, compFocusedTertiary: compFocusedTertiary_result, interactiveHover: interactiveHover_result, interactivePressed: interactivePressed_result, interactiveFocus: interactiveFocus_result, interactiveActive: interactiveActive_result, interactiveSelect: interactiveSelect_result, interactiveClick: interactiveClick_result} as CustomColors) + // return value + // } readDataPanelShadowOptions(): DataPanelShadowOptions { let valueDeserializer : Deserializer = this const radius_buf_runtimeType = (valueDeserializer.readInt8() as int32) @@ -24608,18 +24609,18 @@ export class Deserializer extends DeserializerBase { let value : CustomPopupOptions = ({builder: builder_result, placement: placement_result, popupColor: popupColor_result, enableArrow: enableArrow_result, autoCancel: autoCancel_result, onStateChange: onStateChange_result, arrowOffset: arrowOffset_result, showInSubWindow: showInSubWindow_result, mask: mask_result, targetSpace: targetSpace_result, offset: offset_result, width: width_result, arrowPointPosition: arrowPointPosition_result, arrowWidth: arrowWidth_result, arrowHeight: arrowHeight_result, radius: radius_result, shadow: shadow_result, backgroundBlurStyle: backgroundBlurStyle_result, focusable: focusable_result, transition: transition_result, onWillDismiss: onWillDismiss_result, enableHoverMode: enableHoverMode_result, followTransformOfTarget: followTransformOfTarget_result, keyboardAvoidMode: keyboardAvoidMode_result} as CustomPopupOptions) return value } - readCustomTheme(): CustomTheme { - let valueDeserializer : Deserializer = this - const colors_buf_runtimeType = (valueDeserializer.readInt8() as int32) - let colors_buf : CustomColors | undefined - if ((RuntimeType.UNDEFINED) != (colors_buf_runtimeType)) - { - colors_buf = valueDeserializer.readCustomColors() - } - const colors_result : CustomColors | undefined = colors_buf - let value : CustomTheme = ({colors: colors_result} as CustomTheme) - return value - } + // readCustomTheme(): CustomTheme { + // let valueDeserializer : Deserializer = this + // const colors_buf_runtimeType = (valueDeserializer.readInt8() as int32) + // let colors_buf : CustomColors | undefined + // if ((RuntimeType.UNDEFINED) != (colors_buf_runtimeType)) + // { + // colors_buf = valueDeserializer.readCustomColors() + // } + // const colors_result : CustomColors | undefined = colors_buf + // let value : CustomTheme = ({colors: colors_result} as CustomTheme) + // return value + // } readDigitIndicator(): DigitIndicator { throw new Error("Can not deserialize builder class") } @@ -28652,25 +28653,25 @@ export class Deserializer extends DeserializerBase { let value : TimePickerDialogOptions = ({selected: selected_result, format: format_result, start: start_result, end: end_result, useMilitaryTime: useMilitaryTime_result, disappearTextStyle: disappearTextStyle_result, textStyle: textStyle_result, acceptButtonStyle: acceptButtonStyle_result, cancelButtonStyle: cancelButtonStyle_result, selectedTextStyle: selectedTextStyle_result, maskRect: maskRect_result, alignment: alignment_result, offset: offset_result, onAccept: onAccept_result, onCancel: onCancel_result, onChange: onChange_result, onEnterSelectedArea: onEnterSelectedArea_result, backgroundColor: backgroundColor_result, backgroundBlurStyle: backgroundBlurStyle_result, backgroundBlurStyleOptions: backgroundBlurStyleOptions_result, backgroundEffect: backgroundEffect_result, enableCascade: enableCascade_result, onDidAppear: onDidAppear_result, onDidDisappear: onDidDisappear_result, onWillAppear: onWillAppear_result, onWillDisappear: onWillDisappear_result, shadow: shadow_result, dateTimeOptions: dateTimeOptions_result, enableHoverMode: enableHoverMode_result, hoverModeArea: hoverModeArea_result, enableHapticFeedback: enableHapticFeedback_result} as TimePickerDialogOptions) return value } - readWithThemeOptions(): WithThemeOptions { - let valueDeserializer : Deserializer = this - const theme_buf_runtimeType = (valueDeserializer.readInt8() as int32) - let theme_buf : CustomTheme | undefined - if ((RuntimeType.UNDEFINED) != (theme_buf_runtimeType)) - { - theme_buf = valueDeserializer.readCustomTheme() - } - const theme_result : CustomTheme | undefined = theme_buf - const colorMode_buf_runtimeType = (valueDeserializer.readInt8() as int32) - let colorMode_buf : ThemeColorMode | undefined - if ((RuntimeType.UNDEFINED) != (colorMode_buf_runtimeType)) - { - colorMode_buf = TypeChecker.ThemeColorMode_FromNumeric(valueDeserializer.readInt32()) - } - const colorMode_result : ThemeColorMode | undefined = colorMode_buf - let value : WithThemeOptions = ({theme: theme_result, colorMode: colorMode_result} as WithThemeOptions) - return value - } + // readWithThemeOptions(): WithThemeOptions { + // let valueDeserializer : Deserializer = this + // const theme_buf_runtimeType = (valueDeserializer.readInt8() as int32) + // let theme_buf : CustomTheme | undefined + // if ((RuntimeType.UNDEFINED) != (theme_buf_runtimeType)) + // { + // theme_buf = valueDeserializer.readCustomTheme() + // } + // const theme_result : CustomTheme | undefined = theme_buf + // const colorMode_buf_runtimeType = (valueDeserializer.readInt8() as int32) + // let colorMode_buf : ThemeColorMode | undefined + // if ((RuntimeType.UNDEFINED) != (colorMode_buf_runtimeType)) + // { + // colorMode_buf = TypeChecker.ThemeColorMode_FromNumeric(valueDeserializer.readInt32()) + // } + // const colorMode_result : ThemeColorMode | undefined = colorMode_buf + // let value : WithThemeOptions = ({theme: theme_result, colorMode: colorMode_result} as WithThemeOptions) + // return value + // } readLength(): Length | undefined { const valueType = this.readInt8() if ((RuntimeType.NUMBER) == (valueType)) { diff --git a/frameworks/bridge/arkts_frontend/koala_projects/arkoala-arkts/arkui-ohos/src/component/peers/Serializer.ts b/frameworks/bridge/arkts_frontend/koala_projects/arkoala-arkts/arkui-ohos/src/component/peers/Serializer.ts index 228e1c813d1..df82cd5cfd2 100644 --- a/frameworks/bridge/arkts_frontend/koala_projects/arkoala-arkts/arkui-ohos/src/component/peers/Serializer.ts +++ b/frameworks/bridge/arkts_frontend/koala_projects/arkoala-arkts/arkui-ohos/src/component/peers/Serializer.ts @@ -24,8 +24,9 @@ import { CallbackTransformer } from "./CallbackTransformer" import { SingleLengthDetent, DoubleLengthDetents, TripleLengthDetents, AccessibilityCallback, AccessibilityFocusCallback, Bindable, GestureRecognizerJudgeBeginCallback, HoverCallback, OnDragEventCallback, OnMoveHandler, OnScrollCallback, PopupStateChangeCallback, ReuseIdCallback, ShouldBuiltInRecognizerParallelWithCallback, SizeChangeCallback, TransitionFinishCallback, VisibleAreaChangeCallback, AccessibilityHoverEvent, AccessibilityHoverEventInternal, AccessibilityRoleType, AccessibilitySamePageMode, AdaptiveColor, CommonMethod, BlurStyle, BlendApplyType, BlurStyleActivePolicy, PickerTextStyle, ChainStyle, ContentClipMode, DismissReason, DragBehavior, DragEvent, DragEventInternal, DragResult, Rectangle, DraggingSizeChangeEffect, DragPreviewMode, DrawModifier, EffectEdge, EffectType, FinishCallbackType, GestureModifier, GestureModifierInternal, UIGestureEvent, ScrollableCommonMethod, ItemDragInfo, CustomBuilder, NestedScrollOptions, EdgeEffectOptions, HapticFeedbackMode, HoverModeAreaType, ICurve, ICurveInternal, KeyboardAvoidMode, LayoutPolicy, LayoutSafeAreaEdge, LayoutSafeAreaType, ChildrenMainSize, ChildrenMainSizeInternal, RectResult, MenuPolicy, MenuPreviewMode, ModalTransition, OutlineStyle, PixelMapMock, PixelMapMockInternal, PopupStateChangeParam, PreDragStatus, ProgressMask, ProgressMaskInternal, RepeatMode, SelectionOptions, SafeAreaEdge, SafeAreaType, ScrollSizeMode, TextDecorationOptions, TextContentControllerBase, TextContentControllerBaseInternal, ShadowStyle, ShadowType, SheetKeyboardAvoidMode, SheetMode, SheetSize, SheetType, SourceTool, SourceType, BackgroundEffectOptions, BackgroundBlurStyleOptions, TranslateOptions, InputCounterOptions, ShadowOptions, CaretOffset, TextContentControllerOptions, ThemeColorMode, TouchTestInfo, TouchTestStrategy, TransitionEdge, TransitionEffect, TransitionEffectInternal, TransitionEffects, RotateOptions, ScaleOptions, AnimateParam, TransitionHierarchyStrategy, UICommonEvent, UICommonEventInternal, Callback_ClickEvent_Void, ClickEvent, ClickEventInternal, Callback_TouchEvent_Void, TouchEvent, TouchEventInternal, Callback_KeyEvent_Void, KeyEvent, KeyEventInternal, HoverEvent, HoverEventInternal, Callback_MouseEvent_Void, MouseEvent, MouseEventInternal, VisibleAreaEventOptions, SheetOptions, View, ViewInternal, Callback_KeyEvent_Boolean, Callback_Area_Area_Void, Callback_Array_TouchTestInfo_TouchResult, TouchResult, Callback_AxisEvent_Void, AxisEvent, AxisEventInternal, Callback_Boolean_HoverEvent_Void, Callback_CrownEvent_Void, CrownEvent, Callback_DismissContentCoverAction_Void, DismissContentCoverAction, Callback_DismissPopupAction_Void, DismissPopupAction, Callback_DismissSheetAction_Void, DismissSheetAction, Callback_DragEvent_String_Union_CustomBuilder_DragItemInfo, DragItemInfo, Callback_DragEvent_String_Void, Callback_FocusAxisEvent_Void, FocusAxisEvent, FocusAxisEventInternal, Callback_GestureInfo_BaseGestureEvent_GestureJudgeResult, Callback_HoverEvent_Void, Callback_Literal_Boolean_isVisible_Void, Literal_Boolean_isVisible, Callback_PreDragStatus_Void, Callback_SheetDismiss_Void, SheetDismiss, Callback_SheetType_Void, Callback_SpringBackAction_Void, SpringBackAction, Callback_TouchEvent_HitTestMode, BackgroundBrightnessOptions, BackgroundImageOptions, BlurOptions, ClickEffect, DateRange, DragInteractionOptions, DropOptions, ExpectedFrameRateRange, FocusMovement, ForegroundEffectOptions, GeometryTransitionOptions, InvertOptions, LinearGradient_common, Tuple_ResourceColor_Number, LinearGradientBlurOptions, FractionStop, LinearGradientOptions, LocalizedHorizontalAlignParam, LocalizedVerticalAlignParam, Measurable, MeasurableInternal, MeasureResult, SizeResult, MotionBlurAnchor, MotionBlurOptions, MotionPathOptions, OverlayOffset, PixelRoundPolicy, PixelStretchEffectOptions, PreviewConfiguration, RadialGradientOptions, Tuple_Length_Length, StateStyles, SweepGradientOptions, SystemAdaptiveOptions, TipsOptions, TouchObject, AlignRuleOption, HorizontalAlignOptions, VerticalAlignOptions, BlurStyleOptions, ContentCoverOptions, BindOptions, ContextMenuAnimationOptions, MultiShadowOptions, DragPreviewOptions, EventTarget, FadingEdgeOptions, BaseEvent, BaseEventInternal, ForegroundBlurStyleOptions, HistoricalPoint, LightSource, LocalizedAlignRuleOptions, MenuElement, OverlayOptions, PickerDialogButtonStyle, ReuseOptions, sharedTransitionOptions, SheetTitleOptions, TransitionOptions, BorderImageOption, CustomPopupOptions, Literal_ResourceColor_color, PointLightStyle, PopupMessageOptions, Type_SheetOptions_detents, ContextMenuOptions, BorderRadiusType, MenuOptions, PopupOptions, Literal_String_value_Callback_Void_action, ScrollResult, PopupMaskType, DividerStyle, BlendMode, PopupCommonOptions, PopupButton } from "./../common" import { ButtonTriggerClickCallback, ButtonRole, ButtonStyleMode, ButtonType, ControlSize, ButtonOptions, ButtonLabelStyle, ButtonConfiguration } from "./../button" import { Callback_Extender_OnFinish, Callback_Extender_OnProgress, DoubleAnimationParam } from "./../animationExtender" -import { Callback_RangeUpdate, Context_getGroupDir_Callback, RestrictedWorker_onerror_Callback, RestrictedWorker_onexit_Callback, RestrictedWorker_onmessage_Callback, BuilderNodeOps, BuilderNodeOpsInternal, BuilderNodeOptions, ComponentContent, ComponentContentInternal, UnifiedData, UnifiedDataInternal, SystemBarStyle, Scene, SceneInternal, Context, ContextInternal, WorkerEventListener, WorkerEventListenerInternal, Event, ErrorEvent, MessageEvents, BaseContext, BaseContextInternal, PostMessageOptions, WorkerOptions, CustomColors, RestrictedWorker, RestrictedWorkerInternal, CustomTheme } from "./../arkui-custom" +import { Callback_RangeUpdate, Context_getGroupDir_Callback, RestrictedWorker_onerror_Callback, RestrictedWorker_onexit_Callback, RestrictedWorker_onmessage_Callback, BuilderNodeOps, BuilderNodeOpsInternal, BuilderNodeOptions, ComponentContent, ComponentContentInternal, UnifiedData, UnifiedDataInternal, SystemBarStyle, Scene, SceneInternal, Context, ContextInternal, WorkerEventListener, WorkerEventListenerInternal, Event, ErrorEvent, MessageEvents, BaseContext, BaseContextInternal, PostMessageOptions, WorkerOptions, RestrictedWorker, RestrictedWorkerInternal } from "./../arkui-custom" import { UIContext, TargetInfo } from "@ohos/arkui/UIContext" +import { CustomTheme, CustomColors } from '@ohos/arkui/theme'; import { ContentDidScrollCallback, ContentWillScrollCallback, OnSwiperAnimationEndCallback, OnSwiperAnimationStartCallback, OnSwiperGestureSwipeCallback, SwiperAnimationEvent, SwiperAnimationMode, SwiperAttribute, DotIndicator, DigitIndicator, SwiperDisplayMode, SwiperNestedScrollMode, SwiperContentAnimatedTransition, SwiperContentWillScrollResult, AutoPlayOptions, ArrowStyle, SwiperAutoFill, SwiperContentTransitionProxy, SwiperContentTransitionProxyInternal, SwiperController, SwiperControllerInternal, Callback_SwiperContentTransitionProxy_Void, Indicator } from "./../swiper" import { CustomNodeBuilder } from "./../customBuilder" import { DatePickerSelectedCallback } from "./../datepickerselectedops" @@ -77,7 +78,7 @@ import { TextPickerSelectedCallback } from "./../textpickerselectedops" import { TextPickerValueCallback } from "./../textpickervalueops" import { TimePickerSelectedCallback } from "./../timepickerselectedops" import { VoidCallback, ResourceColor, Font, Position, Length, SizeOptions, Offset, ColorFilter, ColorFilterInternal, ResourceStr, Dimension, PX, VP, FP, LPX, Percentage, LengthConstrain, DividerStyleOptions, ConstraintSizeOptions, Area, AccessibilityOptions, Bias, BorderRadiuses, ChainWeightOptions, DirectionalEdgesT, EdgeOutlineStyles, EdgeOutlineWidths, EdgeWidths, OutlineRadiuses, Padding, EdgeColors, LocalizedBorderRadiuses, LocalizedEdgeColors, LocalizedEdges, LocalizedEdgeWidths, LocalizedPadding, LocalizedPosition, MarkStyle, BorderOptions, OutlineOptions, EdgeStyles, Edges } from "./../units" -import { WithThemeInterface, WithThemeAttribute, WithThemeOptions } from "./../withTheme" +import { WithThemeAttribute, WithThemeOptions } from "./../withTheme" import { AccessibilityHoverType, Alignment, Color, AnimationStatus, AppRotation, ArrowPointPosition, Axis, AxisAction, AxisModel, BarState, BorderStyle, CheckBoxShape, ClickEffectLevel, ColoringStrategy, CopyOptions, CrownAction, CrownSensitivity, Curve, DialogButtonStyle, Direction, DividerMode, Edge, EdgeEffect, EllipsisMode, EmbeddedType, FillMode, FlexAlign, FlexDirection, FlexWrap, FocusDrawLevel, FoldStatus, FontStyle, FontWeight, FunctionKey, GradientDirection, HeightBreakpoint, HitTestMode, HorizontalAlign, HoverEffect, IlluminatedType, ImageFit, ImageRepeat, ImageSize, ImageSpanAlignment, InteractionHand, ItemAlign, KeySource, KeyType, LineBreakStrategy, LineCapStyle, LineJoinStyle, MarqueeUpdateStrategy, ModifierKey, MouseAction, MouseButton, NestedScrollMode, ObscuredReasons, OptionWidthMode, PageFlipMode, PixelRoundCalcPolicy, PixelRoundMode, Placement, PlayMode, RelateType, RenderFit, ResponseType, ScrollSource, TextAlign, SharedTransitionEffectType, TextOverflow, TextContentStyle, TextHeightAdaptivePolicy, WordBreak, TextCase, TextSelectableMode, TextDecorationStyle, TextDecorationType, TitleHeight, TouchType, TransitionType, VerticalAlign, Visibility, Week, WidthBreakpoint, XComponentType } from "./../enums" import { Affinity, LineMetrics, TextBox, RunMetrics, TextDirection } from "./../arkui-graphics-text" import { Resource } from "global.resource" diff --git a/frameworks/bridge/arkts_frontend/koala_projects/arkoala-arkts/arkui-ohos/src/component/text.ts b/frameworks/bridge/arkts_frontend/koala_projects/arkoala-arkts/arkui-ohos/src/component/text.ts index eda430c0cca..d196ba54d0e 100644 --- a/frameworks/bridge/arkts_frontend/koala_projects/arkoala-arkts/arkui-ohos/src/component/text.ts +++ b/frameworks/bridge/arkts_frontend/koala_projects/arkoala-arkts/arkui-ohos/src/component/text.ts @@ -24,7 +24,7 @@ import { unsafeCast, int32, int64, float32 } from "@koalaui/common" import { Serializer } from "./peers/Serializer" import { CallbackTransformer } from "./peers/CallbackTransformer" import { ComponentBase } from "./../ComponentBase" -import { PeerNode } from "./../PeerNode" +import { PeerNode, findPeerNode } from "./../PeerNode" import { ArkCommonMethodPeer, CommonMethod, ShadowOptions, CustomBuilder, ArkCommonMethodComponent, ArkCommonMethodStyle, AttributeModifier } from "./common" import { Font, ResourceColor, Length } from "./units" import { Resource } from "global.resource" @@ -35,6 +35,9 @@ import { NodeAttach, remember } from "@koalaui/runtime" import { InteropNativeModule } from "@koalaui/interop" import { TextModifier } from "../TextModifier" import { hookTextAttributeModifier } from "../handwritten" +import { ArkThemeScopeManager } from '../handwritten/theme/ArkThemeScopeManager'; +import { __context, __id } from "@koalaui/runtime"; +import { ArkUIAniModule } from 'arkui.ani'; export class TextControllerInternal { public static fromPtr(ptr: KPointer): TextController { const obj : TextController = new TextController() @@ -89,9 +92,11 @@ export class ArkTextPeer extends ArkCommonMethodPeer { } public static create(component: ComponentBase | undefined, flags: int32 = 0): ArkTextPeer { const peerId = PeerNode.nextId() + ArkThemeScopeManager.getInstance().onComponentCreateEnter("Text", peerId, component ? component.isFirstBuild : true); const _peerPtr = ArkUIGeneratedNativeModule._Text_construct(peerId, flags) const _peer = new ArkTextPeer(_peerPtr, peerId, "Text", flags) component?.setPeer(_peer) + ArkThemeScopeManager.getInstance().onComponentCreateExit(peerId); return _peer } setTextOptionsAttribute(content?: string | Resource, value?: TextOptions): void { @@ -1588,10 +1593,21 @@ export function Text( const receiver = remember(() => { return new ArkTextComponent() }) + const scope = __context().scope(__id()); NodeAttach((): ArkTextPeer => ArkTextPeer.create(receiver), (_: ArkTextPeer) => { + const parentRef = scope.parent?.nodeRef; + console.log(`FZY Text NodeAttach ${parentRef}`); + const parentPeer = parentRef ? findPeerNode(parentRef) : undefined; + if (parentPeer && parentPeer.peer && receiver.getPeer()) { + console.info(`FZY ArkTextPeer parent ${parentPeer}`) + ArkUIAniModule._ApplyParentThemeScopeId(receiver.getPeer().getPeerPtr(), parentPeer.getPeerPtr()); + } + + ArkThemeScopeManager.getInstance().onComponentCreateEnter("Text", receiver.getPeer()?.getId(), receiver.isFirstBuild) receiver.setTextOptions(content,value) style?.(receiver) content_?.() receiver.applyAttributesFinish() + ArkThemeScopeManager.getInstance().onComponentCreateExit(receiver.getPeer()?.getId()) }) } diff --git a/frameworks/bridge/arkts_frontend/koala_projects/arkoala-arkts/arkui-ohos/src/component/withTheme.ts b/frameworks/bridge/arkts_frontend/koala_projects/arkoala-arkts/arkui-ohos/src/component/withTheme.ts index 39aef1ab586..90eba944bb7 100644 --- a/frameworks/bridge/arkts_frontend/koala_projects/arkoala-arkts/arkui-ohos/src/component/withTheme.ts +++ b/frameworks/bridge/arkts_frontend/koala_projects/arkoala-arkts/arkui-ohos/src/component/withTheme.ts @@ -16,15 +16,164 @@ // WARNING! THIS FILE IS AUTO-GENERATED, DO NOT MAKE CHANGES, THEY WILL BE LOST ON NEXT GENERATION! -import { int32, int64, float32 } from "@koalaui/common" -import { KInt, KPointer, KBoolean, NativeBuffer, KStringPtr, wrapCallback } from "@koalaui/interop" +import { KPointer, runtimeType, RuntimeType } from "@koalaui/interop" +import { int32 } from "@koalaui/common" +import { ComponentBase } from "./../ComponentBase" +import { PeerNode } from "./../PeerNode" +import { ArkUIGeneratedNativeModule } from "#components" +import { CustomTheme } from "@ohos/arkui/theme" +import { AttributeModifier, ThemeColorMode } from "./common" import { NodeAttach, remember } from "@koalaui/runtime" -import { CustomTheme } from "./arkui-custom" -import { ThemeColorMode } from "./common" +import { Serializer } from "./peers/Serializer" +import { Deserializer } from "./peers/Deserializer"; +import { ArkThemeScopeManager } from '../handwritten/theme/ArkThemeScopeManager'; +import { ArkThemeBase } from '../handwritten/theme/ArkThemeBase'; +import { ArkThemeNativeHelper } from '../handwritten/theme/ArkThemeNativeHelper'; + +export class ArkWithThemePeer extends PeerNode { + protected constructor(peerPtr: KPointer, id: int32, name: string = "", flags: int32 = 0) { + super(peerPtr, id, name, flags) + } + public static create(component?: ComponentBase, flags: int32 = 0): ArkWithThemePeer { + const peerId = PeerNode.nextId() + const _peerPtr = ArkUIGeneratedNativeModule._WithTheme_construct(peerId, flags) + const _peer = new ArkWithThemePeer(_peerPtr, peerId, "WithTheme", flags) + component?.setPeer(_peer) + return _peer + } + setWithThemeOptionsAttribute(options: WithThemeOptions): void { + // const thisSerializer : Serializer = Serializer.hold() + // WithThemeOptions_serializer.write(thisSerializer, options) + // ArkUIGeneratedNativeModule._WithThemeInterface_setWithThemeOptions(this.peer.ptr, thisSerializer.asBuffer(), thisSerializer.length()) + // thisSerializer.release() + const elmtId: int32 = this.getId(); + const colorMode = options.colorMode ?? ThemeColorMode.SYSTEM; + const cloneTheme = ArkThemeScopeManager.cloneCustomThemeWithExpand(options.theme); + const theme: ArkThemeBase = ArkThemeScopeManager.getInstance().makeTheme(cloneTheme, colorMode); + // bind theme to theme scope with elmtId + theme.bindToScope(elmtId); + + // prepare on theme scope destroy callback + const onThemeScopeDestroy = () => { + ArkThemeScopeManager.getInstance().onScopeDestroy(elmtId); + } + + // keep for backward compatibility + ArkThemeNativeHelper.sendThemeToNative(theme, elmtId); + // new approach to apply theme in native side + ArkThemeNativeHelper.createInternal(elmtId, theme.id, cloneTheme, colorMode, onThemeScopeDestroy); + + ArkThemeScopeManager.getInstance().onScopeEnter(elmtId, options ?? {} as WithThemeOptions, theme); + } +} export interface WithThemeOptions { theme?: CustomTheme; colorMode?: ThemeColorMode; } -export type WithThemeInterface = (options: WithThemeOptions) => WithThemeAttribute; export interface WithThemeAttribute { + // attributeModifier(value: AttributeModifier | undefined): this +} +export class ArkWithThemeStyle implements WithThemeAttribute { + public attributeModifier(value: AttributeModifier | undefined): this { + throw new Error("Not implemented") + } + public apply(target: WithThemeAttribute): void { + } +} + +export class ArkWithThemeComponent extends ComponentBase implements WithThemeAttribute { + getPeer(): ArkWithThemePeer { + return (this.peer as ArkWithThemePeer) + } + public setWithThemeOptions(options: WithThemeOptions): this { + if (this.checkPriority("setWithThemeOptions")) { + const options_casted = options as (WithThemeOptions) + this.getPeer()?.setWithThemeOptionsAttribute(options_casted) + return this + } + return this + } + _modifier?: AttributeModifier | undefined + public attributeModifier(value: AttributeModifier | undefined): this { + this._modifier = value + return this + } + public applyAttributesFinish(): void { + // we call this function outside of class, so need to make it public + super.applyAttributesFinish() + ArkThemeScopeManager.getInstance().onScopeExit(); + // getUINativeModule().theme.pop(); + } +} +/** @memo */ +export function WithTheme( + /** @memo */ + style: ((attributes: WithThemeAttribute) => void) | undefined, + options: WithThemeOptions, + /** @memo */ + content_: (() => void) | undefined, +): void { + const receiver = remember((): ArkWithThemeComponent => { + return new ArkWithThemeComponent() + }) + NodeAttach((): ArkWithThemePeer => ArkWithThemePeer.create(receiver), (_: ArkWithThemePeer): void => { + ArkThemeScopeManager.getInstance().onComponentCreateEnter("WithTheme", receiver.getPeer()?.getId(), receiver.isFirstBuild) + receiver.setWithThemeOptions(options) + style?.(receiver) + content_?.() + ArkThemeScopeManager.getInstance().onComponentCreateExit(receiver.getPeer()?.getId()) + receiver.applyAttributesFinish() + }) +} + +export class ArkWithThemeSet implements WithThemeAttribute { + _instanceId: number = -1; + setInstanceId(instanceId: number): void { + this._instanceId = instanceId + } + applyModifierPatch(component: WithThemeAttribute): void { + } + public attributeModifier(value: AttributeModifier | undefined): this { + throw new Error("Not implemented") + } +} +export class WithThemeOptions_serializer { + public static write(buffer: Serializer, value: WithThemeOptions): void { + let valueSerializer : Serializer = buffer + const value_theme = value.theme + let value_theme_type : int32 = RuntimeType.UNDEFINED + value_theme_type = runtimeType(value_theme) + valueSerializer.writeInt8((value_theme_type).toChar()) + if ((RuntimeType.UNDEFINED) != (value_theme_type)) { + const value_theme_value = value_theme! + // CustomTheme_serializer.write(valueSerializer, value_theme_value) + } + const value_colorMode = value.colorMode + let value_colorMode_type : int32 = RuntimeType.UNDEFINED + value_colorMode_type = runtimeType(value_colorMode) + valueSerializer.writeInt8((value_colorMode_type).toChar()) + if ((RuntimeType.UNDEFINED) != (value_colorMode_type)) { + const value_colorMode_value = (value_colorMode as ThemeColorMode) + valueSerializer.writeInt32(value_colorMode_value.valueOf()) + } + } + public static read(buffer: Deserializer): WithThemeOptions { + let valueDeserializer : Deserializer = buffer + const theme_buf_runtimeType = valueDeserializer.readInt8().toInt() + let theme_buf : CustomTheme | undefined + if ((RuntimeType.UNDEFINED) != (theme_buf_runtimeType)) + { + // theme_buf = CustomTheme_serializer.read(valueDeserializer) + } + const theme_result : CustomTheme | undefined = theme_buf + const colorMode_buf_runtimeType = valueDeserializer.readInt8().toInt() + let colorMode_buf : ThemeColorMode | undefined + if ((RuntimeType.UNDEFINED) != (colorMode_buf_runtimeType)) + { + colorMode_buf = ThemeColorMode.fromValue(valueDeserializer.readInt32()) + } + const colorMode_result : ThemeColorMode | undefined = colorMode_buf + let value : WithThemeOptions = ({theme: theme_result, colorMode: colorMode_result} as WithThemeOptions) + return value + } } diff --git a/frameworks/bridge/arkts_frontend/koala_projects/arkoala-arkts/arkui-ohos/src/handwritten/theme/ArkThemeBase.ts b/frameworks/bridge/arkts_frontend/koala_projects/arkoala-arkts/arkui-ohos/src/handwritten/theme/ArkThemeBase.ts index 3013b949be3..e853c14e0e3 100644 --- a/frameworks/bridge/arkts_frontend/koala_projects/arkoala-arkts/arkui-ohos/src/handwritten/theme/ArkThemeBase.ts +++ b/frameworks/bridge/arkts_frontend/koala_projects/arkoala-arkts/arkui-ohos/src/handwritten/theme/ArkThemeBase.ts @@ -19,25 +19,26 @@ import { Shapes, Typography } from './index'; import { ThemeColorMode } from 'arkui/component/common'; import { ArkShapesImpl } from './ArkShapesImpl'; import { ArkTypographyImpl } from './ArkTypographyImpl'; +import { int32 } from "@koalaui/common" /** * Theme counter used to generate next theme id */ -let themeCounter = 0; +let themeCounter: int32 = 0; /** * Base ArkTheme class */ export class ArkThemeBase extends Theme { // Theme tokens - colors: Colors; - shapes: Shapes; - typography: Typography; + // colors: Colors; + // shapes: Shapes; + // typography: Typography; /** * Unique theme instance id */ - id: number; + id: int32; /** * Copy of CustomTheme used to create this theme instance diff --git a/frameworks/bridge/arkts_frontend/koala_projects/arkoala-arkts/arkui-ohos/src/handwritten/theme/ArkThemeImpl.ts b/frameworks/bridge/arkts_frontend/koala_projects/arkoala-arkts/arkui-ohos/src/handwritten/theme/ArkThemeImpl.ts index d1a4e23b6ae..c3c85cd15b5 100644 --- a/frameworks/bridge/arkts_frontend/koala_projects/arkoala-arkts/arkui-ohos/src/handwritten/theme/ArkThemeImpl.ts +++ b/frameworks/bridge/arkts_frontend/koala_projects/arkoala-arkts/arkui-ohos/src/handwritten/theme/ArkThemeImpl.ts @@ -21,20 +21,13 @@ import { ArkTypographyImpl } from './ArkTypographyImpl'; export class ArkThemeImpl extends ArkThemeBase { constructor( - customTheme: CustomTheme, + customTheme: CustomTheme | undefined, colorMode: ThemeColorMode, baselineTheme: ArkThemeBase, ) { - // if (!customTheme) { - // super(baselineTheme.id, undefined, colorMode, - // new Colors(undefined, baselineTheme.colors), - // new ArkShapesImpl(undefined, baselineTheme.shapes), - // new ArkTypographyImpl(undefined, baselineTheme.typography)); - // return; - // } super(baselineTheme.id, customTheme, colorMode, - new Colors(customTheme.colors, baselineTheme.colors), - new ArkShapesImpl(customTheme.shapes, baselineTheme.shapes), - new ArkTypographyImpl(customTheme.typography, baselineTheme.typography)); + new Colors(customTheme ? customTheme.colors : undefined, baselineTheme.colors), + new ArkShapesImpl(customTheme ? customTheme.shapes : undefined, baselineTheme.shapes), + new ArkTypographyImpl(customTheme ? customTheme.typography : undefined, baselineTheme.typography)); } } diff --git a/frameworks/bridge/arkts_frontend/koala_projects/arkoala-arkts/arkui-ohos/src/handwritten/theme/ArkThemeNativeHelper.ts b/frameworks/bridge/arkts_frontend/koala_projects/arkoala-arkts/arkui-ohos/src/handwritten/theme/ArkThemeNativeHelper.ts index eef754f899c..73856ce92cc 100644 --- a/frameworks/bridge/arkts_frontend/koala_projects/arkoala-arkts/arkui-ohos/src/handwritten/theme/ArkThemeNativeHelper.ts +++ b/frameworks/bridge/arkts_frontend/koala_projects/arkoala-arkts/arkui-ohos/src/handwritten/theme/ArkThemeNativeHelper.ts @@ -24,9 +24,9 @@ import { Colors } from '@ohos/arkui/theme'; export class ArkThemeNativeHelper { static sendThemeToNative(theme: Theme, elmtId: int32): void { - ArkUIAniModule._SendThemeToNative(ArkThemeNativeHelper.convertThemeToColorArray(theme), elmtId); + ArkUIAniModule._SendThemeToNative(ArkThemeNativeHelper.convertColorsToArray(theme.colors), elmtId); } - static setDefaultTheme(theme: CustomTheme): void { + static setDefaultTheme(theme: CustomTheme | undefined): void { const colorArray = ArkThemeNativeHelper.convertColorsToArray(theme?.colors); ArkThemeScopeManager.getInstance().onEnterLocalColorMode(ThemeColorMode.LIGHT); ArkUIAniModule._SetDefaultTheme(colorArray, false); @@ -34,7 +34,25 @@ export class ArkThemeNativeHelper { ArkUIAniModule._SetDefaultTheme(colorArray, true); ArkThemeScopeManager.getInstance().onExitLocalColorMode(); } - private static convertThemeToColorArray(theme: Theme): ResourceColor[] { + static createInternal(themeScopeId: int32, themeId: int32, theme: CustomTheme | undefined, colorMode: ThemeColorMode, + onThemeScopeDestroy: () => void + ) { + // set local color mode if need + if (colorMode && colorMode !== ThemeColorMode.SYSTEM) { + ArkThemeScopeManager.getInstance().onEnterLocalColorMode(colorMode); + } + + ArkUIAniModule._CreateAndBindTheme(themeScopeId, themeId, + ArkThemeNativeHelper.convertColorsToArray(theme?.colors), colorMode, onThemeScopeDestroy); + // getUINativeModule().theme.createAndBindTheme(themeScopeId, themeId, + // ArkThemeNativeHelper.convertColorsToArray(theme?.colors), colorMode, onThemeScopeDestroy); + + // reset local color mode if need + if (colorMode && colorMode !== ThemeColorMode.SYSTEM) { + ArkThemeScopeManager.getInstance().onExitLocalColorMode(); + } + } + public static convertThemeToColorArray(theme: Theme): ResourceColor[] { return [ theme.colors.brand, theme.colors.warning, @@ -89,7 +107,7 @@ export class ArkThemeNativeHelper { theme.colors.interactiveClick, ]; } - private static convertColorsToArray(colors: CustomColors | undefined): ResourceColor[] { + public static convertColorsToArray(colors: CustomColors | undefined): ResourceColor[] { const basisColors = ArkThemeScopeManager.getSystemColors(); if (!colors) { return new Array(Object.keys(basisColors).length); diff --git a/frameworks/bridge/arkts_frontend/koala_projects/arkoala-arkts/arkui-ohos/src/handwritten/theme/ArkThemeScope.ts b/frameworks/bridge/arkts_frontend/koala_projects/arkoala-arkts/arkui-ohos/src/handwritten/theme/ArkThemeScope.ts new file mode 100644 index 00000000000..f16573a6ba9 --- /dev/null +++ b/frameworks/bridge/arkts_frontend/koala_projects/arkoala-arkts/arkui-ohos/src/handwritten/theme/ArkThemeScope.ts @@ -0,0 +1,254 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +import { CustomTheme } from "@ohos/arkui/theme"; +import { ThemeColorMode } from "arkui/component/common"; +import { ArkThemeBase } from './ArkThemeBase'; +import { WithThemeOptions } from 'arkui/component/withTheme'; +import { int32 } from "@koalaui/common"; + +class ArkThemeScopeItem { + elmtId: int32 = -1; + // ownerId: number; + // owner: ViewPuInternal; + name: string = ""; + isInWhiteList?: boolean = undefined; + // the CustomComponent with same elmtId, receives onWillApplyTheme callback + // listener?: ViewPuInternal | undefined = undefined; +} + +class ArkThemeScopeArray extends Array { + binarySearch(elmtId: int32): number { + let start: int32 = 0; + let end: int32 = (this.length - 1) as int32; + while (start <= end) { + let mid: int32 = (start + end) >> 1; + if (this[mid].elmtId === elmtId) { + return mid; + } + if (elmtId < this[mid].elmtId) { + end = mid - 1; + } else { + start = mid + 1; + } + } + return -1; + } +} + +/** + * Used to store elmtIds of the components that are in WithTheme container scope. + */ +export class ArkThemeScope { + /** + * elmtId of the CustomComponent which defines WithTheme container + */ + private ownerComponentId: number; + + /** + * elmtId of the WithTheme container that defines theme scope + */ + private withThemeId: number; + + /** + * WithTheme container options + */ + private withThemeOptions: WithThemeOptions; + + /** + * Previous scope color mode before option change + */ + private prevColorMode: ThemeColorMode; + + /** + * elmtIds of the components that are in this theme scope + */ + private components?: ArkThemeScopeArray; + + /** + * Theme instance associated with this Theme Scope + */ + private theme: ArkThemeBase; + + /** + * Initialize Theme Scope + * + * @param ownerComponentId elmtId of the CustomComponent which defines WithTheme container + * @param withThemeId elmtId of the WithTheme container that defines theme scope + * @param withThemeOptions WithTheme container options + * @param theme Theme instance associated with this Theme Scope + */ + constructor(ownerComponentId: number, withThemeId: number, withThemeOptions: WithThemeOptions, theme: ArkThemeBase) { + this.ownerComponentId = ownerComponentId; + this.withThemeId = withThemeId; + this.withThemeOptions = withThemeOptions; + this.theme = theme; + this.prevColorMode = this.colorMode(); + } + + /** + * Get elmtId of the CustomComponent which defines WithTheme container + * + * @returns elmtId as number + */ + getOwnerComponentId(): number { + return this.ownerComponentId; + } + + /** + * Get elmtId of the WithTheme container that defines theme scope + * + * @returns elmtId as number + */ + getWithThemeId(): number { + return this.withThemeId; + } + + /** + * Add component to the current theme scope by elmtId + * + * @param elmtId elmtId as number + * @param owner component owner + * @param componentName component name + */ + addComponentToScope(elmtId: int32, componentName: string) { + if (this.isComponentInScope(elmtId)) { + return; + } + if (!this.components) { + this.components = new ArkThemeScopeArray(); + } + this.components!.push({ elmtId: elmtId, name: componentName }); + } + + /** + * Add Custom component to the component items of this scope as listener. + * + * @param listener the Custom component + */ + // addCustomListenerInScope(listener: ViewPuInternal) { + // const len = this.components ? this.components.length : -1; + // if (len <= 0) { + // return; + // } + // const listenerId = listener.id__(); + // // the last ThemeScopeItem probably corresponds to Custom component + // let themeScopeItem = this.components[len - 1]; + // if (themeScopeItem.elmtId === listenerId) { + // themeScopeItem.listener = listener; + // return; + // } + // themeScopeItem = this.components.find((item) => item.elmtId === listenerId); + // if (themeScopeItem) { + // themeScopeItem.listener = listener; + // } + // } + + /** + * Remove components from the current theme scope by elmtId + * + * @param elmtId elmtId as number + */ + removeComponentFromScope(elmtId: int32) { + if (this.components) { + const index = this.components!.binarySearch(elmtId); + if (index > -1) { + this.components!.splice(index, 1); + } + } + } + + /** + * Check whether the component with elmtId is in current theme scope + * + * @param elmtId elmtId as number + * @returns true if theme scope contains component, otherwise false + */ + isComponentInScope(elmtId: int32): boolean { + if (this.components && (this.components!.binarySearch(elmtId) > -1)) { + return true; + } + return false; + } + + /** + * Get all components elmtIds which are in current theme scope + * + * @returns array of elmIds as numbers + */ + componentsInScope(): Array { + return this.components!; + } + + /** + * Get color mode of the current theme scope + * + * @returns DARK, Light or SYSTEM values + */ + colorMode(): ThemeColorMode { + return this.withThemeOptions.colorMode ?? ThemeColorMode.SYSTEM; + } + + /** + * Get Custom Theme of the current theme scope + * + * @returns CustomTheme instance + */ + customTheme(): CustomTheme { + return this.withThemeOptions.theme ?? {} as CustomTheme; + } + + /** + * Get theme instance associated with this Theme Scope + * + * @returns theme instance + */ + getTheme(): ArkThemeBase { + return this.theme; + } + + /** + * Get WithTheme container options + * + * @returns WithThemeOptions instance + */ + options(): WithThemeOptions { + return this.withThemeOptions; + } + + /** + * Update WithThemeOptions + * + * @param options WithThemeOptions instance + * @param theme Theme instance associated with this Theme Scope + */ + updateWithThemeOptions(options: WithThemeOptions, theme: ArkThemeBase) { + this.prevColorMode = this.colorMode(); + this.withThemeOptions = options; + if (this.theme !== theme) { + this.theme?.unbindFromScope(this.getWithThemeId()); + this.theme = theme; + } + } + + /** + * Check whether scope color mode changed in last update + * + * @returns true if color mode changed, otherwise false + */ + isColorModeChanged() { + return this.prevColorMode !== this.colorMode(); + } +} \ No newline at end of file diff --git a/frameworks/bridge/arkts_frontend/koala_projects/arkoala-arkts/arkui-ohos/src/handwritten/theme/ArkThemeScopeManager.ts b/frameworks/bridge/arkts_frontend/koala_projects/arkoala-arkts/arkui-ohos/src/handwritten/theme/ArkThemeScopeManager.ts index a23f57f5101..f02a4f7e9bf 100644 --- a/frameworks/bridge/arkts_frontend/koala_projects/arkoala-arkts/arkui-ohos/src/handwritten/theme/ArkThemeScopeManager.ts +++ b/frameworks/bridge/arkts_frontend/koala_projects/arkoala-arkts/arkui-ohos/src/handwritten/theme/ArkThemeScopeManager.ts @@ -21,6 +21,10 @@ import { ArkSystemTheme } from './system/ArkSystemTheme'; import { ArkThemeCache } from './ArkThemeCache'; import { ArkThemeImpl } from './ArkThemeImpl'; import { ArkThemeNativeHelper } from './ArkThemeNativeHelper'; +import { WithThemeOptions, WithTheme } from '../../component/withTheme'; +import { ArkUIAniModule } from '../../ani/arkts/ArkUIAniModule'; +import { unsafeCast, int32, int64, float32 } from "@koalaui/common"; +import { ArkThemeScope } from './ArkThemeScope'; type ViewPuInternal = Object; @@ -35,6 +39,46 @@ export class ArkThemeScopeManager { * The default Theme */ private defaultTheme: ArkThemeBase | undefined = undefined; + /** + * elmtId of the handled component + */ + private handledComponentElmtId?: int32; + /** + * Theme Scopes are in constructed process. + */ + private localThemeScopes: ArkThemeScope[] = []; + /** + * All existing theme scopes + */ + private themeScopes: Array | undefined = undefined; + /** + * Stack of ifElse Scopes + */ + private ifElseScopes: ArkThemeScope[] = []; + /** + * Theme Scope Id of the last handled component + */ + private lastThemeScopeId: number = 0; + /** + * Rendering state of the handled component + */ + private handledIsFirstRender: boolean; + /** + * Last handled CustomComponent + */ + private handledOwnerComponentId: number; + /** + * Theme Scope of the handled component + */ + private handledThemeScope?: ArkThemeScope; + /** + * Color Mode of the handled component + */ + private handledColorMode: ThemeColorMode = ThemeColorMode.SYSTEM; + /** + * Temporary link to the theme scope for If container branches update + */ + private ifElseLastScope?: ArkThemeScope = undefined; /** * Obtain System Colors @@ -51,14 +95,124 @@ export class ArkThemeScopeManager { * @param colorMode local color mode */ onEnterLocalColorMode(colorMode: ThemeColorMode) { - // getUINativeModule().resource.updateColorMode(colorMode); + console.warn(`FZY onEnterLocalColorMode ${colorMode}`) + ArkUIAniModule._UpdateColorMode(colorMode); } /** * Exit from the local color mode scope */ onExitLocalColorMode() { - // getUINativeModule().resource.restore(); + console.warn(`FZY onExitLocalColorMode`) + ArkUIAniModule._RestoreColorMode(); + } + + /** + * Handle destroy event for theme scope + * + * @param themeScopeId if of destroyed theme scope + */ + onScopeDestroy(themeScopeId: number) { + this.themeScopes = this.themeScopes?.filter((scope) => { + if (scope.getWithThemeId() === themeScopeId) { + this.onScopeDestroyInternal(scope); + return false; + } + return true; + }) + } + + /** + * Start for IfElse branch update + */ + onIfElseBranchUpdateEnter() { + if (this.ifElseLastScope) { + this.ifElseScopes.push(this.ifElseLastScope!); + } + } + + /** + * Destroy theme scope + * + * @param scope theme scope instance + */ + private onScopeDestroyInternal(scope: ArkThemeScope) { + // unbind theme from scope + const theme = scope.getTheme(); + if (theme) { + theme.unbindFromScope(scope.getWithThemeId()); + } + + // remove scope from the list of created scopes + const index = this.localThemeScopes.indexOf(scope); + if (index !== -1) { + this.localThemeScopes.splice(index, 1); + } + ArkUIAniModule._RemoveThemeInNative(scope.getWithThemeId()); + } + +/** + * Handle enter to the theme scope + * + * @param withThemeId WithTheme container`s elmtId + * @param withThemeOptions WithTheme container`s options + */ + onScopeEnter(withThemeId: number, withThemeOptions: WithThemeOptions, theme: ArkThemeBase) { + console.log(`FZY onScopeEnter ${withThemeId}, ${this.handledIsFirstRender}`) + // save theme scope id on scope enter + this.lastThemeScopeId = withThemeId; + if (this.handledIsFirstRender === true) { + // create theme scope + let themeScope = new ArkThemeScope(this.handledOwnerComponentId, withThemeId, withThemeOptions, theme); + // keep created scope to the array of the scopes under construction + console.log(`FZY onScopeEnter push`) + this.localThemeScopes.push(themeScope); + if (!this.themeScopes) { + this.themeScopes = new Array(); + } + // keep created scope to the array of all theme scopes + this.themeScopes!.push(themeScope); + } else { + // retrieve existing theme scope by WithTheme elmtId + const scope = this.themeScopes?.find(item => item.getWithThemeId() === withThemeId); + // update WithTheme options + scope?.updateWithThemeOptions(withThemeOptions, theme); + // re-render all components from the scope + // this.forceRerenderScope(scope); + } + } + + /** + * Handle exit from the theme scope + */ + onScopeExit() { + // remove top theme scope from the array of scopes under construction + if (this.handledIsFirstRender === true) { + console.log(`FZY onScopeExit pop`) + this.localThemeScopes.pop(); + } + } + + /** + * Obtain scope by component`s elmtId + * + * @param elmtId component`s elmtId as number + * @returns ArkThemeScope instance or undefined + */ + scopeForElmtId(elmtId: int32): ArkThemeScope | undefined { + // return theme scope of the handled component if we know it + if (this.handledThemeScope && this.handledComponentElmtId === elmtId) { + return this.handledThemeScope; + } + // fast way to get theme scope for the first rendered component + if (this.handledIsFirstRender) { + if (this.localThemeScopes.length > 0) { // current cunstructed scope + return this.localThemeScopes[this.localThemeScopes.length - 1]; + } + } + + // common way to get scope for the component + return this.themeScopes?.find(item => item.isComponentInScope(elmtId)); } /** @@ -67,12 +221,17 @@ export class ArkThemeScopeManager { * @param customTheme instance of CustomTheme used to create theme * @returns theme instance */ - static cloneCustomThemeWithExpand(customTheme: CustomTheme): CustomTheme { + static cloneCustomThemeWithExpand(customTheme?: CustomTheme): CustomTheme | undefined { + console.log(`FZY cloneCustomThemeWithExpand 111, customTheme`) const theme = ArkThemeBase.copyCustomTheme(customTheme); + console.log('FZY cloneCustomThemeWithExpand 222') + if (theme?.colors) { + console.log('FZY cloneCustomThemeWithExpand 333') Colors.expandByBrandColor(theme!.colors!); } - return theme!; + console.log('FZY cloneCustomThemeWithExpand 555') + return theme; } /** @@ -82,11 +241,13 @@ export class ArkThemeScopeManager { * @param colorMode local colorm mode used for theme * @returns theme instance */ - makeTheme(customTheme: CustomTheme, colorMode: ThemeColorMode): ArkThemeBase { + makeTheme(customTheme: CustomTheme | undefined, colorMode: ThemeColorMode): ArkThemeBase { const baselineTheme = this.defaultTheme ?? ArkThemeScopeManager.systemTheme; // try to take theme from the cache const theme = ArkThemeCache.getInstance().get(baselineTheme.id, customTheme, colorMode); - + if (theme) { + console.info(`FZY makeTheme get theme from cache`); + } // return theme instance from cache or create new theme instance return theme ? theme : new ArkThemeImpl(customTheme, colorMode, baselineTheme); } @@ -103,11 +264,14 @@ export class ArkThemeScopeManager { } setDefaultTheme(customTheme: CustomTheme) { + console.error(`FZY manager setDefaultTheme customTheme ${JSON.stringify(ArkThemeNativeHelper.convertColorsToArray(customTheme!.colors!))}`) // unbind previous default theme from 0 theme scope this.defaultTheme?.unbindFromScope(0); this.defaultTheme = ArkThemeScopeManager.systemTheme; const cloneTheme = ArkThemeScopeManager.cloneCustomThemeWithExpand(customTheme); - this.defaultTheme = this.makeTheme(customTheme, ThemeColorMode.SYSTEM); + console.error(`FZY manager setDefaultTheme cloneTheme ${JSON.stringify(ArkThemeNativeHelper.convertColorsToArray(cloneTheme!.colors!))}`) + this.defaultTheme = this.makeTheme(cloneTheme, ThemeColorMode.SYSTEM); + console.error(`FZY manager setDefaultTheme defaultTheme ${JSON.stringify(ArkThemeNativeHelper.convertColorsToArray(this.defaultTheme!.colors!))}`) // bind new default theme to 0 theme scope this.defaultTheme?.bindToScope(0); @@ -124,4 +288,84 @@ export class ArkThemeScopeManager { } return ArkThemeScopeManager.instance!; } + + onComponentCreateEnter(componentName: string, elmtId: int32 | undefined, isFirstRender: boolean) { + console.log(`FZY onComponentCreateEnter ${componentName} ${elmtId}, isFirst ${isFirstRender}`) + this.handledIsFirstRender = isFirstRender; + this.handledComponentElmtId = elmtId; + + // no need to handle component style if themeScope array is undefined or component is WithTheme container + if (!this.themeScopes || componentName === 'WithTheme') { + return; + } + // no need to handle component style if themeScope array is empty + if (this.themeScopes!.length === 0) { + // probably in the last draw themeScope was not empty + // we have to handle this to flush themeScope for built-in components + this.handleThemeScopeChange(undefined); + return; + } + + let scope: ArkThemeScope | undefined = undefined; + + // we need to keep component to the theme scope before first render + if (isFirstRender) { + console.log(`FZY onComponentCreateEnter currentLocalScope localThemeScopes ${this.localThemeScopes.length}`) + const currentLocalScope: ArkThemeScope | undefined = this.localThemeScopes.length > 0 ? this.localThemeScopes[this.localThemeScopes.length - 1] : undefined; + const currentIfElseScope: ArkThemeScope | undefined = this.ifElseScopes.length > 0 ? this.ifElseScopes[this.ifElseScopes.length - 1] : undefined; + if (currentLocalScope) { + // keep component to the current constructed scope + scope = currentLocalScope; + scope.addComponentToScope(elmtId!, componentName); + } else if (currentIfElseScope) { + // keep component to the current ifElse scope + scope = currentIfElseScope; + scope.addComponentToScope(elmtId!, componentName); + } + // if component didn`t hit any theme scope then we have to use SystemTheme + } + + if (scope === undefined) { + scope = this.scopeForElmtId(elmtId!); + } + // keep color mode for handled container + this.handledColorMode = scope ? scope.colorMode() : ThemeColorMode.SYSTEM; + // trigger for enter local color mode for the component before rendering + if (this.handledColorMode === ThemeColorMode.LIGHT || this.handledColorMode === ThemeColorMode.DARK) { + this.onEnterLocalColorMode(this.handledColorMode); + } + + if (componentName === 'If') { + // keep last ifElse scope + this.ifElseLastScope = scope; + } + + // save theme scope for handled component + this.handledThemeScope = scope; + // probably theme scope changed after previous component draw, handle it + this.handleThemeScopeChange(this.handledThemeScope); + } + + onComponentCreateExit(elmtId?: int32) { + console.log(`FZY onComponentCreateExit ${elmtId}`) + // trigger for exit local color mode for the component after rendering + if (this.handledColorMode === ThemeColorMode.LIGHT || this.handledColorMode === ThemeColorMode.DARK) { + console.log(`FZY onComponentCreateExit ${elmtId}, colorMode: ${this.handledColorMode}`) + this.onExitLocalColorMode(); + } + + // flush theme scope of the handled component + this.handledThemeScope = undefined; + this.handledComponentElmtId = undefined; + } + + private handleThemeScopeChange(scope: ArkThemeScope | undefined) { + const currentThemeScopeId = scope?.getWithThemeId() ?? 0; + if (currentThemeScopeId !== this.lastThemeScopeId) { + this.lastThemeScopeId = currentThemeScopeId; + // @ts-ignore + // WithTheme.setThemeScopeId(currentThemeScopeId); + ArkUIAniModule._SetThemeScopeId(currentThemeScopeId); + } + } } diff --git a/frameworks/bridge/arkts_frontend/koala_projects/arkoala-arkts/components.gni b/frameworks/bridge/arkts_frontend/koala_projects/arkoala-arkts/components.gni index e31435fc64e..2ced3269386 100644 --- a/frameworks/bridge/arkts_frontend/koala_projects/arkoala-arkts/components.gni +++ b/frameworks/bridge/arkts_frontend/koala_projects/arkoala-arkts/components.gni @@ -385,18 +385,19 @@ arkui_files = [ "arkui-preprocessed/arkui/handwritten/modifiers/ArkTextInputNode.ets", "arkui-preprocessed/arkui/handwritten/modifiers/ArkTextNode.ets", "arkui-preprocessed/arkui/handwritten/modifiers/ArkXComponentNode.ets", - "arkui-preprocessed/arkui/handwritten/theme/ArkResourcesHelper.ets", - "arkui-preprocessed/arkui/handwritten/theme/ArkShapesImpl.ets", + "arkui-preprocessed/arkui/handwritten/theme/index.ets", + "arkui-preprocessed/arkui/handwritten/theme/ArkThemeScopeManager.ets", "arkui-preprocessed/arkui/handwritten/theme/ArkThemeBase.ets", - "arkui-preprocessed/arkui/handwritten/theme/ArkThemeCache.ets", + "arkui-preprocessed/arkui/handwritten/theme/ArkShapesImpl.ets", + "arkui-preprocessed/arkui/handwritten/theme/ArkThemeScope.ets", + "arkui-preprocessed/arkui/handwritten/theme/ArkResourcesHelper.ets", "arkui-preprocessed/arkui/handwritten/theme/ArkThemeImpl.ets", - "arkui-preprocessed/arkui/handwritten/theme/ArkThemeNativeHelper.ets", - "arkui-preprocessed/arkui/handwritten/theme/ArkThemeScopeManager.ets", "arkui-preprocessed/arkui/handwritten/theme/ArkTypographyImpl.ets", - "arkui-preprocessed/arkui/handwritten/theme/index.ets", + "arkui-preprocessed/arkui/handwritten/theme/ArkThemeNativeHelper.ets", + "arkui-preprocessed/arkui/handwritten/theme/ArkThemeCache.ets", "arkui-preprocessed/arkui/handwritten/theme/system/ArkSystemShapes.ets", - "arkui-preprocessed/arkui/handwritten/theme/system/ArkSystemTheme.ets", "arkui-preprocessed/arkui/handwritten/theme/system/ArkSystemTypography.ets", + "arkui-preprocessed/arkui/handwritten/theme/system/ArkSystemTheme.ets", "arkui-preprocessed/arkui/index.ets", "arkui-preprocessed/arkui/ohos.arkui.modifier.ets", "arkui-preprocessed/arkui/ohos.arkui.node.ets", diff --git a/frameworks/bridge/arkts_frontend/koala_projects/arkoala/framework/native/src/generated/arkoala_api_generated.h b/frameworks/bridge/arkts_frontend/koala_projects/arkoala/framework/native/src/generated/arkoala_api_generated.h index fe8f742ef59..14c904023db 100644 --- a/frameworks/bridge/arkts_frontend/koala_projects/arkoala/framework/native/src/generated/arkoala_api_generated.h +++ b/frameworks/bridge/arkts_frontend/koala_projects/arkoala/framework/native/src/generated/arkoala_api_generated.h @@ -3277,6 +3277,8 @@ typedef struct Ark_Union_DotIndicator_DigitIndicator_Boolean Ark_Union_DotIndica typedef struct Opt_Union_DotIndicator_DigitIndicator_Boolean Opt_Union_DotIndicator_DigitIndicator_Boolean; typedef struct Ark_Union_LinearStyleOptions_RingStyleOptions_CapsuleStyleOptions_ProgressStyleOptions Ark_Union_LinearStyleOptions_RingStyleOptions_CapsuleStyleOptions_ProgressStyleOptions; typedef struct Opt_Union_LinearStyleOptions_RingStyleOptions_CapsuleStyleOptions_ProgressStyleOptions Opt_Union_LinearStyleOptions_RingStyleOptions_CapsuleStyleOptions_ProgressStyleOptions; +typedef struct Ark_WithThemeOptions Ark_WithThemeOptions; +typedef struct Opt_WithThemeOptions Opt_WithThemeOptions; typedef struct Ark_Union_String_ImageAttachment_CustomSpan Ark_Union_String_ImageAttachment_CustomSpan; typedef struct Opt_Union_String_ImageAttachment_CustomSpan Opt_Union_String_ImageAttachment_CustomSpan; typedef struct Ark_AttachmentType Ark_AttachmentType; @@ -19721,6 +19723,15 @@ typedef struct Opt_Union_LinearStyleOptions_RingStyleOptions_CapsuleStyleOptions Ark_Tag tag; Ark_Union_LinearStyleOptions_RingStyleOptions_CapsuleStyleOptions_ProgressStyleOptions value; } Opt_Union_LinearStyleOptions_RingStyleOptions_CapsuleStyleOptions_ProgressStyleOptions; +typedef struct Ark_WithThemeOptions { + /* kind: Interface */ + Opt_CustomTheme theme; + Opt_ThemeColorMode colorMode; +} Ark_WithThemeOptions; +typedef struct Opt_WithThemeOptions { + Ark_Tag tag; + Ark_WithThemeOptions value; +} Opt_WithThemeOptions; typedef struct Ark_Union_String_ImageAttachment_CustomSpan { Ark_Int32 selector; union { @@ -20116,14 +20127,6 @@ typedef struct Opt_Union_SubTabBarStyle_BottomTabBarStyle { Ark_Tag tag; Ark_Union_SubTabBarStyle_BottomTabBarStyle value; } Opt_Union_SubTabBarStyle_BottomTabBarStyle; -typedef struct Ark_WithThemeOptions { - Opt_CustomTheme theme; - Opt_ThemeColorMode colorMode; -} Ark_WithThemeOptions; -typedef struct Opt_WithThemeOptions { - Ark_Tag tag; - Ark_WithThemeOptions value; -} Opt_WithThemeOptions; typedef struct Ark_RichEditorSpan { Ark_Int32 selector; union { @@ -24161,6 +24164,13 @@ typedef struct GENERATED_ArkUIWindowSceneModifier { const Opt_Number* fraction); } GENERATED_ArkUIWindowSceneModifier; +typedef struct GENERATED_ArkUIWithThemeModifier { + Ark_NativePointer (*construct)(Ark_Int32 id, + Ark_Int32 flags); + void (*setWithThemeOptions)(Ark_NativePointer node, + const Ark_WithThemeOptions* options); +} GENERATED_ArkUIWithThemeModifier; + typedef struct GENERATED_ArkUIXComponentModifier { Ark_NativePointer (*construct)(Ark_Int32 id, Ark_Int32 flags); @@ -28378,6 +28388,7 @@ typedef struct GENERATED_ArkUINodeModifiers { const GENERATED_ArkUIVideoModifier* (*getVideoModifier)(); const GENERATED_ArkUIWebModifier* (*getWebModifier)(); const GENERATED_ArkUIWindowSceneModifier* (*getWindowSceneModifier)(); + const GENERATED_ArkUIWithThemeModifier* (*getWithThemeModifier)(); const GENERATED_ArkUIXComponentModifier* (*getXComponentModifier)(); const GENERATED_ArkUISideBarContainerModifier* (*getSideBarContainerModifier)(); const GENERATED_ArkUIRemoteWindowModifier* (*getRemoteWindowModifier)(); diff --git a/frameworks/bridge/arkts_frontend/koala_projects/arkoala/framework/native/src/generated/bridge_generated.cc b/frameworks/bridge/arkts_frontend/koala_projects/arkoala/framework/native/src/generated/bridge_generated.cc index 75a5aa6eda0..b87bdcf7662 100644 --- a/frameworks/bridge/arkts_frontend/koala_projects/arkoala/framework/native/src/generated/bridge_generated.cc +++ b/frameworks/bridge/arkts_frontend/koala_projects/arkoala/framework/native/src/generated/bridge_generated.cc @@ -30949,6 +30949,17 @@ void impl_WindowSceneAttribute_attractionEffect(Ark_NativePointer thisPtr, KSeri GetNodeModifiers()->getWindowSceneModifier()->setAttractionEffect(self, (const Opt_Position*)&destination_value, (const Opt_Number*)&fraction_value); } KOALA_INTEROP_DIRECT_V3(WindowSceneAttribute_attractionEffect, Ark_NativePointer, KSerializerBuffer, int32_t) +Ark_NativePointer impl_WithTheme_construct(Ark_Int32 id, Ark_Int32 flags) { + return GetNodeModifiers()->getWithThemeModifier()->construct(id, flags); +} +KOALA_INTEROP_DIRECT_2(WithTheme_construct, Ark_NativePointer, Ark_Int32, Ark_Int32) +void impl_WithThemeInterface_setWithThemeOptions(Ark_NativePointer thisPtr, KSerializerBuffer thisArray, int32_t thisLength) { + Ark_NodeHandle self = reinterpret_cast(thisPtr); + Deserializer thisDeserializer(thisArray, thisLength); + Ark_WithThemeOptions options_value = thisDeserializer.readWithThemeOptions();; + GetNodeModifiers()->getWithThemeModifier()->setWithThemeOptions(self, (const Ark_WithThemeOptions*)&options_value); +} +KOALA_INTEROP_DIRECT_V3(WithThemeInterface_setWithThemeOptions, Ark_NativePointer, KSerializerBuffer, int32_t) Ark_NativePointer impl_XComponent_construct(Ark_Int32 id, Ark_Int32 flags) { return GetNodeModifiers()->getXComponentModifier()->construct(id, flags); } diff --git a/frameworks/bridge/arkts_frontend/koala_projects/incremental/runtime/src/states/State.ts b/frameworks/bridge/arkts_frontend/koala_projects/incremental/runtime/src/states/State.ts index 378515ae81c..8d2a9d70a27 100644 --- a/frameworks/bridge/arkts_frontend/koala_projects/incremental/runtime/src/states/State.ts +++ b/frameworks/bridge/arkts_frontend/koala_projects/incremental/runtime/src/states/State.ts @@ -181,6 +181,8 @@ export interface InternalScope { recache(newValue?: Value): Value /** @returns internal state for parameter */ param(index: int32, value: V, equivalent?: Equivalent, name?: string, contextLocal?: boolean): State + + get parent(): ManagedScope | undefined } /** diff --git a/frameworks/bridge/declarative_frontend/ark_theme/theme_apply/js_theme_utils.h b/frameworks/bridge/declarative_frontend/ark_theme/theme_apply/js_theme_utils.h index e87790994aa..5d2e8dda271 100644 --- a/frameworks/bridge/declarative_frontend/ark_theme/theme_apply/js_theme_utils.h +++ b/frameworks/bridge/declarative_frontend/ark_theme/theme_apply/js_theme_utils.h @@ -16,6 +16,7 @@ #ifndef FRAMEWORKS_BRIDGE_DECLARATIVE_FRONTEND_THEME_JS_THEME_UTILS_H #define FRAMEWORKS_BRIDGE_DECLARATIVE_FRONTEND_THEME_JS_THEME_UTILS_H +#include #include "base/utils/utils.h" #include "bridge/common/utils/utils.h" #include "bridge/declarative_frontend/engine/jsi/jsi_declarative_engine.h" @@ -23,6 +24,7 @@ #include "bridge/js_frontend/engine/jsi/js_value.h" #include "core/components_ng/base/frame_node.h" #include "core/components_ng/base/view_stack_processor.h" +#include "core/interfaces/native/ani/ani_theme.h" namespace OHOS::Ace::Framework { class JSThemeUtils { diff --git a/frameworks/core/interfaces/ani/ani_api.h b/frameworks/core/interfaces/ani/ani_api.h index 95451a9ddfe..19bed8086fc 100644 --- a/frameworks/core/interfaces/ani/ani_api.h +++ b/frameworks/core/interfaces/ani/ani_api.h @@ -289,9 +289,14 @@ struct ArkUIAniCommonModifier { ArkUI_Uint32 (*getColorValueByString)(const std::string& src); ArkUI_Uint32 (*getColorValueByNumber)(ArkUI_Uint32 src); void (*sendThemeToNative)(ani_env* env, ani_array colors, ani_int id); + void (*removeThemeInNative)(ani_env* env, ani_int withThemeId); void (*setDefaultTheme)(ani_env* env, ani_array colors, ani_boolean isDark); void (*updateColorMode)(ani_int colorMode); void (*restoreColorMode)(); + void (*setThemeScopeId)(ani_env* env, ani_int themeScopeId); + void (*createAndBindTheme)(ani_env* env, ani_int themeScopeId, ani_int themeId, ani_array colors, ani_int colorMode, + ani_fn_object onThemeScopeDestroy); + void (*applyParentThemeScopeId)(ani_env* env, ani_long self, ani_long parent); }; struct ArkUIAniCustomNodeModifier { ani_long (*constructCustomNode)(ani_int, std::function&& onPageShow, std::function&& onPageHide, diff --git a/frameworks/core/interfaces/native/ani/ani_theme.cpp b/frameworks/core/interfaces/native/ani/ani_theme.cpp index 51bb02e97b9..c999b188108 100644 --- a/frameworks/core/interfaces/native/ani/ani_theme.cpp +++ b/frameworks/core/interfaces/native/ani/ani_theme.cpp @@ -18,6 +18,8 @@ #include #include "ani.h" +#include "ui/base/referenced.h" +#include "ui/resource/resource_object.h" #include "base/log/log_wrapper.h" #include "bridge/arkts_frontend/arkts_ani_utils.h" @@ -34,7 +36,11 @@ void AniThemeColors::SetColors(ani_env* env, ani_array colors) // type ResourceColor = number | string | Resource ani_ref value; env->Array_Get_Ref((ani_array_ref)colors, i, &value); - colors_.push_back((ani_object)value); + LOGI("FZY AniThemeColors::SetColors %{public}s", ArktsAniUtils::JsonStringify(env, (ani_object)value).c_str()); + + ani_ref globalRef; + env->GlobalReference_Create(value, &globalRef); + colors_.push_back((ani_object)globalRef); } env->GetVM(&vm_); } @@ -51,7 +57,22 @@ Color AniThemeColors::ConvertAniValueToColor(ani_object aniValue) const return Color(); } Color color; - ResourceAniModifier::ParseAniColor(env, aniValue, color); + RefPtr resObj; + ResourceAniModifier::ParseAniColor(env, aniValue, color, resObj); + LOGI("FZY AniThemeColors::ConvertAniValueToColor %{public}s, color: %{public}s", + ArktsAniUtils::JsonStringify(env, aniValue).c_str(), color.ToString().c_str()); return color; } + +AniThemeColors::~AniThemeColors() +{ + LOGI("FZY ~AniThemeColors id: %{public}d", id_); + auto* env = ArktsAniUtils::GetAniEnv(vm_); + if (!env) { + return; + } + for (auto& color : colors_) { + env->GlobalReference_Delete(static_cast(color)); + } +} } // namespace OHOS::Ace::NG diff --git a/frameworks/core/interfaces/native/ani/ani_theme.h b/frameworks/core/interfaces/native/ani/ani_theme.h index 0c36888a90c..8614a1e866e 100644 --- a/frameworks/core/interfaces/native/ani/ani_theme.h +++ b/frameworks/core/interfaces/native/ani/ani_theme.h @@ -21,7 +21,9 @@ #include #include +#include "ui/base/referenced.h" #include "ui/properties/color.h" +#include "base/log/log.h" #define COLORS_NUMBER (51) @@ -90,10 +92,12 @@ typedef struct __ani_env ani_env; typedef struct __ani_vm ani_vm; namespace OHOS::Ace::NG { -class AniThemeColors { +class AniThemeColors : public Referenced { public: + int32_t id_ = -1; + AniThemeColors() = default; - virtual ~AniThemeColors() = default; + virtual ~AniThemeColors(); void SetColors(ani_env* env, ani_array colors); @@ -116,6 +120,7 @@ public: Color FontPrimary() const { + LOGI("FZY AniThemeColors FontPrimary, %{public}d", id_); return ConvertAniValueToColor(colors_[FONT_PRIMARY]); } Color FontSecondary() const @@ -321,26 +326,53 @@ public: AniTheme() = default; virtual ~AniTheme() = default; - void SetColors(const AniThemeColors& colors) + void SetColors(const RefPtr& colors) { colors_ = colors; } - const AniThemeColors& Colors() const + const RefPtr& Colors() const { return colors_; } + int32_t id_ = -1; + private: - AniThemeColors colors_; + RefPtr colors_; }; class AniThemeScope { public: - static std::map aniThemes; // keeps the current theme in static optional object inline static std::optional aniCurrentTheme = std::nullopt; inline static bool isCurrentThemeDefault = true; + + static const AniTheme& GetAniTheme(int32_t themeScopeId) + { + return aniThemes[themeScopeId]; + } + + static void AddAniTheme(int32_t themeScopeId, const AniTheme& aniTheme) + { + LOGI("FZY AddAniTheme %{public}d", themeScopeId); + aniThemes[themeScopeId] = aniTheme; + } + + static void RemoveAniTheme(int32_t themeScopeId) + { + LOGI("FZY RemoveAniTheme %{public}d", themeScopeId); + aniThemes.erase(themeScopeId); + } + + static bool IsAniThemeExists(int32_t themeScopeId) + { + LOGI("FZY IsAniThemeExists %{public}d", themeScopeId); + auto iter = aniThemes.find(themeScopeId); + return iter != aniThemes.end(); + } +private: + static std::map aniThemes; }; } // namespace OHOS::Ace::NG #endif // FRAMEWORKS_CORE_INTERFACES_NATIVE_ANI_ANI_THEME_H \ No newline at end of file diff --git a/frameworks/core/interfaces/native/ani/ani_theme_module.cpp b/frameworks/core/interfaces/native/ani/ani_theme_module.cpp index 9891e4716d4..cb3a6e3a540 100644 --- a/frameworks/core/interfaces/native/ani/ani_theme_module.cpp +++ b/frameworks/core/interfaces/native/ani/ani_theme_module.cpp @@ -15,17 +15,27 @@ #include "core/interfaces/native/ani/ani_theme_module.h" +#include "ani.h" + +#include "base/log/log_wrapper.h" +#include "bridge/arkts_frontend/arkts_ani_utils.h" #include "core/common/resource/resource_manager.h" +#include "core/components_ng/syntax/with_theme_node.h" +#include "core/components_ng/token_theme/token_theme_storage.h" +#include "core/interfaces/native/ani/resource_ani_modifier.h" +#include "core/interfaces/native/node/theme_modifier.h" #include "core/pipeline_ng/pipeline_context.h" namespace OHOS::Ace::NG { void AniThemeModule::UpdateColorMode(int32_t colorMode) { ColorMode colorModeValue = MapAniColorModeToColorMode(colorMode); + LOGI("FZY AniThemeModule::UpdateColorMode %{public}d", static_cast(colorModeValue)); if (colorModeValue != ColorMode::COLOR_MODE_UNDEFINED) { #if defined(ANDROID_PLATFORM) || defined(IOS_PLATFORM) UpdateColorModeForThemeConstants(colorModeValue); #else + LOGI("FZY AniThemeModule::UpdateColorMode resMgr UpdateColorMode"); ResourceManager::GetInstance().UpdateColorMode(colorModeValue); #endif auto pipelineContext = NG::PipelineContext::GetCurrentContext(); @@ -43,6 +53,7 @@ void AniThemeModule::RestoreColorMode() #if defined(ANDROID_PLATFORM) || defined(IOS_PLATFORM) UpdateColorModeForThemeConstants(colorModeValue); #else + LOGI("FZY AniThemeModule::RestoreColorMode resMgr UpdateColorMode "); ResourceManager::GetInstance().UpdateColorMode(colorModeValue); #endif } @@ -75,4 +86,39 @@ ColorMode AniThemeModule::MapAniColorModeToColorMode(int32_t aniColorMode) } return ColorMode::COLOR_MODE_UNDEFINED; } + +bool AniThemeModule::HandleThemeColorsArg( + ani_env* env, ani_array colorsArg, std::vector& colors, std::vector>& resObjs) +{ + auto basisTheme = TokenThemeStorage::GetInstance()->GetDefaultTheme(); + if (!basisTheme) { + basisTheme = TokenThemeStorage::GetInstance()->ObtainSystemTheme(); + } + if (!basisTheme) { + return false; + } + for (size_t i = 0; i < TokenColors::TOTAL_NUMBER; i++) { + Color color; + ani_ref colorParams; + RefPtr resObj; + auto status = env->Array_Get(colorsArg, i, &colorParams); + if (status != ANI_OK) { + LOGW("HandleThemeColorsArg colorsArg get index: %{public}d failed", i); + continue; + } + if (!ResourceAniModifier::ParseAniColor(env, static_cast(colorParams), color, resObj)) { + color = basisTheme->Colors()->GetByIndex(i); + } + resObjs.push_back(resObj); + colors.push_back(static_cast(color.GetValue())); + } + return true; +} + +ArkUINodeHandle AniThemeModule::CreateWithThemeNode(int32_t themeScopeId) +{ + auto themeModifier = NodeModifier::GetThemeModifier(); + auto node = themeModifier->createWithThemeNode(themeScopeId); + return node; +} } // namespace OHOS::Ace::NG diff --git a/frameworks/core/interfaces/native/ani/ani_theme_module.h b/frameworks/core/interfaces/native/ani/ani_theme_module.h index 3b4bbe5c751..2828e26655a 100644 --- a/frameworks/core/interfaces/native/ani/ani_theme_module.h +++ b/frameworks/core/interfaces/native/ani/ani_theme_module.h @@ -22,12 +22,20 @@ #include "ui/properties/color.h" #include "base/utils/device_config.h" +#include "core/interfaces/ani/ani_api.h" +#include "ui/resource/resource_object.h" + +typedef struct __ani_env ani_env; +typedef class __ani_array* ani_array; namespace OHOS::Ace::NG { class AniThemeModule final { public: static void UpdateColorMode(int32_t colorMode); static void RestoreColorMode(); + static bool HandleThemeColorsArg( + ani_env* env, ani_array colorsArg, std::vector& colors, std::vector>& resObjs); + static ArkUINodeHandle CreateWithThemeNode(int32_t nodeId); private: static ColorMode MapAniColorModeToColorMode(int32_t aniColorMode); diff --git a/frameworks/core/interfaces/native/ani/common_ani_modifier.cpp b/frameworks/core/interfaces/native/ani/common_ani_modifier.cpp index e17991a32f3..679a1907060 100644 --- a/frameworks/core/interfaces/native/ani/common_ani_modifier.cpp +++ b/frameworks/core/interfaces/native/ani/common_ani_modifier.cpp @@ -14,6 +14,7 @@ */ #include "common_ani_modifier.h" #include "ani_utils.h" +#include "ui/base/referenced.h" #include "base/log/log.h" #include "base/memory/ace_type.h" #include "core/common/container.h" @@ -35,6 +36,8 @@ #include "bridge/arkts_frontend/arkts_frontend.h" #include "bridge/arkts_frontend/ani_context_module.h" #include "core/components/container_modal/container_modal_constants.h" +#include "core/components_ng/token_theme/token_colors.h" +#include "bridge/arkts_frontend/arkts_ani_utils.h" #include #include @@ -437,18 +440,31 @@ ArkUI_Uint32 GetColorValueByNumber(ArkUI_Uint32 src) void SendThemeToNative(ani_env* env, ani_array colorArray, ani_int id) { - auto colors = AniThemeColors(); - colors.SetColors(env, colorArray); - + auto colors = AceType::MakeRefPtr(); + colors->SetColors(env, colorArray); + colors->id_ = id; + auto res = ArktsAniUtils::JsonStringify(env, (ani_object)colorArray); auto themeScopeId = static_cast(id); - AniThemeScope::aniThemes[themeScopeId].SetColors(colors); + + AniTheme aniTheme; + aniTheme.SetColors(colors); + aniTheme.id_ = themeScopeId; + AniThemeScope::AddAniTheme(themeScopeId, aniTheme); + // save the current theme when Theme was created by WithTheme container if (AniThemeScope::isCurrentThemeDefault || themeScopeId > 0) { - std::optional themeOpt = std::make_optional(AniThemeScope::aniThemes[themeScopeId]); + LOGI("FZY SendThemeToNative set currentTheme %{public}d", id); + std::optional themeOpt = std::make_optional(AniThemeScope::GetAniTheme(themeScopeId)); AniThemeScope::aniCurrentTheme.swap(themeOpt); } } +void RemoveThemeInNative(ani_env* env, ani_int withThemeId) +{ + auto themeScopeId = static_cast(withThemeId); + AniThemeScope::RemoveAniTheme(themeScopeId); +} + void SetDefaultTheme(ani_env* env, ani_array colorArray, ani_boolean isDark) { auto isDarkValue = static_cast(isDark); @@ -468,8 +484,9 @@ void SetDefaultTheme(ani_env* env, ani_array colorArray, ani_boolean isDark) continue; } Color color; + RefPtr resObj; bool isColorAvailable = false; - if (!ResourceAniModifier::ParseAniColor(env, static_cast(value), color)) { + if (!ResourceAniModifier::ParseAniColor(env, static_cast(value), color, resObj)) { if (basisTheme) { color = basisTheme->Colors()->GetByIndex(i); isColorAvailable = true; @@ -493,6 +510,78 @@ void RestoreColorMode() AniThemeModule::RestoreColorMode(); } +void SetThemeScopeId(ani_env* env, ani_int themeScopeId) +{ + auto scopeId = static_cast(themeScopeId); + AniThemeScope::isCurrentThemeDefault = scopeId == 0; + + std::optional themeOpt = AniThemeScope::IsAniThemeExists(scopeId) + ? std::make_optional(AniThemeScope::GetAniTheme(scopeId)) + : std::nullopt; + + LOGI("FZY SetThemeScopeId swap currentTHeme %{public}d", themeScopeId); + AniThemeScope::aniCurrentTheme.swap(themeOpt); +} + +void CreateAndBindTheme(ani_env* env, ani_int themeScopeId, ani_int themeId, ani_array colorsArg, ani_int colorMode, + ani_fn_object onThemeScopeDestroy) +{ + int32_t themeScopeIdValue = static_cast(themeScopeId); + int32_t themeIdValue = static_cast(themeId); + int32_t colorModeValue = static_cast(colorMode); + + if (!colorsArg) { + return; + } + + std::vector colors; + std::vector> resObjs; + if (!AniThemeModule::HandleThemeColorsArg(env, colorsArg, colors, resObjs)) { + return; + } + + if (!onThemeScopeDestroy) { + return; + } + auto containerId = Container::CurrentId(); + ani_vm* vm = nullptr; + env->GetVM(&vm); + std::function onThemeScopeDestroyFunc = [vm, func = onThemeScopeDestroy, containerId]() { + ContainerScope scope(containerId); + auto* env = ArktsAniUtils::GetAniEnv(vm); + if (env) { + ani_ref result; + env->FunctionalObject_Call(func, 0, nullptr, &result); + } + }; + + auto themeModifier = NodeModifier::GetThemeModifier(); + auto theme = themeModifier->createTheme(themeId, colors.data(), colorModeValue, static_cast(&resObjs)); + CHECK_NULL_VOID(theme); + ArkUINodeHandle node = themeModifier->getWithThemeNode(themeScopeId); + if (!node) { + node = AniThemeModule::CreateWithThemeNode(themeScopeId); + } + themeModifier->createThemeScope(node, theme); + themeModifier->setOnThemeScopeDestroy(node, reinterpret_cast(&onThemeScopeDestroyFunc)); +} + +void ApplyParentThemeScopeId(ani_env* env, ani_long self, ani_long parent) +{ + auto* selfPtr = reinterpret_cast(self); + auto* parentPtr = reinterpret_cast(parent); + if (!selfPtr || !parentPtr) { + return; + } + int32_t elementThemeScopeId = selfPtr->GetThemeScopeId(); + if (parentPtr && elementThemeScopeId == 0) { + int32_t themeScopeId = parentPtr->GetThemeScopeId(); + if (elementThemeScopeId != themeScopeId) { + selfPtr->SetThemeScopeId(themeScopeId); + } + } +} + const ArkUIAniCommonModifier* GetCommonAniModifier() { static const ArkUIAniCommonModifier impl = { @@ -523,9 +612,13 @@ const ArkUIAniCommonModifier* GetCommonAniModifier() .px2lpx = OHOS::Ace::NG::Px2lpx, .getColorValueByNumber = OHOS::Ace::NG::GetColorValueByNumber, .sendThemeToNative = OHOS::Ace::NG::SendThemeToNative, + .removeThemeInNative = OHOS::Ace::NG::RemoveThemeInNative, .setDefaultTheme = OHOS::Ace::NG::SetDefaultTheme, .updateColorMode = OHOS::Ace::NG::UpdateColorMode, - .restoreColorMode = OHOS::Ace::NG::RestoreColorMode }; + .restoreColorMode = OHOS::Ace::NG::RestoreColorMode, + .setThemeScopeId = OHOS::Ace::NG::SetThemeScopeId, + .createAndBindTheme = OHOS::Ace::NG::CreateAndBindTheme, + .applyParentThemeScopeId = OHOS::Ace::NG::ApplyParentThemeScopeId }; return &impl; } diff --git a/frameworks/core/interfaces/native/ani/resource_ani_modifier.cpp b/frameworks/core/interfaces/native/ani/resource_ani_modifier.cpp index 870bfb4f899..e8f090ea2cf 100644 --- a/frameworks/core/interfaces/native/ani/resource_ani_modifier.cpp +++ b/frameworks/core/interfaces/native/ani/resource_ani_modifier.cpp @@ -39,7 +39,7 @@ uint32_t ColorAlphaAdapt(uint32_t origin) return result; } } // namespace -bool ResourceAniModifier::ParseAniColor(ani_env* env, ani_object aniValue, Color& color) +bool ResourceAniModifier::ParseAniColor(ani_env* env, ani_object aniValue, Color& color, RefPtr& resObj) { ani_status status; ani_class stringClass; @@ -91,11 +91,14 @@ bool ResourceAniModifier::ParseAniColor(ani_env* env, ani_object aniValue, Color if (isResource) { ani_double resId; env->Object_GetPropertyByName_Double(aniValue, "id", &resId); + ani_double resType; + env->Object_GetPropertyByName_Double(aniValue, "type", &resType); ani_ref bundleName; env->Object_GetPropertyByName_Ref(aniValue, "bundleName", &bundleName); ani_ref moduleName; env->Object_GetPropertyByName_Ref(aniValue, "moduleName", &moduleName); - auto resObj = AceType::MakeRefPtr( + std::vector params; + resObj = AceType::MakeRefPtr(resId, resType, params, ArktsAniUtils::ANIStringToStdString(env, static_cast(bundleName)), ArktsAniUtils::ANIStringToStdString(env, static_cast(moduleName)), Container::CurrentIdSafely()); diff --git a/frameworks/core/interfaces/native/ani/resource_ani_modifier.h b/frameworks/core/interfaces/native/ani/resource_ani_modifier.h index 5343e9ae8c7..efc818144be 100644 --- a/frameworks/core/interfaces/native/ani/resource_ani_modifier.h +++ b/frameworks/core/interfaces/native/ani/resource_ani_modifier.h @@ -16,7 +16,9 @@ #ifndef FRAMEWORKS_CORE_INTERFACES_NATIVE_ANI_RESOURCE_ANI_MODIFIER_H #define FRAMEWORKS_CORE_INTERFACES_NATIVE_ANI_RESOURCE_ANI_MODIFIER_H +#include "ui/base/referenced.h" #include "ui/properties/color.h" +#include "ui/resource/resource_object.h" typedef struct __ani_env ani_env; typedef class __ani_object* ani_object; @@ -24,7 +26,7 @@ typedef class __ani_object* ani_object; namespace OHOS::Ace::NG { class ResourceAniModifier final { public: - static bool ParseAniColor(ani_env* env, ani_object aniValue, Color& color); + static bool ParseAniColor(ani_env* env, ani_object aniValue, Color& color, RefPtr& resObj); }; } // namespace OHOS::Ace::NG diff --git a/frameworks/core/interfaces/native/generated/interface/arkoala_api_generated.h b/frameworks/core/interfaces/native/generated/interface/arkoala_api_generated.h index 54301c7e0ba..ac9b9baf06d 100644 --- a/frameworks/core/interfaces/native/generated/interface/arkoala_api_generated.h +++ b/frameworks/core/interfaces/native/generated/interface/arkoala_api_generated.h @@ -3275,6 +3275,8 @@ typedef struct Ark_Union_DotIndicator_DigitIndicator_Boolean Ark_Union_DotIndica typedef struct Opt_Union_DotIndicator_DigitIndicator_Boolean Opt_Union_DotIndicator_DigitIndicator_Boolean; typedef struct Ark_Union_LinearStyleOptions_RingStyleOptions_CapsuleStyleOptions_ProgressStyleOptions Ark_Union_LinearStyleOptions_RingStyleOptions_CapsuleStyleOptions_ProgressStyleOptions; typedef struct Opt_Union_LinearStyleOptions_RingStyleOptions_CapsuleStyleOptions_ProgressStyleOptions Opt_Union_LinearStyleOptions_RingStyleOptions_CapsuleStyleOptions_ProgressStyleOptions; +typedef struct Ark_WithThemeOptions Ark_WithThemeOptions; +typedef struct Opt_WithThemeOptions Opt_WithThemeOptions; typedef struct Ark_Union_String_ImageAttachment_CustomSpan Ark_Union_String_ImageAttachment_CustomSpan; typedef struct Opt_Union_String_ImageAttachment_CustomSpan Opt_Union_String_ImageAttachment_CustomSpan; typedef struct Ark_AttachmentType Ark_AttachmentType; @@ -24160,6 +24162,13 @@ typedef struct GENERATED_ArkUIWindowSceneModifier { const Opt_Number* fraction); } GENERATED_ArkUIWindowSceneModifier; +typedef struct GENERATED_ArkUIWithThemeModifier { + Ark_NativePointer (*construct)(Ark_Int32 id, + Ark_Int32 flags); + void (*setWithThemeOptions)(Ark_NativePointer node, + const Ark_WithThemeOptions* options); +} GENERATED_ArkUIWithThemeModifier; + typedef struct GENERATED_ArkUIXComponentModifier { Ark_NativePointer (*construct)(Ark_Int32 id, Ark_Int32 flags); @@ -28378,6 +28387,7 @@ typedef struct GENERATED_ArkUINodeModifiers { const GENERATED_ArkUIVideoModifier* (*getVideoModifier)(); const GENERATED_ArkUIWebModifier* (*getWebModifier)(); const GENERATED_ArkUIWindowSceneModifier* (*getWindowSceneModifier)(); + const GENERATED_ArkUIWithThemeModifier* (*getWithThemeModifier)(); const GENERATED_ArkUIXComponentModifier* (*getXComponentModifier)(); const GENERATED_ArkUISideBarContainerModifier* (*getSideBarContainerModifier)(); const GENERATED_ArkUIRemoteWindowModifier* (*getRemoteWindowModifier)(); diff --git a/frameworks/core/interfaces/native/generated/interface/node_interface.gni b/frameworks/core/interfaces/native/generated/interface/node_interface.gni index 6ed451b38df..ea03e3614fe 100644 --- a/frameworks/core/interfaces/native/generated/interface/node_interface.gni +++ b/frameworks/core/interfaces/native/generated/interface/node_interface.gni @@ -378,6 +378,6 @@ generated_sources = [ "implementation/worker_event_listener_accessor.cpp", "implementation/x_component_controller_accessor.cpp", "implementation/x_component_modifier.cpp", - + "implementation/with_theme_modifier.cpp", "utility/converter.cpp", ] diff --git a/frameworks/core/interfaces/native/implementation/all_modifiers.cpp b/frameworks/core/interfaces/native/implementation/all_modifiers.cpp index c211694c0c0..7a426156040 100644 --- a/frameworks/core/interfaces/native/implementation/all_modifiers.cpp +++ b/frameworks/core/interfaces/native/implementation/all_modifiers.cpp @@ -198,6 +198,7 @@ const GENERATED_ArkUIToggleModifier* GetToggleModifier(); const GENERATED_ArkUIVideoModifier* GetVideoModifier(); const GENERATED_ArkUIWebModifier* GetWebModifier(); const GENERATED_ArkUIWindowSceneModifier* GetWindowSceneModifier(); +const GENERATED_ArkUIWithThemeModifier* GetWithThemeModifier(); const GENERATED_ArkUIXComponentModifier* GetXComponentModifier(); const GENERATED_ArkUISideBarContainerModifier* GetSideBarContainerModifier(); const GENERATED_ArkUIRemoteWindowModifier* GetRemoteWindowModifier(); @@ -560,6 +561,7 @@ const GENERATED_ArkUINodeModifiers* GENERATED_GetArkUINodeModifiers() GetVideoModifier, GetWebModifier, GetWindowSceneModifier, + GetWithThemeModifier, GetXComponentModifier, GetSideBarContainerModifier, GetRemoteWindowModifier, diff --git a/frameworks/core/interfaces/native/implementation/button_modifier.cpp b/frameworks/core/interfaces/native/implementation/button_modifier.cpp index 0b3c6b5fc4f..c548f81e1ad 100644 --- a/frameworks/core/interfaces/native/implementation/button_modifier.cpp +++ b/frameworks/core/interfaces/native/implementation/button_modifier.cpp @@ -21,6 +21,7 @@ #include "arkoala_api_generated.h" #include "core/interfaces/native/utility/converter.h" #include "core/interfaces/native/utility/validators.h" +#include "core/interfaces/native/implementation/theme/ani_button_theme.h" namespace OHOS::Ace::NG { struct ButtonOptions { @@ -127,6 +128,7 @@ void SetButtonOptions1Impl(Ark_NativePointer node, } else { ButtonModelStatic::SetButtonStyle(frameNode, std::nullopt); } + AniButtonTheme::ApplyTheme(ButtonRole::NORMAL, ButtonStyleMode::EMPHASIZE, true); } void SetButtonOptions2Impl(Ark_NativePointer node, const Ark_ResourceStr* label, @@ -142,6 +144,7 @@ void SetButtonOptions2Impl(Ark_NativePointer node, } auto labelString = Converter::OptConvert(*label); ButtonModelStatic::SetLabel(frameNode, labelString.value_or("").c_str()); + AniButtonTheme::ApplyTheme(ButtonRole::NORMAL, ButtonStyleMode::EMPHASIZE, true); } } // ButtonInterfaceModifier namespace ButtonAttributeModifier { diff --git a/frameworks/core/interfaces/native/implementation/theme/ani_button_theme.h b/frameworks/core/interfaces/native/implementation/theme/ani_button_theme.h new file mode 100644 index 00000000000..746a8a8e060 --- /dev/null +++ b/frameworks/core/interfaces/native/implementation/theme/ani_button_theme.h @@ -0,0 +1,103 @@ +/* + * Copyright (c) 2024 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef FRAMEWORKS_BRIDGE_DECLARATIVE_FRONTEND_THEME_JS_BUTTON_THEME_H +#define FRAMEWORKS_BRIDGE_DECLARATIVE_FRONTEND_THEME_JS_BUTTON_THEME_H + +#include "core/components_ng/base/view_stack_model.h" +#include "core/components_ng/pattern/button/button_model.h" +#include "core/interfaces/native/ani/ani_theme.h" +#include "core/interfaces/native/implementation/theme/ani_theme_utils.h" + +namespace OHOS::Ace::NG { +class AniButtonTheme { +public: + static bool ApplyTheme(const ButtonRole& role, const ButtonStyleMode& styleMode, bool isLabelButton) + { + AniButtonTheme::buttonRole = role; + AniButtonTheme::buttonStyleMode = styleMode; + return AniButtonTheme::ApplyTheme(isLabelButton); + } + static bool ApplyTheme(const ButtonRole& role, bool isLabelButton) + { + AniButtonTheme::buttonRole = role; + return AniButtonTheme::ApplyTheme(isLabelButton); + } + static bool ApplyTheme(const ButtonStyleMode& styleMode, bool isLabelButton) + { + AniButtonTheme::buttonStyleMode = styleMode; + return AniButtonTheme::ApplyTheme(isLabelButton); + } +private: + // last button role value + inline static ButtonRole buttonRole = ButtonRole::NORMAL; + // last button style mode value + inline static ButtonStyleMode buttonStyleMode = ButtonStyleMode::EMPHASIZE; + + static bool ApplyTheme(bool isLabelButton) + { + auto themeColors = AniThemeUtils::GetThemeColors(); + if (!themeColors) { + // no need to apply custom theme colors + return false; + } + + // normal + ViewStackModel::GetInstance()->SetVisualState(VisualState::NORMAL); + if (isLabelButton) { + LOGI("FZY ButtonTheme ApplyTheme FontColor %{public}s", + AniButtonTheme::FontColor(themeColors).ToString().c_str()); + ButtonModel::GetInstance()->SetFontColor(AniButtonTheme::FontColor(themeColors)); + } + ButtonModel::GetInstance()->BackgroundColor(AniButtonTheme::BackgroundColor(themeColors, false), true); + + // clear state + ViewStackModel::GetInstance()->ClearVisualState(); + return true; + } + + static Color FontColor(const RefPtr& themeColors) + { + switch (AniButtonTheme::buttonStyleMode) { + case ButtonStyleMode::NORMAL: + case ButtonStyleMode::TEXT: + if (AniButtonTheme::buttonRole == ButtonRole::ERROR) { + return themeColors->FontPrimary(); + } + return themeColors->FontPrimary(); + case ButtonStyleMode::EMPHASIZE: + default: + return themeColors->FontPrimary(); + } + } + + static Color BackgroundColor(const RefPtr& themeColors, bool isPressed) + { + switch (AniButtonTheme::buttonStyleMode) { + case ButtonStyleMode::TEXT: + return Color::TRANSPARENT; + case ButtonStyleMode::NORMAL: + return themeColors->CompBackgroundTertiary(); + case ButtonStyleMode::EMPHASIZE: + default: + if (AniButtonTheme::buttonRole == ButtonRole::ERROR) { + return themeColors->Warning(); + } + return themeColors->BackgroundEmphasize(); + } + } +}; +} // namespace OHOS::Ace::Framework +#endif // FRAMEWORKS_BRIDGE_DECLARATIVE_FRONTEND_THEME_JS_BUTTON_THEME_H diff --git a/frameworks/core/interfaces/native/implementation/theme/ani_theme_utils.h b/frameworks/core/interfaces/native/implementation/theme/ani_theme_utils.h new file mode 100644 index 00000000000..28e1b26442e --- /dev/null +++ b/frameworks/core/interfaces/native/implementation/theme/ani_theme_utils.h @@ -0,0 +1,45 @@ +/* + * Copyright (c) 2024 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef FRAMEWORKS_CORE_INTERFACES_NATIVE_IMPLEMENTATION_ANI_THEME_UTILS_H +#define FRAMEWORKS_CORE_INTERFACES_NATIVE_IMPLEMENTATION_ANI_THEME_UTILS_H + +#include +#include + +#include "bridge/arkts_frontend/arkts_ani_utils.h" +#include "core/interfaces/native/ani/ani_theme.h" + +namespace OHOS::Ace::NG { +class AniThemeUtils { +public: + static constexpr int32_t DEFAULT_ALPHA = 255; + static constexpr double DEFAULT_OPACITY = 0.2; + + static std::optional GetTheme() + { + return NG::AniThemeScope::aniCurrentTheme; + } + + static RefPtr GetThemeColors() + { + if (NG::AniThemeScope::aniCurrentTheme) { + LOGI("FZY AniThemeUtils GetThemeColors %{public}d", NG::AniThemeScope::aniCurrentTheme.value().id_); + } + return (NG::AniThemeScope::aniCurrentTheme) ? NG::AniThemeScope::aniCurrentTheme->Colors() : nullptr; + } +}; +} +#endif //FRAMEWORKS_CORE_INTERFACES_NATIVE_IMPLEMENTATION_ANI_THEME_UTILS_H \ No newline at end of file diff --git a/frameworks/core/interfaces/native/implementation/with_theme_modifier.cpp b/frameworks/core/interfaces/native/implementation/with_theme_modifier.cpp new file mode 100644 index 00000000000..c9472504f31 --- /dev/null +++ b/frameworks/core/interfaces/native/implementation/with_theme_modifier.cpp @@ -0,0 +1,53 @@ +/* + * Copyright (c) 2024-2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "arkoala_api_generated.h" + +#include "core/components_ng/base/frame_node.h" +#include "core/components_ng/syntax/with_theme_node.h" +#include "core/interfaces/native/utility/converter.h" + +namespace OHOS::Ace::NG::GeneratedModifier { +namespace WithThemeModifier { +Ark_NativePointer ConstructImpl(Ark_Int32 id, + Ark_Int32 flags) +{ + auto frameNode = WithThemeNode::GetOrCreateWithThemeNode(id); + CHECK_NULL_RETURN(frameNode, nullptr); + frameNode->IncRefCount(); + return AceType::RawPtr(frameNode); +} +} // WithThemeModifier +namespace WithThemeInterfaceModifier { +void SetWithThemeOptionsImpl(Ark_NativePointer node, + const Ark_WithThemeOptions* options) +{ + auto frameNode = reinterpret_cast(node); + CHECK_NULL_VOID(frameNode); + CHECK_NULL_VOID(options); + //auto convValue = Converter::OptConvert(*options); + //WithThemeModelNG::SetSetWithThemeOptions(frameNode, convValue); +} +} // WithThemeInterfaceModifier +const GENERATED_ArkUIWithThemeModifier* GetWithThemeModifier() +{ + static const GENERATED_ArkUIWithThemeModifier ArkUIWithThemeModifierImpl { + WithThemeModifier::ConstructImpl, + WithThemeInterfaceModifier::SetWithThemeOptionsImpl, + }; + return &ArkUIWithThemeModifierImpl; +} + +} -- Gitee From 7fda46ba8cecb5d9c55acc35862357fac70fb4af Mon Sep 17 00:00:00 2001 From: fangzhiyuan Date: Sun, 20 Jul 2025 16:05:28 +0800 Subject: [PATCH 03/11] =?UTF-8?q?=E9=80=82=E9=85=8DCustomColors=20interfac?= =?UTF-8?q?e=E6=8E=A5=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: fangzhiyuan Change-Id: I6ae2ae1df2c1bca7565a7c250be8cb7a114e78f6 --- .../arkui-ohos/@ohos.arkui.theme.ts | 347 +++--------------- .../src/handwritten/theme/ArkColorsImpl.ts | 344 +++++++++++++++++ .../src/handwritten/theme/ArkThemeBase.ts | 33 +- .../src/handwritten/theme/ArkThemeImpl.ts | 22 +- .../handwritten/theme/ArkThemeNativeHelper.ts | 155 ++++---- .../handwritten/theme/ArkThemeScopeManager.ts | 10 +- .../arkui-ohos/src/handwritten/theme/index.ts | 10 + .../theme/system/ArkSystemColors.ts | 140 +++++++ .../theme/system/ArkSystemTheme.ts | 4 +- .../arkoala-arkts/components.gni | 4 + 10 files changed, 684 insertions(+), 385 deletions(-) create mode 100644 frameworks/bridge/arkts_frontend/koala_projects/arkoala-arkts/arkui-ohos/src/handwritten/theme/ArkColorsImpl.ts create mode 100644 frameworks/bridge/arkts_frontend/koala_projects/arkoala-arkts/arkui-ohos/src/handwritten/theme/system/ArkSystemColors.ts diff --git a/frameworks/bridge/arkts_frontend/koala_projects/arkoala-arkts/arkui-ohos/@ohos.arkui.theme.ts b/frameworks/bridge/arkts_frontend/koala_projects/arkoala-arkts/arkui-ohos/@ohos.arkui.theme.ts index 6d0ac4bc9ec..481427cb694 100644 --- a/frameworks/bridge/arkts_frontend/koala_projects/arkoala-arkts/arkui-ohos/@ohos.arkui.theme.ts +++ b/frameworks/bridge/arkts_frontend/koala_projects/arkoala-arkts/arkui-ohos/@ohos.arkui.theme.ts @@ -22,305 +22,68 @@ import { Shapes, Typography, CustomTypography, CustomShapes, BrandColors, ArkThe import { Resource } from 'global.resource'; import { ArkUIAniModule } from 'arkui.ani'; -export class Colors { - brand: ResourceColor = ArkResourcesHelper.$r('sys.color.brand', 125830976); - warning: ResourceColor = ArkResourcesHelper.$r('sys.color.warning', 125830979); - alert: ResourceColor = ArkResourcesHelper.$r('sys.color.alert', 125830980); - confirm: ResourceColor = ArkResourcesHelper.$r('sys.color.confirm', 125830981); - - fontPrimary: ResourceColor = ArkResourcesHelper.$r('sys.color.font_primary', 125830982); - fontSecondary: ResourceColor = ArkResourcesHelper.$r('sys.color.font_secondary', 125830983); - fontTertiary: ResourceColor = ArkResourcesHelper.$r('sys.color.font_tertiary', 125830984); - fontFourth: ResourceColor = ArkResourcesHelper.$r('sys.color.font_fourth', 125830985); - fontEmphasize: ResourceColor = ArkResourcesHelper.$r('sys.color.font_emphasize', 125830986); - - fontOnPrimary: ResourceColor = ArkResourcesHelper.$r('sys.color.font_on_primary', 125830987); - fontOnSecondary: ResourceColor = ArkResourcesHelper.$r('sys.color.font_on_secondary', 125830988); - fontOnTertiary: ResourceColor = ArkResourcesHelper.$r('sys.color.font_on_tertiary', 125830989); - fontOnFourth: ResourceColor = ArkResourcesHelper.$r('sys.color.font_on_fourth', 125830990); - - iconPrimary: ResourceColor = ArkResourcesHelper.$r('sys.color.icon_primary', 125830991); - iconSecondary: ResourceColor = ArkResourcesHelper.$r('sys.color.icon_secondary', 125830992); - iconTertiary: ResourceColor = ArkResourcesHelper.$r('sys.color.icon_tertiary', 125830993); - iconFourth: ResourceColor = ArkResourcesHelper.$r('sys.color.icon_fourth', 125830994); - iconEmphasize: ResourceColor = ArkResourcesHelper.$r('sys.color.icon_emphasize', 125830995); - iconSubEmphasize: ResourceColor = ArkResourcesHelper.$r('sys.color.icon_sub_emphasize', 125830996); - - iconOnPrimary: ResourceColor = ArkResourcesHelper.$r('sys.color.icon_on_primary', 125831057); - iconOnSecondary: ResourceColor = ArkResourcesHelper.$r('sys.color.icon_on_secondary', 125831058); - iconOnTertiary: ResourceColor = ArkResourcesHelper.$r('sys.color.icon_on_tertiary', 125831059); - iconOnFourth: ResourceColor = ArkResourcesHelper.$r('sys.color.icon_on_fourth', 125831060); - - backgroundPrimary: ResourceColor = ArkResourcesHelper.$r('sys.color.background_primary', 125831061); - backgroundSecondary: ResourceColor = ArkResourcesHelper.$r('sys.color.background_secondary', 125831062); - backgroundTertiary: ResourceColor = ArkResourcesHelper.$r('sys.color.background_tertiary', 125831063); - backgroundFourth: ResourceColor = ArkResourcesHelper.$r('sys.color.background_fourth', 125831064); - backgroundEmphasize: ResourceColor = ArkResourcesHelper.$r('sys.color.background_emphasize', 125831065); - - compForegroundPrimary: ResourceColor = ArkResourcesHelper.$r('sys.color.comp_foreground_primary', 125831003); - compBackgroundPrimary: ResourceColor = ArkResourcesHelper.$r('sys.color.comp_background_primary', 125831004); - compBackgroundPrimaryTran: ResourceColor = ArkResourcesHelper.$r('sys.color.comp_background_primary_tran'); - compBackgroundPrimaryContrary: ResourceColor = ArkResourcesHelper.$r( - 'sys.color.comp_background_primary_contrary', - 125831005 - ); - compBackgroundGray: ResourceColor = ArkResourcesHelper.$r('sys.color.comp_background_gray', 125831006); - compBackgroundSecondary: ResourceColor = ArkResourcesHelper.$r('sys.color.comp_background_secondary', 125831007); - compBackgroundTertiary: ResourceColor = ArkResourcesHelper.$r('sys.color.comp_background_tertiary', 125831008); - compBackgroundEmphasize: ResourceColor = ArkResourcesHelper.$r('sys.color.comp_background_emphasize', 125831009); - compBackgroundNeutral: ResourceColor = ArkResourcesHelper.$r('sys.color.neutral', 125831066); - compEmphasizeSecondary: ResourceColor = ArkResourcesHelper.$r('sys.color.comp_emphasize_secondary', 125831011); - compEmphasizeTertiary: ResourceColor = ArkResourcesHelper.$r('sys.color.comp_emphasize_tertiary', 125831012); - compDivider: ResourceColor = ArkResourcesHelper.$r('sys.color.comp_divider', 125831013); - compCommonContrary: ResourceColor = ArkResourcesHelper.$r('sys.color.comp_common_contrary', 125831014); - compBackgroundFocus: ResourceColor = ArkResourcesHelper.$r('sys.color.comp_background_focus', 125831015); - compFocusedPrimary: ResourceColor = ArkResourcesHelper.$r('sys.color.comp_focused_primary', 125831016); - compFocusedSecondary: ResourceColor = ArkResourcesHelper.$r('sys.color.comp_focused_secondary', 125831017); - compFocusedTertiary: ResourceColor = ArkResourcesHelper.$r('sys.color.comp_focused_tertiary', 125831018); - - interactiveHover: ResourceColor = ArkResourcesHelper.$r('sys.color.interactive_hover', 125831019); - interactivePressed: ResourceColor = ArkResourcesHelper.$r('sys.color.interactive_pressed', 125831020); - interactiveFocus: ResourceColor = ArkResourcesHelper.$r('sys.color.interactive_focus', 125831021); - interactiveActive: ResourceColor = ArkResourcesHelper.$r('sys.color.interactive_active', 125831022); - interactiveSelect: ResourceColor = ArkResourcesHelper.$r('sys.color.interactive_select', 125831023); - interactiveClick: ResourceColor = ArkResourcesHelper.$r('sys.color.interactive_click', 125831024); - - constructor() { } - - constructor(colors: CustomColors | undefined, baselineColors: Colors) { - Colors.assign(this, baselineColors); - if (colors) { - Colors.assign(this, colors!); - } - } - - static assign(dst: Colors, src: Colors): void { - dst.brand = src.brand; - dst.warning = src.warning; - dst.alert = src.alert; - dst.confirm = src.confirm; - - dst.fontPrimary = src.fontPrimary; - dst.fontSecondary = src.fontSecondary; - dst.fontTertiary = src.fontTertiary; - dst.fontFourth = src.fontFourth; - dst.fontEmphasize = src.fontEmphasize; - - dst.fontOnPrimary = src.fontOnPrimary; - dst.fontOnSecondary = src.fontOnSecondary; - dst.fontOnTertiary = src.fontOnTertiary; - dst.fontOnFourth = src.fontOnFourth; - - dst.iconPrimary = src.iconPrimary; - dst.iconSecondary = src.iconSecondary; - dst.iconTertiary = src.iconTertiary; - dst.iconFourth = src.iconFourth; - dst.iconEmphasize = src.iconEmphasize; - dst.iconSubEmphasize = src.iconSubEmphasize; - - dst.iconOnPrimary = src.iconOnPrimary; - dst.iconOnSecondary = src.iconOnSecondary; - dst.iconOnTertiary = src.iconOnTertiary; - dst.iconOnFourth = src.iconOnFourth; - - dst.backgroundPrimary = src.backgroundPrimary; - dst.backgroundSecondary = src.backgroundSecondary; - dst.backgroundTertiary = src.backgroundTertiary; - dst.backgroundFourth = src.backgroundFourth; - dst.backgroundEmphasize = src.backgroundEmphasize; - - dst.compForegroundPrimary = src.compForegroundPrimary; - dst.compBackgroundPrimary = src.compBackgroundPrimary; - dst.compBackgroundPrimaryTran = src.compBackgroundPrimaryTran; - dst.compBackgroundPrimaryContrary = src.compBackgroundPrimaryContrary; - dst.compBackgroundGray = src.compBackgroundGray; - dst.compBackgroundSecondary = src.compBackgroundSecondary; - dst.compBackgroundTertiary = src.compBackgroundTertiary; - dst.compBackgroundEmphasize = src.compBackgroundEmphasize; - dst.compBackgroundNeutral = src.compBackgroundNeutral; - dst.compEmphasizeSecondary = src.compEmphasizeSecondary; - dst.compEmphasizeTertiary = src.compEmphasizeTertiary; - dst.compDivider = src.compDivider; - dst.compCommonContrary = src.compCommonContrary; - dst.compBackgroundFocus = src.compBackgroundFocus; - dst.compFocusedPrimary = src.compFocusedPrimary; - dst.compFocusedSecondary = src.compFocusedSecondary; - dst.compFocusedTertiary = src.compFocusedTertiary; - - dst.interactiveHover = src.interactiveHover; - dst.interactivePressed = src.interactivePressed; - dst.interactiveFocus = src.interactiveFocus; - dst.interactiveActive = src.interactiveActive; - dst.interactiveSelect = src.interactiveSelect; - dst.interactiveClick = src.interactiveClick; - } - - static expandByBrandColor(colors: CustomColors) { - if (colors.brand) { - const brandColors: BrandColors = Colors.makeBrandColors(colors.brand); - colors.fontEmphasize = colors.fontEmphasize ?? brandColors.primary!; - - colors.iconEmphasize = colors.iconEmphasize ?? brandColors.primary!; - colors.iconSubEmphasize = colors.iconSubEmphasize ?? brandColors.tertiary!; - - colors.backgroundEmphasize = colors.backgroundEmphasize ?? brandColors.primary!; - - colors.compBackgroundEmphasize = colors.compBackgroundEmphasize ?? brandColors.primary!; - - colors.compEmphasizeSecondary = colors.compEmphasizeSecondary ?? brandColors.fourth!; - colors.compEmphasizeTertiary = colors.compEmphasizeTertiary ?? brandColors.fifth!; - - colors.interactiveFocus = colors.interactiveFocus ?? brandColors.primary!; - colors.interactiveActive = colors.interactiveActive ?? brandColors.primary!; - } - } - - static makeBrandColors(brandColor: ResourceColor | undefined): BrandColors { - const result: BrandColors = { - primary: undefined, - secondary: undefined, - tertiary: undefined, - fourth: undefined, - fifth: undefined, - sixth: undefined, - }; - if (brandColor) { - if (brandColor instanceof Color) { - result.primary = Colors.convertColorEnumToValue(brandColor) as string; - result.secondary = Colors.convertColorEnumToValue(brandColor) as string; - result.tertiary = Colors.convertColorEnumToValue(brandColor) as string; - result.fourth = Colors.convertColorEnumToValue(brandColor) as string; - result.fifth = Colors.convertColorEnumToValue(brandColor) as string; - result.sixth = Colors.convertColorEnumToValue(brandColor) as string; - } else if (brandColor instanceof Resource) { - result.primary = brandColor as Resource; - result.secondary = Colors.makeResourceWithOpacity(brandColor as Resource, 0.6) as Resource; - result.tertiary = Colors.makeResourceWithOpacity(brandColor as Resource, 0.4) as Resource; - result.fourth = Colors.makeResourceWithOpacity(brandColor as Resource, 0.2) as Resource; - result.fifth = Colors.makeResourceWithOpacity(brandColor as Resource, 0.1) as Resource; - result.sixth = Colors.makeResourceWithOpacity(brandColor as Resource, 0.05) as Resource; - } else { - const brandColorValue = brandColor as number | string; - const argbColor = ArkUIAniModule._GetColorValue(brandColorValue); - result.primary = argbColor; - result.secondary = Colors.blendOpacity(argbColor, 0.6); - result.tertiary = Colors.blendOpacity(argbColor, 0.4); - result.fourth = Colors.blendOpacity(argbColor, 0.2); - result.fifth = Colors.blendOpacity(argbColor, 0.1); - result.sixth = Colors.blendOpacity(argbColor, 0.05); - } - } - return result; - } - - static makeResourceWithOpacity(resourceColor: Resource, opacityRatio: number): ArkThemeResource { - return { - id: resourceColor.id, - type: resourceColor.type, - params: [...resourceColor.params!], - bundleName: resourceColor.bundleName, - moduleName: resourceColor.moduleName, - opacityRatio: opacityRatio, - } as ArkThemeResource; - } - - static blendOpacity(argbColor: number, opacityRatio: number): number { - if (opacityRatio < 0 || opacityRatio > 1.0) { - return argbColor; - } - const alpha = (argbColor >> 24) & 0xff; - const outAlpha = (alpha * opacityRatio) & 0xff; - return ((argbColor & 0x00ffffff) | ((outAlpha & 0xff) << 24)) >>> 0; - } - - static convertColorEnumToValue(color: Color): string { - switch (color) { - case Color.WHITE: - case Color.White: - return '#ffffffff'; - case Color.BLACK: - case Color.Black: - return '#ff000000'; - case Color.BLUE: - case Color.Blue: - return '#ff0000ff'; - case Color.BROWN: - case Color.Brown: - return '#ffa52a2a'; - case Color.GRAY: - case Color.Gray: - return '#ff808080'; - case Color.GREEN: - case Color.Green: - return '#ff008000'; - case Color.GREY: - case Color.Grey: - return '#ff808080'; - case Color.ORANGE: - case Color.Orange: - return '#ffffa500'; - case Color.PINK: - case Color.Pink: - return '#ffffc0cb'; - case Color.RED: - case Color.Red: - return '#ffff0000'; - case Color.YELLOW: - case Color.Yellow: - return '#ffffff00'; - case Color.TRANSPARENT: - case Color.Transparent: - return '#00000000'; - } - // Do not match the color, return the default. - return '#ff000000'; - } - - static checkIsColor(value: ResourceColor): boolean { - return value instanceof Color; - } +export interface Colors { + brand: ResourceColor; + warning: ResourceColor; + alert: ResourceColor; + confirm: ResourceColor; + fontPrimary: ResourceColor; + fontSecondary: ResourceColor; + fontTertiary: ResourceColor; + fontFourth: ResourceColor; + fontEmphasize: ResourceColor; + fontOnPrimary: ResourceColor; + fontOnSecondary: ResourceColor; + fontOnTertiary: ResourceColor; + fontOnFourth: ResourceColor; + iconPrimary: ResourceColor; + iconSecondary: ResourceColor; + iconTertiary: ResourceColor; + iconFourth: ResourceColor; + iconEmphasize: ResourceColor; + iconSubEmphasize: ResourceColor; + iconOnPrimary: ResourceColor; + iconOnSecondary: ResourceColor; + iconOnTertiary: ResourceColor; + iconOnFourth: ResourceColor; + backgroundPrimary: ResourceColor; + backgroundSecondary: ResourceColor; + backgroundTertiary: ResourceColor; + backgroundFourth: ResourceColor; + backgroundEmphasize: ResourceColor; + compForegroundPrimary: ResourceColor; + compBackgroundPrimary: ResourceColor; + compBackgroundPrimaryTran: ResourceColor; + compBackgroundPrimaryContrary: ResourceColor; + compBackgroundGray: ResourceColor; + compBackgroundSecondary: ResourceColor; + compBackgroundTertiary: ResourceColor; + compBackgroundEmphasize: ResourceColor; + compBackgroundNeutral: ResourceColor; + compEmphasizeSecondary: ResourceColor; + compEmphasizeTertiary: ResourceColor; + compDivider: ResourceColor; + compCommonContrary: ResourceColor; + compBackgroundFocus: ResourceColor; + compFocusedPrimary: ResourceColor; + compFocusedSecondary: ResourceColor; + compFocusedTertiary: ResourceColor; + interactiveHover: ResourceColor; + interactivePressed: ResourceColor; + interactiveFocus: ResourceColor; + interactiveActive: ResourceColor; + interactiveSelect: ResourceColor; + interactiveClick: ResourceColor; } -export type CustomColors = Colors; +export type CustomColors = Partial; -export class Theme { +export interface Theme { colors: Colors; - shapes: Shapes; - typography: Typography; - - constructor() { - this.colors = new Colors(); - this.shapes = new ArkSystemShapes(); - this.typography = new ArkSystemTypography(); - } - - constructor(colors: Colors, shapes: Shapes, typography: Typography) { - this.colors = colors; - this.shapes = shapes; - this.typography = typography; - } } -export class CustomTheme { +export interface CustomTheme { colors?: CustomColors; - shapes?: CustomShapes; - typography?: CustomTypography; - - constructor() { - this.colors = undefined; - this.shapes = undefined; - this.typography = undefined; - } - - constructor(colors: CustomColors) { - this.colors = colors; - } - - constructor(colors: CustomColors, shapes: CustomShapes, typography: CustomTypography) { - this.colors = colors; - this.shapes = shapes; - this.typography = typography; - } } export class ThemeControl { diff --git a/frameworks/bridge/arkts_frontend/koala_projects/arkoala-arkts/arkui-ohos/src/handwritten/theme/ArkColorsImpl.ts b/frameworks/bridge/arkts_frontend/koala_projects/arkoala-arkts/arkui-ohos/src/handwritten/theme/ArkColorsImpl.ts new file mode 100644 index 00000000000..79866421135 --- /dev/null +++ b/frameworks/bridge/arkts_frontend/koala_projects/arkoala-arkts/arkui-ohos/src/handwritten/theme/ArkColorsImpl.ts @@ -0,0 +1,344 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +import { ResourceColor, Color } from 'arkui/component'; +import { ArkResourcesHelper } from 'arkui/handwritten/theme/ArkResourcesHelper'; +import { BrandColors, ArkThemeResource } from 'arkui/handwritten/theme'; +import { Resource } from 'global.resource'; +import { ArkUIAniModule } from 'arkui.ani'; +import { Colors, CustomColors } from '@ohos/arkui/theme'; + +export class ArkColorsImpl implements Colors { + brand: ResourceColor = ArkResourcesHelper.$r('sys.color.brand', 125830976); + warning: ResourceColor = ArkResourcesHelper.$r('sys.color.warning', 125830979); + alert: ResourceColor = ArkResourcesHelper.$r('sys.color.alert', 125830980); + confirm: ResourceColor = ArkResourcesHelper.$r('sys.color.confirm', 125830981); + + fontPrimary: ResourceColor = ArkResourcesHelper.$r('sys.color.font_primary', 125830982); + fontSecondary: ResourceColor = ArkResourcesHelper.$r('sys.color.font_secondary', 125830983); + fontTertiary: ResourceColor = ArkResourcesHelper.$r('sys.color.font_tertiary', 125830984); + fontFourth: ResourceColor = ArkResourcesHelper.$r('sys.color.font_fourth', 125830985); + fontEmphasize: ResourceColor = ArkResourcesHelper.$r('sys.color.font_emphasize', 125830986); + + fontOnPrimary: ResourceColor = ArkResourcesHelper.$r('sys.color.font_on_primary', 125830987); + fontOnSecondary: ResourceColor = ArkResourcesHelper.$r('sys.color.font_on_secondary', 125830988); + fontOnTertiary: ResourceColor = ArkResourcesHelper.$r('sys.color.font_on_tertiary', 125830989); + fontOnFourth: ResourceColor = ArkResourcesHelper.$r('sys.color.font_on_fourth', 125830990); + + iconPrimary: ResourceColor = ArkResourcesHelper.$r('sys.color.icon_primary', 125830991); + iconSecondary: ResourceColor = ArkResourcesHelper.$r('sys.color.icon_secondary', 125830992); + iconTertiary: ResourceColor = ArkResourcesHelper.$r('sys.color.icon_tertiary', 125830993); + iconFourth: ResourceColor = ArkResourcesHelper.$r('sys.color.icon_fourth', 125830994); + iconEmphasize: ResourceColor = ArkResourcesHelper.$r('sys.color.icon_emphasize', 125830995); + iconSubEmphasize: ResourceColor = ArkResourcesHelper.$r('sys.color.icon_sub_emphasize', 125830996); + + iconOnPrimary: ResourceColor = ArkResourcesHelper.$r('sys.color.icon_on_primary', 125831057); + iconOnSecondary: ResourceColor = ArkResourcesHelper.$r('sys.color.icon_on_secondary', 125831058); + iconOnTertiary: ResourceColor = ArkResourcesHelper.$r('sys.color.icon_on_tertiary', 125831059); + iconOnFourth: ResourceColor = ArkResourcesHelper.$r('sys.color.icon_on_fourth', 125831060); + + backgroundPrimary: ResourceColor = ArkResourcesHelper.$r('sys.color.background_primary', 125831061); + backgroundSecondary: ResourceColor = ArkResourcesHelper.$r('sys.color.background_secondary', 125831062); + backgroundTertiary: ResourceColor = ArkResourcesHelper.$r('sys.color.background_tertiary', 125831063); + backgroundFourth: ResourceColor = ArkResourcesHelper.$r('sys.color.background_fourth', 125831064); + backgroundEmphasize: ResourceColor = ArkResourcesHelper.$r('sys.color.background_emphasize', 125831065); + + compForegroundPrimary: ResourceColor = ArkResourcesHelper.$r('sys.color.comp_foreground_primary', 125831003); + compBackgroundPrimary: ResourceColor = ArkResourcesHelper.$r('sys.color.comp_background_primary', 125831004); + compBackgroundPrimaryTran: ResourceColor = ArkResourcesHelper.$r('sys.color.comp_background_primary_tran'); + compBackgroundPrimaryContrary: ResourceColor = ArkResourcesHelper.$r( + 'sys.color.comp_background_primary_contrary', + 125831005 + ); + compBackgroundGray: ResourceColor = ArkResourcesHelper.$r('sys.color.comp_background_gray', 125831006); + compBackgroundSecondary: ResourceColor = ArkResourcesHelper.$r('sys.color.comp_background_secondary', 125831007); + compBackgroundTertiary: ResourceColor = ArkResourcesHelper.$r('sys.color.comp_background_tertiary', 125831008); + compBackgroundEmphasize: ResourceColor = ArkResourcesHelper.$r('sys.color.comp_background_emphasize', 125831009); + compBackgroundNeutral: ResourceColor = ArkResourcesHelper.$r('sys.color.neutral', 125831066); + compEmphasizeSecondary: ResourceColor = ArkResourcesHelper.$r('sys.color.comp_emphasize_secondary', 125831011); + compEmphasizeTertiary: ResourceColor = ArkResourcesHelper.$r('sys.color.comp_emphasize_tertiary', 125831012); + compDivider: ResourceColor = ArkResourcesHelper.$r('sys.color.comp_divider', 125831013); + compCommonContrary: ResourceColor = ArkResourcesHelper.$r('sys.color.comp_common_contrary', 125831014); + compBackgroundFocus: ResourceColor = ArkResourcesHelper.$r('sys.color.comp_background_focus', 125831015); + compFocusedPrimary: ResourceColor = ArkResourcesHelper.$r('sys.color.comp_focused_primary', 125831016); + compFocusedSecondary: ResourceColor = ArkResourcesHelper.$r('sys.color.comp_focused_secondary', 125831017); + compFocusedTertiary: ResourceColor = ArkResourcesHelper.$r('sys.color.comp_focused_tertiary', 125831018); + + interactiveHover: ResourceColor = ArkResourcesHelper.$r('sys.color.interactive_hover', 125831019); + interactivePressed: ResourceColor = ArkResourcesHelper.$r('sys.color.interactive_pressed', 125831020); + interactiveFocus: ResourceColor = ArkResourcesHelper.$r('sys.color.interactive_focus', 125831021); + interactiveActive: ResourceColor = ArkResourcesHelper.$r('sys.color.interactive_active', 125831022); + interactiveSelect: ResourceColor = ArkResourcesHelper.$r('sys.color.interactive_select', 125831023); + interactiveClick: ResourceColor = ArkResourcesHelper.$r('sys.color.interactive_click', 125831024); + + constructor() {} + + constructor(colors: CustomColors | undefined, baselineColors: Colors) { + ArkColorsImpl.assign(this, baselineColors); + if (colors) { + ArkColorsImpl.assign(this, colors!); + } + } + + static assign(dst: Colors, src: Colors): void { + dst.brand = src.brand; + dst.warning = src.warning; + dst.alert = src.alert; + dst.confirm = src.confirm; + + dst.fontPrimary = src.fontPrimary; + dst.fontSecondary = src.fontSecondary; + dst.fontTertiary = src.fontTertiary; + dst.fontFourth = src.fontFourth; + dst.fontEmphasize = src.fontEmphasize; + + dst.fontOnPrimary = src.fontOnPrimary; + dst.fontOnSecondary = src.fontOnSecondary; + dst.fontOnTertiary = src.fontOnTertiary; + dst.fontOnFourth = src.fontOnFourth; + + dst.iconPrimary = src.iconPrimary; + dst.iconSecondary = src.iconSecondary; + dst.iconTertiary = src.iconTertiary; + dst.iconFourth = src.iconFourth; + dst.iconEmphasize = src.iconEmphasize; + dst.iconSubEmphasize = src.iconSubEmphasize; + + dst.iconOnPrimary = src.iconOnPrimary; + dst.iconOnSecondary = src.iconOnSecondary; + dst.iconOnTertiary = src.iconOnTertiary; + dst.iconOnFourth = src.iconOnFourth; + + dst.backgroundPrimary = src.backgroundPrimary; + dst.backgroundSecondary = src.backgroundSecondary; + dst.backgroundTertiary = src.backgroundTertiary; + dst.backgroundFourth = src.backgroundFourth; + dst.backgroundEmphasize = src.backgroundEmphasize; + + dst.compForegroundPrimary = src.compForegroundPrimary; + dst.compBackgroundPrimary = src.compBackgroundPrimary; + dst.compBackgroundPrimaryTran = src.compBackgroundPrimaryTran; + dst.compBackgroundPrimaryContrary = src.compBackgroundPrimaryContrary; + dst.compBackgroundGray = src.compBackgroundGray; + dst.compBackgroundSecondary = src.compBackgroundSecondary; + dst.compBackgroundTertiary = src.compBackgroundTertiary; + dst.compBackgroundEmphasize = src.compBackgroundEmphasize; + dst.compBackgroundNeutral = src.compBackgroundNeutral; + dst.compEmphasizeSecondary = src.compEmphasizeSecondary; + dst.compEmphasizeTertiary = src.compEmphasizeTertiary; + dst.compDivider = src.compDivider; + dst.compCommonContrary = src.compCommonContrary; + dst.compBackgroundFocus = src.compBackgroundFocus; + dst.compFocusedPrimary = src.compFocusedPrimary; + dst.compFocusedSecondary = src.compFocusedSecondary; + dst.compFocusedTertiary = src.compFocusedTertiary; + + dst.interactiveHover = src.interactiveHover; + dst.interactivePressed = src.interactivePressed; + dst.interactiveFocus = src.interactiveFocus; + dst.interactiveActive = src.interactiveActive; + dst.interactiveSelect = src.interactiveSelect; + dst.interactiveClick = src.interactiveClick; + } + + static assign(dst: Colors, src: CustomColors): void { + if (src.brand !== undefined) dst.brand = src.brand!; + if (src.warning !== undefined) dst.warning = src.warning!; + if (src.alert !== undefined) dst.alert = src.alert!; + if (src.confirm !== undefined) dst.confirm = src.confirm!; + + if (src.fontPrimary !== undefined) dst.fontPrimary = src.fontPrimary!; + if (src.fontSecondary !== undefined) dst.fontSecondary = src.fontSecondary!; + if (src.fontTertiary !== undefined) dst.fontTertiary = src.fontTertiary!; + if (src.fontFourth !== undefined) dst.fontFourth = src.fontFourth!; + if (src.fontEmphasize !== undefined) dst.fontEmphasize = src.fontEmphasize!; + + if (src.fontOnPrimary !== undefined) dst.fontOnPrimary = src.fontOnPrimary!; + if (src.fontOnSecondary !== undefined) dst.fontOnSecondary = src.fontOnSecondary!; + if (src.fontOnTertiary !== undefined) dst.fontOnTertiary = src.fontOnTertiary!; + if (src.fontOnFourth !== undefined) dst.fontOnFourth = src.fontOnFourth!; + + if (src.iconPrimary !== undefined) dst.iconPrimary = src.iconPrimary!; + if (src.iconSecondary !== undefined) dst.iconSecondary = src.iconSecondary!; + if (src.iconTertiary !== undefined) dst.iconTertiary = src.iconTertiary!; + if (src.iconFourth !== undefined) dst.iconFourth = src.iconFourth!; + if (src.iconEmphasize !== undefined) dst.iconEmphasize = src.iconEmphasize!; + if (src.iconSubEmphasize !== undefined) dst.iconSubEmphasize = src.iconSubEmphasize!; + + if (src.iconOnPrimary !== undefined) dst.iconOnPrimary = src.iconOnPrimary!; + if (src.iconOnSecondary !== undefined) dst.iconOnSecondary = src.iconOnSecondary!; + if (src.iconOnTertiary !== undefined) dst.iconOnTertiary = src.iconOnTertiary!; + if (src.iconOnFourth !== undefined) dst.iconOnFourth = src.iconOnFourth!; + + if (src.backgroundPrimary !== undefined) dst.backgroundPrimary = src.backgroundPrimary!; + if (src.backgroundSecondary !== undefined) dst.backgroundSecondary = src.backgroundSecondary!; + if (src.backgroundTertiary !== undefined) dst.backgroundTertiary = src.backgroundTertiary!; + if (src.backgroundFourth !== undefined) dst.backgroundFourth = src.backgroundFourth!; + if (src.backgroundEmphasize !== undefined) dst.backgroundEmphasize = src.backgroundEmphasize!; + + if (src.compForegroundPrimary !== undefined) dst.compForegroundPrimary = src.compForegroundPrimary!; + if (src.compBackgroundPrimary !== undefined) dst.compBackgroundPrimary = src.compBackgroundPrimary!; + if (src.compBackgroundPrimaryTran !== undefined) dst.compBackgroundPrimaryTran = src.compBackgroundPrimaryTran!; + if (src.compBackgroundPrimaryContrary !== undefined) + dst.compBackgroundPrimaryContrary = src.compBackgroundPrimaryContrary!; + if (src.compBackgroundGray !== undefined) dst.compBackgroundGray = src.compBackgroundGray!; + if (src.compBackgroundSecondary !== undefined) dst.compBackgroundSecondary = src.compBackgroundSecondary!; + if (src.compBackgroundTertiary !== undefined) dst.compBackgroundTertiary = src.compBackgroundTertiary!; + if (src.compBackgroundEmphasize !== undefined) dst.compBackgroundEmphasize = src.compBackgroundEmphasize!; + if (src.compBackgroundNeutral !== undefined) dst.compBackgroundNeutral = src.compBackgroundNeutral!; + if (src.compEmphasizeSecondary !== undefined) dst.compEmphasizeSecondary = src.compEmphasizeSecondary!; + if (src.compEmphasizeTertiary !== undefined) dst.compEmphasizeTertiary = src.compEmphasizeTertiary!; + if (src.compDivider !== undefined) dst.compDivider = src.compDivider!; + if (src.compCommonContrary !== undefined) dst.compCommonContrary = src.compCommonContrary!; + if (src.compBackgroundFocus !== undefined) dst.compBackgroundFocus = src.compBackgroundFocus!; + if (src.compFocusedPrimary !== undefined) dst.compFocusedPrimary = src.compFocusedPrimary!; + if (src.compFocusedSecondary !== undefined) dst.compFocusedSecondary = src.compFocusedSecondary!; + if (src.compFocusedTertiary !== undefined) dst.compFocusedTertiary = src.compFocusedTertiary!; + + if (src.interactiveHover !== undefined) dst.interactiveHover = src.interactiveHover!; + if (src.interactivePressed !== undefined) dst.interactivePressed = src.interactivePressed!; + if (src.interactiveFocus !== undefined) dst.interactiveFocus = src.interactiveFocus!; + if (src.interactiveActive !== undefined) dst.interactiveActive = src.interactiveActive!; + if (src.interactiveSelect !== undefined) dst.interactiveSelect = src.interactiveSelect!; + if (src.interactiveClick !== undefined) dst.interactiveClick = src.interactiveClick!; + } + + static expandByBrandColor(colors: CustomColors) { + console.warn(`FZY expandByBrandColor ${Object.keys(colors)}`) + console.warn(`FZY expandByBrandColor ${Object.values(colors)}`) + if (colors!.brand) { + const brandColors: BrandColors = ArkColorsImpl.makeBrandColors(colors.brand); + colors.fontEmphasize = colors.fontEmphasize ?? brandColors.primary!; + + colors.iconEmphasize = colors.iconEmphasize ?? brandColors.primary!; + colors.iconSubEmphasize = colors.iconSubEmphasize ?? brandColors.tertiary!; + + colors.backgroundEmphasize = colors.backgroundEmphasize ?? brandColors.primary!; + + colors.compBackgroundEmphasize = colors.compBackgroundEmphasize ?? brandColors.primary!; + + colors.compEmphasizeSecondary = colors.compEmphasizeSecondary ?? brandColors.fourth!; + colors.compEmphasizeTertiary = colors.compEmphasizeTertiary ?? brandColors.fifth!; + + colors.interactiveFocus = colors.interactiveFocus ?? brandColors.primary!; + colors.interactiveActive = colors.interactiveActive ?? brandColors.primary!; + } + } + + static makeBrandColors(brandColor: ResourceColor | undefined): BrandColors { + const result: BrandColors = { + primary: undefined, + secondary: undefined, + tertiary: undefined, + fourth: undefined, + fifth: undefined, + sixth: undefined, + }; + if (brandColor) { + if (brandColor instanceof Color) { + result.primary = ArkColorsImpl.convertColorEnumToValue(brandColor) as string; + result.secondary = ArkColorsImpl.convertColorEnumToValue(brandColor) as string; + result.tertiary = ArkColorsImpl.convertColorEnumToValue(brandColor) as string; + result.fourth = ArkColorsImpl.convertColorEnumToValue(brandColor) as string; + result.fifth = ArkColorsImpl.convertColorEnumToValue(brandColor) as string; + result.sixth = ArkColorsImpl.convertColorEnumToValue(brandColor) as string; + } else if (brandColor instanceof Resource) { + result.primary = brandColor as Resource; + result.secondary = ArkColorsImpl.makeResourceWithOpacity(brandColor as Resource, 0.6) as Resource; + result.tertiary = ArkColorsImpl.makeResourceWithOpacity(brandColor as Resource, 0.4) as Resource; + result.fourth = ArkColorsImpl.makeResourceWithOpacity(brandColor as Resource, 0.2) as Resource; + result.fifth = ArkColorsImpl.makeResourceWithOpacity(brandColor as Resource, 0.1) as Resource; + result.sixth = ArkColorsImpl.makeResourceWithOpacity(brandColor as Resource, 0.05) as Resource; + } else { + const brandColorValue = brandColor as number | string; + const argbColor = ArkUIAniModule._GetColorValue(brandColorValue); + result.primary = argbColor; + result.secondary = ArkColorsImpl.blendOpacity(argbColor, 0.6); + result.tertiary = ArkColorsImpl.blendOpacity(argbColor, 0.4); + result.fourth = ArkColorsImpl.blendOpacity(argbColor, 0.2); + result.fifth = ArkColorsImpl.blendOpacity(argbColor, 0.1); + result.sixth = ArkColorsImpl.blendOpacity(argbColor, 0.05); + } + } + return result; + } + + static makeResourceWithOpacity(resourceColor: Resource, opacityRatio: number): ArkThemeResource { + return { + id: resourceColor.id, + type: resourceColor.type, + params: [...resourceColor.params!], + bundleName: resourceColor.bundleName, + moduleName: resourceColor.moduleName, + opacityRatio: opacityRatio, + } as ArkThemeResource; + } + + static blendOpacity(argbColor: number, opacityRatio: number): number { + if (opacityRatio < 0 || opacityRatio > 1.0) { + return argbColor; + } + const alpha = (argbColor >> 24) & 0xff; + const outAlpha = (alpha * opacityRatio) & 0xff; + return ((argbColor & 0x00ffffff) | ((outAlpha & 0xff) << 24)) >>> 0; + } + + static convertColorEnumToValue(color: Color): string { + switch (color) { + case Color.WHITE: + case Color.White: + return '#ffffffff'; + case Color.BLACK: + case Color.Black: + return '#ff000000'; + case Color.BLUE: + case Color.Blue: + return '#ff0000ff'; + case Color.BROWN: + case Color.Brown: + return '#ffa52a2a'; + case Color.GRAY: + case Color.Gray: + return '#ff808080'; + case Color.GREEN: + case Color.Green: + return '#ff008000'; + case Color.GREY: + case Color.Grey: + return '#ff808080'; + case Color.ORANGE: + case Color.Orange: + return '#ffffa500'; + case Color.PINK: + case Color.Pink: + return '#ffffc0cb'; + case Color.RED: + case Color.Red: + return '#ffff0000'; + case Color.YELLOW: + case Color.Yellow: + return '#ffffff00'; + case Color.TRANSPARENT: + case Color.Transparent: + return '#00000000'; + } + // Do not match the color, return the default. + return '#ff000000'; + } + + static checkIsColor(value: ResourceColor): boolean { + return value instanceof Color; + } +} \ No newline at end of file diff --git a/frameworks/bridge/arkts_frontend/koala_projects/arkoala-arkts/arkui-ohos/src/handwritten/theme/ArkThemeBase.ts b/frameworks/bridge/arkts_frontend/koala_projects/arkoala-arkts/arkui-ohos/src/handwritten/theme/ArkThemeBase.ts index e853c14e0e3..6324519d0ab 100644 --- a/frameworks/bridge/arkts_frontend/koala_projects/arkoala-arkts/arkui-ohos/src/handwritten/theme/ArkThemeBase.ts +++ b/frameworks/bridge/arkts_frontend/koala_projects/arkoala-arkts/arkui-ohos/src/handwritten/theme/ArkThemeBase.ts @@ -13,13 +13,12 @@ * limitations under the License. */ -import { CustomTheme, Theme, Colors } from '@ohos/arkui/theme'; +import { CustomTheme, Colors } from '@ohos/arkui/theme'; import { ArkThemeCache } from './ArkThemeCache'; import { Shapes, Typography } from './index'; import { ThemeColorMode } from 'arkui/component/common'; -import { ArkShapesImpl } from './ArkShapesImpl'; -import { ArkTypographyImpl } from './ArkTypographyImpl'; -import { int32 } from "@koalaui/common" +import { int32 } from "@koalaui/common"; +import { ThemeInternal, CustomThemeInternal } from './index'; /** * Theme counter used to generate next theme id @@ -29,11 +28,11 @@ let themeCounter: int32 = 0; /** * Base ArkTheme class */ -export class ArkThemeBase extends Theme { +export class ArkThemeBase implements ThemeInternal { // Theme tokens - // colors: Colors; - // shapes: Shapes; - // typography: Typography; + colors: Colors; + shapes: Shapes; + typography: Typography; /** * Unique theme instance id @@ -191,16 +190,18 @@ export class ArkThemeBase extends Theme { // return undefined if original custom theme is undefined return undefined; } - const copyTheme: CustomTheme = new CustomTheme(); + const copyTheme: CustomThemeInternal = {} as CustomThemeInternal; if (customTheme.colors) { - copyTheme.colors = new Colors(); - Colors.assign(copyTheme.colors!, customTheme.colors!); + copyTheme.colors = customTheme.colors!; } - if (customTheme.shapes) { - copyTheme.shapes = customTheme.shapes; - } - if (customTheme.typography) { - copyTheme.typography = customTheme.typography!; + if (customTheme instanceof CustomThemeInternal) { + const srcTheme = customTheme as CustomThemeInternal; + if (srcTheme.shapes) { + copyTheme.shapes = srcTheme.shapes!; + } + if (srcTheme.typography) { + copyTheme.typography = srcTheme.typography!; + } } return copyTheme; } diff --git a/frameworks/bridge/arkts_frontend/koala_projects/arkoala-arkts/arkui-ohos/src/handwritten/theme/ArkThemeImpl.ts b/frameworks/bridge/arkts_frontend/koala_projects/arkoala-arkts/arkui-ohos/src/handwritten/theme/ArkThemeImpl.ts index c3c85cd15b5..87a9caff5ef 100644 --- a/frameworks/bridge/arkts_frontend/koala_projects/arkoala-arkts/arkui-ohos/src/handwritten/theme/ArkThemeImpl.ts +++ b/frameworks/bridge/arkts_frontend/koala_projects/arkoala-arkts/arkui-ohos/src/handwritten/theme/ArkThemeImpl.ts @@ -14,10 +14,12 @@ */ import { ArkThemeBase } from './ArkThemeBase'; -import { CustomTheme, Colors } from '@ohos/arkui/theme'; import { ThemeColorMode } from 'arkui/component/common'; import { ArkShapesImpl } from './ArkShapesImpl'; import { ArkTypographyImpl } from './ArkTypographyImpl'; +import { ArkColorsImpl } from './ArkColorsImpl'; +import { CustomThemeInternal } from '../theme'; +import { CustomTheme } from '@ohos/arkui/theme'; export class ArkThemeImpl extends ArkThemeBase { constructor( @@ -25,9 +27,19 @@ export class ArkThemeImpl extends ArkThemeBase { colorMode: ThemeColorMode, baselineTheme: ArkThemeBase, ) { - super(baselineTheme.id, customTheme, colorMode, - new Colors(customTheme ? customTheme.colors : undefined, baselineTheme.colors), - new ArkShapesImpl(customTheme ? customTheme.shapes : undefined, baselineTheme.shapes), - new ArkTypographyImpl(customTheme ? customTheme.typography : undefined, baselineTheme.typography)); + super( + baselineTheme.id, + customTheme, + colorMode, + new ArkColorsImpl(customTheme ? customTheme.colors : undefined, baselineTheme.colors), + new ArkShapesImpl( + customTheme ? (customTheme as CustomThemeInternal).shapes : undefined, + baselineTheme.shapes + ), + new ArkTypographyImpl( + customTheme ? (customTheme as CustomThemeInternal).typography : undefined, + baselineTheme.typography + ) + ); } } diff --git a/frameworks/bridge/arkts_frontend/koala_projects/arkoala-arkts/arkui-ohos/src/handwritten/theme/ArkThemeNativeHelper.ts b/frameworks/bridge/arkts_frontend/koala_projects/arkoala-arkts/arkui-ohos/src/handwritten/theme/ArkThemeNativeHelper.ts index 73856ce92cc..de9ce44e35f 100644 --- a/frameworks/bridge/arkts_frontend/koala_projects/arkoala-arkts/arkui-ohos/src/handwritten/theme/ArkThemeNativeHelper.ts +++ b/frameworks/bridge/arkts_frontend/koala_projects/arkoala-arkts/arkui-ohos/src/handwritten/theme/ArkThemeNativeHelper.ts @@ -17,24 +17,29 @@ import { Theme, CustomTheme } from '@ohos/arkui/theme'; import { ResourceColor, Color } from 'arkui/component'; import { ThemeColorMode } from 'arkui/component/common'; import { ArkUIAniModule } from 'arkui.ani'; -import { CustomColors } from '@ohos/arkui/theme'; +import { CustomColors, Colors } from '@ohos/arkui/theme'; import { ArkThemeScopeManager } from './ArkThemeScopeManager'; import { int32 } from "@koalaui/common" -import { Colors } from '@ohos/arkui/theme'; +import { ArkColorsImpl } from './ArkColorsImpl'; +import { ThemeInternal } from '../theme'; export class ArkThemeNativeHelper { - static sendThemeToNative(theme: Theme, elmtId: int32): void { - ArkUIAniModule._SendThemeToNative(ArkThemeNativeHelper.convertColorsToArray(theme.colors), elmtId); + static sendThemeToNative(theme: ThemeInternal, elmtId: int32): void { + ArkUIAniModule._SendThemeToNative(ArkThemeNativeHelper.convertThemeToColorArray(theme), elmtId); } static setDefaultTheme(theme: CustomTheme | undefined): void { - const colorArray = ArkThemeNativeHelper.convertColorsToArray(theme?.colors); + const colorArray = ArkThemeNativeHelper.convertThemeToColorArray(theme!); ArkThemeScopeManager.getInstance().onEnterLocalColorMode(ThemeColorMode.LIGHT); ArkUIAniModule._SetDefaultTheme(colorArray, false); ArkThemeScopeManager.getInstance().onEnterLocalColorMode(ThemeColorMode.DARK); ArkUIAniModule._SetDefaultTheme(colorArray, true); ArkThemeScopeManager.getInstance().onExitLocalColorMode(); } - static createInternal(themeScopeId: int32, themeId: int32, theme: CustomTheme | undefined, colorMode: ThemeColorMode, + static createInternal( + themeScopeId: int32, + themeId: int32, + theme: CustomTheme | undefined, + colorMode: ThemeColorMode, onThemeScopeDestroy: () => void ) { // set local color mode if need @@ -42,72 +47,92 @@ export class ArkThemeNativeHelper { ArkThemeScopeManager.getInstance().onEnterLocalColorMode(colorMode); } - ArkUIAniModule._CreateAndBindTheme(themeScopeId, themeId, - ArkThemeNativeHelper.convertColorsToArray(theme?.colors), colorMode, onThemeScopeDestroy); - // getUINativeModule().theme.createAndBindTheme(themeScopeId, themeId, - // ArkThemeNativeHelper.convertColorsToArray(theme?.colors), colorMode, onThemeScopeDestroy); + ArkUIAniModule._CreateAndBindTheme( + themeScopeId, + themeId, + ArkThemeNativeHelper.convertThemeToColorArray(theme), + colorMode, + onThemeScopeDestroy + ); // reset local color mode if need if (colorMode && colorMode !== ThemeColorMode.SYSTEM) { ArkThemeScopeManager.getInstance().onExitLocalColorMode(); } } - public static convertThemeToColorArray(theme: Theme): ResourceColor[] { + public static convertThemeToColorArray(theme: Theme | CustomTheme | undefined): ResourceColor[] { + if (!theme) { + return new Array(Object.keys(new ArkColorsImpl()).length); + } + const srcTheme: Theme = { colors: new ArkColorsImpl() }; + if (theme instanceof Theme) { + srcTheme.colors = theme.colors; + } else { + ArkColorsImpl.assign(srcTheme.colors, (theme as CustomTheme).colors!) + } return [ - theme.colors.brand, - theme.colors.warning, - theme.colors.alert, - theme.colors.confirm, - theme.colors.fontPrimary, - theme.colors.fontSecondary, - theme.colors.fontTertiary, - theme.colors.fontFourth, - theme.colors.fontEmphasize, - theme.colors.fontOnPrimary, - theme.colors.fontOnSecondary, - theme.colors.fontOnTertiary, - theme.colors.fontOnFourth, - theme.colors.iconPrimary, - theme.colors.iconSecondary, - theme.colors.iconTertiary, - theme.colors.iconFourth, - theme.colors.iconEmphasize, - theme.colors.iconSubEmphasize, - theme.colors.iconOnPrimary, - theme.colors.iconOnSecondary, - theme.colors.iconOnTertiary, - theme.colors.iconOnFourth, - theme.colors.backgroundPrimary, - theme.colors.backgroundSecondary, - theme.colors.backgroundTertiary, - theme.colors.backgroundFourth, - theme.colors.backgroundEmphasize, - theme.colors.compForegroundPrimary, - theme.colors.compBackgroundPrimary, - theme.colors.compBackgroundPrimaryTran, - theme.colors.compBackgroundPrimaryContrary, - theme.colors.compBackgroundGray, - theme.colors.compBackgroundSecondary, - theme.colors.compBackgroundTertiary, - theme.colors.compBackgroundEmphasize, - theme.colors.compBackgroundNeutral, - theme.colors.compEmphasizeSecondary, - theme.colors.compEmphasizeTertiary, - theme.colors.compDivider, - theme.colors.compCommonContrary, - theme.colors.compBackgroundFocus, - theme.colors.compFocusedPrimary, - theme.colors.compFocusedSecondary, - theme.colors.compFocusedTertiary, - theme.colors.interactiveHover, - theme.colors.interactivePressed, - theme.colors.interactiveFocus, - theme.colors.interactiveActive, - theme.colors.interactiveSelect, - theme.colors.interactiveClick, + ArkThemeNativeHelper.convertColorEnumToValue(srcTheme.colors.brand), + ArkThemeNativeHelper.convertColorEnumToValue(srcTheme.colors.warning), + ArkThemeNativeHelper.convertColorEnumToValue(srcTheme.colors.alert), + ArkThemeNativeHelper.convertColorEnumToValue(srcTheme.colors.confirm), + ArkThemeNativeHelper.convertColorEnumToValue(srcTheme.colors.fontPrimary), + ArkThemeNativeHelper.convertColorEnumToValue(srcTheme.colors.fontSecondary), + ArkThemeNativeHelper.convertColorEnumToValue(srcTheme.colors.fontTertiary), + ArkThemeNativeHelper.convertColorEnumToValue(srcTheme.colors.fontFourth), + ArkThemeNativeHelper.convertColorEnumToValue(srcTheme.colors.fontEmphasize), + ArkThemeNativeHelper.convertColorEnumToValue(srcTheme.colors.fontOnPrimary), + ArkThemeNativeHelper.convertColorEnumToValue(srcTheme.colors.fontOnSecondary), + ArkThemeNativeHelper.convertColorEnumToValue(srcTheme.colors.fontOnTertiary), + ArkThemeNativeHelper.convertColorEnumToValue(srcTheme.colors.fontOnFourth), + ArkThemeNativeHelper.convertColorEnumToValue(srcTheme.colors.iconPrimary), + ArkThemeNativeHelper.convertColorEnumToValue(srcTheme.colors.iconSecondary), + ArkThemeNativeHelper.convertColorEnumToValue(srcTheme.colors.iconTertiary), + ArkThemeNativeHelper.convertColorEnumToValue(srcTheme.colors.iconFourth), + ArkThemeNativeHelper.convertColorEnumToValue(srcTheme.colors.iconEmphasize), + ArkThemeNativeHelper.convertColorEnumToValue(srcTheme.colors.iconSubEmphasize), + ArkThemeNativeHelper.convertColorEnumToValue(srcTheme.colors.iconOnPrimary), + ArkThemeNativeHelper.convertColorEnumToValue(srcTheme.colors.iconOnSecondary), + ArkThemeNativeHelper.convertColorEnumToValue(srcTheme.colors.iconOnTertiary), + ArkThemeNativeHelper.convertColorEnumToValue(srcTheme.colors.iconOnFourth), + ArkThemeNativeHelper.convertColorEnumToValue(srcTheme.colors.backgroundPrimary), + ArkThemeNativeHelper.convertColorEnumToValue(srcTheme.colors.backgroundSecondary), + ArkThemeNativeHelper.convertColorEnumToValue(srcTheme.colors.backgroundTertiary), + ArkThemeNativeHelper.convertColorEnumToValue(srcTheme.colors.backgroundFourth), + ArkThemeNativeHelper.convertColorEnumToValue(srcTheme.colors.backgroundEmphasize), + ArkThemeNativeHelper.convertColorEnumToValue(srcTheme.colors.compForegroundPrimary), + ArkThemeNativeHelper.convertColorEnumToValue(srcTheme.colors.compBackgroundPrimary), + ArkThemeNativeHelper.convertColorEnumToValue(srcTheme.colors.compBackgroundPrimaryTran), + ArkThemeNativeHelper.convertColorEnumToValue(srcTheme.colors.compBackgroundPrimaryContrary), + ArkThemeNativeHelper.convertColorEnumToValue(srcTheme.colors.compBackgroundGray), + ArkThemeNativeHelper.convertColorEnumToValue(srcTheme.colors.compBackgroundSecondary), + ArkThemeNativeHelper.convertColorEnumToValue(srcTheme.colors.compBackgroundTertiary), + ArkThemeNativeHelper.convertColorEnumToValue(srcTheme.colors.compBackgroundEmphasize), + ArkThemeNativeHelper.convertColorEnumToValue(srcTheme.colors.compBackgroundNeutral), + ArkThemeNativeHelper.convertColorEnumToValue(srcTheme.colors.compEmphasizeSecondary), + ArkThemeNativeHelper.convertColorEnumToValue(srcTheme.colors.compEmphasizeTertiary), + ArkThemeNativeHelper.convertColorEnumToValue(srcTheme.colors.compDivider), + ArkThemeNativeHelper.convertColorEnumToValue(srcTheme.colors.compCommonContrary), + ArkThemeNativeHelper.convertColorEnumToValue(srcTheme.colors.compBackgroundFocus), + ArkThemeNativeHelper.convertColorEnumToValue(srcTheme.colors.compFocusedPrimary), + ArkThemeNativeHelper.convertColorEnumToValue(srcTheme.colors.compFocusedSecondary), + ArkThemeNativeHelper.convertColorEnumToValue(srcTheme.colors.compFocusedTertiary), + ArkThemeNativeHelper.convertColorEnumToValue(srcTheme.colors.interactiveHover), + ArkThemeNativeHelper.convertColorEnumToValue(srcTheme.colors.interactivePressed), + ArkThemeNativeHelper.convertColorEnumToValue(srcTheme.colors.interactiveFocus), + ArkThemeNativeHelper.convertColorEnumToValue(srcTheme.colors.interactiveActive), + ArkThemeNativeHelper.convertColorEnumToValue(srcTheme.colors.interactiveSelect), + ArkThemeNativeHelper.convertColorEnumToValue(srcTheme.colors.interactiveClick), ]; } - public static convertColorsToArray(colors: CustomColors | undefined): ResourceColor[] { + + private static convertColorEnumToValue(color: ResourceColor): ResourceColor { + if (ArkColorsImpl.checkIsColor(color)) { + return ArkColorsImpl.convertColorEnumToValue(color as Color); + } + return color; + } + + public static convertColorsToArray(colors: Colors | CustomColors | undefined): ResourceColor[] { const basisColors = ArkThemeScopeManager.getSystemColors(); if (!colors) { return new Array(Object.keys(basisColors).length); @@ -115,8 +140,8 @@ export class ArkThemeNativeHelper { const colorArray: ResourceColor[] = []; for (let attr of Object.values(colors)) { const value: ResourceColor = attr as ResourceColor; - if (Colors.checkIsColor(value)) { - colorArray.push(Colors.convertColorEnumToValue(value as Color)); + if (ArkColorsImpl.checkIsColor(value)) { + colorArray.push(ArkColorsImpl.convertColorEnumToValue(value as Color)); continue; } colorArray.push(value); diff --git a/frameworks/bridge/arkts_frontend/koala_projects/arkoala-arkts/arkui-ohos/src/handwritten/theme/ArkThemeScopeManager.ts b/frameworks/bridge/arkts_frontend/koala_projects/arkoala-arkts/arkui-ohos/src/handwritten/theme/ArkThemeScopeManager.ts index f02a4f7e9bf..70e3b40d416 100644 --- a/frameworks/bridge/arkts_frontend/koala_projects/arkoala-arkts/arkui-ohos/src/handwritten/theme/ArkThemeScopeManager.ts +++ b/frameworks/bridge/arkts_frontend/koala_projects/arkoala-arkts/arkui-ohos/src/handwritten/theme/ArkThemeScopeManager.ts @@ -13,18 +13,18 @@ * limitations under the License. */ -import { CustomTheme, Theme, Colors } from '@ohos/arkui/theme'; +import { CustomTheme, Colors } from '@ohos/arkui/theme'; import { ThemeColorMode } from 'arkui/component/common'; -import { InteropNativeModule } from '@koalaui/interop'; import { ArkThemeBase } from './ArkThemeBase'; import { ArkSystemTheme } from './system/ArkSystemTheme'; import { ArkThemeCache } from './ArkThemeCache'; import { ArkThemeImpl } from './ArkThemeImpl'; import { ArkThemeNativeHelper } from './ArkThemeNativeHelper'; -import { WithThemeOptions, WithTheme } from '../../component/withTheme'; +import { WithThemeOptions } from '../../component/withTheme'; import { ArkUIAniModule } from '../../ani/arkts/ArkUIAniModule'; -import { unsafeCast, int32, int64, float32 } from "@koalaui/common"; +import { int32 } from "@koalaui/common"; import { ArkThemeScope } from './ArkThemeScope'; +import { ArkColorsImpl } from './ArkColorsImpl'; type ViewPuInternal = Object; @@ -228,7 +228,7 @@ export class ArkThemeScopeManager { if (theme?.colors) { console.log('FZY cloneCustomThemeWithExpand 333') - Colors.expandByBrandColor(theme!.colors!); + ArkColorsImpl.expandByBrandColor(theme!.colors!); } console.log('FZY cloneCustomThemeWithExpand 555') return theme; diff --git a/frameworks/bridge/arkts_frontend/koala_projects/arkoala-arkts/arkui-ohos/src/handwritten/theme/index.ts b/frameworks/bridge/arkts_frontend/koala_projects/arkoala-arkts/arkui-ohos/src/handwritten/theme/index.ts index 73232a9772a..ced4750ca22 100644 --- a/frameworks/bridge/arkts_frontend/koala_projects/arkoala-arkts/arkui-ohos/src/handwritten/theme/index.ts +++ b/frameworks/bridge/arkts_frontend/koala_projects/arkoala-arkts/arkui-ohos/src/handwritten/theme/index.ts @@ -315,3 +315,13 @@ export interface ArkThemeResource extends Resource { type?: number; opacityRatio: number; } + +export interface ThemeInternal extends Theme { + shapes: Shapes; + typography: Typography; +} + +export interface CustomThemeInternal extends CustomTheme { + shapes?: CustomShapes; + typography?: CustomTypography; +} diff --git a/frameworks/bridge/arkts_frontend/koala_projects/arkoala-arkts/arkui-ohos/src/handwritten/theme/system/ArkSystemColors.ts b/frameworks/bridge/arkts_frontend/koala_projects/arkoala-arkts/arkui-ohos/src/handwritten/theme/system/ArkSystemColors.ts new file mode 100644 index 00000000000..26dc1d63d5b --- /dev/null +++ b/frameworks/bridge/arkts_frontend/koala_projects/arkoala-arkts/arkui-ohos/src/handwritten/theme/system/ArkSystemColors.ts @@ -0,0 +1,140 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +import { ResourceColor } from 'arkui/component'; +import { ArkResourcesHelper } from 'arkui/handwritten/theme/ArkResourcesHelper'; +import { Colors } from '@ohos/arkui/theme'; + +export class ArkSystemColors implements Colors { + brand: ResourceColor; + warning: ResourceColor; + alert: ResourceColor; + confirm: ResourceColor; + + fontPrimary: ResourceColor; + fontSecondary: ResourceColor; + fontTertiary: ResourceColor; + fontFourth: ResourceColor; + fontEmphasize: ResourceColor; + + fontOnPrimary: ResourceColor; + fontOnSecondary: ResourceColor; + fontOnTertiary: ResourceColor; + fontOnFourth: ResourceColor; + + iconPrimary: ResourceColor; + iconSecondary: ResourceColor; + iconTertiary: ResourceColor; + iconFourth: ResourceColor; + iconEmphasize: ResourceColor; + iconSubEmphasize: ResourceColor; + + iconOnPrimary: ResourceColor; + iconOnSecondary: ResourceColor; + iconOnTertiary: ResourceColor; + iconOnFourth: ResourceColor; + + backgroundPrimary: ResourceColor; + backgroundSecondary: ResourceColor; + backgroundTertiary: ResourceColor; + backgroundFourth: ResourceColor; + backgroundEmphasize: ResourceColor; + + compForegroundPrimary: ResourceColor; + compBackgroundPrimary: ResourceColor; + compBackgroundPrimaryTran: ResourceColor; + compBackgroundPrimaryContrary: ResourceColor; + compBackgroundGray: ResourceColor; + compBackgroundSecondary: ResourceColor; + compBackgroundTertiary: ResourceColor; + compBackgroundEmphasize: ResourceColor; + compBackgroundNeutral: ResourceColor; + compEmphasizeSecondary: ResourceColor; + compEmphasizeTertiary: ResourceColor; + compDivider: ResourceColor; + compCommonContrary: ResourceColor; + compBackgroundFocus: ResourceColor; + compFocusedPrimary: ResourceColor; + compFocusedSecondary: ResourceColor; + compFocusedTertiary: ResourceColor; + + interactiveHover: ResourceColor; + interactivePressed: ResourceColor; + interactiveFocus: ResourceColor; + interactiveActive: ResourceColor; + interactiveSelect: ResourceColor; + interactiveClick: ResourceColor; + + constructor() { + this.brand = ArkResourcesHelper.$r('sys.color.brand', 125830976); + this.warning = ArkResourcesHelper.$r('sys.color.warning', 125830979); + this.alert = ArkResourcesHelper.$r('sys.color.alert', 125830980); + this.confirm = ArkResourcesHelper.$r('sys.color.confirm', 125830981); + + this.fontPrimary = ArkResourcesHelper.$r('sys.color.font_primary', 125830982); + this.fontSecondary = ArkResourcesHelper.$r('sys.color.font_secondary', 125830983); + this.fontTertiary = ArkResourcesHelper.$r('sys.color.font_tertiary', 125830984); + this.fontFourth = ArkResourcesHelper.$r('sys.color.font_fourth', 125830985); + this.fontEmphasize = ArkResourcesHelper.$r('sys.color.font_emphasize', 125830986); + + this.fontOnPrimary = ArkResourcesHelper.$r('sys.color.font_on_primary', 125830987); + this.fontOnSecondary = ArkResourcesHelper.$r('sys.color.font_on_secondary', 125830988); + this.fontOnTertiary = ArkResourcesHelper.$r('sys.color.font_on_tertiary', 125830989); + this.fontOnFourth = ArkResourcesHelper.$r('sys.color.font_on_fourth', 125830990); + + this.iconPrimary = ArkResourcesHelper.$r('sys.color.icon_primary', 125830991); + this.iconSecondary = ArkResourcesHelper.$r('sys.color.icon_secondary', 125830992); + this.iconTertiary = ArkResourcesHelper.$r('sys.color.icon_tertiary', 125830993); + this.iconFourth = ArkResourcesHelper.$r('sys.color.icon_fourth', 125830994); + this.iconEmphasize = ArkResourcesHelper.$r('sys.color.icon_emphasize', 125830995); + this.iconSubEmphasize = ArkResourcesHelper.$r('sys.color.icon_sub_emphasize', 125830996); + + this.iconOnPrimary = ArkResourcesHelper.$r('sys.color.icon_on_primary', 125831057); + this.iconOnSecondary = ArkResourcesHelper.$r('sys.color.icon_on_secondary', 125831058); + this.iconOnTertiary = ArkResourcesHelper.$r('sys.color.icon_on_tertiary', 125831059); + this.iconOnFourth = ArkResourcesHelper.$r('sys.color.icon_on_fourth', 125831060); + + this.backgroundPrimary = ArkResourcesHelper.$r('sys.color.background_primary', 125831061); + this.backgroundSecondary = ArkResourcesHelper.$r('sys.color.background_secondary', 125831062); + this.backgroundTertiary = ArkResourcesHelper.$r('sys.color.background_tertiary', 125831063); + this.backgroundFourth = ArkResourcesHelper.$r('sys.color.background_fourth', 125831064); + this.backgroundEmphasize = ArkResourcesHelper.$r('sys.color.background_emphasize', 125831065); + + this.compForegroundPrimary = ArkResourcesHelper.$r('sys.color.comp_foreground_primary', 125831003); + this.compBackgroundPrimary = ArkResourcesHelper.$r('sys.color.comp_background_primary', 125831004); + this.compBackgroundPrimaryTran = ArkResourcesHelper.$r('sys.color.comp_background_primary_tran'); + this.compBackgroundPrimaryContrary = ArkResourcesHelper.$r('sys.color.comp_background_primary_contrary', 125831005); + this.compBackgroundGray = ArkResourcesHelper.$r('sys.color.comp_background_gray', 125831006); + this.compBackgroundSecondary = ArkResourcesHelper.$r('sys.color.comp_background_secondary', 125831007); + this.compBackgroundTertiary = ArkResourcesHelper.$r('sys.color.comp_background_tertiary', 125831008); + this.compBackgroundEmphasize = ArkResourcesHelper.$r('sys.color.comp_background_emphasize', 125831009); + this.compBackgroundNeutral = ArkResourcesHelper.$r('sys.color.neutral', 125831066); + this.compEmphasizeSecondary = ArkResourcesHelper.$r('sys.color.comp_emphasize_secondary', 125831011); + this.compEmphasizeTertiary = ArkResourcesHelper.$r('sys.color.comp_emphasize_tertiary', 125831012); + this.compDivider = ArkResourcesHelper.$r('sys.color.comp_divider', 125831013); + this.compCommonContrary = ArkResourcesHelper.$r('sys.color.comp_common_contrary', 125831014); + this.compBackgroundFocus = ArkResourcesHelper.$r('sys.color.comp_background_focus', 125831015); + this.compFocusedPrimary = ArkResourcesHelper.$r('sys.color.comp_focused_primary', 125831016); + this.compFocusedSecondary = ArkResourcesHelper.$r('sys.color.comp_focused_secondary', 125831017); + this.compFocusedTertiary = ArkResourcesHelper.$r('sys.color.comp_focused_tertiary', 125831018); + + this.interactiveHover = ArkResourcesHelper.$r('sys.color.interactive_hover', 125831019); + this.interactivePressed = ArkResourcesHelper.$r('sys.color.interactive_pressed', 125831020); + this.interactiveFocus = ArkResourcesHelper.$r('sys.color.interactive_focus', 125831021); + this.interactiveActive = ArkResourcesHelper.$r('sys.color.interactive_active', 125831022); + this.interactiveSelect = ArkResourcesHelper.$r('sys.color.interactive_select', 125831023); + this.interactiveClick = ArkResourcesHelper.$r('sys.color.interactive_click', 125831024); + } +} \ No newline at end of file diff --git a/frameworks/bridge/arkts_frontend/koala_projects/arkoala-arkts/arkui-ohos/src/handwritten/theme/system/ArkSystemTheme.ts b/frameworks/bridge/arkts_frontend/koala_projects/arkoala-arkts/arkui-ohos/src/handwritten/theme/system/ArkSystemTheme.ts index 4519c04917f..219fd0c8b21 100644 --- a/frameworks/bridge/arkts_frontend/koala_projects/arkoala-arkts/arkui-ohos/src/handwritten/theme/system/ArkSystemTheme.ts +++ b/frameworks/bridge/arkts_frontend/koala_projects/arkoala-arkts/arkui-ohos/src/handwritten/theme/system/ArkSystemTheme.ts @@ -13,11 +13,11 @@ * limitations under the License. */ -import { Colors } from '@ohos/arkui/theme'; import { ArkThemeBase } from '../ArkThemeBase'; import { ThemeColorMode } from 'arkui/component/common'; import { ArkSystemShapes } from './ArkSystemShapes'; import { ArkSystemTypography } from './ArkSystemTypography'; +import { ArkSystemColors } from './ArkSystemColors'; export class ArkSystemTheme extends ArkThemeBase { constructor() { @@ -25,7 +25,7 @@ export class ArkSystemTheme extends ArkThemeBase { -1, // no parent theme undefined, ThemeColorMode.SYSTEM, - new Colors(), + new ArkSystemColors(), new ArkSystemShapes(), new ArkSystemTypography() ); diff --git a/frameworks/bridge/arkts_frontend/koala_projects/arkoala-arkts/components.gni b/frameworks/bridge/arkts_frontend/koala_projects/arkoala-arkts/components.gni index 2ced3269386..8e9ec4e7fda 100644 --- a/frameworks/bridge/arkts_frontend/koala_projects/arkoala-arkts/components.gni +++ b/frameworks/bridge/arkts_frontend/koala_projects/arkoala-arkts/components.gni @@ -387,6 +387,9 @@ arkui_files = [ "arkui-preprocessed/arkui/handwritten/modifiers/ArkXComponentNode.ets", "arkui-preprocessed/arkui/handwritten/theme/index.ets", "arkui-preprocessed/arkui/handwritten/theme/ArkThemeScopeManager.ets", + "arkui-preprocessed/arkui/handwritten/theme/ArkColorsImpl.ets", + "arkui-preprocessed/arkui/handwritten/theme/ArkResourcesHelper.ets", + "arkui-preprocessed/arkui/handwritten/theme/ArkShapesImpl.ets", "arkui-preprocessed/arkui/handwritten/theme/ArkThemeBase.ets", "arkui-preprocessed/arkui/handwritten/theme/ArkShapesImpl.ets", "arkui-preprocessed/arkui/handwritten/theme/ArkThemeScope.ets", @@ -395,6 +398,7 @@ arkui_files = [ "arkui-preprocessed/arkui/handwritten/theme/ArkTypographyImpl.ets", "arkui-preprocessed/arkui/handwritten/theme/ArkThemeNativeHelper.ets", "arkui-preprocessed/arkui/handwritten/theme/ArkThemeCache.ets", + "arkui-preprocessed/arkui/handwritten/theme/system/ArkSystemColors.ets", "arkui-preprocessed/arkui/handwritten/theme/system/ArkSystemShapes.ets", "arkui-preprocessed/arkui/handwritten/theme/system/ArkSystemTypography.ets", "arkui-preprocessed/arkui/handwritten/theme/system/ArkSystemTheme.ets", -- Gitee From e9aa4df91c1ee5fe2487b6dba1567b9ba47dabf7 Mon Sep 17 00:00:00 2001 From: fangzhiyuan Date: Sun, 20 Jul 2025 00:55:06 +0800 Subject: [PATCH 04/11] =?UTF-8?q?=E8=87=AA=E5=AE=9A=E4=B9=89=E7=BB=84?= =?UTF-8?q?=E4=BB=B6=E5=92=8Ctext=E9=80=82=E9=85=8DwithTheme?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: fangzhiyuan Change-Id: I6ab823598f13176fdb65e5d7f379bf5ee81e8504 --- .../arkui-ohos/src/ArkCustomComponent.ts | 3 +- .../arkui-ohos/src/component/text.ts | 10 +- .../handwritten/component/customComponent.ts | 12 +- .../component/extendableComponent.ts | 3 + .../src/handwritten/theme/ArkThemeScope.ts | 44 ++-- .../handwritten/theme/ArkThemeScopeManager.ts | 236 ++++++++++++++---- .../handwritten/theme/ArkThemeWhiteList.ts | 62 +++++ 7 files changed, 296 insertions(+), 74 deletions(-) create mode 100644 frameworks/bridge/arkts_frontend/koala_projects/arkoala-arkts/arkui-ohos/src/handwritten/theme/ArkThemeWhiteList.ts diff --git a/frameworks/bridge/arkts_frontend/koala_projects/arkoala-arkts/arkui-ohos/src/ArkCustomComponent.ts b/frameworks/bridge/arkts_frontend/koala_projects/arkoala-arkts/arkui-ohos/src/ArkCustomComponent.ts index 4b4250b5bf1..bc7f80e50c9 100644 --- a/frameworks/bridge/arkts_frontend/koala_projects/arkoala-arkts/arkui-ohos/src/ArkCustomComponent.ts +++ b/frameworks/bridge/arkts_frontend/koala_projects/arkoala-arkts/arkui-ohos/src/ArkCustomComponent.ts @@ -14,7 +14,6 @@ */ import { - Theme, ConstraintSizeOptions, GeometryInfo, Layoutable, @@ -22,6 +21,7 @@ import { SizeResult, } from "./component" import { PeerNode } from "./PeerNode" +import { Theme } from '@ohos/arkui/theme'; /** * This is basically the CustomComponent @@ -51,6 +51,7 @@ export interface ArkCustomComponent { // Theme onWillApplyTheme(theme: Theme): void + onGlobalThemeChanged(theme: Theme): void // Form recover onFormRecycle(): string diff --git a/frameworks/bridge/arkts_frontend/koala_projects/arkoala-arkts/arkui-ohos/src/component/text.ts b/frameworks/bridge/arkts_frontend/koala_projects/arkoala-arkts/arkui-ohos/src/component/text.ts index d196ba54d0e..a722dec4ce0 100644 --- a/frameworks/bridge/arkts_frontend/koala_projects/arkoala-arkts/arkui-ohos/src/component/text.ts +++ b/frameworks/bridge/arkts_frontend/koala_projects/arkoala-arkts/arkui-ohos/src/component/text.ts @@ -1593,16 +1593,8 @@ export function Text( const receiver = remember(() => { return new ArkTextComponent() }) - const scope = __context().scope(__id()); NodeAttach((): ArkTextPeer => ArkTextPeer.create(receiver), (_: ArkTextPeer) => { - const parentRef = scope.parent?.nodeRef; - console.log(`FZY Text NodeAttach ${parentRef}`); - const parentPeer = parentRef ? findPeerNode(parentRef) : undefined; - if (parentPeer && parentPeer.peer && receiver.getPeer()) { - console.info(`FZY ArkTextPeer parent ${parentPeer}`) - ArkUIAniModule._ApplyParentThemeScopeId(receiver.getPeer().getPeerPtr(), parentPeer.getPeerPtr()); - } - + ArkThemeScopeManager.getInstance().applyParentThemeScopeId(receiver); ArkThemeScopeManager.getInstance().onComponentCreateEnter("Text", receiver.getPeer()?.getId(), receiver.isFirstBuild) receiver.setTextOptions(content,value) style?.(receiver) diff --git a/frameworks/bridge/arkts_frontend/koala_projects/arkoala-arkts/arkui-ohos/src/handwritten/component/customComponent.ts b/frameworks/bridge/arkts_frontend/koala_projects/arkoala-arkts/arkui-ohos/src/handwritten/component/customComponent.ts index 043dea87e69..69b07e64879 100644 --- a/frameworks/bridge/arkts_frontend/koala_projects/arkoala-arkts/arkui-ohos/src/handwritten/component/customComponent.ts +++ b/frameworks/bridge/arkts_frontend/koala_projects/arkoala-arkts/arkui-ohos/src/handwritten/component/customComponent.ts @@ -21,10 +21,12 @@ import { ArkUIAniModule } from 'arkui.ani'; import { ConstraintSizeOptions } from './units'; import { ContextRecord } from 'arkui/handwritten/UIContextImpl'; import { ExtendableComponent, IExtendableComponent } from './extendableComponent'; -import { GeometryInfo, Layoutable, Measurable, SizeResult, Theme } from './common'; +import { GeometryInfo, Layoutable, Measurable, SizeResult } from './common'; import { LocalStorage } from '@ohos.arkui.stateManagement'; import { PeerNode } from '../PeerNode'; import { UIContext } from '@ohos/arkui/UIContext'; +import { Theme } from '@ohos/arkui/theme'; +import { ArkThemeScopeManager } from "arkui/handwritten/theme/ArkThemeScopeManager"; export interface PageLifeCycle { onPageShow(): void {} @@ -52,6 +54,8 @@ export class CustomDelegate extends this.uiContext = uiContext; this.instance = instance; this.instance.setDelegate(this); + + ArkThemeScopeManager.getInstance().onViewPUCreate(this); } get isCustomLayout(): boolean { @@ -187,6 +191,8 @@ export class CustomDelegate extends // Theme onWillApplyTheme(theme: Theme): void { // TODO: this.instance.onWillApplyTheme(theme); + this.instance.onWillApplyTheme(theme); + console.log(`FZY CustomDelegate onWillApplyTheme`); } protected __initializeStruct( @@ -233,6 +239,10 @@ export class CustomDelegate extends onCleanup(): void { this.aboutToDisappear(); } + + onGlobalThemeChanged(theme: Theme): void { + this.onWillApplyTheme(theme); + } } function createInstance( diff --git a/frameworks/bridge/arkts_frontend/koala_projects/arkoala-arkts/arkui-ohos/src/handwritten/component/extendableComponent.ts b/frameworks/bridge/arkts_frontend/koala_projects/arkoala-arkts/arkui-ohos/src/handwritten/component/extendableComponent.ts index 0901bbe31de..a7f4b1f8d24 100644 --- a/frameworks/bridge/arkts_frontend/koala_projects/arkoala-arkts/arkui-ohos/src/handwritten/component/extendableComponent.ts +++ b/frameworks/bridge/arkts_frontend/koala_projects/arkoala-arkts/arkui-ohos/src/handwritten/component/extendableComponent.ts @@ -26,6 +26,7 @@ import { } from '@ohos.arkui.stateManagement'; import { UIContext } from '@ohos/arkui/UIContext'; import { PeerNode } from '../PeerNode'; +import { Theme } from "@ohos/arkui/theme"; export interface LifeCycle { aboutToAppear(): void {} @@ -162,4 +163,6 @@ export abstract class ExtendableComponent implements LifeCycle { } return ret; } + + onWillApplyTheme(theme: Theme) {} } \ No newline at end of file diff --git a/frameworks/bridge/arkts_frontend/koala_projects/arkoala-arkts/arkui-ohos/src/handwritten/theme/ArkThemeScope.ts b/frameworks/bridge/arkts_frontend/koala_projects/arkoala-arkts/arkui-ohos/src/handwritten/theme/ArkThemeScope.ts index f16573a6ba9..74321b000ab 100644 --- a/frameworks/bridge/arkts_frontend/koala_projects/arkoala-arkts/arkui-ohos/src/handwritten/theme/ArkThemeScope.ts +++ b/frameworks/bridge/arkts_frontend/koala_projects/arkoala-arkts/arkui-ohos/src/handwritten/theme/ArkThemeScope.ts @@ -18,15 +18,17 @@ import { ThemeColorMode } from "arkui/component/common"; import { ArkThemeBase } from './ArkThemeBase'; import { WithThemeOptions } from 'arkui/component/withTheme'; import { int32 } from "@koalaui/common"; +import { ArkStructBase } from 'arkui/ArkStructBase'; +import { ArkCustomComponent } from 'arkui/ArkCustomComponent'; -class ArkThemeScopeItem { +export class ArkThemeScopeItem { elmtId: int32 = -1; // ownerId: number; - // owner: ViewPuInternal; + owner?: ArkCustomComponent; name: string = ""; isInWhiteList?: boolean = undefined; // the CustomComponent with same elmtId, receives onWillApplyTheme callback - // listener?: ViewPuInternal | undefined = undefined; + listener?: ArkCustomComponent = undefined; } class ArkThemeScopeArray extends Array { @@ -138,23 +140,25 @@ export class ArkThemeScope { * * @param listener the Custom component */ - // addCustomListenerInScope(listener: ViewPuInternal) { - // const len = this.components ? this.components.length : -1; - // if (len <= 0) { - // return; - // } - // const listenerId = listener.id__(); - // // the last ThemeScopeItem probably corresponds to Custom component - // let themeScopeItem = this.components[len - 1]; - // if (themeScopeItem.elmtId === listenerId) { - // themeScopeItem.listener = listener; - // return; - // } - // themeScopeItem = this.components.find((item) => item.elmtId === listenerId); - // if (themeScopeItem) { - // themeScopeItem.listener = listener; - // } - // } + addCustomListenerInScope(listener: ArkCustomComponent) { + console.log(`FZY addCustomListenerInScope 111`); + const len = this.components ? this.components!.length : -1; + if (len <= 0) { + return; + } + const listenerId = listener.getPeer()!.getId(); + console.log(`FZY addCustomListenerInScope 222, ${listenerId}`); + // the last ThemeScopeItem probably corresponds to Custom component + let themeScopeItem = this.components![len - 1]; + if (themeScopeItem.elmtId === listenerId) { + themeScopeItem.listener = listener; + return; + } + let searchThemeScope = this.components!.find((item) => item.elmtId === listenerId); + if (searchThemeScope) { + searchThemeScope.listener = listener; + } + } /** * Remove components from the current theme scope by elmtId diff --git a/frameworks/bridge/arkts_frontend/koala_projects/arkoala-arkts/arkui-ohos/src/handwritten/theme/ArkThemeScopeManager.ts b/frameworks/bridge/arkts_frontend/koala_projects/arkoala-arkts/arkui-ohos/src/handwritten/theme/ArkThemeScopeManager.ts index 70e3b40d416..5425ec0b777 100644 --- a/frameworks/bridge/arkts_frontend/koala_projects/arkoala-arkts/arkui-ohos/src/handwritten/theme/ArkThemeScopeManager.ts +++ b/frameworks/bridge/arkts_frontend/koala_projects/arkoala-arkts/arkui-ohos/src/handwritten/theme/ArkThemeScopeManager.ts @@ -13,7 +13,7 @@ * limitations under the License. */ -import { CustomTheme, Colors } from '@ohos/arkui/theme'; +import { CustomTheme, Colors, Theme } from '@ohos/arkui/theme'; import { ThemeColorMode } from 'arkui/component/common'; import { ArkThemeBase } from './ArkThemeBase'; import { ArkSystemTheme } from './system/ArkSystemTheme'; @@ -22,11 +22,14 @@ import { ArkThemeImpl } from './ArkThemeImpl'; import { ArkThemeNativeHelper } from './ArkThemeNativeHelper'; import { WithThemeOptions } from '../../component/withTheme'; import { ArkUIAniModule } from '../../ani/arkts/ArkUIAniModule'; -import { int32 } from "@koalaui/common"; -import { ArkThemeScope } from './ArkThemeScope'; +import { int32 } from '@koalaui/common'; +import { ArkThemeScope, ArkThemeScopeItem } from './ArkThemeScope'; import { ArkColorsImpl } from './ArkColorsImpl'; - -type ViewPuInternal = Object; +import { ArkCustomComponent } from 'arkui/ArkCustomComponent'; +import { ArkThemeWhiteList } from './ArkThemeWhiteList'; +import { ArkCommonMethodComponent } from 'arkui/component/common'; +import { GlobalStateManager, StateManagerImpl } from "@koalaui/runtime"; +import { findPeerNode } from "arkui/PeerNode"; export class ArkThemeScopeManager { private static instance: ArkThemeScopeManager | undefined = undefined; @@ -34,7 +37,7 @@ export class ArkThemeScopeManager { /** * Theme update listeners */ - private listeners: ViewPuInternal[] = []; + private listeners: ArkCustomComponent[] = []; /** * The default Theme */ @@ -80,6 +83,8 @@ export class ArkThemeScopeManager { */ private ifElseLastScope?: ArkThemeScope = undefined; + private componentsThemeScope: Map = new Map(); + /** * Obtain System Colors * @@ -95,7 +100,7 @@ export class ArkThemeScopeManager { * @param colorMode local color mode */ onEnterLocalColorMode(colorMode: ThemeColorMode) { - console.warn(`FZY onEnterLocalColorMode ${colorMode}`) + console.warn(`FZY onEnterLocalColorMode ${colorMode}`); ArkUIAniModule._UpdateColorMode(colorMode); } @@ -103,7 +108,7 @@ export class ArkThemeScopeManager { * Exit from the local color mode scope */ onExitLocalColorMode() { - console.warn(`FZY onExitLocalColorMode`) + console.warn(`FZY onExitLocalColorMode`); ArkUIAniModule._RestoreColorMode(); } @@ -119,12 +124,12 @@ export class ArkThemeScopeManager { return false; } return true; - }) + }); } /** - * Start for IfElse branch update - */ + * Start for IfElse branch update + */ onIfElseBranchUpdateEnter() { if (this.ifElseLastScope) { this.ifElseScopes.push(this.ifElseLastScope!); @@ -132,10 +137,10 @@ export class ArkThemeScopeManager { } /** - * Destroy theme scope - * - * @param scope theme scope instance - */ + * Destroy theme scope + * + * @param scope theme scope instance + */ private onScopeDestroyInternal(scope: ArkThemeScope) { // unbind theme from scope const theme = scope.getTheme(); @@ -151,21 +156,97 @@ export class ArkThemeScopeManager { ArkUIAniModule._RemoveThemeInNative(scope.getWithThemeId()); } -/** + /** + * Handle create event for CustomComponent which can keep theme scopes + * + * @param ownerComponent theme scope changes listener + */ + public onViewPUCreate(ownerComponent: ArkCustomComponent) { + console.log(`FZY onViewPUCreate `) + this.subscribeListener(ownerComponent); + const peer = ownerComponent.getPeer(); + if (peer) { + const peerId = peer.getId(); + const themeScope = this.scopeForElmtId(peerId); + if (!this.componentsThemeScope.has(peerId)) { + this.componentsThemeScope.set(peer.getId(), themeScope); + } + themeScope?.addCustomListenerInScope(ownerComponent); + } + } + + /** + * Handle close event for CustomComponent which can keep theme scopes + * + * @param ownerComponent is the closing CustomComponent + */ + onViewPUDelete(ownerComponent: ArkCustomComponent) { + // unsubscribe + this.unsubscribeListener(ownerComponent); + + // remove scopes that are related to CustomComponent + const ownerComponentId: number = ownerComponent.getPeer()!.getId(); + this.themeScopes = this.themeScopes?.filter((scope) => { + if (scope.getOwnerComponentId() === ownerComponentId) { + this.onScopeDestroyInternal(scope); + return false; + } + return true; + }); + } + + /** + * Subscribe listener to theme scope changes events + * + * @param listener theme scope changes listener + */ + private subscribeListener(listener: ArkCustomComponent) { + console.log(`FZY subscribeListener 111`); + if (this.listeners.includes(listener)) { + console.log(`FZY subscribeListener 222`); + return; + } + console.log(`FZY subscribeListener 333`); + this.listeners.push(listener); + } + + /** + * Unsubscribe listener from theme scope changes events + * + * @param listener theme scope changes listener + */ + private unsubscribeListener(listener: ArkCustomComponent) { + const index = this.listeners.indexOf(listener, 0); + if (index > -1) { + this.listeners.splice(index, 1); + } + const peer = listener.getPeer(); + if (!peer) { + return; + } + const elmtId = peer.getId(); + const scope = this.componentsThemeScope.get(elmtId); + if (scope) { + scope.removeComponentFromScope(elmtId); + this.componentsThemeScope.delete(elmtId); + } + } + + /** * Handle enter to the theme scope * * @param withThemeId WithTheme container`s elmtId * @param withThemeOptions WithTheme container`s options */ onScopeEnter(withThemeId: number, withThemeOptions: WithThemeOptions, theme: ArkThemeBase) { - console.log(`FZY onScopeEnter ${withThemeId}, ${this.handledIsFirstRender}`) + console.log(`FZY onScopeEnter ${withThemeId}, ${this.handledIsFirstRender}`); // save theme scope id on scope enter this.lastThemeScopeId = withThemeId; if (this.handledIsFirstRender === true) { // create theme scope - let themeScope = new ArkThemeScope(this.handledOwnerComponentId, withThemeId, withThemeOptions, theme); + let themeScope = new ArkThemeScope(withThemeId, withThemeId, withThemeOptions, theme); // keep created scope to the array of the scopes under construction - console.log(`FZY onScopeEnter push`) + console.log(`FZY onScopeEnter push`); this.localThemeScopes.push(themeScope); if (!this.themeScopes) { this.themeScopes = new Array(); @@ -174,11 +255,11 @@ export class ArkThemeScopeManager { this.themeScopes!.push(themeScope); } else { // retrieve existing theme scope by WithTheme elmtId - const scope = this.themeScopes?.find(item => item.getWithThemeId() === withThemeId); + const scope = this.themeScopes?.find((item) => item.getWithThemeId() === withThemeId); // update WithTheme options scope?.updateWithThemeOptions(withThemeOptions, theme); // re-render all components from the scope - // this.forceRerenderScope(scope); + this.forceRerenderScope(scope); } } @@ -188,7 +269,7 @@ export class ArkThemeScopeManager { onScopeExit() { // remove top theme scope from the array of scopes under construction if (this.handledIsFirstRender === true) { - console.log(`FZY onScopeExit pop`) + console.log(`FZY onScopeExit pop`); this.localThemeScopes.pop(); } } @@ -206,13 +287,14 @@ export class ArkThemeScopeManager { } // fast way to get theme scope for the first rendered component if (this.handledIsFirstRender) { - if (this.localThemeScopes.length > 0) { // current cunstructed scope + if (this.localThemeScopes.length > 0) { + // current cunstructed scope return this.localThemeScopes[this.localThemeScopes.length - 1]; } } // common way to get scope for the component - return this.themeScopes?.find(item => item.isComponentInScope(elmtId)); + return this.themeScopes?.find((item) => item.isComponentInScope(elmtId)); } /** @@ -222,15 +304,15 @@ export class ArkThemeScopeManager { * @returns theme instance */ static cloneCustomThemeWithExpand(customTheme?: CustomTheme): CustomTheme | undefined { - console.log(`FZY cloneCustomThemeWithExpand 111, customTheme`) + console.log(`FZY cloneCustomThemeWithExpand 111, customTheme`); const theme = ArkThemeBase.copyCustomTheme(customTheme); - console.log('FZY cloneCustomThemeWithExpand 222') - + console.log('FZY cloneCustomThemeWithExpand 222'); + if (theme?.colors) { - console.log('FZY cloneCustomThemeWithExpand 333') + console.log('FZY cloneCustomThemeWithExpand 333'); ArkColorsImpl.expandByBrandColor(theme!.colors!); } - console.log('FZY cloneCustomThemeWithExpand 555') + console.log('FZY cloneCustomThemeWithExpand 555'); return theme; } @@ -255,23 +337,25 @@ export class ArkThemeScopeManager { /** * Notifies listeners about app Theme change */ - private notifyGlobalThemeChanged() { + private notifyGlobalThemeChanged(theme: Theme) { this.listeners.forEach((listener) => { - // if (listener.parent_ === undefined) { - // listener.onGlobalThemeChanged(); - // } + listener.onGlobalThemeChanged(theme); }); } setDefaultTheme(customTheme: CustomTheme) { - console.error(`FZY manager setDefaultTheme customTheme ${JSON.stringify(ArkThemeNativeHelper.convertColorsToArray(customTheme!.colors!))}`) + console.error(`FZY manager setDefaultTheme customTheme`); // unbind previous default theme from 0 theme scope this.defaultTheme?.unbindFromScope(0); this.defaultTheme = ArkThemeScopeManager.systemTheme; const cloneTheme = ArkThemeScopeManager.cloneCustomThemeWithExpand(customTheme); - console.error(`FZY manager setDefaultTheme cloneTheme ${JSON.stringify(ArkThemeNativeHelper.convertColorsToArray(cloneTheme!.colors!))}`) + console.error(`FZY manager setDefaultTheme cloneTheme`); this.defaultTheme = this.makeTheme(cloneTheme, ThemeColorMode.SYSTEM); - console.error(`FZY manager setDefaultTheme defaultTheme ${JSON.stringify(ArkThemeNativeHelper.convertColorsToArray(this.defaultTheme!.colors!))}`) + console.error( + `FZY manager setDefaultTheme defaultTheme ${JSON.stringify( + ArkThemeNativeHelper.convertColorsToArray(this.defaultTheme!.colors!) + )}` + ); // bind new default theme to 0 theme scope this.defaultTheme?.bindToScope(0); @@ -280,7 +364,7 @@ export class ArkThemeScopeManager { // new approach to apply theme in native side ArkThemeNativeHelper.setDefaultTheme(cloneTheme); - this.notifyGlobalThemeChanged(); + this.notifyGlobalThemeChanged(this.defaultTheme!); } static getInstance(): ArkThemeScopeManager { if (!ArkThemeScopeManager.instance) { @@ -290,7 +374,7 @@ export class ArkThemeScopeManager { } onComponentCreateEnter(componentName: string, elmtId: int32 | undefined, isFirstRender: boolean) { - console.log(`FZY onComponentCreateEnter ${componentName} ${elmtId}, isFirst ${isFirstRender}`) + console.log(`FZY onComponentCreateEnter ${componentName} ${elmtId}, isFirst ${isFirstRender}`); this.handledIsFirstRender = isFirstRender; this.handledComponentElmtId = elmtId; @@ -310,9 +394,13 @@ export class ArkThemeScopeManager { // we need to keep component to the theme scope before first render if (isFirstRender) { - console.log(`FZY onComponentCreateEnter currentLocalScope localThemeScopes ${this.localThemeScopes.length}`) - const currentLocalScope: ArkThemeScope | undefined = this.localThemeScopes.length > 0 ? this.localThemeScopes[this.localThemeScopes.length - 1] : undefined; - const currentIfElseScope: ArkThemeScope | undefined = this.ifElseScopes.length > 0 ? this.ifElseScopes[this.ifElseScopes.length - 1] : undefined; + console.log( + `FZY onComponentCreateEnter currentLocalScope localThemeScopes ${this.localThemeScopes.length}` + ); + const currentLocalScope: ArkThemeScope | undefined = + this.localThemeScopes.length > 0 ? this.localThemeScopes[this.localThemeScopes.length - 1] : undefined; + const currentIfElseScope: ArkThemeScope | undefined = + this.ifElseScopes.length > 0 ? this.ifElseScopes[this.ifElseScopes.length - 1] : undefined; if (currentLocalScope) { // keep component to the current constructed scope scope = currentLocalScope; @@ -347,10 +435,10 @@ export class ArkThemeScopeManager { } onComponentCreateExit(elmtId?: int32) { - console.log(`FZY onComponentCreateExit ${elmtId}`) + console.log(`FZY onComponentCreateExit ${elmtId}`); // trigger for exit local color mode for the component after rendering if (this.handledColorMode === ThemeColorMode.LIGHT || this.handledColorMode === ThemeColorMode.DARK) { - console.log(`FZY onComponentCreateExit ${elmtId}, colorMode: ${this.handledColorMode}`) + console.log(`FZY onComponentCreateExit ${elmtId}, colorMode: ${this.handledColorMode}`); this.onExitLocalColorMode(); } @@ -368,4 +456,66 @@ export class ArkThemeScopeManager { ArkUIAniModule._SetThemeScopeId(currentThemeScopeId); } } + + /** + * Trigger re-render for all components in scope + * + * @param scope scope need to be re-rendered + * @returns + */ + private forceRerenderScope(scope: ArkThemeScope | undefined) { + if (scope === undefined) { + return; + } + const theme: Theme = scope?.getTheme() ?? this.defaultTheme ?? ArkThemeScopeManager.systemTheme; + scope + .componentsInScope() + ?.forEach((item) => this.notifyScopeThemeChanged(item, theme, scope.isColorModeChanged())); + } + + /** + * Notify listeners to re-render component + * + * @param elmtId component`s elmtId as number + * @param themeWillApply Theme that should be passed to onWIllApplyTheme callback + * @param isColorModeChanged notifies about specific case + */ + private notifyScopeThemeChanged(item: ArkThemeScopeItem, themeWillApply: Theme, isColorModeChanged: boolean) { + if (item.owner) { + const listener = item.owner; + if (isColorModeChanged) { + // we need to redraw all nodes if developer set new local colorMode + // listener.forceRerenderNode(item.elmtId); + } else { + // take whitelist info from cache item + let isInWhiteList = item.isInWhiteList; + if (isInWhiteList === undefined) { + // if whitelist info is undefined we have check whitelist directly + isInWhiteList = ArkThemeWhiteList.isInWhiteList(item.name); + // keep result in cache item for the next checks + item.isInWhiteList = isInWhiteList; + } + if (isInWhiteList === true) { + // redraw node only if component within whitelist + // listener.forceRerenderNode(item.elmtId); + } + } + } + if (item.listener) { + const listener = item.listener as ArkCustomComponent; + listener.onWillApplyTheme(themeWillApply); + } + } + + public applyParentThemeScopeId(component: ArkCommonMethodComponent): void { + const stateManager = GlobalStateManager.instance as StateManagerImpl; + const scope = stateManager.current; + const parentRef = scope?.parent?.nodeRef; + console.log(`FZY Text NodeAttach ${parentRef}`); + const parentPeer = parentRef ? findPeerNode(parentRef) : undefined; + if (parentPeer && parentPeer.peer && component.getPeer()) { + console.info(`FZY ArkTextPeer parent ${parentPeer}`) + ArkUIAniModule._ApplyParentThemeScopeId(component.getPeer().getPeerPtr(), parentPeer.getPeerPtr()); + } + } } diff --git a/frameworks/bridge/arkts_frontend/koala_projects/arkoala-arkts/arkui-ohos/src/handwritten/theme/ArkThemeWhiteList.ts b/frameworks/bridge/arkts_frontend/koala_projects/arkoala-arkts/arkui-ohos/src/handwritten/theme/ArkThemeWhiteList.ts new file mode 100644 index 00000000000..b3380f51b97 --- /dev/null +++ b/frameworks/bridge/arkts_frontend/koala_projects/arkoala-arkts/arkui-ohos/src/handwritten/theme/ArkThemeWhiteList.ts @@ -0,0 +1,62 @@ +/* + * Copyright (c) 2024-2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +import { int32 } from "@koalaui/compat"; + +/** + * Class is used to keep built-in components whitelist for Theme application + */ +export class ArkThemeWhiteList { + // add to list only names of built-in components which support ArkTheme + // strongly recommended to use alphabetical order + private static whiteList: Array = [ + 'AlphabetIndexer', + 'Badge', + 'Button', + 'DataPanel', + 'Menu', + 'MenuItem', + 'PatternLock', + 'QRCode', + 'Radio', + 'Scroll', + 'Swiper', + 'Text', + ]; + + /** + * Check whether component is in whitelist + * + * @param componentName original component name + * @returns true if the component is in whitelist, otherwise false + */ + static isInWhiteList(componentName: string): boolean { + let start: int32 = 0; + let end: int32 = (ArkThemeWhiteList.whiteList.length - 1) as int32; + while (start <= end) { + let mid: int32 = (start + end) >> 1; + if (ArkThemeWhiteList.whiteList[mid].localeCompare(componentName) === 0) { + return true; + } + if (ArkThemeWhiteList.whiteList[mid].localeCompare(componentName) === 1) { + end = mid - 1; + } else { + start = mid + 1; + } + } + return false; + } +} + -- Gitee From cb3d9451173eabdfb0b41047e6a7649aaf43da80 Mon Sep 17 00:00:00 2001 From: fangzhiyuan Date: Sun, 20 Jul 2025 15:03:26 +0800 Subject: [PATCH 05/11] =?UTF-8?q?=E8=B0=83=E8=AF=95=E4=BF=A1=E6=81=AF?= =?UTF-8?q?=E7=A7=BB=E9=99=A4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: fangzhiyuan Change-Id: I31dc35b5149af5da2370216b4c05bb7a928f14e2 --- .../handwritten/component/customComponent.ts | 1 - .../src/handwritten/theme/ArkColorsImpl.ts | 2 -- .../src/handwritten/theme/ArkThemeScope.ts | 2 -- .../handwritten/theme/ArkThemeScopeManager.ts | 31 ------------------- .../incremental/runtime/src/states/State.ts | 2 -- .../ark_theme/theme_apply/js_theme_utils.h | 2 -- frameworks/core/interfaces/native/BUILD.gn | 1 - .../core/interfaces/native/ani/ani_theme.cpp | 4 --- .../core/interfaces/native/ani/ani_theme.h | 4 --- .../native/ani/ani_theme_module.cpp | 3 -- .../native/ani/common_ani_modifier.cpp | 2 -- .../implementation/theme/ani_button_theme.h | 2 -- .../implementation/theme/ani_theme_utils.h | 3 -- 13 files changed, 59 deletions(-) diff --git a/frameworks/bridge/arkts_frontend/koala_projects/arkoala-arkts/arkui-ohos/src/handwritten/component/customComponent.ts b/frameworks/bridge/arkts_frontend/koala_projects/arkoala-arkts/arkui-ohos/src/handwritten/component/customComponent.ts index 69b07e64879..53492435acf 100644 --- a/frameworks/bridge/arkts_frontend/koala_projects/arkoala-arkts/arkui-ohos/src/handwritten/component/customComponent.ts +++ b/frameworks/bridge/arkts_frontend/koala_projects/arkoala-arkts/arkui-ohos/src/handwritten/component/customComponent.ts @@ -192,7 +192,6 @@ export class CustomDelegate extends onWillApplyTheme(theme: Theme): void { // TODO: this.instance.onWillApplyTheme(theme); this.instance.onWillApplyTheme(theme); - console.log(`FZY CustomDelegate onWillApplyTheme`); } protected __initializeStruct( diff --git a/frameworks/bridge/arkts_frontend/koala_projects/arkoala-arkts/arkui-ohos/src/handwritten/theme/ArkColorsImpl.ts b/frameworks/bridge/arkts_frontend/koala_projects/arkoala-arkts/arkui-ohos/src/handwritten/theme/ArkColorsImpl.ts index 79866421135..acc0bbe96c1 100644 --- a/frameworks/bridge/arkts_frontend/koala_projects/arkoala-arkts/arkui-ohos/src/handwritten/theme/ArkColorsImpl.ts +++ b/frameworks/bridge/arkts_frontend/koala_projects/arkoala-arkts/arkui-ohos/src/handwritten/theme/ArkColorsImpl.ts @@ -216,8 +216,6 @@ export class ArkColorsImpl implements Colors { } static expandByBrandColor(colors: CustomColors) { - console.warn(`FZY expandByBrandColor ${Object.keys(colors)}`) - console.warn(`FZY expandByBrandColor ${Object.values(colors)}`) if (colors!.brand) { const brandColors: BrandColors = ArkColorsImpl.makeBrandColors(colors.brand); colors.fontEmphasize = colors.fontEmphasize ?? brandColors.primary!; diff --git a/frameworks/bridge/arkts_frontend/koala_projects/arkoala-arkts/arkui-ohos/src/handwritten/theme/ArkThemeScope.ts b/frameworks/bridge/arkts_frontend/koala_projects/arkoala-arkts/arkui-ohos/src/handwritten/theme/ArkThemeScope.ts index 74321b000ab..4bb7ff5467c 100644 --- a/frameworks/bridge/arkts_frontend/koala_projects/arkoala-arkts/arkui-ohos/src/handwritten/theme/ArkThemeScope.ts +++ b/frameworks/bridge/arkts_frontend/koala_projects/arkoala-arkts/arkui-ohos/src/handwritten/theme/ArkThemeScope.ts @@ -141,13 +141,11 @@ export class ArkThemeScope { * @param listener the Custom component */ addCustomListenerInScope(listener: ArkCustomComponent) { - console.log(`FZY addCustomListenerInScope 111`); const len = this.components ? this.components!.length : -1; if (len <= 0) { return; } const listenerId = listener.getPeer()!.getId(); - console.log(`FZY addCustomListenerInScope 222, ${listenerId}`); // the last ThemeScopeItem probably corresponds to Custom component let themeScopeItem = this.components![len - 1]; if (themeScopeItem.elmtId === listenerId) { diff --git a/frameworks/bridge/arkts_frontend/koala_projects/arkoala-arkts/arkui-ohos/src/handwritten/theme/ArkThemeScopeManager.ts b/frameworks/bridge/arkts_frontend/koala_projects/arkoala-arkts/arkui-ohos/src/handwritten/theme/ArkThemeScopeManager.ts index 5425ec0b777..ee3ab884176 100644 --- a/frameworks/bridge/arkts_frontend/koala_projects/arkoala-arkts/arkui-ohos/src/handwritten/theme/ArkThemeScopeManager.ts +++ b/frameworks/bridge/arkts_frontend/koala_projects/arkoala-arkts/arkui-ohos/src/handwritten/theme/ArkThemeScopeManager.ts @@ -100,7 +100,6 @@ export class ArkThemeScopeManager { * @param colorMode local color mode */ onEnterLocalColorMode(colorMode: ThemeColorMode) { - console.warn(`FZY onEnterLocalColorMode ${colorMode}`); ArkUIAniModule._UpdateColorMode(colorMode); } @@ -108,7 +107,6 @@ export class ArkThemeScopeManager { * Exit from the local color mode scope */ onExitLocalColorMode() { - console.warn(`FZY onExitLocalColorMode`); ArkUIAniModule._RestoreColorMode(); } @@ -162,7 +160,6 @@ export class ArkThemeScopeManager { * @param ownerComponent theme scope changes listener */ public onViewPUCreate(ownerComponent: ArkCustomComponent) { - console.log(`FZY onViewPUCreate `) this.subscribeListener(ownerComponent); const peer = ownerComponent.getPeer(); if (peer) { @@ -201,12 +198,9 @@ export class ArkThemeScopeManager { * @param listener theme scope changes listener */ private subscribeListener(listener: ArkCustomComponent) { - console.log(`FZY subscribeListener 111`); if (this.listeners.includes(listener)) { - console.log(`FZY subscribeListener 222`); return; } - console.log(`FZY subscribeListener 333`); this.listeners.push(listener); } @@ -239,14 +233,12 @@ export class ArkThemeScopeManager { * @param withThemeOptions WithTheme container`s options */ onScopeEnter(withThemeId: number, withThemeOptions: WithThemeOptions, theme: ArkThemeBase) { - console.log(`FZY onScopeEnter ${withThemeId}, ${this.handledIsFirstRender}`); // save theme scope id on scope enter this.lastThemeScopeId = withThemeId; if (this.handledIsFirstRender === true) { // create theme scope let themeScope = new ArkThemeScope(withThemeId, withThemeId, withThemeOptions, theme); // keep created scope to the array of the scopes under construction - console.log(`FZY onScopeEnter push`); this.localThemeScopes.push(themeScope); if (!this.themeScopes) { this.themeScopes = new Array(); @@ -269,7 +261,6 @@ export class ArkThemeScopeManager { onScopeExit() { // remove top theme scope from the array of scopes under construction if (this.handledIsFirstRender === true) { - console.log(`FZY onScopeExit pop`); this.localThemeScopes.pop(); } } @@ -304,15 +295,11 @@ export class ArkThemeScopeManager { * @returns theme instance */ static cloneCustomThemeWithExpand(customTheme?: CustomTheme): CustomTheme | undefined { - console.log(`FZY cloneCustomThemeWithExpand 111, customTheme`); const theme = ArkThemeBase.copyCustomTheme(customTheme); - console.log('FZY cloneCustomThemeWithExpand 222'); if (theme?.colors) { - console.log('FZY cloneCustomThemeWithExpand 333'); ArkColorsImpl.expandByBrandColor(theme!.colors!); } - console.log('FZY cloneCustomThemeWithExpand 555'); return theme; } @@ -327,9 +314,6 @@ export class ArkThemeScopeManager { const baselineTheme = this.defaultTheme ?? ArkThemeScopeManager.systemTheme; // try to take theme from the cache const theme = ArkThemeCache.getInstance().get(baselineTheme.id, customTheme, colorMode); - if (theme) { - console.info(`FZY makeTheme get theme from cache`); - } // return theme instance from cache or create new theme instance return theme ? theme : new ArkThemeImpl(customTheme, colorMode, baselineTheme); } @@ -344,18 +328,11 @@ export class ArkThemeScopeManager { } setDefaultTheme(customTheme: CustomTheme) { - console.error(`FZY manager setDefaultTheme customTheme`); // unbind previous default theme from 0 theme scope this.defaultTheme?.unbindFromScope(0); this.defaultTheme = ArkThemeScopeManager.systemTheme; const cloneTheme = ArkThemeScopeManager.cloneCustomThemeWithExpand(customTheme); - console.error(`FZY manager setDefaultTheme cloneTheme`); this.defaultTheme = this.makeTheme(cloneTheme, ThemeColorMode.SYSTEM); - console.error( - `FZY manager setDefaultTheme defaultTheme ${JSON.stringify( - ArkThemeNativeHelper.convertColorsToArray(this.defaultTheme!.colors!) - )}` - ); // bind new default theme to 0 theme scope this.defaultTheme?.bindToScope(0); @@ -374,7 +351,6 @@ export class ArkThemeScopeManager { } onComponentCreateEnter(componentName: string, elmtId: int32 | undefined, isFirstRender: boolean) { - console.log(`FZY onComponentCreateEnter ${componentName} ${elmtId}, isFirst ${isFirstRender}`); this.handledIsFirstRender = isFirstRender; this.handledComponentElmtId = elmtId; @@ -394,9 +370,6 @@ export class ArkThemeScopeManager { // we need to keep component to the theme scope before first render if (isFirstRender) { - console.log( - `FZY onComponentCreateEnter currentLocalScope localThemeScopes ${this.localThemeScopes.length}` - ); const currentLocalScope: ArkThemeScope | undefined = this.localThemeScopes.length > 0 ? this.localThemeScopes[this.localThemeScopes.length - 1] : undefined; const currentIfElseScope: ArkThemeScope | undefined = @@ -435,10 +408,8 @@ export class ArkThemeScopeManager { } onComponentCreateExit(elmtId?: int32) { - console.log(`FZY onComponentCreateExit ${elmtId}`); // trigger for exit local color mode for the component after rendering if (this.handledColorMode === ThemeColorMode.LIGHT || this.handledColorMode === ThemeColorMode.DARK) { - console.log(`FZY onComponentCreateExit ${elmtId}, colorMode: ${this.handledColorMode}`); this.onExitLocalColorMode(); } @@ -511,10 +482,8 @@ export class ArkThemeScopeManager { const stateManager = GlobalStateManager.instance as StateManagerImpl; const scope = stateManager.current; const parentRef = scope?.parent?.nodeRef; - console.log(`FZY Text NodeAttach ${parentRef}`); const parentPeer = parentRef ? findPeerNode(parentRef) : undefined; if (parentPeer && parentPeer.peer && component.getPeer()) { - console.info(`FZY ArkTextPeer parent ${parentPeer}`) ArkUIAniModule._ApplyParentThemeScopeId(component.getPeer().getPeerPtr(), parentPeer.getPeerPtr()); } } diff --git a/frameworks/bridge/arkts_frontend/koala_projects/incremental/runtime/src/states/State.ts b/frameworks/bridge/arkts_frontend/koala_projects/incremental/runtime/src/states/State.ts index 8d2a9d70a27..378515ae81c 100644 --- a/frameworks/bridge/arkts_frontend/koala_projects/incremental/runtime/src/states/State.ts +++ b/frameworks/bridge/arkts_frontend/koala_projects/incremental/runtime/src/states/State.ts @@ -181,8 +181,6 @@ export interface InternalScope { recache(newValue?: Value): Value /** @returns internal state for parameter */ param(index: int32, value: V, equivalent?: Equivalent, name?: string, contextLocal?: boolean): State - - get parent(): ManagedScope | undefined } /** diff --git a/frameworks/bridge/declarative_frontend/ark_theme/theme_apply/js_theme_utils.h b/frameworks/bridge/declarative_frontend/ark_theme/theme_apply/js_theme_utils.h index 5d2e8dda271..e87790994aa 100644 --- a/frameworks/bridge/declarative_frontend/ark_theme/theme_apply/js_theme_utils.h +++ b/frameworks/bridge/declarative_frontend/ark_theme/theme_apply/js_theme_utils.h @@ -16,7 +16,6 @@ #ifndef FRAMEWORKS_BRIDGE_DECLARATIVE_FRONTEND_THEME_JS_THEME_UTILS_H #define FRAMEWORKS_BRIDGE_DECLARATIVE_FRONTEND_THEME_JS_THEME_UTILS_H -#include #include "base/utils/utils.h" #include "bridge/common/utils/utils.h" #include "bridge/declarative_frontend/engine/jsi/jsi_declarative_engine.h" @@ -24,7 +23,6 @@ #include "bridge/js_frontend/engine/jsi/js_value.h" #include "core/components_ng/base/frame_node.h" #include "core/components_ng/base/view_stack_processor.h" -#include "core/interfaces/native/ani/ani_theme.h" namespace OHOS::Ace::Framework { class JSThemeUtils { diff --git a/frameworks/core/interfaces/native/BUILD.gn b/frameworks/core/interfaces/native/BUILD.gn index 11024a155bb..53cf3e419bc 100644 --- a/frameworks/core/interfaces/native/BUILD.gn +++ b/frameworks/core/interfaces/native/BUILD.gn @@ -188,7 +188,6 @@ template("ace_core_interfaces_native_node") { "ani/list_ani_modifier.cpp", "ani/drag_controller_ani_modifier.cpp", "ani/drag_controller_utils.cpp", - "ani/web_ani_modifier.cpp", ] } diff --git a/frameworks/core/interfaces/native/ani/ani_theme.cpp b/frameworks/core/interfaces/native/ani/ani_theme.cpp index c999b188108..707bee96dd5 100644 --- a/frameworks/core/interfaces/native/ani/ani_theme.cpp +++ b/frameworks/core/interfaces/native/ani/ani_theme.cpp @@ -36,7 +36,6 @@ void AniThemeColors::SetColors(ani_env* env, ani_array colors) // type ResourceColor = number | string | Resource ani_ref value; env->Array_Get_Ref((ani_array_ref)colors, i, &value); - LOGI("FZY AniThemeColors::SetColors %{public}s", ArktsAniUtils::JsonStringify(env, (ani_object)value).c_str()); ani_ref globalRef; env->GlobalReference_Create(value, &globalRef); @@ -59,14 +58,11 @@ Color AniThemeColors::ConvertAniValueToColor(ani_object aniValue) const Color color; RefPtr resObj; ResourceAniModifier::ParseAniColor(env, aniValue, color, resObj); - LOGI("FZY AniThemeColors::ConvertAniValueToColor %{public}s, color: %{public}s", - ArktsAniUtils::JsonStringify(env, aniValue).c_str(), color.ToString().c_str()); return color; } AniThemeColors::~AniThemeColors() { - LOGI("FZY ~AniThemeColors id: %{public}d", id_); auto* env = ArktsAniUtils::GetAniEnv(vm_); if (!env) { return; diff --git a/frameworks/core/interfaces/native/ani/ani_theme.h b/frameworks/core/interfaces/native/ani/ani_theme.h index 8614a1e866e..16dee9720ad 100644 --- a/frameworks/core/interfaces/native/ani/ani_theme.h +++ b/frameworks/core/interfaces/native/ani/ani_theme.h @@ -120,7 +120,6 @@ public: Color FontPrimary() const { - LOGI("FZY AniThemeColors FontPrimary, %{public}d", id_); return ConvertAniValueToColor(colors_[FONT_PRIMARY]); } Color FontSecondary() const @@ -355,19 +354,16 @@ public: static void AddAniTheme(int32_t themeScopeId, const AniTheme& aniTheme) { - LOGI("FZY AddAniTheme %{public}d", themeScopeId); aniThemes[themeScopeId] = aniTheme; } static void RemoveAniTheme(int32_t themeScopeId) { - LOGI("FZY RemoveAniTheme %{public}d", themeScopeId); aniThemes.erase(themeScopeId); } static bool IsAniThemeExists(int32_t themeScopeId) { - LOGI("FZY IsAniThemeExists %{public}d", themeScopeId); auto iter = aniThemes.find(themeScopeId); return iter != aniThemes.end(); } diff --git a/frameworks/core/interfaces/native/ani/ani_theme_module.cpp b/frameworks/core/interfaces/native/ani/ani_theme_module.cpp index cb3a6e3a540..115cbb483cf 100644 --- a/frameworks/core/interfaces/native/ani/ani_theme_module.cpp +++ b/frameworks/core/interfaces/native/ani/ani_theme_module.cpp @@ -30,12 +30,10 @@ namespace OHOS::Ace::NG { void AniThemeModule::UpdateColorMode(int32_t colorMode) { ColorMode colorModeValue = MapAniColorModeToColorMode(colorMode); - LOGI("FZY AniThemeModule::UpdateColorMode %{public}d", static_cast(colorModeValue)); if (colorModeValue != ColorMode::COLOR_MODE_UNDEFINED) { #if defined(ANDROID_PLATFORM) || defined(IOS_PLATFORM) UpdateColorModeForThemeConstants(colorModeValue); #else - LOGI("FZY AniThemeModule::UpdateColorMode resMgr UpdateColorMode"); ResourceManager::GetInstance().UpdateColorMode(colorModeValue); #endif auto pipelineContext = NG::PipelineContext::GetCurrentContext(); @@ -53,7 +51,6 @@ void AniThemeModule::RestoreColorMode() #if defined(ANDROID_PLATFORM) || defined(IOS_PLATFORM) UpdateColorModeForThemeConstants(colorModeValue); #else - LOGI("FZY AniThemeModule::RestoreColorMode resMgr UpdateColorMode "); ResourceManager::GetInstance().UpdateColorMode(colorModeValue); #endif } diff --git a/frameworks/core/interfaces/native/ani/common_ani_modifier.cpp b/frameworks/core/interfaces/native/ani/common_ani_modifier.cpp index 679a1907060..18fbe6a2b16 100644 --- a/frameworks/core/interfaces/native/ani/common_ani_modifier.cpp +++ b/frameworks/core/interfaces/native/ani/common_ani_modifier.cpp @@ -453,7 +453,6 @@ void SendThemeToNative(ani_env* env, ani_array colorArray, ani_int id) // save the current theme when Theme was created by WithTheme container if (AniThemeScope::isCurrentThemeDefault || themeScopeId > 0) { - LOGI("FZY SendThemeToNative set currentTheme %{public}d", id); std::optional themeOpt = std::make_optional(AniThemeScope::GetAniTheme(themeScopeId)); AniThemeScope::aniCurrentTheme.swap(themeOpt); } @@ -519,7 +518,6 @@ void SetThemeScopeId(ani_env* env, ani_int themeScopeId) ? std::make_optional(AniThemeScope::GetAniTheme(scopeId)) : std::nullopt; - LOGI("FZY SetThemeScopeId swap currentTHeme %{public}d", themeScopeId); AniThemeScope::aniCurrentTheme.swap(themeOpt); } diff --git a/frameworks/core/interfaces/native/implementation/theme/ani_button_theme.h b/frameworks/core/interfaces/native/implementation/theme/ani_button_theme.h index 746a8a8e060..7402184424a 100644 --- a/frameworks/core/interfaces/native/implementation/theme/ani_button_theme.h +++ b/frameworks/core/interfaces/native/implementation/theme/ani_button_theme.h @@ -57,8 +57,6 @@ private: // normal ViewStackModel::GetInstance()->SetVisualState(VisualState::NORMAL); if (isLabelButton) { - LOGI("FZY ButtonTheme ApplyTheme FontColor %{public}s", - AniButtonTheme::FontColor(themeColors).ToString().c_str()); ButtonModel::GetInstance()->SetFontColor(AniButtonTheme::FontColor(themeColors)); } ButtonModel::GetInstance()->BackgroundColor(AniButtonTheme::BackgroundColor(themeColors, false), true); diff --git a/frameworks/core/interfaces/native/implementation/theme/ani_theme_utils.h b/frameworks/core/interfaces/native/implementation/theme/ani_theme_utils.h index 28e1b26442e..2e84a67b846 100644 --- a/frameworks/core/interfaces/native/implementation/theme/ani_theme_utils.h +++ b/frameworks/core/interfaces/native/implementation/theme/ani_theme_utils.h @@ -35,9 +35,6 @@ public: static RefPtr GetThemeColors() { - if (NG::AniThemeScope::aniCurrentTheme) { - LOGI("FZY AniThemeUtils GetThemeColors %{public}d", NG::AniThemeScope::aniCurrentTheme.value().id_); - } return (NG::AniThemeScope::aniCurrentTheme) ? NG::AniThemeScope::aniCurrentTheme->Colors() : nullptr; } }; -- Gitee From 2ffe88ba2ad4fd343950835727c1a4974124ebad Mon Sep 17 00:00:00 2001 From: fangzhiyuan Date: Mon, 21 Jul 2025 22:41:19 +0800 Subject: [PATCH 06/11] =?UTF-8?q?Color=E6=9E=9A=E4=B8=BE=E5=80=BC=E9=80=82?= =?UTF-8?q?=E9=85=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: fangzhiyuan Change-Id: Iaf1a9cb4a56d87985cc45d962eea8f6a2ab3702d --- .../src/handwritten/theme/ArkColorsImpl.ts | 96 +++++++-------- .../handwritten/theme/ArkThemeNativeHelper.ts | 116 +++++++++--------- 2 files changed, 106 insertions(+), 106 deletions(-) diff --git a/frameworks/bridge/arkts_frontend/koala_projects/arkoala-arkts/arkui-ohos/src/handwritten/theme/ArkColorsImpl.ts b/frameworks/bridge/arkts_frontend/koala_projects/arkoala-arkts/arkui-ohos/src/handwritten/theme/ArkColorsImpl.ts index acc0bbe96c1..00e72be6412 100644 --- a/frameworks/bridge/arkts_frontend/koala_projects/arkoala-arkts/arkui-ohos/src/handwritten/theme/ArkColorsImpl.ts +++ b/frameworks/bridge/arkts_frontend/koala_projects/arkoala-arkts/arkui-ohos/src/handwritten/theme/ArkColorsImpl.ts @@ -246,12 +246,12 @@ export class ArkColorsImpl implements Colors { }; if (brandColor) { if (brandColor instanceof Color) { - result.primary = ArkColorsImpl.convertColorEnumToValue(brandColor) as string; - result.secondary = ArkColorsImpl.convertColorEnumToValue(brandColor) as string; - result.tertiary = ArkColorsImpl.convertColorEnumToValue(brandColor) as string; - result.fourth = ArkColorsImpl.convertColorEnumToValue(brandColor) as string; - result.fifth = ArkColorsImpl.convertColorEnumToValue(brandColor) as string; - result.sixth = ArkColorsImpl.convertColorEnumToValue(brandColor) as string; + result.primary = brandColor as string; + result.secondary = brandColor as string; + result.tertiary = brandColor as string; + result.fourth = brandColor as string; + result.fifth = brandColor as string; + result.sixth = brandColor as string; } else if (brandColor instanceof Resource) { result.primary = brandColor as Resource; result.secondary = ArkColorsImpl.makeResourceWithOpacity(brandColor as Resource, 0.6) as Resource; @@ -293,48 +293,48 @@ export class ArkColorsImpl implements Colors { return ((argbColor & 0x00ffffff) | ((outAlpha & 0xff) << 24)) >>> 0; } - static convertColorEnumToValue(color: Color): string { - switch (color) { - case Color.WHITE: - case Color.White: - return '#ffffffff'; - case Color.BLACK: - case Color.Black: - return '#ff000000'; - case Color.BLUE: - case Color.Blue: - return '#ff0000ff'; - case Color.BROWN: - case Color.Brown: - return '#ffa52a2a'; - case Color.GRAY: - case Color.Gray: - return '#ff808080'; - case Color.GREEN: - case Color.Green: - return '#ff008000'; - case Color.GREY: - case Color.Grey: - return '#ff808080'; - case Color.ORANGE: - case Color.Orange: - return '#ffffa500'; - case Color.PINK: - case Color.Pink: - return '#ffffc0cb'; - case Color.RED: - case Color.Red: - return '#ffff0000'; - case Color.YELLOW: - case Color.Yellow: - return '#ffffff00'; - case Color.TRANSPARENT: - case Color.Transparent: - return '#00000000'; - } - // Do not match the color, return the default. - return '#ff000000'; - } + // static convertColorEnumToValue(color: Color): string { + // switch (color) { + // case Color.WHITE: + // case Color.White: + // return '#ffffffff'; + // case Color.BLACK: + // case Color.Black: + // return '#ff000000'; + // case Color.BLUE: + // case Color.Blue: + // return '#ff0000ff'; + // case Color.BROWN: + // case Color.Brown: + // return '#ffa52a2a'; + // case Color.GRAY: + // case Color.Gray: + // return '#ff808080'; + // case Color.GREEN: + // case Color.Green: + // return '#ff008000'; + // case Color.GREY: + // case Color.Grey: + // return '#ff808080'; + // case Color.ORANGE: + // case Color.Orange: + // return '#ffffa500'; + // case Color.PINK: + // case Color.Pink: + // return '#ffffc0cb'; + // case Color.RED: + // case Color.Red: + // return '#ffff0000'; + // case Color.YELLOW: + // case Color.Yellow: + // return '#ffffff00'; + // case Color.TRANSPARENT: + // case Color.Transparent: + // return '#00000000'; + // } + // // Do not match the color, return the default. + // return '#ff000000'; + // } static checkIsColor(value: ResourceColor): boolean { return value instanceof Color; diff --git a/frameworks/bridge/arkts_frontend/koala_projects/arkoala-arkts/arkui-ohos/src/handwritten/theme/ArkThemeNativeHelper.ts b/frameworks/bridge/arkts_frontend/koala_projects/arkoala-arkts/arkui-ohos/src/handwritten/theme/ArkThemeNativeHelper.ts index de9ce44e35f..30042d2c345 100644 --- a/frameworks/bridge/arkts_frontend/koala_projects/arkoala-arkts/arkui-ohos/src/handwritten/theme/ArkThemeNativeHelper.ts +++ b/frameworks/bridge/arkts_frontend/koala_projects/arkoala-arkts/arkui-ohos/src/handwritten/theme/ArkThemeNativeHelper.ts @@ -71,66 +71,66 @@ export class ArkThemeNativeHelper { ArkColorsImpl.assign(srcTheme.colors, (theme as CustomTheme).colors!) } return [ - ArkThemeNativeHelper.convertColorEnumToValue(srcTheme.colors.brand), - ArkThemeNativeHelper.convertColorEnumToValue(srcTheme.colors.warning), - ArkThemeNativeHelper.convertColorEnumToValue(srcTheme.colors.alert), - ArkThemeNativeHelper.convertColorEnumToValue(srcTheme.colors.confirm), - ArkThemeNativeHelper.convertColorEnumToValue(srcTheme.colors.fontPrimary), - ArkThemeNativeHelper.convertColorEnumToValue(srcTheme.colors.fontSecondary), - ArkThemeNativeHelper.convertColorEnumToValue(srcTheme.colors.fontTertiary), - ArkThemeNativeHelper.convertColorEnumToValue(srcTheme.colors.fontFourth), - ArkThemeNativeHelper.convertColorEnumToValue(srcTheme.colors.fontEmphasize), - ArkThemeNativeHelper.convertColorEnumToValue(srcTheme.colors.fontOnPrimary), - ArkThemeNativeHelper.convertColorEnumToValue(srcTheme.colors.fontOnSecondary), - ArkThemeNativeHelper.convertColorEnumToValue(srcTheme.colors.fontOnTertiary), - ArkThemeNativeHelper.convertColorEnumToValue(srcTheme.colors.fontOnFourth), - ArkThemeNativeHelper.convertColorEnumToValue(srcTheme.colors.iconPrimary), - ArkThemeNativeHelper.convertColorEnumToValue(srcTheme.colors.iconSecondary), - ArkThemeNativeHelper.convertColorEnumToValue(srcTheme.colors.iconTertiary), - ArkThemeNativeHelper.convertColorEnumToValue(srcTheme.colors.iconFourth), - ArkThemeNativeHelper.convertColorEnumToValue(srcTheme.colors.iconEmphasize), - ArkThemeNativeHelper.convertColorEnumToValue(srcTheme.colors.iconSubEmphasize), - ArkThemeNativeHelper.convertColorEnumToValue(srcTheme.colors.iconOnPrimary), - ArkThemeNativeHelper.convertColorEnumToValue(srcTheme.colors.iconOnSecondary), - ArkThemeNativeHelper.convertColorEnumToValue(srcTheme.colors.iconOnTertiary), - ArkThemeNativeHelper.convertColorEnumToValue(srcTheme.colors.iconOnFourth), - ArkThemeNativeHelper.convertColorEnumToValue(srcTheme.colors.backgroundPrimary), - ArkThemeNativeHelper.convertColorEnumToValue(srcTheme.colors.backgroundSecondary), - ArkThemeNativeHelper.convertColorEnumToValue(srcTheme.colors.backgroundTertiary), - ArkThemeNativeHelper.convertColorEnumToValue(srcTheme.colors.backgroundFourth), - ArkThemeNativeHelper.convertColorEnumToValue(srcTheme.colors.backgroundEmphasize), - ArkThemeNativeHelper.convertColorEnumToValue(srcTheme.colors.compForegroundPrimary), - ArkThemeNativeHelper.convertColorEnumToValue(srcTheme.colors.compBackgroundPrimary), - ArkThemeNativeHelper.convertColorEnumToValue(srcTheme.colors.compBackgroundPrimaryTran), - ArkThemeNativeHelper.convertColorEnumToValue(srcTheme.colors.compBackgroundPrimaryContrary), - ArkThemeNativeHelper.convertColorEnumToValue(srcTheme.colors.compBackgroundGray), - ArkThemeNativeHelper.convertColorEnumToValue(srcTheme.colors.compBackgroundSecondary), - ArkThemeNativeHelper.convertColorEnumToValue(srcTheme.colors.compBackgroundTertiary), - ArkThemeNativeHelper.convertColorEnumToValue(srcTheme.colors.compBackgroundEmphasize), - ArkThemeNativeHelper.convertColorEnumToValue(srcTheme.colors.compBackgroundNeutral), - ArkThemeNativeHelper.convertColorEnumToValue(srcTheme.colors.compEmphasizeSecondary), - ArkThemeNativeHelper.convertColorEnumToValue(srcTheme.colors.compEmphasizeTertiary), - ArkThemeNativeHelper.convertColorEnumToValue(srcTheme.colors.compDivider), - ArkThemeNativeHelper.convertColorEnumToValue(srcTheme.colors.compCommonContrary), - ArkThemeNativeHelper.convertColorEnumToValue(srcTheme.colors.compBackgroundFocus), - ArkThemeNativeHelper.convertColorEnumToValue(srcTheme.colors.compFocusedPrimary), - ArkThemeNativeHelper.convertColorEnumToValue(srcTheme.colors.compFocusedSecondary), - ArkThemeNativeHelper.convertColorEnumToValue(srcTheme.colors.compFocusedTertiary), - ArkThemeNativeHelper.convertColorEnumToValue(srcTheme.colors.interactiveHover), - ArkThemeNativeHelper.convertColorEnumToValue(srcTheme.colors.interactivePressed), - ArkThemeNativeHelper.convertColorEnumToValue(srcTheme.colors.interactiveFocus), - ArkThemeNativeHelper.convertColorEnumToValue(srcTheme.colors.interactiveActive), - ArkThemeNativeHelper.convertColorEnumToValue(srcTheme.colors.interactiveSelect), - ArkThemeNativeHelper.convertColorEnumToValue(srcTheme.colors.interactiveClick), + srcTheme.colors.brand, + srcTheme.colors.warning, + srcTheme.colors.alert, + srcTheme.colors.confirm, + srcTheme.colors.fontPrimary, + srcTheme.colors.fontSecondary, + srcTheme.colors.fontTertiary, + srcTheme.colors.fontFourth, + srcTheme.colors.fontEmphasize, + srcTheme.colors.fontOnPrimary, + srcTheme.colors.fontOnSecondary, + srcTheme.colors.fontOnTertiary, + srcTheme.colors.fontOnFourth, + srcTheme.colors.iconPrimary, + srcTheme.colors.iconSecondary, + srcTheme.colors.iconTertiary, + srcTheme.colors.iconFourth, + srcTheme.colors.iconEmphasize, + srcTheme.colors.iconSubEmphasize, + srcTheme.colors.iconOnPrimary, + srcTheme.colors.iconOnSecondary, + srcTheme.colors.iconOnTertiary, + srcTheme.colors.iconOnFourth, + srcTheme.colors.backgroundPrimary, + srcTheme.colors.backgroundSecondary, + srcTheme.colors.backgroundTertiary, + srcTheme.colors.backgroundFourth, + srcTheme.colors.backgroundEmphasize, + srcTheme.colors.compForegroundPrimary, + srcTheme.colors.compBackgroundPrimary, + srcTheme.colors.compBackgroundPrimaryTran, + srcTheme.colors.compBackgroundPrimaryContrary, + srcTheme.colors.compBackgroundGray, + srcTheme.colors.compBackgroundSecondary, + srcTheme.colors.compBackgroundTertiary, + srcTheme.colors.compBackgroundEmphasize, + srcTheme.colors.compBackgroundNeutral, + srcTheme.colors.compEmphasizeSecondary, + srcTheme.colors.compEmphasizeTertiary, + srcTheme.colors.compDivider, + srcTheme.colors.compCommonContrary, + srcTheme.colors.compBackgroundFocus, + srcTheme.colors.compFocusedPrimary, + srcTheme.colors.compFocusedSecondary, + srcTheme.colors.compFocusedTertiary, + srcTheme.colors.interactiveHover, + srcTheme.colors.interactivePressed, + srcTheme.colors.interactiveFocus, + srcTheme.colors.interactiveActive, + srcTheme.colors.interactiveSelect, + srcTheme.colors.interactiveClick, ]; } - private static convertColorEnumToValue(color: ResourceColor): ResourceColor { - if (ArkColorsImpl.checkIsColor(color)) { - return ArkColorsImpl.convertColorEnumToValue(color as Color); - } - return color; - } + // private static convertColorEnumToValue(color: ResourceColor): ResourceColor { + // if (ArkColorsImpl.checkIsColor(color)) { + // return ArkColorsImpl.convertColorEnumToValue(color as Color); + // } + // return color; + // } public static convertColorsToArray(colors: Colors | CustomColors | undefined): ResourceColor[] { const basisColors = ArkThemeScopeManager.getSystemColors(); @@ -141,7 +141,7 @@ export class ArkThemeNativeHelper { for (let attr of Object.values(colors)) { const value: ResourceColor = attr as ResourceColor; if (ArkColorsImpl.checkIsColor(value)) { - colorArray.push(ArkColorsImpl.convertColorEnumToValue(value as Color)); + colorArray.push(value as Color); continue; } colorArray.push(value); -- Gitee From 28f09c8d553d4884ca7bec58d9b97942a1554519 Mon Sep 17 00:00:00 2001 From: fangzhiyuan Date: Sun, 20 Jul 2025 21:13:24 +0800 Subject: [PATCH 07/11] =?UTF-8?q?Ani=E6=9E=B6=E6=9E=84=E8=B0=83=E6=95=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: fangzhiyuan Change-Id: I5f0666785f73fd39f14eb44a9f89b32b6d76f20f --- .../arkui-ohos/src/ani/native/BUILD.gn | 1 + .../src/ani/native/common/common_module.cpp | 46 ++++- .../ani/native/resource/resource_module.cpp | 158 ++++++++++++++++ .../src/ani/native/resource/resource_module.h | 35 ++++ .../src/handwritten/theme/ArkColorsImpl.ts | 3 +- frameworks/core/interfaces/ani/ani_api.h | 25 ++- frameworks/core/interfaces/native/BUILD.gn | 2 + .../core/interfaces/native/ani/ani_theme.cpp | 6 +- .../native/ani/ani_theme_module.cpp | 54 +++--- .../core/interfaces/native/ani/ani_utils.cpp | 86 +++++++++ .../core/interfaces/native/ani/ani_utils.h | 3 + .../native/ani/color_ani_modifier.cpp | 37 ++++ .../native/ani/color_ani_modifier.h | 25 +++ .../native/ani/common_ani_modifier.cpp | 49 +---- .../native/ani/node_ani_modifier.cpp | 6 + .../native/ani/resource_ani_modifier.cpp | 171 ++++++++++-------- .../native/ani/resource_ani_modifier.h | 12 +- .../native/ani/theme_ani_modifier.cpp | 62 +++++++ .../native/ani/theme_ani_modifier.h | 25 +++ 19 files changed, 644 insertions(+), 162 deletions(-) create mode 100644 frameworks/bridge/arkts_frontend/koala_projects/arkoala-arkts/arkui-ohos/src/ani/native/resource/resource_module.cpp create mode 100644 frameworks/bridge/arkts_frontend/koala_projects/arkoala-arkts/arkui-ohos/src/ani/native/resource/resource_module.h create mode 100644 frameworks/core/interfaces/native/ani/color_ani_modifier.cpp create mode 100644 frameworks/core/interfaces/native/ani/color_ani_modifier.h create mode 100644 frameworks/core/interfaces/native/ani/theme_ani_modifier.cpp create mode 100644 frameworks/core/interfaces/native/ani/theme_ani_modifier.h diff --git a/frameworks/bridge/arkts_frontend/koala_projects/arkoala-arkts/arkui-ohos/src/ani/native/BUILD.gn b/frameworks/bridge/arkts_frontend/koala_projects/arkoala-arkts/arkui-ohos/src/ani/native/BUILD.gn index ded9ab40dca..99ee43a960e 100644 --- a/frameworks/bridge/arkts_frontend/koala_projects/arkoala-arkts/arkui-ohos/src/ani/native/BUILD.gn +++ b/frameworks/bridge/arkts_frontend/koala_projects/arkoala-arkts/arkui-ohos/src/ani/native/BUILD.gn @@ -42,6 +42,7 @@ ohos_shared_library("arkoala_native_ani") { "interop/interop_module.cpp", "load.cpp", "module.cpp", + "resource/resource_module.cpp", "shape/shape_module_methods.cpp", "styled_string/styled_string_module.cpp", "utils/ani_utils.cpp", diff --git a/frameworks/bridge/arkts_frontend/koala_projects/arkoala-arkts/arkui-ohos/src/ani/native/common/common_module.cpp b/frameworks/bridge/arkts_frontend/koala_projects/arkoala-arkts/arkui-ohos/src/ani/native/common/common_module.cpp index 04e9eaf5684..d1c47ee7324 100644 --- a/frameworks/bridge/arkts_frontend/koala_projects/arkoala-arkts/arkui-ohos/src/ani/native/common/common_module.cpp +++ b/frameworks/bridge/arkts_frontend/koala_projects/arkoala-arkts/arkui-ohos/src/ani/native/common/common_module.cpp @@ -21,8 +21,10 @@ #include "ani.h" #include "load.h" +#include "log/log.h" #include "base/utils/utils.h" +#include "resource/resource_module.h" // #include "pixel_map_taihe_ani.h" #include "utils/ani_utils.h" @@ -559,7 +561,43 @@ void SetDefaultTheme(ani_env* env, ani_object aniClass, ani_array colorArray, an if (!modifier) { return; } - modifier->getCommonAniModifier()->setDefaultTheme(env, colorArray, isDark); + + auto aniThemeModifier = modifier->getAniThemeModifier(); + int32_t tokenColorsSize = aniThemeModifier->getTokenColorsSize(); + auto isDarkValue = static_cast(isDark); + ani_size length; + env->Array_GetLength(colorArray, &length); + if (length < tokenColorsSize) { + HILOGW("colorArray incorrect in SetDefaultTheme"); + } + + std::vector colors; + // auto basisTheme = TokenThemeStorage::GetInstance()->ObtainSystemTheme(); + std::vector systemColors; + modifier->getAniThemeModifier()->obtainSystemColors(systemColors); + for (int32_t i = 0; i < tokenColorsSize; i++) { + // type ResourceColor = number | string | Resource + ani_ref value; + auto status = env->Array_Get(colorArray, i, &value); + if (status != ANI_OK) { + HILOGW("SetDefaultTheme colorArray get index: %{public}d failed", i); + continue; + } + uint32_t color = 0; + RefPtr resObj; + bool isColorAvailable = false; + if (!ResourceModule::ParseAniColor(env, static_cast(value), color)) { + if (i < systemColors.size()) { + color = systemColors[i]; + isColorAvailable = true; + } + } else { + isColorAvailable = true; + } + colors.push_back(color); + } + + modifier->getCommonAniModifier()->setDefaultTheme(env, colors, isDarkValue); } void UpdateColorMode(ani_env* env, ani_object aniClass, ani_int colorMode) @@ -596,8 +634,12 @@ void CreateAndBindTheme(ani_env* env, ani_object aniClass, ani_int themeScopeId, if (!modifier) { return; } + std::vector colorsArr; + if (!ResourceModule::HandleThemeColorsArg(env, colors, colorsArr)) { + return; + } modifier->getCommonAniModifier()->createAndBindTheme( - env, themeScopeId, themeId, colors, colorMode, onThemeScopeDestroy); + env, themeScopeId, themeId, colorsArr, colorMode, onThemeScopeDestroy); } void ApplyParentThemeScopeId(ani_env* env, ani_object aniClass, ani_long self, ani_long parent) diff --git a/frameworks/bridge/arkts_frontend/koala_projects/arkoala-arkts/arkui-ohos/src/ani/native/resource/resource_module.cpp b/frameworks/bridge/arkts_frontend/koala_projects/arkoala-arkts/arkui-ohos/src/ani/native/resource/resource_module.cpp new file mode 100644 index 00000000000..73c3054c5cb --- /dev/null +++ b/frameworks/bridge/arkts_frontend/koala_projects/arkoala-arkts/arkui-ohos/src/ani/native/resource/resource_module.cpp @@ -0,0 +1,158 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "resource_module.h" + +#include + +#include "ani.h" +#include "load.h" +#include "log/log.h" +#include "utils/ani_utils.h" + +namespace OHOS::Ace::Ani { +namespace { +constexpr uint32_t COLOR_ALPHA_OFFSET = 24; +constexpr uint32_t COLOR_ALPHA_VALUE = 0xFF000000; +uint32_t ColorAlphaAdapt(uint32_t origin) +{ + uint32_t result = origin; + if ((origin >> COLOR_ALPHA_OFFSET) == 0) { + result = origin | COLOR_ALPHA_VALUE; + } + return result; +} +} // namespace +bool ResourceModule::ParseAniColor(ani_env* env, ani_object aniValue, uint32_t& color) +{ + const auto* modifier = GetNodeAniModifier(); + if (!modifier) { + return false; + } + + auto aniObj = static_cast(aniValue); + if (AniUtils::IsString(env, aniObj)) { + auto srcString = AniUtils::ANIStringToStdString(env, static_cast(aniValue)); + return modifier->getColorModifier()->parseColorString(srcString, color); + return true; + } + + if (AniUtils::IsNumber(env, aniObj)) { + ani_status status; + ani_double doubleSrc; + if ((status = env->Object_CallMethodByName_Double(aniValue, "unboxed", ":d", &doubleSrc)) != ANI_OK) { + HILOGW("GetColorValue unboxed double failed. %{public}d", status); + return false; + } + color = ColorAlphaAdapt(static_cast(doubleSrc)); + return true; + } + + if (IsResource(env, aniObj)) { + int32_t resId = -1; + int32_t resType = -1; + std::string bundleName; + std::string moduleName; + ParseAniResource(env, aniObj, resId, resType, bundleName, moduleName); + + color = modifier->getResourceModifier()->getColorById(resId, resType, bundleName, moduleName); + return true; + } + return false; +} + +bool ResourceModule::IsResource(ani_env* env, ani_object obj) +{ + ani_status status; + ani_class resourceClass; + if ((status = env->FindClass("Lglobal/resource/Resource;", &resourceClass)) != ANI_OK) { + HILOGW("IsResource find Resource failed. %{public}d", status); + return false; + } + ani_boolean isResource; + if ((status = env->Object_InstanceOf(obj, resourceClass, &isResource)) != ANI_OK) { + HILOGW("IsResource call instanceof Resource failed. %{public}d", status); + return false; + } + return isResource; +} + +void ResourceModule::ParseAniResource(ani_env* env, ani_object aniValue, int32_t& resId, int32_t& resType, + std::string& resBundleName, std::string& resModuleName) +{ + ani_double id; + env->Object_GetPropertyByName_Double(aniValue, "id", &id); + resId = static_cast(id); + + ani_double type; + env->Object_GetPropertyByName_Double(aniValue, "type", &type); + resType = static_cast(type); + + ani_ref bundleName; + env->Object_GetPropertyByName_Ref(aniValue, "bundleName", &bundleName); + resBundleName = AniUtils::ANIStringToStdString(env, static_cast(bundleName)); + + ani_ref moduleName; + env->Object_GetPropertyByName_Ref(aniValue, "moduleName", &moduleName); + resModuleName = AniUtils::ANIStringToStdString(env, static_cast(moduleName)); +} + +bool ResourceModule::HandleThemeColorsArg(ani_env* env, ani_array colorsArg, std::vector& colors) +{ + const auto* modifier = GetNodeAniModifier(); + if (!modifier) { + return false; + } + auto aniThemeModifier = modifier->getAniThemeModifier(); + int32_t tokenColorsSize = aniThemeModifier->getTokenColorsSize(); + + ani_size length; + env->Array_GetLength(colorsArg, &length); + if (length < tokenColorsSize) { + HILOGW("colorArray incorrect in SetDefaultTheme"); + } + std::vector basisColors; + modifier->getAniThemeModifier()->obtainDefaultColors(basisColors); + if (basisColors.empty()) { + modifier->getAniThemeModifier()->obtainSystemColors(basisColors); + } + if (basisColors.empty()) { + return false; + } + + for (int32_t i = 0; i < tokenColorsSize; i++) { + // type ResourceColor = number | string | Resource + ani_ref value; + auto status = env->Array_Get(colorsArg, i, &value); + if (status != ANI_OK) { + HILOGW("SetDefaultTheme colorArray get index: %{public}d failed", i); + continue; + } + uint32_t color = 0; + RefPtr resObj; + bool isColorAvailable = false; + if (!ResourceModule::ParseAniColor(env, static_cast(value), color)) { + if (i < basisColors.size()) { + color = basisColors[i]; + isColorAvailable = true; + } + } else { + isColorAvailable = true; + } + colors.push_back(color); + } + return true; +} +} // namespace OHOS::Ace::Ani diff --git a/frameworks/bridge/arkts_frontend/koala_projects/arkoala-arkts/arkui-ohos/src/ani/native/resource/resource_module.h b/frameworks/bridge/arkts_frontend/koala_projects/arkoala-arkts/arkui-ohos/src/ani/native/resource/resource_module.h new file mode 100644 index 00000000000..b14e7c8e032 --- /dev/null +++ b/frameworks/bridge/arkts_frontend/koala_projects/arkoala-arkts/arkui-ohos/src/ani/native/resource/resource_module.h @@ -0,0 +1,35 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef KOALA_PROJECTS_ARKOALA_ARKTS_ARKUI_OHOS_RESOURCE_MODULE_H +#define KOALA_PROJECTS_ARKOALA_ARKTS_ARKUI_OHOS_RESOURCE_MODULE_H + +#include +#include + +#include "ani.h" + +namespace OHOS::Ace::Ani { +class ResourceModule final { +public: + static bool ParseAniColor(ani_env* env, ani_object aniValue, uint32_t& color); + static bool IsResource(ani_env* env, ani_object obj); + static void ParseAniResource(ani_env* env, ani_object aniValue, int32_t& resId, int32_t& resType, + std::string& resBundleName, std::string& resModuleName); + static bool HandleThemeColorsArg(ani_env* env, ani_array colorsArg, std::vector& colors); +}; +} // namespace OHOS::Ace::Ani + +#endif diff --git a/frameworks/bridge/arkts_frontend/koala_projects/arkoala-arkts/arkui-ohos/src/handwritten/theme/ArkColorsImpl.ts b/frameworks/bridge/arkts_frontend/koala_projects/arkoala-arkts/arkui-ohos/src/handwritten/theme/ArkColorsImpl.ts index 00e72be6412..7278a1f55c4 100644 --- a/frameworks/bridge/arkts_frontend/koala_projects/arkoala-arkts/arkui-ohos/src/handwritten/theme/ArkColorsImpl.ts +++ b/frameworks/bridge/arkts_frontend/koala_projects/arkoala-arkts/arkui-ohos/src/handwritten/theme/ArkColorsImpl.ts @@ -13,7 +13,8 @@ * limitations under the License. */ -import { ResourceColor, Color } from 'arkui/component'; +import { ResourceColor } from 'arkui/component'; +import { Color } from 'arkui/component/enums'; import { ArkResourcesHelper } from 'arkui/handwritten/theme/ArkResourcesHelper'; import { BrandColors, ArkThemeResource } from 'arkui/handwritten/theme'; import { Resource } from 'global.resource'; diff --git a/frameworks/core/interfaces/ani/ani_api.h b/frameworks/core/interfaces/ani/ani_api.h index 19bed8086fc..46730ab5f85 100644 --- a/frameworks/core/interfaces/ani/ani_api.h +++ b/frameworks/core/interfaces/ani/ani_api.h @@ -290,12 +290,12 @@ struct ArkUIAniCommonModifier { ArkUI_Uint32 (*getColorValueByNumber)(ArkUI_Uint32 src); void (*sendThemeToNative)(ani_env* env, ani_array colors, ani_int id); void (*removeThemeInNative)(ani_env* env, ani_int withThemeId); - void (*setDefaultTheme)(ani_env* env, ani_array colors, ani_boolean isDark); + void (*setDefaultTheme)(ani_env* env, const std::vector& colors, ani_boolean isDark); void (*updateColorMode)(ani_int colorMode); void (*restoreColorMode)(); void (*setThemeScopeId)(ani_env* env, ani_int themeScopeId); - void (*createAndBindTheme)(ani_env* env, ani_int themeScopeId, ani_int themeId, ani_array colors, ani_int colorMode, - ani_fn_object onThemeScopeDestroy); + void (*createAndBindTheme)(ani_env* env, ani_int themeScopeId, ani_int themeId, + const std::vector& colors, ani_int colorMode, ani_fn_object onThemeScopeDestroy); void (*applyParentThemeScopeId)(ani_env* env, ani_long self, ani_long parent); }; struct ArkUIAniCustomNodeModifier { @@ -435,6 +435,22 @@ struct ArkUIAniCanvasModifier { ani_double dirtyHeight); }; +struct ArkUIResourceModifier { + uint32_t (*getColorById)(int32_t id, int32_t type, std::string bundleName, std::string moduleName); + bool (*parseAniColor)(ani_env* env, ani_object aniValue, OHOS::Ace::Color& color, + OHOS::Ace::RefPtr& resObj); +}; + +struct ArkUIColorModifier { + bool (*parseColorString)(std::string src, uint32_t& color); +}; + +struct ArkUIAniThemeModifier { + void (*obtainDefaultColors)(std::vector& defaultColors); + void (*obtainSystemColors)(std::vector& systemColors); + int32_t (*getTokenColorsSize)(); +}; + struct ArkUIAniModifiers { ArkUI_Int32 version; const ArkUIAniImageModifier* (*getImageAniModifier)(); @@ -461,6 +477,9 @@ struct ArkUIAniModifiers { const ArkUIAniConditionScopeModifier* (*getArkUIAniConditionScopeModifier)(); const ArkUIAniComponentConentModifier* (*getArkUIAniComponentConentModifier)(); const ArkUIAniCanvasModifier* (*getCanvasAniModifier)(); + const ArkUIResourceModifier* (*getResourceModifier)(); + const ArkUIColorModifier* (*getColorModifier)(); + const ArkUIAniThemeModifier* (*getAniThemeModifier)(); }; __attribute__((visibility("default"))) const ArkUIAniModifiers* GetArkUIAniModifiers(void); diff --git a/frameworks/core/interfaces/native/BUILD.gn b/frameworks/core/interfaces/native/BUILD.gn index 53cf3e419bc..99fa4722f7d 100644 --- a/frameworks/core/interfaces/native/BUILD.gn +++ b/frameworks/core/interfaces/native/BUILD.gn @@ -172,6 +172,8 @@ template("ace_core_interfaces_native_node") { "ani/xcomponent_ani_modifier.cpp", "ani/list_ani_modifier.cpp", "ani/condition_scope_ani_modifier.cpp", + "ani/color_ani_modifier.cpp", + "ani/theme_ani_modifier.cpp" ] if (build_ohos_sdk) { sources -= [ diff --git a/frameworks/core/interfaces/native/ani/ani_theme.cpp b/frameworks/core/interfaces/native/ani/ani_theme.cpp index 707bee96dd5..89351243025 100644 --- a/frameworks/core/interfaces/native/ani/ani_theme.cpp +++ b/frameworks/core/interfaces/native/ani/ani_theme.cpp @@ -23,7 +23,9 @@ #include "base/log/log_wrapper.h" #include "bridge/arkts_frontend/arkts_ani_utils.h" -#include "core/interfaces/native/ani/resource_ani_modifier.h" +#include "core/common/resource/resource_manager.h" +#include "core/common/resource/resource_object.h" +#include "core/interfaces/native/ani/ani_utils.h" namespace OHOS::Ace::NG { std::map AniThemeScope::aniThemes = {}; @@ -57,7 +59,7 @@ Color AniThemeColors::ConvertAniValueToColor(ani_object aniValue) const } Color color; RefPtr resObj; - ResourceAniModifier::ParseAniColor(env, aniValue, color, resObj); + AniUtils::ParseAniColor(env, aniValue, color, resObj); return color; } diff --git a/frameworks/core/interfaces/native/ani/ani_theme_module.cpp b/frameworks/core/interfaces/native/ani/ani_theme_module.cpp index 115cbb483cf..230867f6ea4 100644 --- a/frameworks/core/interfaces/native/ani/ani_theme_module.cpp +++ b/frameworks/core/interfaces/native/ani/ani_theme_module.cpp @@ -84,33 +84,33 @@ ColorMode AniThemeModule::MapAniColorModeToColorMode(int32_t aniColorMode) return ColorMode::COLOR_MODE_UNDEFINED; } -bool AniThemeModule::HandleThemeColorsArg( - ani_env* env, ani_array colorsArg, std::vector& colors, std::vector>& resObjs) -{ - auto basisTheme = TokenThemeStorage::GetInstance()->GetDefaultTheme(); - if (!basisTheme) { - basisTheme = TokenThemeStorage::GetInstance()->ObtainSystemTheme(); - } - if (!basisTheme) { - return false; - } - for (size_t i = 0; i < TokenColors::TOTAL_NUMBER; i++) { - Color color; - ani_ref colorParams; - RefPtr resObj; - auto status = env->Array_Get(colorsArg, i, &colorParams); - if (status != ANI_OK) { - LOGW("HandleThemeColorsArg colorsArg get index: %{public}d failed", i); - continue; - } - if (!ResourceAniModifier::ParseAniColor(env, static_cast(colorParams), color, resObj)) { - color = basisTheme->Colors()->GetByIndex(i); - } - resObjs.push_back(resObj); - colors.push_back(static_cast(color.GetValue())); - } - return true; -} +// bool AniThemeModule::HandleThemeColorsArg( +// ani_env* env, ani_array colorsArg, std::vector& colors, std::vector>& resObjs) +// { +// auto basisTheme = TokenThemeStorage::GetInstance()->GetDefaultTheme(); +// if (!basisTheme) { +// basisTheme = TokenThemeStorage::GetInstance()->ObtainSystemTheme(); +// } +// if (!basisTheme) { +// return false; +// } +// for (size_t i = 0; i < TokenColors::TOTAL_NUMBER; i++) { +// Color color; +// ani_ref colorParams; +// RefPtr resObj; +// auto status = env->Array_Get(colorsArg, i, &colorParams); +// if (status != ANI_OK) { +// LOGW("HandleThemeColorsArg colorsArg get index: %{public}d failed", i); +// continue; +// } +// if (!ResourceAniModifier::ParseAniColor(env, static_cast(colorParams), color, resObj)) { +// color = basisTheme->Colors()->GetByIndex(i); +// } +// resObjs.push_back(resObj); +// colors.push_back(static_cast(color.GetValue())); +// } +// return true; +// } ArkUINodeHandle AniThemeModule::CreateWithThemeNode(int32_t themeScopeId) { diff --git a/frameworks/core/interfaces/native/ani/ani_utils.cpp b/frameworks/core/interfaces/native/ani/ani_utils.cpp index 8f923d3b657..c307ebac9d7 100644 --- a/frameworks/core/interfaces/native/ani/ani_utils.cpp +++ b/frameworks/core/interfaces/native/ani/ani_utils.cpp @@ -16,8 +16,94 @@ #include "ani_utils.h" #include "interfaces/inner_api/ace_kit/include/ui/base/utils/utils.h" +#include "base/log/log.h" +#include "bridge/arkts_frontend/arkts_ani_utils.h" +#include "core/common/resource/resource_manager.h" +#include "core/common/container.h" namespace OHOS::Ace::NG { +namespace { +constexpr uint32_t COLOR_ALPHA_OFFSET = 24; +constexpr uint32_t COLOR_ALPHA_VALUE = 0xFF000000; +uint32_t ColorAlphaAdapt(uint32_t origin) +{ + uint32_t result = origin; + if ((origin >> COLOR_ALPHA_OFFSET) == 0) { + result = origin | COLOR_ALPHA_VALUE; + } + return result; +} +} // namespace +bool AniUtils::ParseAniColor(ani_env* env, ani_object aniValue, Color& color, RefPtr& resObj) +{ + ani_status status; + ani_class stringClass; + if ((status = env->FindClass("Lstd/core/String;", &stringClass)) != ANI_OK) { + LOGW("ParseAniColor find string failed. %{public}d", status); + return false; + } + ani_boolean isString; + if ((status = env->Object_InstanceOf(aniValue, stringClass, &isString)) != ANI_OK) { + LOGW("ParseAniColor call instanceof string failed. %{public}d", status); + return false; + } + if (isString) { + auto srcString = ArktsAniUtils::ANIStringToStdString(env, static_cast(aniValue)); + Color::ParseColorString(srcString, color); + return true; + } + + ani_class doubleClass; + if ((status = env->FindClass("Lstd/core/Double;", &doubleClass)) != ANI_OK) { + LOGW("ParseAniColor find int failed. %{public}d", status); + return false; + } + ani_boolean isDouble; + if ((status = env->Object_InstanceOf(aniValue, doubleClass, &isDouble)) != ANI_OK) { + LOGW("ParseAniColor call instanceof double failed. %{public}d", status); + return false; + } + if (isDouble) { + ani_double doubleSrc; + if ((status = env->Object_CallMethodByName_Double(aniValue, "unboxed", ":d", &doubleSrc)) != ANI_OK) { + LOGW("GetColorValue unboxed double failed. %{public}d", status); + return false; + } + color = Color(ColorAlphaAdapt(static_cast(doubleSrc))); + return true; + } + + ani_class resourceClass; + if ((status = env->FindClass("Lglobal/resource/Resource;", &resourceClass)) != ANI_OK) { + LOGW("ParseAniColor find Resource failed. %{public}d", status); + return false; + } + ani_boolean isResource; + if ((status = env->Object_InstanceOf(aniValue, resourceClass, &isResource)) != ANI_OK) { + LOGW("ParseAniColor call instanceof Resource failed. %{public}d", status); + return false; + } + if (isResource) { + ani_double resId; + env->Object_GetPropertyByName_Double(aniValue, "id", &resId); + ani_double resType; + env->Object_GetPropertyByName_Double(aniValue, "type", &resType); + ani_ref bundleName; + env->Object_GetPropertyByName_Ref(aniValue, "bundleName", &bundleName); + ani_ref moduleName; + env->Object_GetPropertyByName_Ref(aniValue, "moduleName", &moduleName); + std::vector params; + resObj = AceType::MakeRefPtr(resId, resType, params, + ArktsAniUtils::ANIStringToStdString(env, static_cast(bundleName)), + ArktsAniUtils::ANIStringToStdString(env, static_cast(moduleName)), + Container::CurrentIdSafely()); + auto resAdapter = ResourceManager::GetInstance().GetOrCreateResourceAdapter(resObj); + color = resAdapter->GetColor(static_cast(resId)); + return true; + } + return false; +} + std::string AniUtils::ANIStringToStdString(ani_env* env, ani_string aniStr) { diff --git a/frameworks/core/interfaces/native/ani/ani_utils.h b/frameworks/core/interfaces/native/ani/ani_utils.h index 2aa8bc6ddea..030c8a31d59 100644 --- a/frameworks/core/interfaces/native/ani/ani_utils.h +++ b/frameworks/core/interfaces/native/ani/ani_utils.h @@ -20,6 +20,8 @@ #include #include "ani.h" +#include "ui/properties/color.h" +#include "core/common/resource/resource_object.h" namespace OHOS::Ace::NG { class AniUtils { @@ -30,6 +32,7 @@ public: // The return value means the parse result. True means success. // If the ref is undefined, it will return false. static bool GetOptionalDouble(ani_env* env, ani_ref value, double& result); + static bool ParseAniColor(ani_env* env, ani_object aniValue, Color& color, RefPtr& resObj); }; } // namespace OHOS::Ace::NG diff --git a/frameworks/core/interfaces/native/ani/color_ani_modifier.cpp b/frameworks/core/interfaces/native/ani/color_ani_modifier.cpp new file mode 100644 index 00000000000..c6928750165 --- /dev/null +++ b/frameworks/core/interfaces/native/ani/color_ani_modifier.cpp @@ -0,0 +1,37 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "color_ani_modifier.h" +#include "ui/properties/color.h" + +namespace OHOS::Ace::NG { +bool ParseColorString(std::string src, uint32_t& color) +{ + Color colorObj; + if (!Color::ParseColorString(src, colorObj)) { + return false; + } + color = colorObj.GetValue(); + return true; +} + +const ArkUIColorModifier* GetColorAniModifier() +{ + static const ArkUIColorModifier impl = { + .parseColorString = OHOS::Ace::NG::ParseColorString, + }; + return &impl; +} +} // namespace OHOS::Ace::NG diff --git a/frameworks/core/interfaces/native/ani/color_ani_modifier.h b/frameworks/core/interfaces/native/ani/color_ani_modifier.h new file mode 100644 index 00000000000..c2cd0981dd8 --- /dev/null +++ b/frameworks/core/interfaces/native/ani/color_ani_modifier.h @@ -0,0 +1,25 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef FRAMEWORKS_CORE_INTERFACES_NATIVE_ANI_COLOR_ANI_MODIFIER_H +#define FRAMEWORKS_CORE_INTERFACES_NATIVE_ANI_COLOR_ANI_MODIFIER_H + +#include "core/interfaces/ani/ani_api.h" + +namespace OHOS::Ace::NG { +const ArkUIColorModifier* GetColorAniModifier(); +} // namespace OHOS::Ace::NG + +#endif diff --git a/frameworks/core/interfaces/native/ani/common_ani_modifier.cpp b/frameworks/core/interfaces/native/ani/common_ani_modifier.cpp index 18fbe6a2b16..b97b32a53cc 100644 --- a/frameworks/core/interfaces/native/ani/common_ani_modifier.cpp +++ b/frameworks/core/interfaces/native/ani/common_ani_modifier.cpp @@ -25,6 +25,7 @@ #include "core/components_ng/base/view_abstract.h" #include "core/components_ng/pattern/stack/stack_pattern.h" #include "core/components_ng/token_theme/token_theme_storage.h" +#include "core/interfaces/arkoala/arkoala_api.h" #include "core/interfaces/native/ani/ani_theme.h" #include "core/interfaces/native/ani/ani_theme_module.h" #include "core/interfaces/native/ani/resource_ani_modifier.h" @@ -464,37 +465,9 @@ void RemoveThemeInNative(ani_env* env, ani_int withThemeId) AniThemeScope::RemoveAniTheme(themeScopeId); } -void SetDefaultTheme(ani_env* env, ani_array colorArray, ani_boolean isDark) +void SetDefaultTheme(ani_env* env, const std::vector& colors, ani_boolean isDark) { auto isDarkValue = static_cast(isDark); - ani_size length; - env->Array_GetLength(colorArray, &length); - if (length < TokenColors::TOTAL_NUMBER) { - LOGW("colorArray incorrect in SetDefaultTheme"); - } - std::vector colors; - auto basisTheme = TokenThemeStorage::GetInstance()->ObtainSystemTheme(); - for (size_t i = 0; i < TokenColors::TOTAL_NUMBER; i++) { - // type ResourceColor = number | string | Resource - ani_ref value; - auto status = env->Array_Get(colorArray, i, &value); - if (status != ANI_OK) { - LOGW("SetDefaultTheme colorArray get index: %{public}d failed", i); - continue; - } - Color color; - RefPtr resObj; - bool isColorAvailable = false; - if (!ResourceAniModifier::ParseAniColor(env, static_cast(value), color, resObj)) { - if (basisTheme) { - color = basisTheme->Colors()->GetByIndex(i); - isColorAvailable = true; - } - } else { - isColorAvailable = true; - } - colors.push_back(color.GetValue()); - } NodeModifier::GetThemeModifier()->setDefaultTheme(colors.data(), isDarkValue); } @@ -521,22 +494,18 @@ void SetThemeScopeId(ani_env* env, ani_int themeScopeId) AniThemeScope::aniCurrentTheme.swap(themeOpt); } -void CreateAndBindTheme(ani_env* env, ani_int themeScopeId, ani_int themeId, ani_array colorsArg, ani_int colorMode, - ani_fn_object onThemeScopeDestroy) +void CreateAndBindTheme(ani_env* env, ani_int themeScopeId, ani_int themeId, const std::vector& colorsArg, + ani_int colorMode, ani_fn_object onThemeScopeDestroy) { int32_t themeScopeIdValue = static_cast(themeScopeId); int32_t themeIdValue = static_cast(themeId); int32_t colorModeValue = static_cast(colorMode); - - if (!colorsArg) { - return; - } - std::vector colors; + // std::vector colors; std::vector> resObjs; - if (!AniThemeModule::HandleThemeColorsArg(env, colorsArg, colors, resObjs)) { - return; - } + // if (!AniThemeModule::HandleThemeColorsArg(env, colorsArg, colors, resObjs)) { + // return; + // } if (!onThemeScopeDestroy) { return; @@ -554,7 +523,7 @@ void CreateAndBindTheme(ani_env* env, ani_int themeScopeId, ani_int themeId, ani }; auto themeModifier = NodeModifier::GetThemeModifier(); - auto theme = themeModifier->createTheme(themeId, colors.data(), colorModeValue, static_cast(&resObjs)); + auto theme = themeModifier->createTheme(themeId, colorsArg.data(), colorModeValue, static_cast(&resObjs)); CHECK_NULL_VOID(theme); ArkUINodeHandle node = themeModifier->getWithThemeNode(themeScopeId); if (!node) { diff --git a/frameworks/core/interfaces/native/ani/node_ani_modifier.cpp b/frameworks/core/interfaces/native/ani/node_ani_modifier.cpp index 294f5c3bdd8..e82ae572c21 100644 --- a/frameworks/core/interfaces/native/ani/node_ani_modifier.cpp +++ b/frameworks/core/interfaces/native/ani/node_ani_modifier.cpp @@ -36,6 +36,9 @@ #include "xcomponent_ani_modifier.h" #include "lazy_for_each_node_ani_modifier.h" #include "condition_scope_ani_modifier.h" +#include "resource_ani_modifier.h" +#include "color_ani_modifier.h" +#include "theme_ani_modifier.h" extern "C" { const ArkUIAniModifiers* GetArkUIAniModifiers() @@ -66,6 +69,9 @@ const ArkUIAniModifiers* GetArkUIAniModifiers() .getArkUIAniConditionScopeModifier = OHOS::Ace::NG::GetConditionScopeAniModifier, .getArkUIAniComponentConentModifier = OHOS::Ace::NG::GetArkUIAniComponentConentModifier, .getCanvasAniModifier = OHOS::Ace::NG::GetCanvasAniModifier, + .getResourceModifier = OHOS::Ace::NG::GetResourceAniModifier, + .getColorModifier = OHOS::Ace::NG::GetColorAniModifier, + .getAniThemeModifier = OHOS::Ace::NG::GetThemeAniModifier }; return &impl; } diff --git a/frameworks/core/interfaces/native/ani/resource_ani_modifier.cpp b/frameworks/core/interfaces/native/ani/resource_ani_modifier.cpp index e8f090ea2cf..d23f923f5fb 100644 --- a/frameworks/core/interfaces/native/ani/resource_ani_modifier.cpp +++ b/frameworks/core/interfaces/native/ani/resource_ani_modifier.cpp @@ -16,6 +16,7 @@ #include "core/interfaces/native/ani/resource_ani_modifier.h" #include +#include #include "ani.h" @@ -27,85 +28,101 @@ #include "core/common/resource/resource_object.h" namespace OHOS::Ace::NG { -namespace { -constexpr uint32_t COLOR_ALPHA_OFFSET = 24; -constexpr uint32_t COLOR_ALPHA_VALUE = 0xFF000000; -uint32_t ColorAlphaAdapt(uint32_t origin) +// namespace { +// constexpr uint32_t COLOR_ALPHA_OFFSET = 24; +// constexpr uint32_t COLOR_ALPHA_VALUE = 0xFF000000; +// uint32_t ColorAlphaAdapt(uint32_t origin) +// { +// uint32_t result = origin; +// if ((origin >> COLOR_ALPHA_OFFSET) == 0) { +// result = origin | COLOR_ALPHA_VALUE; +// } +// return result; +// } +// } // namespace +// bool ParseAniColor(ani_env* env, ani_object aniValue, Color& color, RefPtr& resObj) +// { +// ani_status status; +// ani_class stringClass; +// if ((status = env->FindClass("Lstd/core/String;", &stringClass)) != ANI_OK) { +// LOGW("ParseAniColor find string failed. %{public}d", status); +// return false; +// } +// ani_boolean isString; +// if ((status = env->Object_InstanceOf(aniValue, stringClass, &isString)) != ANI_OK) { +// LOGW("ParseAniColor call instanceof string failed. %{public}d", status); +// return false; +// } +// if (isString) { +// auto srcString = ArktsAniUtils::ANIStringToStdString(env, static_cast(aniValue)); +// Color::ParseColorString(srcString, color); +// return true; +// } + +// ani_class doubleClass; +// if ((status = env->FindClass("Lstd/core/Double;", &doubleClass)) != ANI_OK) { +// LOGW("ParseAniColor find int failed. %{public}d", status); +// return false; +// } +// ani_boolean isDouble; +// if ((status = env->Object_InstanceOf(aniValue, doubleClass, &isDouble)) != ANI_OK) { +// LOGW("ParseAniColor call instanceof double failed. %{public}d", status); +// return false; +// } +// if (isDouble) { +// ani_double doubleSrc; +// if ((status = env->Object_CallMethodByName_Double(aniValue, "unboxed", ":d", &doubleSrc)) != ANI_OK) { +// LOGW("GetColorValue unboxed double failed. %{public}d", status); +// return false; +// } +// color = Color(ColorAlphaAdapt(static_cast(doubleSrc))); +// return true; +// } + +// ani_class resourceClass; +// if ((status = env->FindClass("Lglobal/resource/Resource;", &resourceClass)) != ANI_OK) { +// LOGW("ParseAniColor find Resource failed. %{public}d", status); +// return false; +// } +// ani_boolean isResource; +// if ((status = env->Object_InstanceOf(aniValue, resourceClass, &isResource)) != ANI_OK) { +// LOGW("ParseAniColor call instanceof Resource failed. %{public}d", status); +// return false; +// } +// if (isResource) { +// ani_double resId; +// env->Object_GetPropertyByName_Double(aniValue, "id", &resId); +// ani_double resType; +// env->Object_GetPropertyByName_Double(aniValue, "type", &resType); +// ani_ref bundleName; +// env->Object_GetPropertyByName_Ref(aniValue, "bundleName", &bundleName); +// ani_ref moduleName; +// env->Object_GetPropertyByName_Ref(aniValue, "moduleName", &moduleName); +// std::vector params; +// resObj = AceType::MakeRefPtr(resId, resType, params, +// ArktsAniUtils::ANIStringToStdString(env, static_cast(bundleName)), +// ArktsAniUtils::ANIStringToStdString(env, static_cast(moduleName)), +// Container::CurrentIdSafely()); +// auto resAdapter = ResourceManager::GetInstance().GetOrCreateResourceAdapter(resObj); +// color = resAdapter->GetColor(static_cast(resId)); +// return true; +// } +// return false; +// } + +uint32_t GetColorById(int32_t id, int32_t type, std::string bundleName, std::string moduleName) { - uint32_t result = origin; - if ((origin >> COLOR_ALPHA_OFFSET) == 0) { - result = origin | COLOR_ALPHA_VALUE; - } - return result; + auto resObj = AceType::MakeRefPtr(bundleName, moduleName, Container::CurrentIdSafely()); + auto resAdapter = ResourceManager::GetInstance().GetOrCreateResourceAdapter(resObj); + auto color = resAdapter->GetColor(static_cast(id)); + return color.GetValue(); } -} // namespace -bool ResourceAniModifier::ParseAniColor(ani_env* env, ani_object aniValue, Color& color, RefPtr& resObj) -{ - ani_status status; - ani_class stringClass; - if ((status = env->FindClass("Lstd/core/String;", &stringClass)) != ANI_OK) { - LOGW("ParseAniColor find string failed. %{public}d", status); - return false; - } - ani_boolean isString; - if ((status = env->Object_InstanceOf(aniValue, stringClass, &isString)) != ANI_OK) { - LOGW("ParseAniColor call instanceof string failed. %{public}d", status); - return false; - } - if (isString) { - auto srcString = ArktsAniUtils::ANIStringToStdString(env, static_cast(aniValue)); - Color::ParseColorString(srcString, color); - return true; - } - - ani_class doubleClass; - if ((status = env->FindClass("Lstd/core/Double;", &doubleClass)) != ANI_OK) { - LOGW("ParseAniColor find int failed. %{public}d", status); - return false; - } - ani_boolean isDouble; - if ((status = env->Object_InstanceOf(aniValue, doubleClass, &isDouble)) != ANI_OK) { - LOGW("ParseAniColor call instanceof double failed. %{public}d", status); - return false; - } - if (isDouble) { - ani_double doubleSrc; - if ((status = env->Object_CallMethodByName_Double(aniValue, "unboxed", ":d", &doubleSrc)) != ANI_OK) { - LOGW("GetColorValue unboxed double failed. %{public}d", status); - return false; - } - color = Color(ColorAlphaAdapt(static_cast(doubleSrc))); - return true; - } - ani_class resourceClass; - if ((status = env->FindClass("Lglobal/resource/Resource;", &resourceClass)) != ANI_OK) { - LOGW("ParseAniColor find Resource failed. %{public}d", status); - return false; - } - ani_boolean isResource; - if ((status = env->Object_InstanceOf(aniValue, resourceClass, &isResource)) != ANI_OK) { - LOGW("ParseAniColor call instanceof Resource failed. %{public}d", status); - return false; - } - if (isResource) { - ani_double resId; - env->Object_GetPropertyByName_Double(aniValue, "id", &resId); - ani_double resType; - env->Object_GetPropertyByName_Double(aniValue, "type", &resType); - ani_ref bundleName; - env->Object_GetPropertyByName_Ref(aniValue, "bundleName", &bundleName); - ani_ref moduleName; - env->Object_GetPropertyByName_Ref(aniValue, "moduleName", &moduleName); - std::vector params; - resObj = AceType::MakeRefPtr(resId, resType, params, - ArktsAniUtils::ANIStringToStdString(env, static_cast(bundleName)), - ArktsAniUtils::ANIStringToStdString(env, static_cast(moduleName)), - Container::CurrentIdSafely()); - auto resAdapter = ResourceManager::GetInstance().GetOrCreateResourceAdapter(resObj); - color = resAdapter->GetColor(static_cast(resId)); - return true; - } - return false; +const ArkUIResourceModifier* GetResourceAniModifier() +{ + static const ArkUIResourceModifier impl = { + .getColorById = OHOS::Ace::NG::GetColorById, + }; + return &impl; } } // namespace OHOS::Ace::NG diff --git a/frameworks/core/interfaces/native/ani/resource_ani_modifier.h b/frameworks/core/interfaces/native/ani/resource_ani_modifier.h index efc818144be..c2ab50529f8 100644 --- a/frameworks/core/interfaces/native/ani/resource_ani_modifier.h +++ b/frameworks/core/interfaces/native/ani/resource_ani_modifier.h @@ -16,18 +16,10 @@ #ifndef FRAMEWORKS_CORE_INTERFACES_NATIVE_ANI_RESOURCE_ANI_MODIFIER_H #define FRAMEWORKS_CORE_INTERFACES_NATIVE_ANI_RESOURCE_ANI_MODIFIER_H -#include "ui/base/referenced.h" -#include "ui/properties/color.h" -#include "ui/resource/resource_object.h" - -typedef struct __ani_env ani_env; -typedef class __ani_object* ani_object; +#include "core/interfaces/ani/ani_api.h" namespace OHOS::Ace::NG { -class ResourceAniModifier final { -public: - static bool ParseAniColor(ani_env* env, ani_object aniValue, Color& color, RefPtr& resObj); -}; +const ArkUIResourceModifier* GetResourceAniModifier(); } // namespace OHOS::Ace::NG #endif diff --git a/frameworks/core/interfaces/native/ani/theme_ani_modifier.cpp b/frameworks/core/interfaces/native/ani/theme_ani_modifier.cpp new file mode 100644 index 00000000000..2315aa80887 --- /dev/null +++ b/frameworks/core/interfaces/native/ani/theme_ani_modifier.cpp @@ -0,0 +1,62 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "theme_ani_modifier.h" + +#include +#include + +#include "ui/view/theme/token_colors.h" + +#include "core/components_ng/token_theme/token_theme_storage.h" + +namespace OHOS::Ace::NG { +void ObtainDefaultColors(std::vector& defaultColors) +{ + auto basisTheme = TokenThemeStorage::GetInstance()->GetDefaultTheme(); + CHECK_NULL_VOID(basisTheme); + auto colorsRef = basisTheme->Colors(); + CHECK_NULL_VOID(colorsRef); + for (auto& color : colorsRef->GetColors()) { + defaultColors.push_back(color.GetValue()); + } +} + +void ObtainSystemColors(std::vector& systemColors) +{ + auto basisTheme = TokenThemeStorage::GetInstance()->ObtainSystemTheme(); + CHECK_NULL_VOID(basisTheme); + auto colorsRef = basisTheme->Colors(); + CHECK_NULL_VOID(colorsRef); + for (auto& color : colorsRef->GetColors()) { + systemColors.push_back(color.GetValue()); + } +} + +int32_t GetTokenColorsSize() +{ + return TokenColors::TOTAL_NUMBER; +} + +const ArkUIAniThemeModifier* GetThemeAniModifier() +{ + static const ArkUIAniThemeModifier impl = { + .obtainDefaultColors = OHOS::Ace::NG::ObtainDefaultColors, + .obtainSystemColors = OHOS::Ace::NG::ObtainSystemColors, + .getTokenColorsSize = OHOS::Ace::NG::GetTokenColorsSize + }; + return &impl; +} +} // namespace OHOS::Ace::NG diff --git a/frameworks/core/interfaces/native/ani/theme_ani_modifier.h b/frameworks/core/interfaces/native/ani/theme_ani_modifier.h new file mode 100644 index 00000000000..63713bc9902 --- /dev/null +++ b/frameworks/core/interfaces/native/ani/theme_ani_modifier.h @@ -0,0 +1,25 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef FRAMEWORKS_CORE_INTERFACES_NATIVE_ANI_THEME_ANI_MODIFIER_H +#define FRAMEWORKS_CORE_INTERFACES_NATIVE_ANI_THEME_ANI_MODIFIER_H + +#include "core/interfaces/ani/ani_api.h" + +namespace OHOS::Ace::NG { +const ArkUIAniThemeModifier* GetThemeAniModifier(); +} // namespace OHOS::Ace::NG + +#endif -- Gitee From f5ee7f6b6d37d7e1d8e9a26e6281528fef8b116c Mon Sep 17 00:00:00 2001 From: fangzhiyuan Date: Wed, 23 Jul 2025 19:09:31 +0800 Subject: [PATCH 08/11] =?UTF-8?q?Resource=E7=B1=BB=E5=9E=8B=E8=B0=83?= =?UTF-8?q?=E6=95=B4=E9=80=82=E9=85=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: fangzhiyuan Change-Id: Ia2f2cd2e24d541afdbb4318e22c2c8dc53843cef --- .../src/handwritten/theme/ArkResourcesHelper.ts | 8 ++++---- .../arkui-ohos/src/handwritten/theme/index.ts | 4 ++-- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/frameworks/bridge/arkts_frontend/koala_projects/arkoala-arkts/arkui-ohos/src/handwritten/theme/ArkResourcesHelper.ts b/frameworks/bridge/arkts_frontend/koala_projects/arkoala-arkts/arkui-ohos/src/handwritten/theme/ArkResourcesHelper.ts index 9e99f811f02..91522980939 100644 --- a/frameworks/bridge/arkts_frontend/koala_projects/arkoala-arkts/arkui-ohos/src/handwritten/theme/ArkResourcesHelper.ts +++ b/frameworks/bridge/arkts_frontend/koala_projects/arkoala-arkts/arkui-ohos/src/handwritten/theme/ArkResourcesHelper.ts @@ -16,13 +16,13 @@ import { Resource } from 'global.resource'; export class ArkResourcesHelper { - static COLOR: number = 10001; - static FLOAT: number = 10002; + static COLOR: int = 10001; + static FLOAT: int = 10002; - static $r(name: string, id?: number): Resource { + static $r(name: string, id?: long): Resource { let splitted = name.split('.', 2); let strType = splitted[1]; - let type: number = ArkResourcesHelper.COLOR; + let type: int = ArkResourcesHelper.COLOR; if (strType === 'float') { type = ArkResourcesHelper.FLOAT; } diff --git a/frameworks/bridge/arkts_frontend/koala_projects/arkoala-arkts/arkui-ohos/src/handwritten/theme/index.ts b/frameworks/bridge/arkts_frontend/koala_projects/arkoala-arkts/arkui-ohos/src/handwritten/theme/index.ts index ced4750ca22..0d1f1c5d419 100644 --- a/frameworks/bridge/arkts_frontend/koala_projects/arkoala-arkts/arkui-ohos/src/handwritten/theme/index.ts +++ b/frameworks/bridge/arkts_frontend/koala_projects/arkoala-arkts/arkui-ohos/src/handwritten/theme/index.ts @@ -310,9 +310,9 @@ export function makeRecordfromObj(obj: Object): Record { export interface ArkThemeResource extends Resource { bundleName: string; moduleName: string; - id: number; + id: long; params?: Array; - type?: number; + type?: int; opacityRatio: number; } -- Gitee From 16deec4342125949c5a7710685b020e6c7f95e20 Mon Sep 17 00:00:00 2001 From: fangzhiyuan Date: Wed, 23 Jul 2025 19:28:38 +0800 Subject: [PATCH 09/11] CodeCheck fix Signed-off-by: fangzhiyuan Change-Id: Ifa5a27fc841e4edbec1aaf42e50872605f1d4d4a --- .../src/ani/native/common/common_module.cpp | 13 ++- .../native/ani/ani_theme_module.cpp | 28 ------- .../native/ani/common_ani_modifier.cpp | 5 -- .../native/ani/resource_ani_modifier.cpp | 82 ------------------- .../implementation/with_theme_modifier.cpp | 2 - 5 files changed, 6 insertions(+), 124 deletions(-) diff --git a/frameworks/bridge/arkts_frontend/koala_projects/arkoala-arkts/arkui-ohos/src/ani/native/common/common_module.cpp b/frameworks/bridge/arkts_frontend/koala_projects/arkoala-arkts/arkui-ohos/src/ani/native/common/common_module.cpp index d1c47ee7324..d07e8d8419e 100644 --- a/frameworks/bridge/arkts_frontend/koala_projects/arkoala-arkts/arkui-ohos/src/ani/native/common/common_module.cpp +++ b/frameworks/bridge/arkts_frontend/koala_projects/arkoala-arkts/arkui-ohos/src/ani/native/common/common_module.cpp @@ -508,29 +508,29 @@ ani_int GetColorValue(ani_env* env, ani_object aniClass, ani_object src) ani_status status; ani_class stringClass; if ((status = env->FindClass("Lstd/core/String;", &stringClass)) != ANI_OK) { - // LOGW("GetColorValue find string failed. %{public}d", status); + HILOGW("GetColorValue find string failed. %{public}d", status); } ani_boolean isString; if ((status = env->Object_InstanceOf(src, stringClass, &isString)) != ANI_OK) { - // LOGW("GetColorValue call instanceof string failed. %{public}d", status); + HILOGW("GetColorValue call instanceof string failed. %{public}d", status); } - if(isString){ + if (isString) { auto srcString = ANIUtils_ANIStringToStdString(env, static_cast(src)); return modifier->getCommonAniModifier()->getColorValueByString(srcString); } ani_class intClass; if ((status = env->FindClass("Lstd/core/Int;", &intClass)) != ANI_OK) { - // LOGW("GetColorValue find int failed. %{public}d", status); + HILOGW("GetColorValue find int failed. %{public}d", status); } ani_boolean isInt; if ((status = env->Object_InstanceOf(src, intClass, &isInt)) != ANI_OK) { - // LOGW("GetColorValue call instanceof int failed. %{public}d", status); + HILOGW("GetColorValue call instanceof int failed. %{public}d", status); } if (isInt) { ani_int intSrc; if ((status = env->Object_CallMethodByName_Int(src, "unboxed", ":I", &intSrc)) != ANI_OK) { - // LOGW("GetColorValue unboxed int failed. %{public}d", status); + HILOGW("GetColorValue unboxed int failed. %{public}d", status); } return modifier->getCommonAniModifier()->getColorValueByNumber(static_cast(intSrc)); } @@ -572,7 +572,6 @@ void SetDefaultTheme(ani_env* env, ani_object aniClass, ani_array colorArray, an } std::vector colors; - // auto basisTheme = TokenThemeStorage::GetInstance()->ObtainSystemTheme(); std::vector systemColors; modifier->getAniThemeModifier()->obtainSystemColors(systemColors); for (int32_t i = 0; i < tokenColorsSize; i++) { diff --git a/frameworks/core/interfaces/native/ani/ani_theme_module.cpp b/frameworks/core/interfaces/native/ani/ani_theme_module.cpp index 230867f6ea4..b4f1b15eed0 100644 --- a/frameworks/core/interfaces/native/ani/ani_theme_module.cpp +++ b/frameworks/core/interfaces/native/ani/ani_theme_module.cpp @@ -84,34 +84,6 @@ ColorMode AniThemeModule::MapAniColorModeToColorMode(int32_t aniColorMode) return ColorMode::COLOR_MODE_UNDEFINED; } -// bool AniThemeModule::HandleThemeColorsArg( -// ani_env* env, ani_array colorsArg, std::vector& colors, std::vector>& resObjs) -// { -// auto basisTheme = TokenThemeStorage::GetInstance()->GetDefaultTheme(); -// if (!basisTheme) { -// basisTheme = TokenThemeStorage::GetInstance()->ObtainSystemTheme(); -// } -// if (!basisTheme) { -// return false; -// } -// for (size_t i = 0; i < TokenColors::TOTAL_NUMBER; i++) { -// Color color; -// ani_ref colorParams; -// RefPtr resObj; -// auto status = env->Array_Get(colorsArg, i, &colorParams); -// if (status != ANI_OK) { -// LOGW("HandleThemeColorsArg colorsArg get index: %{public}d failed", i); -// continue; -// } -// if (!ResourceAniModifier::ParseAniColor(env, static_cast(colorParams), color, resObj)) { -// color = basisTheme->Colors()->GetByIndex(i); -// } -// resObjs.push_back(resObj); -// colors.push_back(static_cast(color.GetValue())); -// } -// return true; -// } - ArkUINodeHandle AniThemeModule::CreateWithThemeNode(int32_t themeScopeId) { auto themeModifier = NodeModifier::GetThemeModifier(); diff --git a/frameworks/core/interfaces/native/ani/common_ani_modifier.cpp b/frameworks/core/interfaces/native/ani/common_ani_modifier.cpp index b97b32a53cc..e6cc54727f1 100644 --- a/frameworks/core/interfaces/native/ani/common_ani_modifier.cpp +++ b/frameworks/core/interfaces/native/ani/common_ani_modifier.cpp @@ -501,12 +501,7 @@ void CreateAndBindTheme(ani_env* env, ani_int themeScopeId, ani_int themeId, con int32_t themeIdValue = static_cast(themeId); int32_t colorModeValue = static_cast(colorMode); - // std::vector colors; std::vector> resObjs; - // if (!AniThemeModule::HandleThemeColorsArg(env, colorsArg, colors, resObjs)) { - // return; - // } - if (!onThemeScopeDestroy) { return; } diff --git a/frameworks/core/interfaces/native/ani/resource_ani_modifier.cpp b/frameworks/core/interfaces/native/ani/resource_ani_modifier.cpp index d23f923f5fb..0dcd77ceacb 100644 --- a/frameworks/core/interfaces/native/ani/resource_ani_modifier.cpp +++ b/frameworks/core/interfaces/native/ani/resource_ani_modifier.cpp @@ -28,88 +28,6 @@ #include "core/common/resource/resource_object.h" namespace OHOS::Ace::NG { -// namespace { -// constexpr uint32_t COLOR_ALPHA_OFFSET = 24; -// constexpr uint32_t COLOR_ALPHA_VALUE = 0xFF000000; -// uint32_t ColorAlphaAdapt(uint32_t origin) -// { -// uint32_t result = origin; -// if ((origin >> COLOR_ALPHA_OFFSET) == 0) { -// result = origin | COLOR_ALPHA_VALUE; -// } -// return result; -// } -// } // namespace -// bool ParseAniColor(ani_env* env, ani_object aniValue, Color& color, RefPtr& resObj) -// { -// ani_status status; -// ani_class stringClass; -// if ((status = env->FindClass("Lstd/core/String;", &stringClass)) != ANI_OK) { -// LOGW("ParseAniColor find string failed. %{public}d", status); -// return false; -// } -// ani_boolean isString; -// if ((status = env->Object_InstanceOf(aniValue, stringClass, &isString)) != ANI_OK) { -// LOGW("ParseAniColor call instanceof string failed. %{public}d", status); -// return false; -// } -// if (isString) { -// auto srcString = ArktsAniUtils::ANIStringToStdString(env, static_cast(aniValue)); -// Color::ParseColorString(srcString, color); -// return true; -// } - -// ani_class doubleClass; -// if ((status = env->FindClass("Lstd/core/Double;", &doubleClass)) != ANI_OK) { -// LOGW("ParseAniColor find int failed. %{public}d", status); -// return false; -// } -// ani_boolean isDouble; -// if ((status = env->Object_InstanceOf(aniValue, doubleClass, &isDouble)) != ANI_OK) { -// LOGW("ParseAniColor call instanceof double failed. %{public}d", status); -// return false; -// } -// if (isDouble) { -// ani_double doubleSrc; -// if ((status = env->Object_CallMethodByName_Double(aniValue, "unboxed", ":d", &doubleSrc)) != ANI_OK) { -// LOGW("GetColorValue unboxed double failed. %{public}d", status); -// return false; -// } -// color = Color(ColorAlphaAdapt(static_cast(doubleSrc))); -// return true; -// } - -// ani_class resourceClass; -// if ((status = env->FindClass("Lglobal/resource/Resource;", &resourceClass)) != ANI_OK) { -// LOGW("ParseAniColor find Resource failed. %{public}d", status); -// return false; -// } -// ani_boolean isResource; -// if ((status = env->Object_InstanceOf(aniValue, resourceClass, &isResource)) != ANI_OK) { -// LOGW("ParseAniColor call instanceof Resource failed. %{public}d", status); -// return false; -// } -// if (isResource) { -// ani_double resId; -// env->Object_GetPropertyByName_Double(aniValue, "id", &resId); -// ani_double resType; -// env->Object_GetPropertyByName_Double(aniValue, "type", &resType); -// ani_ref bundleName; -// env->Object_GetPropertyByName_Ref(aniValue, "bundleName", &bundleName); -// ani_ref moduleName; -// env->Object_GetPropertyByName_Ref(aniValue, "moduleName", &moduleName); -// std::vector params; -// resObj = AceType::MakeRefPtr(resId, resType, params, -// ArktsAniUtils::ANIStringToStdString(env, static_cast(bundleName)), -// ArktsAniUtils::ANIStringToStdString(env, static_cast(moduleName)), -// Container::CurrentIdSafely()); -// auto resAdapter = ResourceManager::GetInstance().GetOrCreateResourceAdapter(resObj); -// color = resAdapter->GetColor(static_cast(resId)); -// return true; -// } -// return false; -// } - uint32_t GetColorById(int32_t id, int32_t type, std::string bundleName, std::string moduleName) { auto resObj = AceType::MakeRefPtr(bundleName, moduleName, Container::CurrentIdSafely()); diff --git a/frameworks/core/interfaces/native/implementation/with_theme_modifier.cpp b/frameworks/core/interfaces/native/implementation/with_theme_modifier.cpp index c9472504f31..6e369b1149f 100644 --- a/frameworks/core/interfaces/native/implementation/with_theme_modifier.cpp +++ b/frameworks/core/interfaces/native/implementation/with_theme_modifier.cpp @@ -37,8 +37,6 @@ void SetWithThemeOptionsImpl(Ark_NativePointer node, auto frameNode = reinterpret_cast(node); CHECK_NULL_VOID(frameNode); CHECK_NULL_VOID(options); - //auto convValue = Converter::OptConvert(*options); - //WithThemeModelNG::SetSetWithThemeOptions(frameNode, convValue); } } // WithThemeInterfaceModifier const GENERATED_ArkUIWithThemeModifier* GetWithThemeModifier() -- Gitee From 08d9486c84b2538bd1e301848e87cc41057c2569 Mon Sep 17 00:00:00 2001 From: fangzhiyuan Date: Wed, 23 Jul 2025 21:48:37 +0800 Subject: [PATCH 10/11] undefined symbol fix Signed-off-by: fangzhiyuan Change-Id: I43d3985d1cac0844ad2e3e2863171378f7a001e2 --- .../core/interfaces/native/implementation/button_modifier.cpp | 3 --- 1 file changed, 3 deletions(-) diff --git a/frameworks/core/interfaces/native/implementation/button_modifier.cpp b/frameworks/core/interfaces/native/implementation/button_modifier.cpp index c548f81e1ad..0b3c6b5fc4f 100644 --- a/frameworks/core/interfaces/native/implementation/button_modifier.cpp +++ b/frameworks/core/interfaces/native/implementation/button_modifier.cpp @@ -21,7 +21,6 @@ #include "arkoala_api_generated.h" #include "core/interfaces/native/utility/converter.h" #include "core/interfaces/native/utility/validators.h" -#include "core/interfaces/native/implementation/theme/ani_button_theme.h" namespace OHOS::Ace::NG { struct ButtonOptions { @@ -128,7 +127,6 @@ void SetButtonOptions1Impl(Ark_NativePointer node, } else { ButtonModelStatic::SetButtonStyle(frameNode, std::nullopt); } - AniButtonTheme::ApplyTheme(ButtonRole::NORMAL, ButtonStyleMode::EMPHASIZE, true); } void SetButtonOptions2Impl(Ark_NativePointer node, const Ark_ResourceStr* label, @@ -144,7 +142,6 @@ void SetButtonOptions2Impl(Ark_NativePointer node, } auto labelString = Converter::OptConvert(*label); ButtonModelStatic::SetLabel(frameNode, labelString.value_or("").c_str()); - AniButtonTheme::ApplyTheme(ButtonRole::NORMAL, ButtonStyleMode::EMPHASIZE, true); } } // ButtonInterfaceModifier namespace ButtonAttributeModifier { -- Gitee From b43e0c5adc85936448bdeb7e5a1afbb98b3e368e Mon Sep 17 00:00:00 2001 From: fangzhiyuan Date: Fri, 25 Jul 2025 00:16:26 +0800 Subject: [PATCH 11/11] compile fix Signed-off-by: fangzhiyuan Change-Id: Ib4a7e4ab79d76c96cc680efe51cd8622ee87dfc6 --- .../arkui-ohos/src/ani/native/common/common_module.cpp | 1 - .../arkui-ohos/src/ani/native/resource/resource_module.cpp | 1 - frameworks/core/interfaces/ani/ani_api.h | 3 +-- frameworks/core/interfaces/native/ani/theme_ani_modifier.cpp | 1 + 4 files changed, 2 insertions(+), 4 deletions(-) diff --git a/frameworks/bridge/arkts_frontend/koala_projects/arkoala-arkts/arkui-ohos/src/ani/native/common/common_module.cpp b/frameworks/bridge/arkts_frontend/koala_projects/arkoala-arkts/arkui-ohos/src/ani/native/common/common_module.cpp index d07e8d8419e..240893cb9ba 100644 --- a/frameworks/bridge/arkts_frontend/koala_projects/arkoala-arkts/arkui-ohos/src/ani/native/common/common_module.cpp +++ b/frameworks/bridge/arkts_frontend/koala_projects/arkoala-arkts/arkui-ohos/src/ani/native/common/common_module.cpp @@ -583,7 +583,6 @@ void SetDefaultTheme(ani_env* env, ani_object aniClass, ani_array colorArray, an continue; } uint32_t color = 0; - RefPtr resObj; bool isColorAvailable = false; if (!ResourceModule::ParseAniColor(env, static_cast(value), color)) { if (i < systemColors.size()) { diff --git a/frameworks/bridge/arkts_frontend/koala_projects/arkoala-arkts/arkui-ohos/src/ani/native/resource/resource_module.cpp b/frameworks/bridge/arkts_frontend/koala_projects/arkoala-arkts/arkui-ohos/src/ani/native/resource/resource_module.cpp index 73c3054c5cb..6f740848c71 100644 --- a/frameworks/bridge/arkts_frontend/koala_projects/arkoala-arkts/arkui-ohos/src/ani/native/resource/resource_module.cpp +++ b/frameworks/bridge/arkts_frontend/koala_projects/arkoala-arkts/arkui-ohos/src/ani/native/resource/resource_module.cpp @@ -141,7 +141,6 @@ bool ResourceModule::HandleThemeColorsArg(ani_env* env, ani_array colorsArg, std continue; } uint32_t color = 0; - RefPtr resObj; bool isColorAvailable = false; if (!ResourceModule::ParseAniColor(env, static_cast(value), color)) { if (i < basisColors.size()) { diff --git a/frameworks/core/interfaces/ani/ani_api.h b/frameworks/core/interfaces/ani/ani_api.h index 46730ab5f85..3f35ac8acf3 100644 --- a/frameworks/core/interfaces/ani/ani_api.h +++ b/frameworks/core/interfaces/ani/ani_api.h @@ -56,6 +56,7 @@ typedef struct napi_value__* napi_value; typedef class __ani_array* ani_array; typedef _ArkUINode* ArkUINodeHandle; typedef int ArkUI_Int32; +typedef uint32_t ArkUI_Uint32; typedef size_t ani_size; typedef _ArkUIContentSlot* ArkUIContentSlot; typedef _ArkUINodeContent* ArkUINodeContent; @@ -437,8 +438,6 @@ struct ArkUIAniCanvasModifier { struct ArkUIResourceModifier { uint32_t (*getColorById)(int32_t id, int32_t type, std::string bundleName, std::string moduleName); - bool (*parseAniColor)(ani_env* env, ani_object aniValue, OHOS::Ace::Color& color, - OHOS::Ace::RefPtr& resObj); }; struct ArkUIColorModifier { diff --git a/frameworks/core/interfaces/native/ani/theme_ani_modifier.cpp b/frameworks/core/interfaces/native/ani/theme_ani_modifier.cpp index 2315aa80887..2e738655b42 100644 --- a/frameworks/core/interfaces/native/ani/theme_ani_modifier.cpp +++ b/frameworks/core/interfaces/native/ani/theme_ani_modifier.cpp @@ -18,6 +18,7 @@ #include #include +#include "ui/base/utils/utils.h" #include "ui/view/theme/token_colors.h" #include "core/components_ng/token_theme/token_theme_storage.h" -- Gitee