From 3e26ff9365ecc04dfca1e17f6a6da85c44e63f1c Mon Sep 17 00:00:00 2001 From: xingguang Date: Thu, 7 Dec 2023 18:15:05 +0800 Subject: [PATCH] =?UTF-8?q?=E3=80=90UX=E5=A2=9E=E5=BC=BA=E3=80=91Common?= =?UTF-8?q?=E7=BB=84=E4=BB=B6Button=E7=BB=84=E4=BB=B6=E5=92=8CTab=E7=BB=84?= =?UTF-8?q?=E4=BB=B6,=E5=AF=B9resource=E6=94=AF=E6=8C=81=20Signed-off-by:?= =?UTF-8?q?=20xingguang=20?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../ark_component/src/ArkButton.ts | 133 +++++++------- .../ark_component/src/ArkComponent.ts | 173 ++++++++++-------- .../ark_component/src/ArkTabs.ts | 93 ++++++---- .../arkts_native_button_bridge.cpp | 40 ++-- .../arkts_native_common_bridge.cpp | 92 ++++------ .../nativeModule/arkts_native_tabs_bridge.cpp | 60 +++--- 6 files changed, 306 insertions(+), 285 deletions(-) diff --git a/frameworks/bridge/declarative_frontend/ark_component/src/ArkButton.ts b/frameworks/bridge/declarative_frontend/ark_component/src/ArkButton.ts index 557303fc1d4..39932f0d32d 100644 --- a/frameworks/bridge/declarative_frontend/ark_component/src/ArkButton.ts +++ b/frameworks/bridge/declarative_frontend/ark_component/src/ArkButton.ts @@ -44,20 +44,11 @@ class ArkButtonComponent extends ArkComponent implements ButtonAttribute { return this; } fontColor(value: ResourceColor): this { - let arkColor = new ArkColor(); - if (arkColor.parseColorValue(value)) { - modifier(this._modifiers, ButtonFontColorModifier, arkColor.color); - } else { - modifier(this._modifiers, ButtonFontColorModifier, undefined); - } + modifierWithKey(this._modifiersWithKeys, ButtonFontColorModifier.identity, ButtonFontColorModifier, value); return this; } fontSize(value: Length): this { - if (typeof value === 'number' || typeof value === 'string') { - modifier(this._modifiers, ButtonFontSizeModifier, value); - } else { - modifier(this._modifiers, ButtonFontSizeModifier, undefined); - } + modifierWithKey(this._modifiersWithKeys, ButtonFontSizeModifier.identity, ButtonFontSizeModifier, value); return this; } fontWeight(value: string | number | FontWeight): this { @@ -77,31 +68,11 @@ class ArkButtonComponent extends ArkComponent implements ButtonAttribute { return this; } fontFamily(value: string | Resource): this { - if (isString(value)) { - modifier(this._modifiers, ButtonFontFamilyModifier, value as string); - } else { - modifier(this._modifiers, ButtonFontFamilyModifier, undefined); - } + modifierWithKey(this._modifiersWithKeys, ButtonFontFamilyModifier.identity, ButtonFontFamilyModifier, value); return this; } labelStyle(value: LabelStyle): this { - if (isObject(value)) { - let data = new ArkLabelStyle(); - data.heightAdaptivePolicy = value.heightAdaptivePolicy; - data.maxFontSize = value.maxFontSize; - data.maxLines = value.maxLines; - data.minFontSize = value.minFontSize; - data.overflow = value.overflow; - if (isObject(value.font)) { - data.font.family = value.font.family; - data.font.size = value.font.size; - data.font.style = value.font.style; - data.font.weight = value.font.weight; - } - modifier(this._modifiers, ButtonLabelStyleModifier, data); - } else { - modifier(this._modifiers, ButtonLabelStyleModifier, undefined); - } + modifierWithKey(this._modifiersWithKeys, ButtonLabelStyleModifier.identity,ButtonLabelStyleModifier, value); return this; } } @@ -145,7 +116,7 @@ class ButtonFontStyleModifier extends Modifier { } } } -class ButtonFontFamilyModifier extends Modifier { +class ButtonFontFamilyModifier extends ModifierWithKey { static identity: Symbol = Symbol('buttonFontFamily'); applyPeer(node: KNode, reset: boolean): void { if (reset) { @@ -155,44 +126,64 @@ class ButtonFontFamilyModifier extends Modifier { GetUINativeModule().button.setFontFamily(node, this.value); } } + checkObjectDiff(): boolean { + if (isResource(this.stageValue) && isResource(this.value)) { + return !isResourceEqual(this.stageValue, this.value); + } + else { + return true; + } + } } -class ButtonLabelStyleModifier extends Modifier { +class ButtonLabelStyleModifier extends ModifierWithKey { static identity: Symbol = Symbol('buttonLabelStyle'); applyPeer(node: KNode, reset: boolean): void { if (reset) { GetUINativeModule().button.resetLabelStyle(node); } else { - if (isObject(this.value)) + let textOverflow = this.value.overflow; // number -> Ace::TextOverflow + let maxLines = this.value.maxLines; // number -> uint32_t + let minFontSize = this.value.minFontSize; // number/string -> Dimension + let maxFontSize = this.value.maxFontSize; // number/string -> Dimension + let heightAdaptivePolicy = this.value.heightAdaptivePolicy; // number -> Ace::TextHeightAdaptivePolicy + let fontSize = undefined; // number/string ->Dimension + let fontWeight = undefined; // string -> Ace::FontWeight + let fontStyle = undefined; // number -> Ace::FontStyle + let fontFamily = undefined; // string ->std::vector + if (isObject(this.value.font)) { - let textOverflow = this.value.overflow; // number -> Ace::TextOverflow - let maxLines = this.value.maxLines; // number -> uint32_t - let minFontSize = this.value.minFontSize; // number/string -> Dimension - let maxFontSize = this.value.maxFontSize; // number/string -> Dimension - let heightAdaptivePolicy = this.value.heightAdaptivePolicy; // number -> Ace::TextHeightAdaptivePolicy - let fontSize = undefined; // number/string ->Dimension - let fontWeight = undefined; // string -> Ace::FontWeight - let fontStyle = undefined; // number -> Ace::FontStyle - let fontFamily = undefined; // string ->std::vector - if (isObject(this.value.font)) - { - fontSize = this.value.font.size; - fontWeight = 'normal'; - fontStyle = this.value.font.style; - fontFamily = this.value.font.family; - if (typeof this.value.font.weight === "string") { - fontWeight = this.value.font.weight; - } else { - if (this.value.font.weight in FontWeightMap) { - fontWeight = FontWeightMap[this.value.font.weight]; - } + fontSize = this.value.font.size; + fontWeight = 'normal'; + fontStyle = this.value.font.style; + fontFamily = this.value.font.family; + if (typeof this.value.font.weight === "string") { + fontWeight = this.value.font.weight; + } else { + if (this.value.font.weight in FontWeightMap) { + fontWeight = FontWeightMap[this.value.font.weight]; } - } - GetUINativeModule().button.setLabelStyle(node, textOverflow, maxLines, minFontSize, maxFontSize, - heightAdaptivePolicy, fontSize, fontWeight, fontStyle, fontFamily); + } + GetUINativeModule().button.setLabelStyle(node, textOverflow, maxLines, minFontSize, maxFontSize, + heightAdaptivePolicy, fontSize, fontWeight, fontStyle, fontFamily); } } } + checkObjectDiff(): boolean { + if (isResource(this.stageValue) && isResource(this.value)) { + return !isResourceEqual(this.stageValue, this.value); + }else if(!isResource(this.stageValue) && !isResource(this.value)){ + return !(this.value.overflow === this.stageValue.overflow && + this.value.maxLines === this.stageValue.maxLines && + this.value.minFontSize === this.stageValue.minFontSize && + this.value.maxFontSize === this.stageValue.maxFontSize && + this.value.heightAdaptivePolicy === this.stageValue.heightAdaptivePolicy && + this.value.font === this.stageValue.font) + } + else { + return true; + } + } } class ButtonTypeModifier extends Modifier { static identity: Symbol = Symbol('buttonType'); @@ -205,7 +196,7 @@ class ButtonTypeModifier extends Modifier { } } } -class ButtonFontColorModifier extends Modifier { +class ButtonFontColorModifier extends ModifierWithKey { static identity: Symbol = Symbol('buttonFontColor'); applyPeer(node: KNode, reset: boolean): void { if (reset) { @@ -215,8 +206,17 @@ class ButtonFontColorModifier extends Modifier { GetUINativeModule().button.setFontColor(node, this.value); } } + + checkObjectDiff(): boolean { + if (isResource(this.stageValue) && isResource(this.value)) { + return !isResourceEqual(this.stageValue, this.value); + } + else { + return true; + } + } } -class ButtonFontSizeModifier extends Modifier { +class ButtonFontSizeModifier extends ModifierWithKey { static identity: Symbol = Symbol('buttonFontSize'); applyPeer(node: KNode, reset: boolean): void { if (reset) { @@ -226,6 +226,15 @@ class ButtonFontSizeModifier extends Modifier { GetUINativeModule().button.setFontSize(node, this.value); } } + + checkObjectDiff(): boolean { + if (isResource(this.stageValue) && isResource(this.value)) { + return !isResourceEqual(this.stageValue, this.value); + } + else { + return true; + } + } } class ButtonFontWeightModifier extends Modifier { static identity: Symbol = Symbol('buttonFontWeight'); diff --git a/frameworks/bridge/declarative_frontend/ark_component/src/ArkComponent.ts b/frameworks/bridge/declarative_frontend/ark_component/src/ArkComponent.ts index 88b664c9a07..8581a355284 100644 --- a/frameworks/bridge/declarative_frontend/ark_component/src/ArkComponent.ts +++ b/frameworks/bridge/declarative_frontend/ark_component/src/ArkComponent.ts @@ -341,11 +341,11 @@ class ShadowModifier extends ModifierWithKey { checkObjectDiff(): boolean { return !((this.stageValue as ShadowOptions).radius === (this.value as ShadowOptions).radius && - (this.stageValue as ShadowOptions).type === (this.value as ShadowOptions).type && - (this.stageValue as ShadowOptions).color === (this.value as ShadowOptions).color && - (this.stageValue as ShadowOptions).offsetX === (this.value as ShadowOptions).offsetX && - (this.stageValue as ShadowOptions).offsetY === (this.value as ShadowOptions).offsetY && - (this.stageValue as ShadowOptions).fill === (this.value as ShadowOptions).fill); + (this.stageValue as ShadowOptions).type === (this.value as ShadowOptions).type && + (this.stageValue as ShadowOptions).color === (this.value as ShadowOptions).color && + (this.stageValue as ShadowOptions).offsetX === (this.value as ShadowOptions).offsetX && + (this.stageValue as ShadowOptions).offsetY === (this.value as ShadowOptions).offsetY && + (this.stageValue as ShadowOptions).fill === (this.value as ShadowOptions).fill); } } @@ -465,7 +465,7 @@ class SaturateModifier extends Modifier { } } -class ColorBlendModifier extends Modifier { +class ColorBlendModifier extends Modifier { static identity: Symbol = Symbol("colorBlend"); applyPeer(node: KNode, reset: boolean): void { if (reset) { @@ -475,6 +475,14 @@ class ColorBlendModifier extends Modifier { GetUINativeModule().common.setColorBlend(node, this.value); } } + + checkObjectDiff(): boolean { + if (isResource(this.stageValue) && isResource(this.value)) { + return !isResourceEqual(this.stageValue, this.value); + } else { + return true; + } + } } class GrayscaleModifier extends Modifier { @@ -525,7 +533,7 @@ class BlurModifier extends Modifier { } } -class LinearGradientModifier extends Modifier { +class LinearGradientModifier extends ModifierWithKey<{ angle?: number | string; direction?: GradientDirection; colors: Array; repeating?: boolean; }> { static identity: Symbol = Symbol("linearGradient"); applyPeer(node: KNode, reset: boolean): void { if (reset) { @@ -537,9 +545,15 @@ class LinearGradientModifier extends Modifier { this.value.colors, this.value.repeating); } } + checkObjectDiff(): boolean { + return !((this.stageValue.angle === this.value.angle) && + (this.stageValue.direction === this.value.direction) && + (this.stageValue.colors === this.value.colors) && + (this.stageValue.repeating ===this.value.repeating)); + } } -class RadialGradientModifier extends Modifier { +class RadialGradientModifier extends ModifierWithKey<{ center: Array; radius: number | string; colors: Array; repeating?: boolean }> { static identity: Symbol = Symbol("radialGradient"); applyPeer(node: KNode, reset: boolean): void { if (reset) { @@ -550,9 +564,15 @@ class RadialGradientModifier extends Modifier { this.value.center, this.value.radius, this.value.colors, this.value.repeating); } } + checkObjectDiff(): boolean { + return !((this.stageValue.center === this.value.center) && + (this.stageValue .radius === this.value.radius) && + (this.stageValue.colors === this.value.colors) && + (this.stageValue.repeating === this.value.repeating)); + } } -class SweepGradientModifier extends Modifier { +class SweepGradientModifier extends ModifierWithKey<{ center: Array; start?: number | string; end?: number | string; rotation?: number | string; colors: Array; repeating?: boolean; }> { static identity: Symbol = Symbol("sweepGradient"); applyPeer(node: KNode, reset: boolean): void { if (reset) { @@ -565,6 +585,14 @@ class SweepGradientModifier extends Modifier { this.value.colors, this.value.repeating); } } + checkObjectDiff(): boolean { + return !((this.stageValue.center === this.value.center) && + (this.stageValue.start === this.value.start) && + (this.stageValue.end === this.value.end) && + (this.stageValue.rotation === this.value.rotation) && + (this.stageValue.colors === this.value.colors) && + (this.stageValue.repeating === this.value.repeating)); + } } class OverlayModifier extends ModifierWithKey { @@ -713,17 +741,37 @@ class ForegroundBlurStyleModifier extends ModifierWithKey{ +class BackgroundImagePositionModifier extends ModifierWithKey{ static identity: Symbol = Symbol("backgroundImagePosition"); applyPeer(node: KNode, reset: boolean): void { if (reset) { GetUINativeModule().common.resetBackgroundImagePosition(node); } else { - GetUINativeModule().common.setBackgroundImagePosition(node, this.value.alignment, this.value.x, this.value.y); + if (isNumber(this.value)) { + GetUINativeModule().common.setBackgroundImagePosition(node, this.value, undefined, undefined); + } else { + GetUINativeModule().common.setBackgroundImagePosition(node, undefined, (this.value as Position)?.x, (this.value as Position)?.y); + } + } + } + checkObjectDiff(): boolean { + if (!((isResource(this.stageValue) && isResource(this.value) && + isResourceEqual(this.stageValue, this.value)) || + (!isResource(this.stageValue) && !isResource(this.value) && + this.stageValue === this.value))) { + return true; } + return false; } } @@ -740,7 +788,7 @@ class LinearGradientBlurModifier extends Modifier { } } -class BackgroundImageModifier extends Modifier{ +class BackgroundImageModifier extends ModifierWithKey{ static identity: Symbol = Symbol("backgroundImage"); applyPeer(node: KNode, reset: boolean): void { if (reset) { @@ -750,6 +798,10 @@ class BackgroundImageModifier extends Modifier{ GetUINativeModule().common.setBackgroundImage(node, this.value.src, this.value.repeat); } } + checkObjectDiff(): boolean { + return !((this.stageValue as ArkBackgroundImage).src === (this.value as ArkBackgroundImage).src && + (this.stageValue as ArkBackgroundImage).repeat === (this.value as ArkBackgroundImage).repeat) + } } class BackgroundBlurStyleModifier extends ModifierWithKey { @@ -765,16 +817,29 @@ class BackgroundBlurStyleModifier extends ModifierWithKey{ +class BackgroundImageSizeModifier extends ModifierWithKey{ static identity: Symbol = Symbol("backgroundImageSize"); applyPeer(node: KNode, reset: boolean): void { if (reset) { GetUINativeModule().common.resetBackgroundImageSize(node); } else { - GetUINativeModule().common.setBackgroundImageSize(node, this.value.imageSize, this.value.width, this.value.height); + if (isNumber(this.value)) { + GetUINativeModule().common.setBackgroundImageSize(node, this.value, undefined, undefined); + } else { + GetUINativeModule().common.setBackgroundImageSize(node, undefined, (this.value as SizeOptions)?.width, (this.value as SizeOptions)?.height); + } } } + checkObjectDiff(): boolean { + if (!((isResource(this.stageValue) && isResource(this.value) && + isResourceEqual(this.stageValue, this.value)) || + (!isResource(this.stageValue) && !isResource(this.value) && + this.stageValue === this.value))) { + return true; + } + return false; + } } class TranslateModifier extends Modifier{ @@ -869,6 +934,13 @@ class PixelStretchEffectModifier extends ModifierWithKey { @@ -1871,53 +1943,19 @@ class ArkComponent implements CommonMethod { backgroundImage(src: ResourceStr, repeat?: ImageRepeat): this { let arkBackgroundImage = new ArkBackgroundImage() - if (isString(src)) { - arkBackgroundImage.src = src - } - if (isNumber(repeat)) { - arkBackgroundImage.repeat = repeat - } - modifier(this._modifiers, BackgroundImageModifier, arkBackgroundImage); + arkBackgroundImage.src = src + arkBackgroundImage.repeat = repeat + modifierWithKey(this._modifiersWithKeys, BackgroundImageModifier.identity, BackgroundImageModifier, arkBackgroundImage); return this; } backgroundImageSize(value: SizeOptions | ImageSize): this { - if (isResource(value) || isUndefined(value)) { - modifier(this._modifiers, BackgroundImageSizeModifier, undefined); - return this - } - let arkBackgroundImageSize = new ArkBackgroundImageSize() - if (isNumber(value)) { - arkBackgroundImageSize.imageSize = value - } else { - if (isNumber((value as SizeOptions)?.width) || isString((value as SizeOptions)?.width)) { - arkBackgroundImageSize.width = (value as SizeOptions)?.width; - } - if (isNumber((value as SizeOptions)?.height) || isString((value as SizeOptions)?.height)) { - arkBackgroundImageSize.height = (value as SizeOptions)?.height; - } - } - modifier(this._modifiers, BackgroundImageSizeModifier, arkBackgroundImageSize); + modifierWithKey(this._modifiersWithKeys, BackgroundImageSizeModifier.identity, BackgroundImageSizeModifier, value); return this; } backgroundImagePosition(value: Position | Alignment): this { - if (isResource(value) || isUndefined(value)) { - modifier(this._modifiers, BackgroundImagePositionModifier, undefined); - return this - } - let arkBackgroundImagePosition = new ArkBackgroundImagePosition() - if (isNumber(value)) { - arkBackgroundImagePosition.alignment = value - } else { - if (isNumber((value as Position)?.x) || isString((value as Position)?.x)) { - arkBackgroundImagePosition.x = (value as Position)?.x; - } - if (isNumber((value as Position)?.y) || isString((value as Position)?.y)) { - arkBackgroundImagePosition.y = (value as Position)?.y; - } - } - modifier(this._modifiers, BackgroundImagePositionModifier, arkBackgroundImagePosition); + modifierWithKey(this._modifiersWithKeys, BackgroundImagePositionModifier.identity, BackgroundImagePositionModifier, value); return this; } @@ -2217,12 +2255,7 @@ class ArkComponent implements CommonMethod { } colorBlend(value: Color | string | Resource): this { - let arkColor = new ArkColor(); - if (arkColor.parseColorValue(value)) { - modifier(this._modifiers, ColorBlendModifier, arkColor.color); - } else { - modifier(this._modifiers, ColorBlendModifier, undefined); - } + modifierWithKey(this._modifiersWithKeys, ColorBlendModifier.identity, ColorBlendModifier, value); return this; } @@ -2640,12 +2673,7 @@ class ArkComponent implements CommonMethod { colors: Array; repeating?: boolean; }): this { - if (isUndefined(value)) { - modifier(this._modifiers, LinearGradientModifier, undefined); - return this; - } - let arkLinearGradient = new ArkLinearGradient(value.angle, value.direction, value.colors, value.repeating); - modifier(this._modifiers, LinearGradientModifier, arkLinearGradient); + modifierWithKey(this._modifiersWithKeys, LinearGradientModifier.identity, LinearGradientModifier, value); return this; } @@ -2657,23 +2685,12 @@ class ArkComponent implements CommonMethod { colors: Array; repeating?: boolean; }): this { - if (isUndefined(value)) { - modifier(this._modifiers, SweepGradientModifier, undefined); - return this; - } - let arkSweepGradient = new ArkSweepGradient(value.center, value.start, value.end, value.rotation, - value.colors, value.repeating); - modifier(this._modifiers, SweepGradientModifier, arkSweepGradient); + modifierWithKey(this._modifiersWithKeys, SweepGradientModifier.identity, SweepGradientModifier, value); return this; } radialGradient(value: { center: Array; radius: number | string; colors: Array; repeating?: boolean }): this { - if (isUndefined(value)) { - modifier(this._modifiers, RadialGradientModifier, undefined); - return this; - } - let arkRadialGradient = new ArkRadialGradient(value.center, value.radius, value.colors, value.repeating); - modifier(this._modifiers, RadialGradientModifier, arkRadialGradient); + modifierWithKey(this._modifiersWithKeys, RadialGradientModifier.identity, RadialGradientModifier, value); return this; } diff --git a/frameworks/bridge/declarative_frontend/ark_component/src/ArkTabs.ts b/frameworks/bridge/declarative_frontend/ark_component/src/ArkTabs.ts index 11444772888..8b87b5ebb67 100644 --- a/frameworks/bridge/declarative_frontend/ark_component/src/ArkTabs.ts +++ b/frameworks/bridge/declarative_frontend/ark_component/src/ArkTabs.ts @@ -22,11 +22,9 @@ class ArkTabsComponent extends ArkComponent implements TabsAttribute { return this; } barMode(value: BarMode, options?: ScrollableBarModeOptions | undefined): TabsAttribute { - let arkBarMode: ArkBarMode = new ArkBarMode(); - arkBarMode.barMode = value; - arkBarMode.options = options; - - modifier(this._modifiers, TabBarModeModifier, arkBarMode); + modifierWithKey(this._modifiersWithKeys, ScrollableBarModeOptionsModifier.identity, + ScrollableBarModeOptionsModifier, options); + modifierWithKey(this._modifiersWithKeys, TabBarModeModifier.identity, TabBarModeModifier, value); return this; } @@ -60,17 +58,7 @@ class ArkTabsComponent extends ArkComponent implements TabsAttribute { return this; } divider(value: DividerStyle | null): TabsAttribute { - let arkDrivider = new ArkDivider(); - if (!!value) { - arkDrivider.divider.strokeWidth = value?.strokeWidth; - arkDrivider.divider.color = value?.color; - arkDrivider.divider.startMargin = value?.startMargin; - arkDrivider.divider.endMargin = value?.endMargin; - modifier(this._modifiers, DividerModifier, arkDrivider); - } else { - modifier(this._modifiers, DividerModifier, undefined); - } - + modifierWithKey(this._modifiersWithKeys, DividerModifier.identity, DividerModifier, value); return this; } barOverlap(value: boolean): TabsAttribute { @@ -82,47 +70,50 @@ class ArkTabsComponent extends ArkComponent implements TabsAttribute { return this; } barGridAlign(value: BarGridColumnOptions): TabsAttribute { - if (isObject(value)) { - let arkBarGridAlign = new ArkBarGridAlign(); - arkBarGridAlign.barGridAlign = value; - modifier(this._modifiers, BarGridAlignModifier, arkBarGridAlign); - } else { - modifier(this._modifiers, BarGridAlignModifier, undefined); - } - + modifierWithKey(this._modifiersWithKeys, BarGridAlignModifier.identity, BarGridAlignModifier, value); return this; } } -class BarGridAlignModifier extends Modifier { +class BarGridAlignModifier extends ModifierWithKey { static identity: Symbol = Symbol('barGridAlign'); applyPeer(node: KNode, reset: boolean): void { if (reset) { GetUINativeModule().tabs.resetBarGridAlign(node); } else { - GetUINativeModule().tabs.setBarGridAlign(node, this.value.barGridAlign.sm - , this.value.barGridAlign?.md - , this.value.barGridAlign?.lg - , this.value.barGridAlign?.margin - , this.value.barGridAlign?.gutter); + GetUINativeModule().tabs.setBarGridAlign(node, this.value.sm, + this.value.md, this.value.lg, this.value.gutter, this.value.margin); } } + + checkObjectDiff(): boolean { + return !(this.stageValue.sm === this.value.sm && + this.stageValue.md === this.value.md && + this.stageValue.lg === this.value.lg && + this.stageValue.gutter === this.value.gutter && + this.stageValue.margin === this.value.margin); + } } -class DividerModifier extends Modifier { +class DividerModifier extends ModifierWithKey { static identity: Symbol = Symbol('Divider'); applyPeer(node: KNode, reset: boolean): void { if (reset) { GetUINativeModule().tabs.resetDivider(node); } else { - GetUINativeModule().tabs.setDivider(node, this.value.divider.strokeWidth - , this.value.divider.color - , this.value.divider.startMargin - , this.value.divider.endMargin); + GetUINativeModule().tabs.setDivider(node, this.value.strokeWidth, + this.value.color, this.value.startMargin, this.value.endMargin); } } + + checkObjectDiff(): boolean { + return !(this.stageValue.strokeWidth === this.value.strokeWidth && + this.stageValue.color === this.value.color && + this.stageValue.startMargin === this.value.startMargin && + this.stageValue.endMargin === this.value.endMargin); + } } class BarWidthModifier extends ModifierWithKey { @@ -225,18 +216,20 @@ class ScrollableModifier extends Modifier { } } -class TabBarModeModifier extends Modifier { +class TabBarModeModifier extends ModifierWithKey { static identity: Symbol = Symbol('tabsbarMode'); applyPeer(node: KNode, reset: boolean): void { if (reset) { GetUINativeModule().tabs.resetTabBarMode(node); } else { - GetUINativeModule().tabs.setTabBarMode(node, this.value.barMode, - this.value.options?.margin, - this.value.options?.nonScrollableLayoutStyle); + GetUINativeModule().tabs.setTabBarMode(node, this.value); } } + + checkObjectDiff(): boolean { + return !(this.stageValue === this.value); + } } class BarPositionModifier extends Modifier { @@ -295,6 +288,28 @@ class FadingEdgeModifier extends Modifier { } } +class ScrollableBarModeOptionsModifier extends ModifierWithKey { + static identity: Symbol = Symbol('tabsscrollableBarModeOptions'); + + applyPeer(node: KNode, reset: boolean): void { + if (reset) { + GetUINativeModule().tabs.resetScrollableBarModeOptions(node); + } else { + GetUINativeModule().tabs.setScrollableBarModeOptions( + node, + this.value['margin'], + this.value['nonScrollableLayoutStyle'] + ); + } + } + + checkObjectDiff(): boolean { + return !(this.stageValue.margin === this.value.margin && + this.stageValue.nonScrollableLayoutStyle === this.value.nonScrollableLayoutStyle); + } + +} + // @ts-ignore globalThis.Tabs.attributeModifier = function (modifier) { const elmtId = ViewStackProcessor.GetElmtIdToAccountFor(); diff --git a/frameworks/bridge/declarative_frontend/engine/jsi/nativeModule/arkts_native_button_bridge.cpp b/frameworks/bridge/declarative_frontend/engine/jsi/nativeModule/arkts_native_button_bridge.cpp index b17d331240f..448bd8b6e6d 100644 --- a/frameworks/bridge/declarative_frontend/engine/jsi/nativeModule/arkts_native_button_bridge.cpp +++ b/frameworks/bridge/declarative_frontend/engine/jsi/nativeModule/arkts_native_button_bridge.cpp @@ -98,8 +98,12 @@ ArkUINativeModuleValue ButtonBridge::SetFontColor(ArkUIRuntimeCallInfo* runtimeC Local firstArg = runtimeCallInfo->GetCallArgRef(CALL_ARG_0); Local secondArg = runtimeCallInfo->GetCallArgRef(CALL_ARG_1); void* nativeNode = firstArg->ToNativePointer(vm)->Value(); - uint32_t fontColor = secondArg->Uint32Value(vm); - GetArkUIInternalNodeAPI()->GetButtonModifier().SetButtonFontColor(nativeNode, fontColor); + Color color; + if (!ArkTSUtils::ParseJsColorAlpha(vm, secondArg, color)) { + GetArkUIInternalNodeAPI()->GetButtonModifier().ResetButtonFontColor(nativeNode); + } else { + GetArkUIInternalNodeAPI()->GetButtonModifier().SetButtonFontColor(nativeNode, color.GetValue()); + } return panda::JSValueRef::Undefined(vm); } @@ -123,7 +127,7 @@ ArkUINativeModuleValue ButtonBridge::SetFontSize(ArkUIRuntimeCallInfo* runtimeCa Ace::CalcDimension fontSize; if (ArkTSUtils::ParseJsDimensionVpNG(vm, secondArg, fontSize) && fontSize.Unit() != DimensionUnit::PERCENT && GreatOrEqual(fontSize.Value(), 0.0)) { - ButtonParseJsDimensionFp(vm, secondArg, fontSize); + ArkTSUtils::ParseJsDimensionFp(vm, secondArg, fontSize); } else { auto pipeline = PipelineBase::GetCurrentContext(); CHECK_NULL_RETURN(pipeline, panda::NativePointerRef::New(vm, nullptr)); @@ -197,11 +201,15 @@ ArkUINativeModuleValue ButtonBridge::SetFontFamily(ArkUIRuntimeCallInfo* runtime Local firstArg = runtimeCallInfo->GetCallArgRef(CALL_ARG_0); Local secondArg = runtimeCallInfo->GetCallArgRef(CALL_ARG_1); void* nativeNode = firstArg->ToNativePointer(vm)->Value(); - if (!secondArg->IsString()) { + std::string src; + if (secondArg->IsString()) { + src = secondArg->ToString(vm)->ToString(); + } else if (secondArg->IsObject()) { + ArkTSUtils::ParseJsMedia(vm, secondArg, src); + } else { return panda::JSValueRef::Undefined(vm); } - std::string families = secondArg->ToString(vm)->ToString(); - GetArkUIInternalNodeAPI()->GetButtonModifier().SetButtonFontFamily(nativeNode, families.c_str()); + GetArkUIInternalNodeAPI()->GetButtonModifier().SetButtonFontFamily(nativeNode, src.c_str()); return panda::JSValueRef::Undefined(vm); } @@ -284,9 +292,11 @@ ArkUINativeModuleValue ButtonBridge::SetLabelStyle(ArkUIRuntimeCallInfo* runtime } PutButtonDimensionParameters(runtimeCallInfo, vm, dimensionValueArray, dimensionUnitArray); Local tenthArg = runtimeCallInfo->GetCallArgRef(CALL_ARG_9); - std::string families = tenthArg->ToString(vm)->ToString(); - GetArkUIInternalNodeAPI()->GetButtonModifier().SetButtonLabelStyle( - nativeNode, families.c_str(), valueArray, dimensionValueArray, dimensionUnitArray); + std::vector fontFamilies; + if (ArkTSUtils::ParseJsFontFamilies(vm, tenthArg, fontFamilies)) { + GetArkUIInternalNodeAPI()->GetButtonModifier().SetButtonLabelStyle( + nativeNode, fontFamilies[0].c_str(), valueArray, dimensionValueArray, dimensionUnitArray); + } return panda::JSValueRef::Undefined(vm); } @@ -295,20 +305,20 @@ void ButtonBridge::PutButtonDimensionParameters( { if (dimensionValueArray != nullptr && dimensionUnitArray != nullptr) { Local fourthArg = runtimeCallInfo->GetCallArgRef(CALL_ARG_3); - CalcDimension minFontSize; - if (ButtonParseJsDimensionFp(vm, fourthArg, minFontSize)) { + CalcDimension minFontSize(0, DimensionUnit::FP); + if (ArkTSUtils::ParseJsDimensionFp(vm, fourthArg, minFontSize, false)) { dimensionValueArray[INDEX_MIN_FONT_SIZE_0] = minFontSize.Value(); dimensionUnitArray[INDEX_MIN_FONT_SIZE_0] = static_cast(minFontSize.Unit()); } Local fifthArg = runtimeCallInfo->GetCallArgRef(CALL_ARG_4); - CalcDimension maxFontSize; - if (ButtonParseJsDimensionFp(vm, fifthArg, maxFontSize)) { + CalcDimension maxFontSize(0, DimensionUnit::FP); + if (ArkTSUtils::ParseJsDimensionFp(vm, fifthArg, maxFontSize, false)) { dimensionValueArray[INDEX_MAX_FONT_SIZE_1] = maxFontSize.Value(); dimensionUnitArray[INDEX_MAX_FONT_SIZE_1] = static_cast(maxFontSize.Unit()); } Local seventhArg = runtimeCallInfo->GetCallArgRef(CALL_ARG_6); - CalcDimension fontSize; - if (ButtonParseJsDimensionFp(vm, seventhArg, fontSize)) { + CalcDimension fontSize(0, DimensionUnit::FP); + if (ArkTSUtils::ParseJsDimensionFp(vm, seventhArg, fontSize, false)) { dimensionValueArray[INDEX_FONT_SIZE_2] = fontSize.Value(); dimensionUnitArray[INDEX_FONT_SIZE_2] = static_cast(fontSize.Unit()); } diff --git a/frameworks/bridge/declarative_frontend/engine/jsi/nativeModule/arkts_native_common_bridge.cpp b/frameworks/bridge/declarative_frontend/engine/jsi/nativeModule/arkts_native_common_bridge.cpp index 9b0107eb7bd..c5bb700a569 100644 --- a/frameworks/bridge/declarative_frontend/engine/jsi/nativeModule/arkts_native_common_bridge.cpp +++ b/frameworks/bridge/declarative_frontend/engine/jsi/nativeModule/arkts_native_common_bridge.cpp @@ -74,30 +74,6 @@ BorderStyle ConvertBorderStyle(int32_t value) return style; } -bool ParseJsDimensionVp(const EcmaVM *vm, const Local &value, CalcDimension &result) -{ - if (value->IsNumber()) { - result = CalcDimension(value->ToNumber(vm)->Value(), DimensionUnit::VP); - return true; - } - if (value->IsString()) { - result = StringUtils::StringToCalcDimension(value->ToString(vm)->ToString(), false, DimensionUnit::VP); - return true; - } - - return false; -} - -bool ParseJsInteger(const EcmaVM *vm, const Local &value, int32_t &result) -{ - if (value->IsNumber()) { - result = value->Int32Value(vm); - return true; - } - - return false; -} - bool ParseJsDouble(const EcmaVM *vm, const Local &value, double &result) { if (value->IsNumber()) { @@ -740,7 +716,6 @@ bool ParseMotionPath(const Framework::JSRef& jsValue, MotionPa return true; } - bool ParseJsDoublePair(const EcmaVM *vm, const Local &value, double &first, double &second) { if (!value->IsArray(vm)) { @@ -1557,7 +1532,7 @@ ArkUINativeModuleValue CommonBridge::SetShadow(ArkUIRuntimeCallInfo *runtimeCall auto fillArg = runtimeCallInfo->GetCallArgRef(NUM_7); auto nativeNode = firstArg->ToNativePointer(vm)->Value(); int32_t shadowStyle = 0; - if (ParseJsInteger(vm, styleArg, shadowStyle)) { + if (ArkTSUtils::ParseJsInteger(vm, styleArg, shadowStyle)) { double shadows[] = { shadowStyle }; GetArkUIInternalNodeAPI()->GetCommonModifier().SetBackShadow(nativeNode, shadows, (sizeof(shadows) / sizeof(shadows[NUM_0]))); @@ -1838,8 +1813,12 @@ ArkUINativeModuleValue CommonBridge::SetColorBlend(ArkUIRuntimeCallInfo *runtime Local firstArg = runtimeCallInfo->GetCallArgRef(NUM_0); Local secondArg = runtimeCallInfo->GetCallArgRef(NUM_1); void *nativeNode = firstArg->ToNativePointer(vm)->Value(); - uint32_t color = secondArg->Uint32Value(vm); - GetArkUIInternalNodeAPI()->GetCommonModifier().SetColorBlend(nativeNode, color); + Color color; + if (!ArkTSUtils::ParseJsColorAlpha(vm, secondArg, color)) { + GetArkUIInternalNodeAPI()->GetCommonModifier().ResetColorBlend(nativeNode); + } else { + GetArkUIInternalNodeAPI()->GetCommonModifier().SetColorBlend(nativeNode, color.GetValue()); + } return panda::JSValueRef::Undefined(vm); } @@ -2343,19 +2322,16 @@ ArkUINativeModuleValue CommonBridge::SetBackgroundImagePosition(ArkUIRuntimeCall int32_t align = secondArg->ToNumber(vm)->Value(); ParseBackgroundImagePositionAlign(align, valueX, valueY, typeX, typeY); isAlign = true; - } else if (xArg->IsNumber() || xArg->IsString() || yArg->IsNumber() || yArg->IsString()) { - CalcDimension x; - CalcDimension y; + } else { + CalcDimension x(0, DimensionUnit::VP); + CalcDimension y(0, DimensionUnit::VP); - bool hasX = ParseJsDimensionVp(vm, xArg, x); - bool hasY = ParseJsDimensionVp(vm, yArg, y); - if (hasX || hasY) { + if (ArkTSUtils::ParseJsDimensionVp(vm, xArg, x)) { valueX = x.Value(); + } + if (ArkTSUtils::ParseJsDimensionVp(vm, yArg, y)) { valueY = y.Value(); - typeX = DimensionUnit::PX; - typeY = DimensionUnit::PX; } - if (x.Unit() == DimensionUnit::PERCENT) { valueX = x.Value(); typeX = DimensionUnit::PERCENT; @@ -2408,23 +2384,24 @@ ArkUINativeModuleValue CommonBridge::SetBackgroundImageSize(ArkUIRuntimeCallInfo typeWidth = static_cast(sizeType); typeHeight = static_cast(sizeType); } else { - CalcDimension width; - CalcDimension height; - ArkTSUtils::ParseJsDimensionVp(vm, widthArg, width); - ArkTSUtils::ParseJsDimensionVp(vm, heightArg, height); - - valueWidth = width.ConvertToPx(); - valueHeight = height.ConvertToPx(); - typeWidth = BackgroundImageSizeType::LENGTH; - typeHeight = BackgroundImageSizeType::LENGTH; - - if (width.Unit() == DimensionUnit::PERCENT) { - typeWidth = BackgroundImageSizeType::PERCENT; - valueWidth = width.Value() * FULL_DIMENSION; - } - if (height.Unit() == DimensionUnit::PERCENT) { - typeHeight = BackgroundImageSizeType::PERCENT; - valueHeight = height.Value() * FULL_DIMENSION; + CalcDimension width(0, DimensionUnit::VP); + CalcDimension height(0, DimensionUnit::VP); + bool hasWidth = ArkTSUtils::ParseJsDimensionVp(vm, widthArg, width); + bool hasHeight = ArkTSUtils::ParseJsDimensionVp(vm, heightArg, height); + if (hasWidth || hasHeight) { + valueWidth = width.ConvertToPx(); + valueHeight = height.ConvertToPx(); + typeWidth = BackgroundImageSizeType::LENGTH; + typeHeight = BackgroundImageSizeType::LENGTH; + + if (width.Unit() == DimensionUnit::PERCENT) { + typeWidth = BackgroundImageSizeType::PERCENT; + valueWidth = width.Value() * FULL_DIMENSION; + } + if (height.Unit() == DimensionUnit::PERCENT) { + typeHeight = BackgroundImageSizeType::PERCENT; + valueHeight = height.Value() * FULL_DIMENSION; + } } } GetArkUIInternalNodeAPI()->GetCommonModifier().SetBackgroundImageSize(nativeNode, valueWidth, valueHeight, @@ -2452,15 +2429,16 @@ ArkUINativeModuleValue CommonBridge::SetBackgroundImage(ArkUIRuntimeCallInfo *ru void *nativeNode = firstArg->ToNativePointer(vm)->Value(); std::string src; int32_t repeatIndex = 0; - if (!srcArg->IsString()) { + if (!ArkTSUtils::ParseJsMedia(vm, srcArg, src)) { GetArkUIInternalNodeAPI()->GetCommonModifier().ResetBackgroundImage(nativeNode); return panda::JSValueRef::Undefined(vm); } - src = srcArg->ToString(vm)->ToString(); if (repeatArg->IsNumber()) { repeatIndex = repeatArg->ToNumber(vm)->Value(); + } else { + GetArkUIInternalNodeAPI()->GetCommonModifier().ResetBackgroundImage(nativeNode); + return panda::JSValueRef::Undefined(vm); } - GetArkUIInternalNodeAPI()->GetCommonModifier().SetBackgroundImage(nativeNode, src.c_str(), repeatIndex); return panda::JSValueRef::Undefined(vm); } diff --git a/frameworks/bridge/declarative_frontend/engine/jsi/nativeModule/arkts_native_tabs_bridge.cpp b/frameworks/bridge/declarative_frontend/engine/jsi/nativeModule/arkts_native_tabs_bridge.cpp index 16b99aa0c1d..50e25541123 100644 --- a/frameworks/bridge/declarative_frontend/engine/jsi/nativeModule/arkts_native_tabs_bridge.cpp +++ b/frameworks/bridge/declarative_frontend/engine/jsi/nativeModule/arkts_native_tabs_bridge.cpp @@ -24,21 +24,6 @@ #include "frameworks/core/components_ng/pattern/tabs/tabs_node.h" namespace OHOS::Ace::NG { -namespace { -bool ParseJsDimensionVp(const EcmaVM* vm, const Local& value, CalcDimension& result) -{ - if (value->IsNumber()) { - result = CalcDimension(value->ToNumber(vm)->Value(), DimensionUnit::VP); - return true; - } - if (value->IsString()) { - result = StringUtils::StringToCalcDimension(value->ToString(vm)->ToString(), false, DimensionUnit::VP); - return true; - } - // resouce ignore by design - return false; -} -} // namespace constexpr int SIZE_OF_FIVE = 5; constexpr int SIZE_OF_THREE = 3; constexpr int SIZE_OF_VALUES = 2; @@ -79,15 +64,21 @@ ArkUINativeModuleValue TabsBridge::SetScrollableBarModeOptions(ArkUIRuntimeCallI { EcmaVM* vm = runtimeCallInfo->GetVM(); CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr)); - Local firstArg = runtimeCallInfo->GetCallArgRef(0); - Local secondArg = runtimeCallInfo->GetCallArgRef(1); + Local firstArg = runtimeCallInfo->GetCallArgRef(NUM_0); + Local secondArg = runtimeCallInfo->GetCallArgRef(NUM_1); Local thirdArg = runtimeCallInfo->GetCallArgRef(NUM_2); void* nativeNode = firstArg->ToNativePointer(vm)->Value(); - Local barModeValue = secondArg->ToString(vm); - int barModeStyle = thirdArg->Int32Value(vm); - CalcDimension margin = Dimension(0.0, DimensionUnit::VP); - margin = StringUtils::StringToCalcDimension(barModeValue->ToString(), false, DimensionUnit::VP); + if (thirdArg->IsUndefined()) { + GetArkUIInternalNodeAPI()->GetTabsModifier().ResetScrollableBarModeOptions(nativeNode); + return panda::JSValueRef::Undefined(vm); + } + int barModeStyle = thirdArg->Int32Value(vm); + + CalcDimension margin(0.0, DimensionUnit::VP); + if (!ArkTSUtils::ParseJsDimensionVp(vm, secondArg, margin)) { + margin.Reset(); + } GetArkUIInternalNodeAPI()->GetTabsModifier().SetScrollableBarModeOptions( nativeNode, margin.Value(), static_cast(margin.Unit()), barModeStyle); @@ -132,13 +123,13 @@ ArkUINativeModuleValue TabsBridge::SetBarGridAlign(ArkUIRuntimeCallInfo* runtime lg = lgArg->Int32Value(vm); } - CalcDimension columnGutter; - CalcDimension columnMargin; - if (!ParseJsDimensionVp(vm, gutterArg, columnGutter) || !NonNegative(columnGutter.Value()) || + CalcDimension columnGutter(0.0, DimensionUnit::VP); + CalcDimension columnMargin(0.0, DimensionUnit::VP); + if (!ArkTSUtils::ParseJsDimensionVp(vm, gutterArg, columnGutter) || !NonNegative(columnGutter.Value()) || columnGutter.Unit() == DimensionUnit::PERCENT) { columnGutter.Reset(); } - if (!ParseJsDimensionVp(vm, marginArg, columnMargin) || NonNegative(columnMargin.Value()) || + if (!ArkTSUtils::ParseJsDimensionVp(vm, marginArg, columnMargin) || !NonNegative(columnMargin.Value()) || columnMargin.Unit() == DimensionUnit::PERCENT) { columnMargin.Reset(); } @@ -185,9 +176,9 @@ ArkUINativeModuleValue TabsBridge::SetDivider(ArkUIRuntimeCallInfo* runtimeCallI return panda::JSValueRef::Undefined(vm); } - CalcDimension dividerStrokeWidth; - CalcDimension dividerStartMargin; - CalcDimension dividerEndMargin; + CalcDimension dividerStrokeWidth(0.0, DimensionUnit::VP); + CalcDimension dividerStartMargin(0.0, DimensionUnit::VP); + CalcDimension dividerEndMargin(0.0, DimensionUnit::VP); uint32_t color; auto* frameNode = reinterpret_cast(nativeNode); auto context = frameNode->GetContext(); @@ -196,20 +187,21 @@ ArkUINativeModuleValue TabsBridge::SetDivider(ArkUIRuntimeCallInfo* runtimeCallI auto tabTheme = themeManager->GetTheme(); CHECK_NULL_RETURN(tabTheme, panda::NativePointerRef::New(vm, nullptr)); - if (dividerStrokeWidthArgs->IsUndefined() || !ParseJsDimensionVp(vm, dividerStrokeWidthArgs, dividerStrokeWidth) || + if (!ArkTSUtils::ParseJsDimensionVp(vm, dividerStrokeWidthArgs, dividerStrokeWidth) || dividerStrokeWidth.Value() < 0.0f || dividerStrokeWidth.Unit() == DimensionUnit::PERCENT) { dividerStrokeWidth.Reset(); } - if (colorArg->IsUndefined()) { + Color colorObj; + if (!ArkTSUtils::ParseJsColorAlpha(vm, colorArg, colorObj)) { color = tabTheme->GetDividerColor().GetValue(); } else { - color = colorArg->Uint32Value(vm); + color = colorObj.GetValue(); } - if (dividerStartMarginArgs->IsUndefined() || !ParseJsDimensionVp(vm, dividerStartMarginArgs, dividerStartMargin) || + if (!ArkTSUtils::ParseJsDimensionVp(vm, dividerStartMarginArgs, dividerStartMargin) || dividerStartMargin.Value() < 0.0f || dividerStartMargin.Unit() == DimensionUnit::PERCENT) { dividerStartMargin.Reset(); } - if (dividerEndMarginArgs->IsUndefined() || !ParseJsDimensionVp(vm, dividerEndMarginArgs, dividerEndMargin) || + if (!ArkTSUtils::ParseJsDimensionVp(vm, dividerEndMarginArgs, dividerEndMargin) || dividerEndMargin.Value() < 0.0f || dividerEndMargin.Unit() == DimensionUnit::PERCENT) { dividerEndMargin.Reset(); } @@ -513,4 +505,4 @@ ArkUINativeModuleValue TabsBridge::ResetBarPosition(ArkUIRuntimeCallInfo* runtim GetArkUIInternalNodeAPI()->GetTabsModifier().ResetTabBarPosition(nativeNode); return panda::JSValueRef::Undefined(vm); } -} // namespace OHOS::Ace::NG \ No newline at end of file +} // namespace OHOS::Ace::NG -- Gitee