From 5f2603c8fcbdac1d35f57d60a7d75f7a4bce753b Mon Sep 17 00:00:00 2001 From: wujinhui Date: Sat, 23 Aug 2025 17:09:43 +0800 Subject: [PATCH] bug fix attribute modifier Signed-off-by: wujinhui --- .../arkui-ohos/src/AttributeUpdater.ts | 3 +- .../arkui-ohos/src/CommonModifier.ts | 14 ++++++ .../arkui-ohos/src/component/common.ts | 19 ++++++++ .../modifiers/ArkCommonModifier.ts | 43 +++++++++++++------ 4 files changed, 66 insertions(+), 13 deletions(-) diff --git a/frameworks/bridge/arkts_frontend/koala_projects/arkoala-arkts/arkui-ohos/src/AttributeUpdater.ts b/frameworks/bridge/arkts_frontend/koala_projects/arkoala-arkts/arkui-ohos/src/AttributeUpdater.ts index dc58eee5355..b15d376d548 100644 --- a/frameworks/bridge/arkts_frontend/koala_projects/arkoala-arkts/arkui-ohos/src/AttributeUpdater.ts +++ b/frameworks/bridge/arkts_frontend/koala_projects/arkoala-arkts/arkui-ohos/src/AttributeUpdater.ts @@ -14,6 +14,7 @@ */ import { AttributeModifier, ArkCommonMethodPeer } from "arkui/component/common"; +import { PeerNode } from './PeerNode'; export type Initializer = (...params:FixedArray) => T; @@ -25,7 +26,7 @@ export class AttributeUpdater implements AttributeModifier { } private value: T | undefined = undefined; private constructorParams: Initializer | undefined = undefined; - public peerNode_?: ArkCommonMethodPeer; + public peerNode_?: PeerNode; public set attribute(value: T) { this.value = value diff --git a/frameworks/bridge/arkts_frontend/koala_projects/arkoala-arkts/arkui-ohos/src/CommonModifier.ts b/frameworks/bridge/arkts_frontend/koala_projects/arkoala-arkts/arkui-ohos/src/CommonModifier.ts index 2f768d374f2..512bbcf1188 100644 --- a/frameworks/bridge/arkts_frontend/koala_projects/arkoala-arkts/arkui-ohos/src/CommonModifier.ts +++ b/frameworks/bridge/arkts_frontend/koala_projects/arkoala-arkts/arkui-ohos/src/CommonModifier.ts @@ -22,4 +22,18 @@ export class CommonModifier extends CommonMethodModifier implements CommonAttri applyFocusedAttribute(instance: CommonAttribute) : void {} applyDisabledAttribute(instance: CommonAttribute) : void {} applySelectedAttribute(instance: CommonAttribute) : void {} + onlyHaveNormalFunc(): boolean { + const applyPressedAttribute1 = ( Type.of(this) as ClassType).getMethodByName("applyPressedAttribute"); + const applyPressedAttribute2 = (Type.from() as ClassType).getMethodByName("applyPressedAttribute"); + const applyFocusedAttribute1 = ( Type.of(this) as ClassType).getMethodByName("applyFocusedAttribute"); + const applyFocusedAttribute2 = (Type.from() as ClassType).getMethodByName("applyFocusedAttribute"); + const applyDisabledAttribute1 = ( Type.of(this) as ClassType).getMethodByName("applyDisabledAttribute"); + const applyDisabledAttribute2 = (Type.from() as ClassType).getMethodByName("applyDisabledAttribute"); + const applySelectedAttribute1 = ( Type.of(this) as ClassType).getMethodByName("applySelectedAttribute"); + const applySelectedAttribute2 = (Type.from() as ClassType).getMethodByName("applySelectedAttribute"); + return applyPressedAttribute1.toString() === applyPressedAttribute2.toString() && + applyFocusedAttribute1.toString() === applyFocusedAttribute2.toString() && + applyDisabledAttribute1.toString() === applyDisabledAttribute2.toString() && + applySelectedAttribute1.toString() === applySelectedAttribute2.toString(); + } } \ No newline at end of file diff --git a/frameworks/bridge/arkts_frontend/koala_projects/arkoala-arkts/arkui-ohos/src/component/common.ts b/frameworks/bridge/arkts_frontend/koala_projects/arkoala-arkts/arkui-ohos/src/component/common.ts index 7ff37273c8d..d9def25785f 100644 --- a/frameworks/bridge/arkts_frontend/koala_projects/arkoala-arkts/arkui-ohos/src/component/common.ts +++ b/frameworks/bridge/arkts_frontend/koala_projects/arkoala-arkts/arkui-ohos/src/component/common.ts @@ -13390,6 +13390,25 @@ export interface AttributeModifier { applyFocusedAttribute(instance: T) : void {} applyDisabledAttribute(instance: T) : void {} applySelectedAttribute(instance: T) : void {} + onlyHaveNormalFunc(): boolean { + const applyPressedAttribute1 = this.getMethodByName('applyPressedAttribute', (Type.of(this) as ClassType)); + const applyFocusedAttribute1 = this.getMethodByName('applyFocusedAttribute', (Type.of(this) as ClassType)); + const applyDisabledAttribute1 = this.getMethodByName('applyDisabledAttribute', (Type.of(this) as ClassType)); + const applySelectedAttribute1 = this.getMethodByName('applySelectedAttribute', (Type.of(this) as ClassType)); + return applyPressedAttribute1 == undefined && + applyFocusedAttribute1 == undefined && + applyDisabledAttribute1 == undefined && + applyDisabledAttribute1 == undefined; + } + getMethodByName(name: string, interfaceType : ClassType): Method | undefined { + for (let methodIdx = 0; methodIdx < interfaceType.getMethodsNum(); ++methodIdx) { + const method = interfaceType.getMethod(methodIdx) + if (method.getName() == name && !method.isStatic()) { + return method; + } + } + return undefined; + } } export interface Type_CommonMethod_linearGradient_value { diff --git a/frameworks/bridge/arkts_frontend/koala_projects/arkoala-arkts/arkui-ohos/src/handwritten/modifiers/ArkCommonModifier.ts b/frameworks/bridge/arkts_frontend/koala_projects/arkoala-arkts/arkui-ohos/src/handwritten/modifiers/ArkCommonModifier.ts index d51d23d887e..5d1840b4876 100644 --- a/frameworks/bridge/arkts_frontend/koala_projects/arkoala-arkts/arkui-ohos/src/handwritten/modifiers/ArkCommonModifier.ts +++ b/frameworks/bridge/arkts_frontend/koala_projects/arkoala-arkts/arkui-ohos/src/handwritten/modifiers/ArkCommonModifier.ts @@ -34,6 +34,8 @@ import { int32} from "@koalaui/common" import { PeerNode } from '../../PeerNode'; import { InteropNativeModule } from '@koalaui/interop'; import { CommonMethodModifier } from '../../CommonMethodModifier'; +import { ComponentBase } from '../../ComponentBase'; + export enum ModifierType { ORIGIN = 0, STATE = 1, @@ -106,7 +108,7 @@ const UI_STATE_FOCUSED = 1 << 1; const UI_STATE_DISABLED = 1 << 2; const UI_STATE_SELECTED = 1 << 3; -export function applyUIAttributes(modifier: AttributeModifier, attributeSet: CommonMethodModifier, state: int32 = 0): void { +export function applyUIAttributes(modifier: AttributeModifier, attributeSet: MethodSet, state: int32 = 0): void { modifier.applyNormalAttribute(attributeSet as T); if (state & UI_STATE_PRESSED) { modifier.applyPressedAttribute(attributeSet as T); @@ -122,7 +124,7 @@ export function applyUIAttributes(modifier: AttributeModifier, attributeSe } } -export function applyUIAttributesUpdate(modifier: AttributeModifier, attributeSet: CommonMethodModifier, state: int32 = 0, isInit:boolean = true): void { +export function applyUIAttributesUpdate(modifier: AttributeModifier, attributeSet: MethodSet, state: int32 = 0, isInit:boolean = true): void { if (state == UI_STATE_NORMAL && !isInit) { modifier.applyNormalAttribute(attributeSet as T); } @@ -2009,8 +2011,9 @@ export class ArkCommonAttributeSet implements CommonAttribute { } } -export function applyAttributeModifierBase - (modifier: AttributeModifier, attributeSet: () => MethodSet, func: (component: MethodComponent, ...params: FixedArray) => void, updaterReceiver: () => MethodComponent, node: ArkCommonMethodPeer): void { +export function applyAttributeModifierNoCommonMethod + (modifier: AttributeModifier, attributeSet: () => MethodSet, func: (component: MethodComponent, ...params: FixedArray) => void, updaterReceiver: () => MethodComponent, node: PeerNode, + isStateStyle: boolean = true): MethodSet { let attributeSet_ = attributeSet(); let isAttributeUpdater: boolean = (modifier instanceof AttributeUpdater); if (isAttributeUpdater) { @@ -2036,18 +2039,34 @@ export function applyAttributeModifierBase + (modifier: AttributeModifier, attributeSet: () => MethodSet, func: (component: MethodComponent, ...params: FixedArray) => void, updaterReceiver: () => MethodComponent, node: ArkCommonMethodPeer, + isStateStyle: boolean = true): void { + let attributeSet_ = applyAttributeModifierNoCommonMethod(modifier, attributeSet, func, updaterReceiver, node, isStateStyle) as CommonMethodModifier; + attributeSet_!.applyModifierPatch(node); } export function applyCommonModifier(peerNode: ArkCommonMethodPeer, modifier: AttributeModifier) { -- Gitee