Merge branch 'master' of gitee.com:openharmony/arkui_ace_engine into logAce

Signed-off-by: 邹林肯 <735001321@qq.com>
This commit is contained in:
邹林肯 2023-12-06 09:14:25 +00:00 committed by Gitee
commit a9162d46bf
51 changed files with 3064 additions and 790 deletions

View File

@ -45,6 +45,23 @@ config("ace_config") {
"-Werror=return-stack-address",
]
if (is_ohos && is_clang && (target_cpu == "arm" || target_cpu == "arm64") &&
enhanced_opt) {
if (ace_engine_feature_enable_pgo) {
cflags += [
"-fprofile-use=" + rebase_path(
"${ace_engine_feature_pgo_path}/libace_compatible.profdata",
root_build_dir),
"-Wno-error=backend-plugin",
"-Wno-profile-instr-out-of-date",
"-Wno-profile-instr-unprofiled",
]
}
if (ace_engine_feature_enable_atomic) {
cflags += [ "-moutline-atomics" ]
}
}
cflags_cc = [
"-fvisibility-inlines-hidden",
"-Wno-non-c-typedef-for-linkage",

View File

@ -35,6 +35,15 @@ declare_args() {
# Enable metal in iOS or MacOS
shell_enable_metal = false
# Enable pgo for building.
ace_engine_feature_enable_pgo = false
# Set pgo profdata path
ace_engine_feature_pgo_path = ""
# Enable atomic for building.
ace_engine_feature_enable_atomic = false
# Enable test coverage
ace_engine_feature_enable_coverage = false

View File

@ -97,6 +97,7 @@ const std::map<AceLogTag, const char*> DOMAIN_CONTENTS_MAP = {
{ AceLogTag::ACE_UIEVENT, "AceUIEvent" },
{ AceLogTag::ACE_UI_SERVICE, "AceUIService" },
{ AceLogTag::ACE_DISPLAY_SYNC, "AceDisplaySync" },
{ AceLogTag::ACE_RESOURCE, "AceResource" }
};
const char* APP_DOMAIN_CONTENT = "JSApp";

View File

@ -18,6 +18,7 @@
#include <set>
#include "base/i18n/localization.h"
#include "base/log/log.h"
#include "base/utils/system_properties.h"
#include "core/common/ace_application_info.h"
#include "core/common/container.h"
@ -265,6 +266,10 @@ RefPtr<ResourceAdapter> ResourceAdapter::Create()
RefPtr<ResourceAdapter> ResourceAdapter::CreateNewResourceAdapter(
const std::string& bundleName, const std::string& moduleName)
{
TAG_LOGW(AceLogTag::ACE_RESOURCE,
"Cannot preview the component from the %{public}s module, because it contains a resource reference. Preview it "
"in the %{public}s module instead.",
moduleName.c_str(), moduleName.c_str());
return nullptr;
}

View File

@ -18,6 +18,7 @@
#include "adapter/ohos/osal/resource_theme_style.h"
#include "adapter/preview/entrance/ace_application_info.h"
#include "adapter/preview/osal/resource_convertor.h"
#include "base/log/log.h"
#include "core/common/container.h"
#include "core/components/theme/theme_attributes.h"
@ -148,6 +149,10 @@ void ResourceAdapterImpl::Init(const ResourceInfo& resourceInfo)
RefPtr<ResourceAdapter> ResourceAdapter::CreateNewResourceAdapter(
const std::string& bundleName, const std::string& moduleName)
{
TAG_LOGW(AceLogTag::ACE_RESOURCE,
"Cannot preview the component from the %{public}s module, because it contains a resource reference. Preview it "
"in the %{public}s module instead.",
moduleName.c_str(), moduleName.c_str());
return nullptr;
}

View File

@ -128,6 +128,7 @@ enum class AceLogTag : uint8_t {
ACE_UIEVENT, // C03934
ACE_UI_SERVICE, // C03935 ace_engine/adapter/ohos/services/uiservice/src/ui_service_hilog.h
ACE_DISPLAY_SYNC, // C03936
ACE_RESOURCE, // C03937
FORM_RENDER = 255, // C039FF FormRenderer
END = 256, // Last one, do not use

View File

@ -1,3 +1,17 @@
/*
* Copyright (c) 2022 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.
*/
/// <reference path='./import.ts' />
class ArkBorderStyle implements Equable {
@ -1422,4 +1436,23 @@ class ArkTextAreaShowCounter implements Equable {
return (this.value === another.value) &&
(this.options === another.options);
}
}
class ArkMesh {
value: Array<any> | undefined;
column: number | undefined;
row: number | undefined;
constructor() {
this.value = undefined;
this.column = undefined;
this.row = undefined;
}
isEqual(another: ArkMesh): boolean {
return (
deepCompareArrays(this.value, another.value) &&
this.column === another.column &&
this.row === another.row
);
}
}

View File

@ -0,0 +1,237 @@
/*
* Copyright (c) 2022 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.
*/
/// <reference path="./import.ts" />
class ArkCommonShapeComponent extends ArkComponent implements CommonShapeMethod<ShapeAttribute> {
viewPort(value: { x?: string | number | undefined; y?: string | number | undefined; width?: string | number | undefined; height?: string | number | undefined; }): this {
throw new Error('Method not implemented.');
}
stroke(value: ResourceColor): this {
modifierWithKey(this._modifiersWithKeys, StrokeModifier.identity, StrokeModifier, value);
return this;
}
fill(value: ResourceColor): this {
modifierWithKey(this._modifiersWithKeys, FillModifier.identity, FillModifier, value);
return this;
}
strokeDashOffset(value: string | number): this {
modifierWithKey(this._modifiersWithKeys, StrokeDashOffsetModifier.identity,
StrokeDashOffsetModifier, value);
return this;
}
strokeLineCap(value: LineCapStyle): this {
modifierWithKey(this._modifiersWithKeys, StrokeLineCapModifier.identity, StrokeLineCapModifier, value);
return this;
}
strokeLineJoin(value: LineJoinStyle): this {
modifierWithKey(this._modifiersWithKeys, StrokeLineJoinModifier.identity, StrokeLineJoinModifier, value);
return this;
}
strokeMiterLimit(value: string | number): this {
modifierWithKey(this._modifiersWithKeys, StrokeMiterLimitModifier.identity,
StrokeMiterLimitModifier, value);
return this;
}
strokeOpacity(value: number | string | Resource): this {
modifierWithKey(this._modifiersWithKeys, StrokeOpacityModifier.identity, StrokeOpacityModifier, value);
return this;
}
fillOpacity(value: number | string | Resource): this {
modifierWithKey(this._modifiersWithKeys, FillOpacityModifier.identity, FillOpacityModifier, value);
return this;
}
strokeWidth(value: string | number): this {
modifierWithKey(this._modifiersWithKeys, StrokeWidthModifier.identity, StrokeWidthModifier, value);
return this;
}
antiAlias(value: boolean): this {
modifierWithKey(this._modifiersWithKeys, AntiAliasModifier.identity, AntiAliasModifier, value);
return this;
}
strokeDashArray(value: any[]): this {
modifierWithKey(this._modifiersWithKeys, Symbol('strokeDashArray'), StrokeDashArrayModifier, value);
return this;
}
mesh(value: any[], column: number, row: number): this {
throw new Error('Method not implemented.');
}
}
class StrokeDashArrayModifier extends ModifierWithKey<object> {
static identity: Symbol = Symbol('strokeDashArray');
applyPeer(node: KNode, reset: boolean): void {
if (reset) {
GetUINativeModule().commonShape.resetStrokeDashArray(node);
}
else {
GetUINativeModule().commonShape.setStrokeDashArray(node, this.value);
}
}
checkObjectDiff(): boolean {
if (isResource(this.stageValue) && isResource(this.value)) {
return !isResourceEqual(this.stageValue, this.value);
} else {
return true;
}
}
}
class StrokeModifier extends ModifierWithKey<ResourceColor> {
static identity: Symbol = Symbol('stroke');
applyPeer(node: KNode, reset: boolean): void {
if (reset) {
GetUINativeModule().commonShape.resetStroke(node);
} else {
GetUINativeModule().commonShape.setStroke(node, this.value);
}
}
checkObjectDiff(): boolean {
if (isResource(this.stageValue) && isResource(this.value)) {
return !isResourceEqual(this.stageValue, this.value);
} else {
return true;
}
}
}
class FillModifier extends Modifier<ResourceColor> {
static identity: Symbol = Symbol('fill');
applyPeer(node: KNode, reset: boolean): void {
if (reset) {
GetUINativeModule().commonShape.resetFill(node);
} else {
GetUINativeModule().commonShape.setFill(node, this.value);
}
}
checkObjectDiff(): boolean {
if (isResource(this.stageValue) && isResource(this.value)) {
return !isResourceEqual(this.stageValue, this.value);
} else {
return true;
}
}
}
class StrokeDashOffsetModifier extends ModifierWithKey<number | string> {
static identity: Symbol = Symbol('strokeDashOffset');
applyPeer(node: KNode, reset: boolean): void {
if (reset) {
GetUINativeModule().commonShape.resetStrokeDashOffset(node);
} else {
GetUINativeModule().commonShape.setStrokeDashOffset(node, this.value);
}
}
checkObjectDiff(): boolean {
if (isResource(this.stageValue) && isResource(this.value)) {
return !isResourceEqual(this.stageValue, this.value);
} else {
return true;
}
}
}
class StrokeLineCapModifier extends ModifierWithKey<number> {
static identity: Symbol = Symbol('strokeLineCap');
applyPeer(node: KNode, reset: boolean): void {
if (reset) {
GetUINativeModule().commonShape.resetStrokeLineCap(node);
} else {
GetUINativeModule().commonShape.setStrokeLineCap(node, this.value);
}
}
}
class StrokeLineJoinModifier extends ModifierWithKey<number> {
static identity: Symbol = Symbol('strokeLineJoin');
applyPeer(node: KNode, reset: boolean): void {
if (reset) {
GetUINativeModule().commonShape.resetStrokeLineJoin(node);
} else {
GetUINativeModule().commonShape.setStrokeLineJoin(node, this.value);
}
}
}
class StrokeMiterLimitModifier extends ModifierWithKey<number | string> {
static identity: Symbol = Symbol('strokeMiterLimit');
applyPeer(node: KNode, reset: boolean): void {
if (reset) {
GetUINativeModule().commonShape.resetStrokeMiterLimit(node);
} else {
GetUINativeModule().commonShape.setStrokeMiterLimit(node, this.value);
}
}
}
class FillOpacityModifier extends ModifierWithKey<number | string | Resource> {
static identity: Symbol = Symbol('FillOpacity');
applyPeer(node: KNode, reset: boolean): void {
if (reset) {
GetUINativeModule().commonShape.resetFillOpacity(node);
} else {
GetUINativeModule().commonShape.setFillOpacity(node, this.value);
}
}
checkObjectDiff(): boolean {
if (isResource(this.stageValue) && isResource(this.value)) {
return !isResourceEqual(this.stageValue, this.value);
} else {
return true;
}
}
}
class StrokeOpacityModifier extends ModifierWithKey<number | string | Resource> {
static identity: Symbol = Symbol('StrokeOpacity');
applyPeer(node: KNode, reset: boolean): void {
if (reset) {
GetUINativeModule().commonShape.resetStrokeOpacity(node);
} else {
GetUINativeModule().commonShape.setStrokeOpacity(node, this.value);
}
}
checkObjectDiff(): boolean {
if (isResource(this.stageValue) && isResource(this.value)) {
return !isResourceEqual(this.stageValue, this.value);
} else {
return true;
}
}
}
class StrokeWidthModifier extends ModifierWithKey<number | string> {
static identity: Symbol = Symbol('strokeWidth');
applyPeer(node: KNode, reset: boolean): void {
if (reset) {
GetUINativeModule().commonShape.resetStrokeWidth(node);
} else {
GetUINativeModule().commonShape.setStrokeWidth(node, this.value);
}
}
}
class AntiAliasModifier extends ModifierWithKey<boolean> {
static identity: Symbol = Symbol('antiAlias');
applyPeer(node: KNode, reset: boolean): void {
if (reset) {
GetUINativeModule().commonShape.resetAntiAlias(node);
} else {
GetUINativeModule().commonShape.setAntiAlias(node, this.value);
}
}
}

View File

@ -3,7 +3,8 @@ const TITLE_MODE_RANGE = 2;
const NAV_BAR_POSITION_RANGE = 1;
const NAVIGATION_MODE_RANGE = 2;
const DEFAULT_NAV_BAR_WIDTH = 240;
const MIN_NAV_BAR_WIDTH_DEFAULT = '0vp';
const MIN_NAV_BAR_WIDTH_DEFAULT = '240vp';
const MAX_NAV_BAR_WIDTH_DEFAULT = '40%';
const NAVIGATION_TITLE_MODE_DEFAULT = 0
const DEFAULT_UNIT = 'vp';
@ -13,6 +14,10 @@ class ArkNavigationComponent extends ArkComponent implements NavigationAttribute
value = value + DEFAULT_UNIT;
}
if(value === null || value === undefined) {
value = DEFAULT_NAV_BAR_WIDTH + DEFAULT_UNIT;
}
if (isString(value)) {
modifier(this._modifiers, NavBarWidthModifier, value.toString());
}
@ -48,14 +53,14 @@ class ArkNavigationComponent extends ArkComponent implements NavigationAttribute
let max: string | number;
if (isNumber(value[1])) {
max = max + DEFAULT_UNIT
max = value[1] + DEFAULT_UNIT;
} else {
max = value[1].toString()
max = value[1].toString();
}
modifier(this._modifiers, MaxNavBarWidthModifier, max);
} else {
modifier(this._modifiers, MaxNavBarWidthModifier, MIN_NAV_BAR_WIDTH_DEFAULT);
modifier(this._modifiers, MaxNavBarWidthModifier, MAX_NAV_BAR_WIDTH_DEFAULT);
}
return this;

View File

@ -1,49 +1,66 @@
/// <reference path='./import.ts' />
class ArkRectComponent extends ArkComponent implements RectAttribute {
/*
* Copyright (c) 2022 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.
*/
/// <reference path="./import.ts" />
/// <reference path="./ArkCommonShape.ts" />
class RectRadiusWidthModifier extends ModifierWithKey<string | number> {
static identity: Symbol = Symbol('rectRadiusWidth');
applyPeer(node: KNode, reset: boolean): void {
if (reset) {
GetUINativeModule().rect.resetRectRadiusWidth(node);
} else {
GetUINativeModule().rect.setRectRadiusWidth(node, this.value);
}
}
}
class RectRadiusHeightModifier extends ModifierWithKey<string | number> {
static identity: Symbol = Symbol('rectRadiusHeight');
applyPeer(node: KNode, reset: boolean): void {
if (reset) {
GetUINativeModule().rect.resetRectRadiusHeight(node);
} else {
GetUINativeModule().rect.setRectRadiusHeight(node, this.value);
}
}
}
class RectRadiusModifier extends ModifierWithKey<string | number | Array<any>> {
static identity: Symbol = Symbol('rectRadius');
applyPeer(node: KNode, reset: boolean): void {
if (reset) {
GetUINativeModule().rect.resetRectRadius(node);
} else {
GetUINativeModule().rect.setRectRadius(node, this.value);
}
}
checkObjectDiff(): boolean {
return !(this.stageValue === this.value);
}
}
class ArkRectComponent extends ArkCommonShapeComponent implements RectAttribute {
radiusWidth(value: string | number): this {
throw new Error('Method not implemented.');
modifierWithKey(this._modifiersWithKeys, RectRadiusWidthModifier.identity, RectRadiusWidthModifier, value);
return this;
}
radiusHeight(value: string | number): this {
throw new Error('Method not implemented.');
modifierWithKey(this._modifiersWithKeys, RectRadiusHeightModifier.identity, RectRadiusHeightModifier, value);
return this;
}
radius(value: string | number | any[]): this {
throw new Error('Method not implemented.');
}
stroke(value: any): this {
throw new Error('Method not implemented.');
}
fill(value: any): this {
throw new Error('Method not implemented.');
}
strokeDashOffset(value: string | number): this {
throw new Error('Method not implemented.');
}
strokeLineCap(value: LineCapStyle): this {
throw new Error('Method not implemented.');
}
strokeLineJoin(value: LineJoinStyle): this {
throw new Error('Method not implemented.');
}
strokeMiterLimit(value: string | number): this {
throw new Error('Method not implemented.');
}
strokeOpacity(value: any): this {
throw new Error('Method not implemented.');
}
fillOpacity(value: any): this {
throw new Error('Method not implemented.');
}
strokeWidth(value: any): this {
throw new Error('Method not implemented.');
}
antiAlias(value: boolean): this {
throw new Error('Method not implemented.');
}
strokeDashArray(value: any[]): this {
throw new Error('Method not implemented.');
}
monopolizeEvents(monopolize: boolean): this {
throw new Error('Method not implemented.');
radius(value: string | number | Array<any>): this {
modifierWithKey(this._modifiersWithKeys, RectRadiusModifier.identity, RectRadiusModifier, value);
return this;
}
}

View File

@ -1,46 +1,64 @@
/// <reference path='./import.ts' />
class ArkShapeComponent extends ArkComponent implements ShapeAttribute {
/*
* Copyright (c) 2022 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.
*/
/// <reference path="./import.ts" />
/// <reference path="./ArkCommonShape.ts" />
class ShapeViewPortModifier extends ModifierWithKey<{ x?: string | number | undefined; y?: string | number | undefined; width?: string | number | undefined; height?: string | number | undefined; }> {
static identity: Symbol = Symbol('shapeViewPort');
applyPeer(node: KNode, reset: boolean): void {
if (reset) {
GetUINativeModule().shape.resetShapeViewPort(node);
} else {
GetUINativeModule().shape.setShapeViewPort(node, this.value.x, this.value.y, this.value.width, this.value.height);
}
}
checkObjectDiff(): boolean {
return !(this.stageValue.x === this.value.x && this.stageValue.y === this.value.y &&
this.stageValue.width === this.value.width && this.stageValue.height === this.value.height);
}
}
class ShapeMeshModifier extends ModifierWithKey<ArkMesh> {
static identity: Symbol = Symbol('shapeMesh');
applyPeer(node: KNode, reset: boolean): void {
if (reset) {
GetUINativeModule().shape.resetShapeMesh(node);
} else {
GetUINativeModule().shape.setShapeMesh(node, this.value.value, this.value.column, this.value.row);
}
}
checkObjectDiff(): boolean {
return !(this.stageValue as ArkMesh).isEqual(this.value as ArkMesh);
}
}
class ArkShapeComponent extends ArkCommonShapeComponent implements ShapeAttribute {
viewPort(value: { x?: string | number | undefined; y?: string | number | undefined; width?: string | number | undefined; height?: string | number | undefined; }): this {
throw new Error('Method not implemented.');
if (value === null) {
value = undefined;
}
modifierWithKey(this._modifiersWithKeys, ShapeViewPortModifier.identity, ShapeViewPortModifier, value);
return this;
}
stroke(value: any): this {
throw new Error('Method not implemented.');
}
fill(value: any): this {
throw new Error('Method not implemented.');
}
strokeDashOffset(value: string | number): this {
throw new Error('Method not implemented.');
}
strokeDashArray(value: any[]): this {
throw new Error('Method not implemented.');
}
strokeLineCap(value: LineCapStyle): this {
throw new Error('Method not implemented.');
}
strokeLineJoin(value: LineJoinStyle): this {
throw new Error('Method not implemented.');
}
strokeMiterLimit(value: string | number): this {
throw new Error('Method not implemented.');
}
strokeOpacity(value: any): this {
throw new Error('Method not implemented.');
}
fillOpacity(value: any): this {
throw new Error('Method not implemented.');
}
strokeWidth(value: string | number): this {
throw new Error('Method not implemented.');
}
antiAlias(value: boolean): this {
throw new Error('Method not implemented.');
}
mesh(value: any[], column: number, row: number): this {
throw new Error('Method not implemented.');
}
monopolizeEvents(monopolize: boolean): this {
throw new Error('Method not implemented.');
mesh(value: Array<any> | undefined, column: number | undefined, row: number | undefined): this {
let arkMesh = new ArkMesh();
if (value !== null && column !== null && row !== null) {
arkMesh.value = value;
arkMesh.column = column;
arkMesh.row = row;
}
modifierWithKey(this._modifiersWithKeys, ShapeMeshModifier.identity, ShapeMeshModifier, arkMesh);
return this;
}
}
@ -48,7 +66,7 @@ class ArkShapeComponent extends ArkComponent implements ShapeAttribute {
globalThis.Shape.attributeModifier = function (modifier) {
const elmtId = ViewStackProcessor.GetElmtIdToAccountFor();
let nativeNode = GetUINativeModule().getFrameNodeById(elmtId);
let component = this.createOrGetNode(elmtId, () => {
let component = this.createOrGetNode(elmtId, ()=> {
return new ArkShapeComponent(nativeNode);
});
modifier.applyNormalAttribute(component);

View File

@ -93,7 +93,8 @@
"src/ArkCanvas.ts",
"src/ArkGridContainer.ts",
"src/ArkWindowScene.ts",
"src/ArkDatePicker.ts",
"src/ArkDatePicker.ts",
"src/ArkCommonShape.ts",
],
"compilerOptions": {

File diff suppressed because it is too large Load Diff

View File

@ -154,6 +154,7 @@ template("declarative_js_engine_ark") {
"components/arkts_native_column_modifier.cpp",
"components/arkts_native_column_split_modifier.cpp",
"components/arkts_native_common_modifier.cpp",
"components/arkts_native_common_shape_modifier.cpp",
"components/arkts_native_counter_modifier.cpp",
"components/arkts_native_date_picker_modifier.cpp",
"components/arkts_native_divider_modifier.cpp",
@ -173,11 +174,13 @@ template("declarative_js_engine_ark") {
"components/arkts_native_pattern_lock_modifier.cpp",
"components/arkts_native_radio_modifier.cpp",
"components/arkts_native_rating_modifier.cpp",
"components/arkts_native_rect_modifier.cpp",
"components/arkts_native_rich_editor_modifier.cpp",
"components/arkts_native_row_modifier.cpp",
"components/arkts_native_row_split_modifier.cpp",
"components/arkts_native_search_modifier.cpp",
"components/arkts_native_select_modifier.cpp",
"components/arkts_native_shape_modifier.cpp",
"components/arkts_native_side_bar_container_modifier.cpp",
"components/arkts_native_slider_modifier.cpp",
"components/arkts_native_span_modifier.cpp",
@ -215,6 +218,7 @@ template("declarative_js_engine_ark") {
"nativeModule/arkts_native_column_bridge.cpp",
"nativeModule/arkts_native_column_split_bridge.cpp",
"nativeModule/arkts_native_common_bridge.cpp",
"nativeModule/arkts_native_common_shape_bridge.cpp",
"nativeModule/arkts_native_counter_bridge.cpp",
"nativeModule/arkts_native_date_picker_bridge.cpp",
"nativeModule/arkts_native_divider_bridge.cpp",
@ -234,11 +238,13 @@ template("declarative_js_engine_ark") {
"nativeModule/arkts_native_pattern_lock_bridge.cpp",
"nativeModule/arkts_native_radio_bridge.cpp",
"nativeModule/arkts_native_rating_bridge.cpp",
"nativeModule/arkts_native_rect_bridge.cpp",
"nativeModule/arkts_native_rich_editor_bridge.cpp",
"nativeModule/arkts_native_row_bridge.cpp",
"nativeModule/arkts_native_row_split_bridge.cpp",
"nativeModule/arkts_native_search_bridge.cpp",
"nativeModule/arkts_native_select_bridge.cpp",
"nativeModule/arkts_native_shape_bridge.cpp",
"nativeModule/arkts_native_side_bar_container_bridge.cpp",
"nativeModule/arkts_native_slider_bridge.cpp",
"nativeModule/arkts_native_span_bridge.cpp",

View File

@ -1089,6 +1089,49 @@ struct ArkUIFormComponentModifierAPI {
};
#endif
struct ArkUICommonShapeModifierAPI {
void (*SetStrokeDashArray)(NodeHandle node, double* dashArray, int32_t* dimUnits, int32_t size);
void (*ResetStrokeDashArray)(NodeHandle node);
void (*SetStrokeMiterLimit)(NodeHandle node, const double miterLimit);
void (*ResetStrokeMiterLimit)(NodeHandle node);
void (*SetFillOpacity)(NodeHandle node, const double fillOpacity);
void (*ResetFillOpacity)(NodeHandle node);
void (*SetStrokeOpacity)(NodeHandle node, const double strokeOpacity);
void (*ResetStrokeOpacity)(NodeHandle node);
void (*SetStrokeWidth)(NodeHandle node, double value, int unit);
void (*ResetStrokeWidth)(NodeHandle node);
void (*SetAntiAlias)(NodeHandle node, const bool antiAlias);
void (*ResetAntiAlias)(NodeHandle node);
void (*SetStroke)(NodeHandle node, const uint32_t stroke);
void (*ResetStroke)(NodeHandle node);
void (*SetFill)(NodeHandle node, const uint32_t fill);
void (*ResetFill)(NodeHandle node);
void (*SetStrokeDashOffset)(NodeHandle node, double value, int unit);
void (*ResetStrokeDashOffset)(NodeHandle node);
void (*SetStrokeLineCap)(NodeHandle node, const int strokeLineCap);
void (*ResetStrokeLineCap)(NodeHandle node);
void (*SetStrokeLineJoin)(NodeHandle node, const int lineJoinStyle);
void (*ResetStrokeLineJoin)(NodeHandle node);
};
struct ArkUIShapeModifierAPI {
void (*SetShapeViewPort)(NodeHandle node, double* dimValues, int32_t* dimUnits);
void (*ResetShapeViewPort)(NodeHandle node);
void (*SetShapeMesh)(NodeHandle node, const double* mesh, size_t arrayItemCount, int32_t column, int32_t row);
void (*ResetShapeMesh)(NodeHandle node);
};
struct ArkUIRectModifierAPI {
void (*SetRectRadiusWidth)(NodeHandle node, double radiusWidthValue, int32_t radiusWidthUnit);
void (*ResetRectRadiusWidth)(NodeHandle node);
void (*SetRectRadiusHeight)(NodeHandle node, double radiusHeightValue, int32_t radiusHeightUnit);
void (*ResetRectRadiusHeight)(NodeHandle node);
void (*SetRectRadiusWithArray)(NodeHandle node, double* radiusValues, int32_t* radiusUnits, bool* radiusValidPairs,
int32_t radiusValidPairsSize);
void (*SetRectRadiusWithValue)(NodeHandle node, double radiusValue, int32_t radiusUnit);
void (*ResetRectRadius)(NodeHandle node);
};
struct ArkUINodeAPI {
NodeHandle (*GetFrameNodeById)(int nodeId);
ArkUICommonModifierAPI (*GetCommonModifier)();
@ -1137,6 +1180,9 @@ struct ArkUINodeAPI {
ArkUIMenuModifierAPI (*GetMenuModifier)();
ArkUIDatePickerModifierAPI (*GetDatePickerModifier)();
ArkUIAlphabetIndexerModifierAPI (*GetAlphabetIndexerModifier)();
ArkUICommonShapeModifierAPI(*GetCommonShapeModifier)();
ArkUIShapeModifierAPI(*GetShapeModifier)();
ArkUIRectModifierAPI (*GetRectModifier)();
#ifdef FORM_SUPPORTED
ArkUIFormComponentModifierAPI (*GetFormComponentModifier)();

View File

@ -64,6 +64,9 @@
#include "core/pipeline/base/element_register.h"
#include "bridge/declarative_frontend/engine/jsi/components/arkts_native_calendar_picker_modifier.h"
#include "bridge/declarative_frontend/engine/jsi/components/arkts_native_alphabet_indexer_modifier.h"
#include "bridge/declarative_frontend/engine/jsi/components/arkts_native_common_shape_modifier.h"
#include "bridge/declarative_frontend/engine/jsi/components/arkts_native_shape_modifier.h"
#include "bridge/declarative_frontend/engine/jsi/components/arkts_native_rect_modifier.h"
#ifdef FORM_SUPPORTED
#include "bridge/declarative_frontend/engine/jsi/components/arkts_native_form_component_modifier.h"
@ -125,6 +128,9 @@ static struct ArkUINodeAPI impl = {
GetMenuModifier,
GetDatePickerModifier,
GetAlphabetIndexerModifier,
GetCommonShapeModifier,
GetShapeModifier,
GetRectModifier,
#ifdef FORM_SUPPORTED
GetFormComponentModifier,

View File

@ -0,0 +1,202 @@
/*
* Copyright (c) 2023 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 "bridge/declarative_frontend/engine/jsi/components/arkts_native_common_shape_modifier.h"
#include "core/components/common/layout/constants.h"
#include "core/components_ng/base/frame_node.h"
#include "core/components_ng/pattern/shape/shape_model_ng.h"
#include "core/pipeline/base/element_register.h"
#include "core/components/common/properties/color.h"
namespace OHOS::Ace::NG {
constexpr double DEFAULT_MITER_LIMIT = 4.0f;
constexpr double DEFAULT_FILL_OPACITY = 1.0f;
constexpr double DEFAULT_STROKE_OPACITY = 1.0f;
constexpr double DEFAULT_STROKE_WIDTH = 1.0f;
constexpr int DEFAULT_STROKE_DASH_OFFSET = 0;
constexpr int DEFAULT_STROKE_LINE_CAPS = 0;
constexpr int DEFAULT_STROKE_LINE_JOIN = 0;
void SetStrokeMiterLimit(NodeHandle node, const double miterLimit)
{
auto* frameNode = reinterpret_cast<FrameNode*>(node);
CHECK_NULL_VOID(frameNode);
ShapeModelNG::SetStrokeMiterLimit(frameNode, miterLimit);
}
void ResetStrokeMiterLimit(NodeHandle node)
{
auto* frameNode = reinterpret_cast<FrameNode*>(node);
CHECK_NULL_VOID(frameNode);
ShapeModelNG::SetStrokeMiterLimit(frameNode, DEFAULT_MITER_LIMIT);
}
void SetFillOpacity(NodeHandle node, const double fillOpacity)
{
auto* frameNode = reinterpret_cast<FrameNode*>(node);
CHECK_NULL_VOID(frameNode);
ShapeModelNG::SetFillOpacity(frameNode, fillOpacity);
}
void ResetFillOpacity(NodeHandle node)
{
auto* frameNode = reinterpret_cast<FrameNode*>(node);
CHECK_NULL_VOID(frameNode);
ShapeModelNG::SetFillOpacity(frameNode, DEFAULT_FILL_OPACITY);
}
void SetStrokeOpacity(NodeHandle node, const double strokeOpacity)
{
auto* frameNode = reinterpret_cast<FrameNode*>(node);
CHECK_NULL_VOID(frameNode);
ShapeModelNG::SetStrokeOpacity(frameNode, strokeOpacity);
}
void ResetStrokeOpacity(NodeHandle node)
{
auto* frameNode = reinterpret_cast<FrameNode*>(node);
CHECK_NULL_VOID(frameNode);
ShapeModelNG::SetStrokeOpacity(frameNode, DEFAULT_STROKE_OPACITY);
}
void SetStrokeWidth(NodeHandle node, double value, int unit)
{
auto* frameNode = reinterpret_cast<FrameNode*>(node);
CHECK_NULL_VOID(frameNode);
auto unitEnum = static_cast<OHOS::Ace::DimensionUnit>(unit);
ShapeModelNG::SetStrokeWidth(frameNode, Dimension(value, unitEnum));
}
void ResetStrokeWidth(NodeHandle node)
{
auto* frameNode = reinterpret_cast<FrameNode*>(node);
CHECK_NULL_VOID(frameNode);
ShapeModelNG::SetStrokeWidth(frameNode, Dimension(DEFAULT_STROKE_WIDTH));
}
void SetAntiAlias(NodeHandle node, const bool antiAlias)
{
auto* frameNode = reinterpret_cast<FrameNode*>(node);
CHECK_NULL_VOID(frameNode);
ShapeModelNG::SetAntiAlias(frameNode, antiAlias);
}
void ResetAntiAlias(NodeHandle node)
{
auto* frameNode = reinterpret_cast<FrameNode*>(node);
CHECK_NULL_VOID(frameNode);
ShapeModelNG::SetAntiAlias(frameNode, true);
}
void SetStroke(NodeHandle node, const uint32_t stroke)
{
auto* frameNode = reinterpret_cast<FrameNode*>(node);
CHECK_NULL_VOID(frameNode);
ShapeModelNG::SetStroke(frameNode, Color(stroke));
}
void ResetStroke(NodeHandle node)
{
auto* frameNode = reinterpret_cast<FrameNode*>(node);
CHECK_NULL_VOID(frameNode);
ShapeModelNG::SetStroke(frameNode, Color::TRANSPARENT);
}
void SetFill(NodeHandle node, const uint32_t fill)
{
auto* frameNode = reinterpret_cast<FrameNode*>(node);
CHECK_NULL_VOID(frameNode);
ShapeModelNG::SetFill(frameNode, Color(fill));
}
void ResetFill(NodeHandle node)
{
auto* frameNode = reinterpret_cast<FrameNode*>(node);
CHECK_NULL_VOID(frameNode);
ShapeModelNG::SetFill(frameNode, Color::BLACK);
}
void SetStrokeDashOffset(NodeHandle node, double value, int unit)
{
auto* frameNode = reinterpret_cast<FrameNode*>(node);
CHECK_NULL_VOID(frameNode);
auto unitEnum = static_cast<OHOS::Ace::DimensionUnit>(unit);
ShapeModelNG::SetStrokeDashOffset(frameNode, Dimension(value, unitEnum));
}
void ResetStrokeDashOffset(NodeHandle node)
{
auto* frameNode = reinterpret_cast<FrameNode*>(node);
CHECK_NULL_VOID(frameNode);
ShapeModelNG::SetStrokeDashOffset(frameNode, Dimension(DEFAULT_STROKE_DASH_OFFSET));
}
void SetStrokeLineCap(NodeHandle node, const int strokeLineCap)
{
auto* frameNode = reinterpret_cast<FrameNode*>(node);
CHECK_NULL_VOID(frameNode);
ShapeModelNG::SetStrokeLineCap(frameNode, strokeLineCap);
}
void ResetStrokeLineCap(NodeHandle node)
{
auto* frameNode = reinterpret_cast<FrameNode*>(node);
CHECK_NULL_VOID(frameNode);
ShapeModelNG::SetStrokeLineCap(frameNode, DEFAULT_STROKE_LINE_CAPS);
}
void SetStrokeLineJoin(NodeHandle node, const int lineJoinStyle)
{
auto* frameNode = reinterpret_cast<FrameNode*>(node);
CHECK_NULL_VOID(frameNode);
ShapeModelNG::SetStrokeLineJoin(frameNode, lineJoinStyle);
}
void ResetStrokeLineJoin(NodeHandle node)
{
auto* frameNode = reinterpret_cast<FrameNode*>(node);
CHECK_NULL_VOID(frameNode);
ShapeModelNG::SetStrokeLineJoin(frameNode, DEFAULT_STROKE_LINE_JOIN);
}
void SetStrokeDashArray(NodeHandle node, double* dashArrayArray, int32_t* dimUnits, int32_t size)
{
auto* frameNode = reinterpret_cast<FrameNode*>(node);
CHECK_NULL_VOID(frameNode);
std::vector<Dimension> dashArray;
for (int32_t i = 0; i < size; i++) {
dashArray.emplace_back(CalcDimension(dashArrayArray[i], (DimensionUnit)dimUnits[i]));
}
ShapeModelNG::SetStrokeDashArray(frameNode, dashArray);
}
void ResetStrokeDashArray(NodeHandle node)
{
auto* frameNode = reinterpret_cast<FrameNode*>(node);
CHECK_NULL_VOID(frameNode);
std::vector<Dimension> dashArray;
ShapeModelNG::SetStrokeDashArray(frameNode, dashArray);
}
ArkUICommonShapeModifierAPI GetCommonShapeModifier()
{
static const ArkUICommonShapeModifierAPI modifier = { SetStrokeDashArray, ResetStrokeDashArray,
SetStrokeMiterLimit, ResetStrokeMiterLimit, SetFillOpacity, ResetFillOpacity, SetStrokeOpacity,
ResetStrokeOpacity, SetStrokeWidth, ResetStrokeWidth, SetAntiAlias, ResetAntiAlias, SetStroke, ResetStroke,
SetFill, ResetFill, SetStrokeDashOffset, ResetStrokeDashOffset, SetStrokeLineCap, ResetStrokeLineCap,
SetStrokeLineJoin, ResetStrokeLineJoin };
return modifier;
}
} // namespace OHOS::Ace::NG

View File

@ -0,0 +1,24 @@
/*
* Copyright (c) 2023 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_INTERFACE_INNER_API_COMPONENTS_ARKTS_NATIVE_COMMON_SHAPE_MODIFIER_H
#define FRAMEWORKS_INTERFACE_INNER_API_COMPONENTS_ARKTS_NATIVE_COMMON_SHAPE_MODIFIER_H
#include "bridge/declarative_frontend/engine/jsi/components/arkts_native_api.h"
namespace OHOS::Ace::NG {
ArkUICommonShapeModifierAPI GetCommonShapeModifier();
}
#endif // FRAMEWORKS_INTERFACE_INNER_API_COMPONENTS_ARKTS_NATIVE_COMMON_SHAPE_MODIFIER_H

View File

@ -0,0 +1,94 @@
/*
* Copyright (c) 2023 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 "bridge/declarative_frontend/engine/jsi/components/arkts_native_rect_modifier.h"
#include "core/components_ng/base/frame_node.h"
#include "core/components_ng/pattern/shape/rect_model_ng.h"
namespace OHOS::Ace::NG {
void SetRectRadiusWidth(NodeHandle node, double radiusWidthValue, int32_t radiusWidthUnit)
{
auto* frameNode = reinterpret_cast<FrameNode*>(node);
CHECK_NULL_VOID(frameNode);
RectModelNG::SetRadiusWidth(frameNode, CalcDimension(radiusWidthValue, (DimensionUnit)radiusWidthUnit));
}
void ResetRectRadiusWidth(NodeHandle node)
{
auto* frameNode = reinterpret_cast<FrameNode*>(node);
CHECK_NULL_VOID(frameNode);
CalcDimension defaultDimension;
defaultDimension.Reset();
RectModelNG::SetRadiusWidth(frameNode, defaultDimension);
return;
}
void SetRectRadiusHeight(NodeHandle node, double radiusHeightValue, int32_t radiusHeightUnit)
{
auto* frameNode = reinterpret_cast<FrameNode*>(node);
CHECK_NULL_VOID(frameNode);
RectModelNG::SetRadiusHeight(frameNode, CalcDimension(radiusHeightValue, (DimensionUnit)radiusHeightUnit));
}
void ResetRectRadiusHeight(NodeHandle node)
{
auto* frameNode = reinterpret_cast<FrameNode*>(node);
CHECK_NULL_VOID(frameNode);
CalcDimension defaultDimension;
defaultDimension.Reset();
RectModelNG::SetRadiusHeight(frameNode, defaultDimension);
}
void SetRectRadiusWithArray(
NodeHandle node, double* radiusValues, int32_t* radiusUnits, bool* radiusValidPairs, int32_t radiusValidPairsSize)
{
auto* frameNode = reinterpret_cast<FrameNode*>(node);
CHECK_NULL_VOID(frameNode);
for (int index = 0; index < radiusValidPairsSize; index++) {
if (radiusValidPairs[index]) {
int xIndex = index * 2;
int yIndex = xIndex + 1;
auto radiusX = CalcDimension(radiusValues[xIndex], (DimensionUnit)radiusUnits[xIndex]);
auto radiusY = CalcDimension(radiusValues[yIndex], (DimensionUnit)radiusUnits[yIndex]);
RectModelNG::SetRadiusValue(frameNode, radiusX, radiusY, index);
}
}
}
void SetRectRadiusWithValue(NodeHandle node, double radiusValue, int32_t radiusUnit)
{
auto* frameNode = reinterpret_cast<FrameNode*>(node);
CHECK_NULL_VOID(frameNode);
RectModelNG::SetRadiusWidth(frameNode, CalcDimension(radiusValue, (DimensionUnit)radiusUnit));
RectModelNG::SetRadiusHeight(frameNode, CalcDimension(radiusValue, (DimensionUnit)radiusUnit));
}
void ResetRectRadius(NodeHandle node)
{
auto* frameNode = reinterpret_cast<FrameNode*>(node);
CHECK_NULL_VOID(frameNode);
NG::ResetRectRadiusHeight(frameNode);
NG::ResetRectRadiusWidth(frameNode);
}
ArkUIRectModifierAPI GetRectModifier()
{
static const ArkUIRectModifierAPI modifier = { SetRectRadiusWidth, ResetRectRadiusWidth, SetRectRadiusHeight,
ResetRectRadiusHeight, SetRectRadiusWithArray, SetRectRadiusWithValue, ResetRectRadius };
return modifier;
}
} // namespace OHOS::Ace::NG

View File

@ -0,0 +1,25 @@
/*
* Copyright (c) 2023 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_INTERFACE_INNER_API_COMPONENTS_ARKTS_NATIVE_RECT_MODIFIER_H
#define FRAMEWORKS_INTERFACE_INNER_API_COMPONENTS_ARKTS_NATIVE_RECT_MODIFIER_H
#include "bridge/declarative_frontend/engine/jsi/components/arkts_native_api.h"
namespace OHOS::Ace::NG {
ArkUIRectModifierAPI GetRectModifier();
}
#endif // FRAMEWORKS_INTERFACE_INNER_API_COMPONENTS_ARKTS_NATIVE_RECT_MODIFIER_H

View File

@ -0,0 +1,70 @@
/*
* Copyright (c) 2023 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 "bridge/declarative_frontend/engine/jsi/components/arkts_native_shape_modifier.h"
#include "core/components/common/layout/constants.h"
#include "core/components/common/properties/color.h"
#include "core/components_ng/base/frame_node.h"
#include "core/components_ng/pattern/shape/shape_model_ng.h"
#include "core/pipeline/base/element_register.h"
namespace OHOS::Ace::NG {
void SetShapeViewPort(NodeHandle node, double* dimValues, int32_t* dimUnits)
{
auto* frameNode = reinterpret_cast<FrameNode*>(node);
CHECK_NULL_VOID(frameNode);
CalcDimension dimLeft = CalcDimension(dimValues[0], (DimensionUnit)dimUnits[0]);
CalcDimension dimTop = CalcDimension(dimValues[1], (DimensionUnit)dimUnits[1]);
CalcDimension dimWidth = CalcDimension(dimValues[2], (DimensionUnit)dimUnits[2]);
CalcDimension dimHeight = CalcDimension(dimValues[3], (DimensionUnit)dimUnits[3]);
ShapeModelNG::SetViewPort(frameNode, dimLeft, dimTop, dimWidth, dimHeight);
}
void ResetShapeViewPort(NodeHandle node)
{
auto* frameNode = reinterpret_cast<FrameNode*>(node);
CHECK_NULL_VOID(frameNode);
CalcDimension dimLeft = CalcDimension(0.0, DimensionUnit::PX);
CalcDimension dimTop = CalcDimension(0.0, DimensionUnit::PX);
CalcDimension dimWidth = CalcDimension(0.0, DimensionUnit::PX);
CalcDimension dimHeight = CalcDimension(0.0, DimensionUnit::PX);
ShapeModelNG::SetViewPort(frameNode, dimLeft, dimTop, dimWidth, dimHeight);
}
void SetShapeMesh(NodeHandle node, const double* mesh, size_t arrayItemCount, int32_t column, int32_t row)
{
auto* frameNode = reinterpret_cast<FrameNode*>(node);
CHECK_NULL_VOID(frameNode);
std::vector<double> meshVaules(mesh, mesh + arrayItemCount);
ShapeModelNG::SetBitmapMesh(frameNode, meshVaules, column, row);
}
void ResetShapeMesh(NodeHandle node)
{
auto* frameNode = reinterpret_cast<FrameNode*>(node);
CHECK_NULL_VOID(frameNode);
std::vector<double> meshVaules;
int32_t column = 0;
int32_t row = 0;
ShapeModelNG::SetBitmapMesh(frameNode, meshVaules, column, row);
}
ArkUIShapeModifierAPI GetShapeModifier()
{
static const ArkUIShapeModifierAPI modifier = { SetShapeViewPort, ResetShapeViewPort, SetShapeMesh,
ResetShapeMesh };
return modifier;
}
} // namespace OHOS::Ace::NG

View File

@ -0,0 +1,24 @@
/*
* Copyright (c) 2023 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_INTERFACE_INNER_API_COMPONENTS_ARKTS_NATIVE_SHAPE_MODIFIER_H
#define FRAMEWORKS_INTERFACE_INNER_API_COMPONENTS_ARKTS_NATIVE_SHAPE_MODIFIER_H
#include "bridge/declarative_frontend/engine/jsi/components/arkts_native_api.h"
namespace OHOS::Ace::NG {
ArkUIShapeModifierAPI GetShapeModifier();
}
#endif // FRAMEWORKS_INTERFACE_INNER_API_COMPONENTS_ARKTS_NATIVE_SHAPE_MODIFIER_H

View File

@ -59,6 +59,9 @@ private:
static void RegisterTimepickerAttributes(Local<panda::ObjectRef> object, EcmaVM* vm);
static void RegisterTextpickerAttributes(Local<panda::ObjectRef> object, EcmaVM* vm);
static void RegisterCheckboxAttributes(Local<panda::ObjectRef> object, EcmaVM* vm);
static void RegisterCommonShapeAttributes(Local<panda::ObjectRef> object, EcmaVM* vm);
static void RegisterShapeAttributes(Local<panda::ObjectRef> object, EcmaVM* vm);
static void RegisterRectAttributes(Local<panda::ObjectRef> object, EcmaVM* vm);
};
} // namespace OHOS::Ace::NG
#endif // FRAMEWORKS_BRIDGE_DECLARATIVE_FRONTEND_ENGINE_JSI_NATIVEMODULE_ARKTS_NATIVE_API_BRIDGE_H

View File

@ -60,6 +60,10 @@
#include "bridge/declarative_frontend/engine/jsi/nativeModule/arkts_native_side_bar_container_bridge.h"
#include "bridge/declarative_frontend/engine/jsi/nativeModule/arkts_native_calendar_picker_bridge.h"
#include "bridge/declarative_frontend/engine/jsi/nativeModule/arkts_native_alphabet_indexer_bridge.h"
#include "bridge/declarative_frontend/engine/jsi/nativeModule/arkts_native_common_shape_bridge.h"
#include "bridge/declarative_frontend/engine/jsi/nativeModule/arkts_native_shape_bridge.h"
#include "bridge/declarative_frontend/engine/jsi/nativeModule/arkts_native_rect_bridge.h"
#ifdef FORM_SUPPORTED
#include "bridge/declarative_frontend/engine/jsi/nativeModule/arkts_native_form_component_bridge.h"
#endif
@ -1078,6 +1082,9 @@ ArkUINativeModuleValue ArkUINativeModule::GetArkUINativeModule(ArkUIRuntimeCallI
RegisterTimepickerAttributes(object, vm);
RegisterTextpickerAttributes(object, vm);
RegisterCheckboxAttributes(object, vm);
RegisterCommonShapeAttributes(object, vm);
RegisterShapeAttributes(object, vm);
RegisterRectAttributes(object, vm);
#ifdef FORM_SUPPORTED
RegisterFormAttributes(object, vm);
@ -1917,4 +1924,86 @@ void ArkUINativeModule::RegisterAlphabetIndexerAttributes(Local<panda::ObjectRef
panda::FunctionRef::New(const_cast<panda::EcmaVM*>(vm), AlphabetIndexerBridge::ResetPopupPosition));
object->Set(vm, panda::StringRef::NewFromUtf8(vm, "alphabetIndexer"), alphabetIndexer);
}
void ArkUINativeModule::RegisterCommonShapeAttributes(Local<panda::ObjectRef> object, EcmaVM* vm)
{
auto commonShape = panda::ObjectRef::New(vm);
commonShape->Set(vm, panda::StringRef::NewFromUtf8(vm, "setStrokeDashArray"),
panda::FunctionRef::New(const_cast<panda::EcmaVM*>(vm), CommonShapeBridge::SetStrokeDashArray));
commonShape->Set(vm, panda::StringRef::NewFromUtf8(vm, "resetStrokeDashArray"),
panda::FunctionRef::New(const_cast<panda::EcmaVM*>(vm), CommonShapeBridge::ResetStrokeDashArray));
commonShape->Set(vm, panda::StringRef::NewFromUtf8(vm, "setStrokeMiterLimit"),
panda::FunctionRef::New(const_cast<panda::EcmaVM*>(vm), CommonShapeBridge::SetStrokeMiterLimit));
commonShape->Set(vm, panda::StringRef::NewFromUtf8(vm, "resetStrokeMiterLimit"),
panda::FunctionRef::New(const_cast<panda::EcmaVM*>(vm), CommonShapeBridge::ResetStrokeMiterLimit));
commonShape->Set(vm, panda::StringRef::NewFromUtf8(vm, "setFillOpacity"),
panda::FunctionRef::New(const_cast<panda::EcmaVM*>(vm), CommonShapeBridge::SetFillOpacity));
commonShape->Set(vm, panda::StringRef::NewFromUtf8(vm, "resetFillOpacity"),
panda::FunctionRef::New(const_cast<panda::EcmaVM*>(vm), CommonShapeBridge::ResetFillOpacity));
commonShape->Set(vm, panda::StringRef::NewFromUtf8(vm, "setStrokeOpacity"),
panda::FunctionRef::New(const_cast<panda::EcmaVM*>(vm), CommonShapeBridge::SetStrokeOpacity));
commonShape->Set(vm, panda::StringRef::NewFromUtf8(vm, "resetStrokeOpacity"),
panda::FunctionRef::New(const_cast<panda::EcmaVM*>(vm), CommonShapeBridge::ResetStrokeOpacity));
commonShape->Set(vm, panda::StringRef::NewFromUtf8(vm, "setStrokeWidth"),
panda::FunctionRef::New(const_cast<panda::EcmaVM*>(vm), CommonShapeBridge::SetStrokeWidth));
commonShape->Set(vm, panda::StringRef::NewFromUtf8(vm, "resetStrokeWidth"),
panda::FunctionRef::New(const_cast<panda::EcmaVM*>(vm), CommonShapeBridge::ResetStrokeWidth));
commonShape->Set(vm, panda::StringRef::NewFromUtf8(vm, "setAntiAlias"),
panda::FunctionRef::New(const_cast<panda::EcmaVM*>(vm), CommonShapeBridge::SetAntiAlias));
commonShape->Set(vm, panda::StringRef::NewFromUtf8(vm, "resetAntiAlias"),
panda::FunctionRef::New(const_cast<panda::EcmaVM*>(vm), CommonShapeBridge::ResetAntiAlias));
commonShape->Set(vm, panda::StringRef::NewFromUtf8(vm, "setStroke"),
panda::FunctionRef::New(const_cast<panda::EcmaVM*>(vm), CommonShapeBridge::SetStroke));
commonShape->Set(vm, panda::StringRef::NewFromUtf8(vm, "resetStroke"),
panda::FunctionRef::New(const_cast<panda::EcmaVM*>(vm), CommonShapeBridge::ResetStroke));
commonShape->Set(vm, panda::StringRef::NewFromUtf8(vm, "setFill"),
panda::FunctionRef::New(const_cast<panda::EcmaVM*>(vm), CommonShapeBridge::SetFill));
commonShape->Set(vm, panda::StringRef::NewFromUtf8(vm, "resetFill"),
panda::FunctionRef::New(const_cast<panda::EcmaVM*>(vm), CommonShapeBridge::ResetFill));
commonShape->Set(vm, panda::StringRef::NewFromUtf8(vm, "setStrokeDashOffset"),
panda::FunctionRef::New(const_cast<panda::EcmaVM*>(vm), CommonShapeBridge::SetStrokeDashOffset));
commonShape->Set(vm, panda::StringRef::NewFromUtf8(vm, "resetStrokeDashOffset"),
panda::FunctionRef::New(const_cast<panda::EcmaVM*>(vm), CommonShapeBridge::ResetStrokeDashOffset));
commonShape->Set(vm, panda::StringRef::NewFromUtf8(vm, "setStrokeLineCap"),
panda::FunctionRef::New(const_cast<panda::EcmaVM*>(vm), CommonShapeBridge::SetStrokeLineCap));
commonShape->Set(vm, panda::StringRef::NewFromUtf8(vm, "resetStrokeLineCap"),
panda::FunctionRef::New(const_cast<panda::EcmaVM*>(vm), CommonShapeBridge::ResetStrokeLineCap));
commonShape->Set(vm, panda::StringRef::NewFromUtf8(vm, "setStrokeLineJoin"),
panda::FunctionRef::New(const_cast<panda::EcmaVM*>(vm), CommonShapeBridge::SetStrokeLineJoin));
commonShape->Set(vm, panda::StringRef::NewFromUtf8(vm, "resetStrokeLineJoin"),
panda::FunctionRef::New(const_cast<panda::EcmaVM*>(vm), CommonShapeBridge::ResetStrokeLineJoin));
object->Set(vm, panda::StringRef::NewFromUtf8(vm, "commonShape"), commonShape);
}
void ArkUINativeModule::RegisterShapeAttributes(Local<panda::ObjectRef> object, EcmaVM* vm)
{
auto shape = panda::ObjectRef::New(vm);
shape->Set(vm, panda::StringRef::NewFromUtf8(vm, "setShapeViewPort"),
panda::FunctionRef::New(const_cast<panda::EcmaVM*>(vm), ShapeBridge::SetViewPort));
shape->Set(vm, panda::StringRef::NewFromUtf8(vm, "resetShapeViewPort"),
panda::FunctionRef::New(const_cast<panda::EcmaVM*>(vm), ShapeBridge::ResetViewPort));
shape->Set(vm, panda::StringRef::NewFromUtf8(vm, "setShapeMesh"),
panda::FunctionRef::New(const_cast<panda::EcmaVM*>(vm), ShapeBridge::SetMesh));
shape->Set(vm, panda::StringRef::NewFromUtf8(vm, "resetShapeMesh"),
panda::FunctionRef::New(const_cast<panda::EcmaVM*>(vm), ShapeBridge::ResetMesh));
object->Set(vm, panda::StringRef::NewFromUtf8(vm, "shape"), shape);
}
void ArkUINativeModule::RegisterRectAttributes(Local<panda::ObjectRef> object, EcmaVM* vm)
{
auto rect = panda::ObjectRef::New(vm);
rect->Set(vm, panda::StringRef::NewFromUtf8(vm, "setRectRadiusWidth"),
panda::FunctionRef::New(const_cast<panda::EcmaVM*>(vm), RectBridge::SetRadiusWidth));
rect->Set(vm, panda::StringRef::NewFromUtf8(vm, "resetRectRadiusWidth"),
panda::FunctionRef::New(const_cast<panda::EcmaVM*>(vm), RectBridge::ResetRadiusWidth));
rect->Set(vm, panda::StringRef::NewFromUtf8(vm, "setRectRadiusHeight"),
panda::FunctionRef::New(const_cast<panda::EcmaVM*>(vm), RectBridge::SetRadiusHeight));
rect->Set(vm, panda::StringRef::NewFromUtf8(vm, "resetRectRadiusHeight"),
panda::FunctionRef::New(const_cast<panda::EcmaVM*>(vm), RectBridge::ResetRadiusHeight));
rect->Set(vm, panda::StringRef::NewFromUtf8(vm, "setRectRadius"),
panda::FunctionRef::New(const_cast<panda::EcmaVM*>(vm), RectBridge::SetRadius));
rect->Set(vm, panda::StringRef::NewFromUtf8(vm, "resetRectRadius"),
panda::FunctionRef::New(const_cast<panda::EcmaVM*>(vm), RectBridge::ResetRadius));
object->Set(vm, panda::StringRef::NewFromUtf8(vm, "rect"), rect);
}
} // namespace OHOS::Ace::NG

View File

@ -0,0 +1,348 @@
/*
* Copyright (c) 2023 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 "bridge/declarative_frontend/engine/jsi/nativeModule/arkts_native_common_shape_bridge.h"
#include "bridge/declarative_frontend/engine/jsi/components/arkts_native_api.h"
#include "frameworks/bridge/declarative_frontend/engine/jsi/nativeModule/arkts_utils.h"
namespace OHOS::Ace::NG {
constexpr int NUM_0 = 0;
constexpr int NUM_1 = 1;
constexpr double STROKE_MITERLIMIT_DEFAULT = 4.0f;
constexpr double DEFAULT_OPACITY = 1.0;
ArkUINativeModuleValue CommonShapeBridge::SetStrokeDashArray(ArkUIRuntimeCallInfo* runtimeCallInfo)
{
EcmaVM* vm = runtimeCallInfo->GetVM();
CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(NUM_0);
Local<JSValueRef> secondArg = runtimeCallInfo->GetCallArgRef(NUM_1);
if (!secondArg->IsArray(vm)) {
return panda::JSValueRef::Undefined(vm);
}
void* nativeNode = firstArg->ToNativePointer(vm)->Value();
auto array = Local<panda::ArrayRef>(secondArg);
auto length = array->Length(vm);
std::vector<double> dashArray;
std::vector<int32_t> dimUnits;
for (uint32_t index = 0; index < length; index++) {
Local<JSValueRef> value = panda::ArrayRef::GetValueAt(vm, array, index);
CalcDimension dimDash;
ArkTSUtils::ParseJsDimensionVp(vm, value, dimDash);
dashArray.emplace_back(dimDash.Value());
dimUnits.emplace_back(static_cast<int32_t>(dimDash.Unit()));
}
if ((static_cast<uint32_t>(length) & 1)) {
for (uint32_t i = 0; i < length; i++) {
dashArray.emplace_back(dashArray[i]);
dimUnits.emplace_back(dimUnits[i]);
}
}
GetArkUIInternalNodeAPI()->GetCommonShapeModifier().SetStrokeDashArray(nativeNode, dashArray.data(),
dimUnits.data(), dashArray.size());
return panda::JSValueRef::Undefined(vm);
}
ArkUINativeModuleValue CommonShapeBridge::ResetStrokeDashArray(ArkUIRuntimeCallInfo* runtimeCallInfo)
{
EcmaVM* vm = runtimeCallInfo->GetVM();
CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(NUM_0);
void* nativeNode = firstArg->ToNativePointer(vm)->Value();
GetArkUIInternalNodeAPI()->GetCommonShapeModifier().ResetStrokeDashArray(nativeNode);
return panda::JSValueRef::Undefined(vm);
}
ArkUINativeModuleValue CommonShapeBridge::SetStroke(ArkUIRuntimeCallInfo* runtimeCallInfo)
{
EcmaVM* vm = runtimeCallInfo->GetVM();
CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(NUM_0);
Local<JSValueRef> secondArg = runtimeCallInfo->GetCallArgRef(NUM_1);
void* nativeNode = firstArg->ToNativePointer(vm)->Value();
Color color;
if (!ArkTSUtils::ParseJsColorAlpha(vm, secondArg, color)) {
GetArkUIInternalNodeAPI()->GetCommonShapeModifier().ResetStroke(nativeNode);
} else {
GetArkUIInternalNodeAPI()->GetCommonShapeModifier().SetStroke(nativeNode, color.GetValue());
}
return panda::JSValueRef::Undefined(vm);
}
ArkUINativeModuleValue CommonShapeBridge::ResetStroke(ArkUIRuntimeCallInfo* runtimeCallInfo)
{
EcmaVM* vm = runtimeCallInfo->GetVM();
CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(NUM_0);
void* nativeNode = firstArg->ToNativePointer(vm)->Value();
GetArkUIInternalNodeAPI()->GetCommonShapeModifier().ResetStroke(nativeNode);
return panda::JSValueRef::Undefined(vm);
}
ArkUINativeModuleValue CommonShapeBridge::SetFill(ArkUIRuntimeCallInfo* runtimeCallInfo)
{
EcmaVM* vm = runtimeCallInfo->GetVM();
CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(NUM_0);
Local<JSValueRef> secondArg = runtimeCallInfo->GetCallArgRef(NUM_1);
void* nativeNode = firstArg->ToNativePointer(vm)->Value();
Color color;
if (!ArkTSUtils::ParseJsColorAlpha(vm, secondArg, color)) {
GetArkUIInternalNodeAPI()->GetCommonShapeModifier().ResetFill(nativeNode);
} else {
GetArkUIInternalNodeAPI()->GetCommonShapeModifier().SetFill(nativeNode, color.GetValue());
}
return panda::JSValueRef::Undefined(vm);
}
ArkUINativeModuleValue CommonShapeBridge::ResetFill(ArkUIRuntimeCallInfo* runtimeCallInfo)
{
EcmaVM* vm = runtimeCallInfo->GetVM();
CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(NUM_0);
void* nativeNode = firstArg->ToNativePointer(vm)->Value();
GetArkUIInternalNodeAPI()->GetCommonShapeModifier().ResetFill(nativeNode);
return panda::JSValueRef::Undefined(vm);
}
ArkUINativeModuleValue CommonShapeBridge::SetStrokeDashOffset(ArkUIRuntimeCallInfo* runtimeCallInfo)
{
EcmaVM* vm = runtimeCallInfo->GetVM();
CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(NUM_0);
Local<JSValueRef> secondArg = runtimeCallInfo->GetCallArgRef(NUM_1);
void* nativeNode = firstArg->ToNativePointer(vm)->Value();
CalcDimension strokeDashOffset;
std::string calcStr;
if (secondArg->IsUndefined() || !ArkTSUtils::ParseJsDimensionVpNG(vm, secondArg, strokeDashOffset)) {
GetArkUIInternalNodeAPI()->GetCommonShapeModifier().ResetStrokeDashOffset(nativeNode);
} else {
if (LessNotEqual(strokeDashOffset.Value(), 0.0)) {
strokeDashOffset.SetValue(0.0);
}
GetArkUIInternalNodeAPI()->GetCommonShapeModifier().SetStrokeDashOffset(
nativeNode, strokeDashOffset.Value(), static_cast<int>(strokeDashOffset.Unit()));
}
return panda::JSValueRef::Undefined(vm);
}
ArkUINativeModuleValue CommonShapeBridge::ResetStrokeDashOffset(ArkUIRuntimeCallInfo* runtimeCallInfo)
{
EcmaVM* vm = runtimeCallInfo->GetVM();
CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(NUM_0);
void* nativeNode = firstArg->ToNativePointer(vm)->Value();
GetArkUIInternalNodeAPI()->GetCommonShapeModifier().ResetStrokeDashOffset(nativeNode);
return panda::JSValueRef::Undefined(vm);
}
ArkUINativeModuleValue CommonShapeBridge::SetStrokeLineCap(ArkUIRuntimeCallInfo* runtimeCallInfo)
{
EcmaVM* vm = runtimeCallInfo->GetVM();
CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(NUM_0);
Local<JSValueRef> secondArg = runtimeCallInfo->GetCallArgRef(NUM_1);
void* nativeNode = firstArg->ToNativePointer(vm)->Value();
if (secondArg->IsUndefined()) {
GetArkUIInternalNodeAPI()->GetCommonShapeModifier().ResetStrokeLineCap(nativeNode);
} else {
int strokeLineCap = secondArg->ToNumber(vm)->Value();
GetArkUIInternalNodeAPI()->GetCommonShapeModifier().SetStrokeLineCap(nativeNode, strokeLineCap);
}
return panda::JSValueRef::Undefined(vm);
}
ArkUINativeModuleValue CommonShapeBridge::ResetStrokeLineCap(ArkUIRuntimeCallInfo* runtimeCallInfo)
{
EcmaVM* vm = runtimeCallInfo->GetVM();
CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(NUM_0);
void* nativeNode = firstArg->ToNativePointer(vm)->Value();
GetArkUIInternalNodeAPI()->GetCommonShapeModifier().ResetStrokeLineCap(nativeNode);
return panda::JSValueRef::Undefined(vm);
}
ArkUINativeModuleValue CommonShapeBridge::SetStrokeLineJoin(ArkUIRuntimeCallInfo* runtimeCallInfo)
{
EcmaVM* vm = runtimeCallInfo->GetVM();
CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(NUM_0);
Local<JSValueRef> secondArg = runtimeCallInfo->GetCallArgRef(NUM_1);
void* nativeNode = firstArg->ToNativePointer(vm)->Value();
if (secondArg->IsUndefined()) {
GetArkUIInternalNodeAPI()->GetCommonShapeModifier().ResetStrokeLineJoin(nativeNode);
} else {
int strokeLineJoin = secondArg->ToNumber(vm)->Value();
GetArkUIInternalNodeAPI()->GetCommonShapeModifier().SetStrokeLineJoin(nativeNode, strokeLineJoin);
}
return panda::JSValueRef::Undefined(vm);
}
ArkUINativeModuleValue CommonShapeBridge::ResetStrokeLineJoin(ArkUIRuntimeCallInfo* runtimeCallInfo)
{
EcmaVM* vm = runtimeCallInfo->GetVM();
CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(NUM_0);
void* nativeNode = firstArg->ToNativePointer(vm)->Value();
GetArkUIInternalNodeAPI()->GetCommonShapeModifier().ResetStrokeLineJoin(nativeNode);
return panda::JSValueRef::Undefined(vm);
}
ArkUINativeModuleValue CommonShapeBridge::SetStrokeMiterLimit(ArkUIRuntimeCallInfo* runtimeCallInfo)
{
EcmaVM* vm = runtimeCallInfo->GetVM();
CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(NUM_0);
Local<JSValueRef> secondArg = runtimeCallInfo->GetCallArgRef(NUM_1);
void* nativeNode = firstArg->ToNativePointer(vm)->Value();
double strokeMiterLimit = STROKE_MITERLIMIT_DEFAULT;
if (secondArg->IsUndefined() || !ArkTSUtils::ParseJsDouble(vm, secondArg, strokeMiterLimit)) {
GetArkUIInternalNodeAPI()->GetCommonShapeModifier().ResetStrokeMiterLimit(nativeNode);
} else {
GetArkUIInternalNodeAPI()->GetCommonShapeModifier().SetStrokeMiterLimit(nativeNode, strokeMiterLimit);
}
return panda::JSValueRef::Undefined(vm);
}
ArkUINativeModuleValue CommonShapeBridge::ResetStrokeMiterLimit(ArkUIRuntimeCallInfo* runtimeCallInfo)
{
EcmaVM* vm = runtimeCallInfo->GetVM();
CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(NUM_0);
void* nativeNode = firstArg->ToNativePointer(vm)->Value();
GetArkUIInternalNodeAPI()->GetCommonShapeModifier().ResetStrokeMiterLimit(nativeNode);
return panda::JSValueRef::Undefined(vm);
}
ArkUINativeModuleValue CommonShapeBridge::SetFillOpacity(ArkUIRuntimeCallInfo* runtimeCallInfo)
{
EcmaVM* vm = runtimeCallInfo->GetVM();
CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(NUM_0);
Local<JSValueRef> secondArg = runtimeCallInfo->GetCallArgRef(NUM_1);
void* nativeNode = firstArg->ToNativePointer(vm)->Value();
if (secondArg->IsUndefined()) {
GetArkUIInternalNodeAPI()->GetCommonShapeModifier().ResetFillOpacity(nativeNode);
} else {
double opacity = DEFAULT_OPACITY;
if (!ArkTSUtils::ParseJsDouble(vm, secondArg, opacity)) {
GetArkUIInternalNodeAPI()->GetCommonShapeModifier().ResetFillOpacity(nativeNode);
} else {
GetArkUIInternalNodeAPI()->GetCommonShapeModifier().SetFillOpacity(nativeNode, opacity);
}
}
return panda::JSValueRef::Undefined(vm);
}
ArkUINativeModuleValue CommonShapeBridge::ResetFillOpacity(ArkUIRuntimeCallInfo* runtimeCallInfo)
{
EcmaVM* vm = runtimeCallInfo->GetVM();
CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(NUM_0);
void* nativeNode = firstArg->ToNativePointer(vm)->Value();
GetArkUIInternalNodeAPI()->GetCommonShapeModifier().ResetFillOpacity(nativeNode);
return panda::JSValueRef::Undefined(vm);
}
ArkUINativeModuleValue CommonShapeBridge::SetStrokeOpacity(ArkUIRuntimeCallInfo* runtimeCallInfo)
{
EcmaVM* vm = runtimeCallInfo->GetVM();
CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(NUM_0);
Local<JSValueRef> secondArg = runtimeCallInfo->GetCallArgRef(NUM_1);
void* nativeNode = firstArg->ToNativePointer(vm)->Value();
if (secondArg->IsUndefined()) {
GetArkUIInternalNodeAPI()->GetCommonShapeModifier().ResetStrokeOpacity(nativeNode);
} else {
double opacity = DEFAULT_OPACITY;
if (!ArkTSUtils::ParseJsDouble(vm, secondArg, opacity)) {
GetArkUIInternalNodeAPI()->GetCommonShapeModifier().ResetStrokeOpacity(nativeNode);
} else {
GetArkUIInternalNodeAPI()->GetCommonShapeModifier().SetStrokeOpacity(nativeNode, opacity);
}
}
return panda::JSValueRef::Undefined(vm);
}
ArkUINativeModuleValue CommonShapeBridge::ResetStrokeOpacity(ArkUIRuntimeCallInfo* runtimeCallInfo)
{
EcmaVM* vm = runtimeCallInfo->GetVM();
CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(NUM_0);
void* nativeNode = firstArg->ToNativePointer(vm)->Value();
GetArkUIInternalNodeAPI()->GetCommonShapeModifier().ResetStrokeOpacity(nativeNode);
return panda::JSValueRef::Undefined(vm);
}
ArkUINativeModuleValue CommonShapeBridge::SetStrokeWidth(ArkUIRuntimeCallInfo* runtimeCallInfo)
{
EcmaVM* vm = runtimeCallInfo->GetVM();
CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(NUM_0);
Local<JSValueRef> secondArg = runtimeCallInfo->GetCallArgRef(NUM_1);
void* nativeNode = firstArg->ToNativePointer(vm)->Value();
CalcDimension strokeWidth = CalcDimension(1.0, DimensionUnit::VP);
if (secondArg->IsString()) {
const std::string& value = secondArg->ToString(vm)->ToString();
strokeWidth = StringUtils::StringToDimensionWithUnit(value, DimensionUnit::VP, 1.0);
} else {
ArkTSUtils::ParseJsDimension(vm, secondArg, strokeWidth, DimensionUnit::VP);
}
if (strokeWidth.IsNegative()) {
strokeWidth = CalcDimension(1.0, DimensionUnit::VP);
}
GetArkUIInternalNodeAPI()->GetCommonShapeModifier().SetStrokeWidth(
nativeNode, strokeWidth.Value(), static_cast<int>(strokeWidth.Unit()));
return panda::JSValueRef::Undefined(vm);
}
ArkUINativeModuleValue CommonShapeBridge::ResetStrokeWidth(ArkUIRuntimeCallInfo* runtimeCallInfo)
{
EcmaVM* vm = runtimeCallInfo->GetVM();
CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(NUM_0);
void* nativeNode = firstArg->ToNativePointer(vm)->Value();
GetArkUIInternalNodeAPI()->GetCommonShapeModifier().ResetStrokeWidth(nativeNode);
return panda::JSValueRef::Undefined(vm);
}
ArkUINativeModuleValue CommonShapeBridge::SetAntiAlias(ArkUIRuntimeCallInfo* runtimeCallInfo)
{
EcmaVM* vm = runtimeCallInfo->GetVM();
CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(NUM_0);
Local<JSValueRef> secondArg = runtimeCallInfo->GetCallArgRef(NUM_1);
void* nativeNode = firstArg->ToNativePointer(vm)->Value();
if (secondArg->IsUndefined()) {
GetArkUIInternalNodeAPI()->GetCommonShapeModifier().ResetAntiAlias(nativeNode);
} else {
bool antiAlias = secondArg->ToBoolean(vm)->Value();
GetArkUIInternalNodeAPI()->GetCommonShapeModifier().SetAntiAlias(nativeNode, antiAlias);
}
return panda::JSValueRef::Undefined(vm);
}
ArkUINativeModuleValue CommonShapeBridge::ResetAntiAlias(ArkUIRuntimeCallInfo* runtimeCallInfo)
{
EcmaVM* vm = runtimeCallInfo->GetVM();
CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(NUM_0);
void* nativeNode = firstArg->ToNativePointer(vm)->Value();
GetArkUIInternalNodeAPI()->GetCommonShapeModifier().ResetAntiAlias(nativeNode);
return panda::JSValueRef::Undefined(vm);
}
} // namespace OHOS::Ace::NG

View File

@ -0,0 +1,50 @@
/*
* Copyright (c) 2023 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_ENGINE_JSI_NATIVEMODULE_ARKTS_NATIVE_COMMON_SHAPE_BRIDGE_H
#define FRAMEWORKS_BRIDGE_DECLARATIVE_FRONTEND_ENGINE_JSI_NATIVEMODULE_ARKTS_NATIVE_COMMON_SHAPE_BRIDGE_H
#include "bridge/declarative_frontend/engine/jsi/nativeModule/arkts_native_api_bridge.h"
#include "bridge/declarative_frontend/engine/jsi/nativeModule/arkts_native_common_bridge.h"
namespace OHOS::Ace::NG {
class CommonShapeBridge : public CommonBridge {
public:
static ArkUINativeModuleValue SetStrokeDashArray(ArkUIRuntimeCallInfo* runtimeCallInfo);
static ArkUINativeModuleValue ResetStrokeDashArray(ArkUIRuntimeCallInfo* runtimeCallInfo);
static ArkUINativeModuleValue SetStroke(ArkUIRuntimeCallInfo* runtimeCallInfo);
static ArkUINativeModuleValue ResetStroke(ArkUIRuntimeCallInfo* runtimeCallInfo);
static ArkUINativeModuleValue SetFill(ArkUIRuntimeCallInfo* runtimeCallInfo);
static ArkUINativeModuleValue ResetFill(ArkUIRuntimeCallInfo* runtimeCallInfo);
static ArkUINativeModuleValue SetStrokeDashOffset(ArkUIRuntimeCallInfo* runtimeCallInfo);
static ArkUINativeModuleValue ResetStrokeDashOffset(ArkUIRuntimeCallInfo* runtimeCallInfo);
static ArkUINativeModuleValue SetStrokeLineCap(ArkUIRuntimeCallInfo* runtimeCallInfo);
static ArkUINativeModuleValue ResetStrokeLineCap(ArkUIRuntimeCallInfo* runtimeCallInfo);
static ArkUINativeModuleValue SetStrokeLineJoin(ArkUIRuntimeCallInfo* runtimeCallInfo);
static ArkUINativeModuleValue ResetStrokeLineJoin(ArkUIRuntimeCallInfo* runtimeCallInfo);
static ArkUINativeModuleValue SetStrokeMiterLimit(ArkUIRuntimeCallInfo* runtimeCallInfo);
static ArkUINativeModuleValue ResetStrokeMiterLimit(ArkUIRuntimeCallInfo* runtimeCallInfo);
static ArkUINativeModuleValue SetFillOpacity(ArkUIRuntimeCallInfo* runtimeCallInfo);
static ArkUINativeModuleValue ResetFillOpacity(ArkUIRuntimeCallInfo* runtimeCallInfo);
static ArkUINativeModuleValue SetStrokeOpacity(ArkUIRuntimeCallInfo* runtimeCallInfo);
static ArkUINativeModuleValue ResetStrokeOpacity(ArkUIRuntimeCallInfo* runtimeCallInfo);
static ArkUINativeModuleValue SetStrokeWidth(ArkUIRuntimeCallInfo* runtimeCallInfo);
static ArkUINativeModuleValue ResetStrokeWidth(ArkUIRuntimeCallInfo* runtimeCallInfo);
static ArkUINativeModuleValue SetAntiAlias(ArkUIRuntimeCallInfo* runtimeCallInfo);
static ArkUINativeModuleValue ResetAntiAlias(ArkUIRuntimeCallInfo* runtimeCallInfo);
};
} // namespace OHOS::Ace::NG
#endif // FRAMEWORKS_BRIDGE_DECLARATIVE_FRONTEND_ENGINE_JSI_NATIVEMODULE_ARKTS_NATIVE_COMMON_SHAPE_BRIDGE_H

View File

@ -0,0 +1,184 @@
/*
* Copyright (c) 2023 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 "bridge/declarative_frontend/engine/jsi/nativeModule/arkts_native_rect_bridge.h"
#include "ecmascript/napi/include/jsnapi.h"
#include "base/geometry/calc_dimension.h"
#include "base/geometry/dimension.h"
#include "bridge/declarative_frontend/engine/jsi/components/arkts_native_api.h"
#include "bridge/declarative_frontend/engine/jsi/nativeModule/arkts_utils.h"
using namespace OHOS::Ace::Framework;
namespace OHOS::Ace::NG {
constexpr int CALL_ARG_0 = 0;
constexpr int CALL_ARG_1 = 1;
ArkUINativeModuleValue RectBridge::SetRadiusWidth(ArkUIRuntimeCallInfo* runtimeCallInfo)
{
EcmaVM* vm = runtimeCallInfo->GetVM();
CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(CALL_ARG_0);
void* nativeNode = firstArg->ToNativePointer(vm)->Value();
Local<JSValueRef> jsValue = runtimeCallInfo->GetCallArgRef(CALL_ARG_1);
CalcDimension radiusWidth;
bool isSupportPercent = true;
if (!ArkTSUtils::ParseJsDimensionVpNG(vm, jsValue, radiusWidth, isSupportPercent)) {
GetArkUIInternalNodeAPI()->GetRectModifier().ResetRectRadiusWidth(nativeNode);
}
GetArkUIInternalNodeAPI()->GetRectModifier().SetRectRadiusWidth(
nativeNode, radiusWidth.Value(), static_cast<int32_t>(radiusWidth.Unit()));
return panda::JSValueRef::Undefined(vm);
}
ArkUINativeModuleValue RectBridge::ResetRadiusWidth(ArkUIRuntimeCallInfo* runtimeCallInfo)
{
EcmaVM* vm = runtimeCallInfo->GetVM();
CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(CALL_ARG_0);
void* nativeNode = firstArg->ToNativePointer(vm)->Value();
GetArkUIInternalNodeAPI()->GetRectModifier().ResetRectRadiusWidth(nativeNode);
return panda::JSValueRef::Undefined(vm);
}
ArkUINativeModuleValue RectBridge::SetRadiusHeight(ArkUIRuntimeCallInfo* runtimeCallInfo)
{
EcmaVM* vm = runtimeCallInfo->GetVM();
CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(CALL_ARG_0);
void* nativeNode = firstArg->ToNativePointer(vm)->Value();
Local<JSValueRef> jsValue = runtimeCallInfo->GetCallArgRef(CALL_ARG_1);
CalcDimension radiusHeight;
bool isSupportPercent = true;
if (!ArkTSUtils::ParseJsDimensionVpNG(vm, jsValue, radiusHeight, isSupportPercent)) {
GetArkUIInternalNodeAPI()->GetRectModifier().ResetRectRadiusHeight(nativeNode);
}
GetArkUIInternalNodeAPI()->GetRectModifier().SetRectRadiusHeight(
nativeNode, radiusHeight.Value(), static_cast<int32_t>(radiusHeight.Unit()));
return panda::JSValueRef::Undefined(vm);
}
ArkUINativeModuleValue RectBridge::ResetRadiusHeight(ArkUIRuntimeCallInfo* runtimeCallInfo)
{
EcmaVM* vm = runtimeCallInfo->GetVM();
CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(CALL_ARG_0);
void* nativeNode = firstArg->ToNativePointer(vm)->Value();
GetArkUIInternalNodeAPI()->GetRectModifier().ResetRectRadiusHeight(nativeNode);
return panda::JSValueRef::Undefined(vm);
}
ArkUINativeModuleValue RectBridge::SetRadius(ArkUIRuntimeCallInfo* runtimeCallInfo)
{
EcmaVM* vm = runtimeCallInfo->GetVM();
CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(CALL_ARG_0);
void* nativeNode = firstArg->ToNativePointer(vm)->Value();
Local<JSValueRef> jsValue = runtimeCallInfo->GetCallArgRef(CALL_ARG_1);
std::vector<double> radiusValues;
std::vector<int32_t> radiusUnits;
int32_t radiusPairsCount = 4;
bool radiusValidPairs[] { false, false, false, false };
if (jsValue->IsArray(vm)) {
RectBridge::SetRadiusWithArray(vm, jsValue, radiusValues, radiusUnits, radiusValidPairs);
GetArkUIInternalNodeAPI()->GetRectModifier().SetRectRadiusWithArray(
nativeNode, radiusValues.data(), radiusUnits.data(), radiusValidPairs, radiusPairsCount);
return panda::JSValueRef::Undefined(vm);
}
if (jsValue->IsNumber() || jsValue->IsString() || jsValue->IsObject()) {
CalcDimension parsedValue;
bool isSupportPercent = true;
if (!ArkTSUtils::ParseJsDimensionVpNG(vm, jsValue, parsedValue, isSupportPercent)) {
parsedValue.Reset();
}
GetArkUIInternalNodeAPI()->GetRectModifier().SetRectRadiusWithValue(
nativeNode, parsedValue.Value(), static_cast<int32_t>(parsedValue.Unit()));
}
return panda::JSValueRef::Undefined(vm);
}
ArkUINativeModuleValue RectBridge::ResetRadius(ArkUIRuntimeCallInfo* runtimeCallInfo)
{
EcmaVM* vm = runtimeCallInfo->GetVM();
CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(CALL_ARG_0);
void* nativeNode = firstArg->ToNativePointer(vm)->Value();
GetArkUIInternalNodeAPI()->GetRectModifier().ResetRectRadius(nativeNode);
return panda::JSValueRef::Undefined(vm);
}
void RectBridge::SetRadiusWithArray(const EcmaVM* vm, const Local<JSValueRef>& jsValue,
std::vector<double>& radiusValues, std::vector<int32_t>& radiusUnits, bool* radiusValidPairs)
{
if (!jsValue->IsArray(vm)) {
return;
}
auto arrayVal = panda::Local<panda::ArrayRef>(jsValue);
auto length = arrayVal->Length(vm);
if (length <= 0) {
return;
}
size_t radiusPairsCount = 4;
size_t dataCount = 2;
for (size_t i = 0; i < radiusPairsCount; i++) {
if (i >= length && length < radiusPairsCount) {
SetRadiusArraysInvalidValue(radiusValues, radiusUnits, radiusValidPairs, i);
break;
}
Local<JSValueRef> radiusItem = panda::ArrayRef::GetValueAt(vm, arrayVal, i);
if (!radiusItem->IsArray(vm)) {
SetRadiusArraysInvalidValue(radiusValues, radiusUnits, radiusValidPairs, i);
break;
}
auto radiusArray = panda::Local<panda::ArrayRef>(radiusItem);
if (radiusArray->Length(vm) != dataCount) {
SetRadiusArraysInvalidValue(radiusValues, radiusUnits, radiusValidPairs, i);
break;
}
uint32_t indexX = 0;
uint32_t indexY = 1;
Local<JSValueRef> radiusX = panda::ArrayRef::GetValueAt(vm, radiusArray, indexX);
Local<JSValueRef> radiusY = panda::ArrayRef::GetValueAt(vm, radiusArray, indexY);
CalcDimension radiusXValue;
CalcDimension radiusYValue;
bool isSupportPercent = true;
if (!ArkTSUtils::ParseJsDimensionVpNG(vm, radiusX, radiusXValue, isSupportPercent)) {
radiusXValue.Reset();
}
if (!ArkTSUtils::ParseJsDimensionVpNG(vm, radiusY, radiusYValue, isSupportPercent)) {
radiusYValue.Reset();
}
radiusValidPairs[i] = true;
radiusValues.push_back(radiusXValue.Value());
radiusValues.push_back(radiusYValue.Value());
radiusUnits.push_back(static_cast<int32_t>(radiusXValue.Unit()));
radiusUnits.push_back(static_cast<int32_t>(radiusYValue.Unit()));
}
}
void RectBridge::SetRadiusArraysInvalidValue(
std::vector<double>& radiusValues, std::vector<int32_t>& radiusUnits, bool* radiusValidPairs, int index)
{
radiusValidPairs[index] = false;
CalcDimension radiusXValue;
CalcDimension radiusYValue;
radiusXValue.Reset();
radiusYValue.Reset();
radiusValues.push_back(radiusXValue.Value());
radiusValues.push_back(radiusYValue.Value());
radiusUnits.push_back(static_cast<int32_t>(radiusXValue.Unit()));
radiusUnits.push_back(static_cast<int32_t>(radiusYValue.Unit()));
}
} // namespace OHOS::Ace::NG

View File

@ -0,0 +1,39 @@
/*
* Copyright (c) 2023 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_ENGINE_JSI_NATIVEMODULE_ARKTS_NATIVE_RECT_BRIDGE_H
#define FRAMEWORKS_BRIDGE_DECLARATIVE_FRONTEND_ENGINE_JSI_NATIVEMODULE_ARKTS_NATIVE_RECT_BRIDGE_H
#include "bridge/declarative_frontend/engine/jsi/nativeModule/arkts_native_api_bridge.h"
namespace OHOS::Ace::NG {
class RectBridge {
public:
static ArkUINativeModuleValue SetRadiusWidth(ArkUIRuntimeCallInfo* runtimeCallInfo);
static ArkUINativeModuleValue ResetRadiusWidth(ArkUIRuntimeCallInfo* runtimeCallInfo);
static ArkUINativeModuleValue SetRadiusHeight(ArkUIRuntimeCallInfo* runtimeCallInfo);
static ArkUINativeModuleValue ResetRadiusHeight(ArkUIRuntimeCallInfo* runtimeCallInfo);
static ArkUINativeModuleValue SetRadius(ArkUIRuntimeCallInfo* runtimeCallInfo);
static ArkUINativeModuleValue ResetRadius(ArkUIRuntimeCallInfo* runtimeCallInfo);
private:
static void SetRadiusWithArray(const EcmaVM* vm, const Local<JSValueRef>& jsValue,
std::vector<double>& radiusValues, std::vector<int32_t>& radiusUnits, bool* radiusValidPairs);
static void SetRadiusArraysInvalidValue(
std::vector<double>& radiusValues, std::vector<int32_t>& radiusUnits, bool* radiusValidPairs, int index);
};
} // namespace OHOS::Ace::NG
#endif // FRAMEWORKS_BRIDGE_DECLARATIVE_FRONTEND_ENGINE_JSI_NATIVEMODULE_ARKTS_NATIVE_RECT__BRIDGE_H

View File

@ -0,0 +1,114 @@
/*
* Copyright (c) 2023 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 "bridge/declarative_frontend/engine/jsi/nativeModule/arkts_native_shape_bridge.h"
#include "bridge/declarative_frontend/engine/jsi/components/arkts_native_api.h"
#include "frameworks/bridge/declarative_frontend/engine/jsi/nativeModule/arkts_utils.h"
namespace OHOS::Ace::NG {
constexpr int NUM_0 = 0;
constexpr int NUM_1 = 1;
constexpr int NUM_2 = 2;
constexpr int NUM_3 = 3;
constexpr int NUM_4 = 4;
ArkUINativeModuleValue ShapeBridge::SetViewPort(ArkUIRuntimeCallInfo* runtimeCallInfo)
{
EcmaVM* vm = runtimeCallInfo->GetVM();
CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
Local<JSValueRef> nodeArg = runtimeCallInfo->GetCallArgRef(NUM_0);
void* nativeNode = nodeArg->ToNativePointer(vm)->Value();
Local<JSValueRef> xArg = runtimeCallInfo->GetCallArgRef(NUM_1);
Local<JSValueRef> yArg = runtimeCallInfo->GetCallArgRef(NUM_2);
Local<JSValueRef> widthArg = runtimeCallInfo->GetCallArgRef(NUM_3);
Local<JSValueRef> heightArg = runtimeCallInfo->GetCallArgRef(NUM_4);
CalcDimension dimLeft;
ArkTSUtils::ParseJsDimensionVp(vm, xArg, dimLeft);
CalcDimension dimTop;
ArkTSUtils::ParseJsDimensionVp(vm, yArg, dimTop);
CalcDimension dimWidth;
ArkTSUtils::ParseJsDimensionVp(vm, widthArg, dimWidth);
CalcDimension dimHeight;
ArkTSUtils::ParseJsDimensionVp(vm, heightArg, dimHeight);
std::vector<double> dimValues;
std::vector<int32_t> dimUnits;
dimValues.push_back(dimLeft.Value());
dimValues.push_back(dimTop.Value());
dimValues.push_back(dimWidth.Value());
dimValues.push_back(dimHeight.Value());
dimUnits.push_back(static_cast<int32_t>(dimLeft.Unit()));
dimUnits.push_back(static_cast<int32_t>(dimTop.Unit()));
dimUnits.push_back(static_cast<int32_t>(dimWidth.Unit()));
dimUnits.push_back(static_cast<int32_t>(dimHeight.Unit()));
GetArkUIInternalNodeAPI()->GetShapeModifier().SetShapeViewPort(nativeNode, dimValues.data(), dimUnits.data());
return panda::JSValueRef::Undefined(vm);
}
ArkUINativeModuleValue ShapeBridge::ResetViewPort(ArkUIRuntimeCallInfo* runtimeCallInfo)
{
EcmaVM* vm = runtimeCallInfo->GetVM();
CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(NUM_0);
void* nativeNode = firstArg->ToNativePointer(vm)->Value();
GetArkUIInternalNodeAPI()->GetShapeModifier().ResetShapeViewPort(nativeNode);
return panda::JSValueRef::Undefined(vm);
}
ArkUINativeModuleValue ShapeBridge::SetMesh(ArkUIRuntimeCallInfo* runtimeCallInfo)
{
EcmaVM* vm = runtimeCallInfo->GetVM();
CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
Local<JSValueRef> nodeArg = runtimeCallInfo->GetCallArgRef(NUM_0);
void* nativeNode = nodeArg->ToNativePointer(vm)->Value();
Local<JSValueRef> valueArrayArg = runtimeCallInfo->GetCallArgRef(NUM_1);
Local<JSValueRef> columnArg = runtimeCallInfo->GetCallArgRef(NUM_2);
Local<JSValueRef> rowArg = runtimeCallInfo->GetCallArgRef(NUM_3);
std::vector<double> mesh;
if (valueArrayArg->IsArray(vm)) {
auto arrayVal = panda::Local<panda::ArrayRef>(valueArrayArg);
auto length = arrayVal->Length(vm);
if (length <= 0) {
return panda::JSValueRef::Undefined(vm);
}
for (size_t i = 0; i < length; i++) {
Local<JSValueRef> radiusItem = panda::ArrayRef::GetValueAt(vm, arrayVal, i);
double vert;
if (ArkTSUtils::ParseJsDouble(vm, radiusItem, vert)) {
mesh.push_back(vert);
}
}
}
int32_t column = 0;
int32_t row = 0;
if (!ArkTSUtils::ParseJsInteger(vm, columnArg, column)) {
return panda::JSValueRef::Undefined(vm);
}
if (!ArkTSUtils::ParseJsInteger(vm, rowArg, row)) {
return panda::JSValueRef::Undefined(vm);
}
GetArkUIInternalNodeAPI()->GetShapeModifier().SetShapeMesh(nativeNode, mesh.data(), mesh.size(), column, row);
return panda::JSValueRef::Undefined(vm);
}
ArkUINativeModuleValue ShapeBridge::ResetMesh(ArkUIRuntimeCallInfo* runtimeCallInfo)
{
EcmaVM* vm = runtimeCallInfo->GetVM();
CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(NUM_0);
void* nativeNode = firstArg->ToNativePointer(vm)->Value();
GetArkUIInternalNodeAPI()->GetShapeModifier().ResetShapeMesh(nativeNode);
return panda::JSValueRef::Undefined(vm);
}
} // namespace OHOS::Ace::NG

View File

@ -0,0 +1,32 @@
/*
* Copyright (c) 2023 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_ENGINE_JSI_NATIVEMODULE_ARKTS_NATIVE_SHAPE_BRIDGE_H
#define FRAMEWORKS_BRIDGE_DECLARATIVE_FRONTEND_ENGINE_JSI_NATIVEMODULE_ARKTS_NATIVE_SHAPE_BRIDGE_H
#include "bridge/declarative_frontend/engine/jsi/nativeModule/arkts_native_api_bridge.h"
#include "bridge/declarative_frontend/engine/jsi/nativeModule/arkts_native_common_bridge.h"
namespace OHOS::Ace::NG {
class ShapeBridge : public CommonBridge {
public:
static ArkUINativeModuleValue SetViewPort(ArkUIRuntimeCallInfo* runtimeCallInfo);
static ArkUINativeModuleValue ResetViewPort(ArkUIRuntimeCallInfo* runtimeCallInfo);
static ArkUINativeModuleValue SetMesh(ArkUIRuntimeCallInfo* runtimeCallInfo);
static ArkUINativeModuleValue ResetMesh(ArkUIRuntimeCallInfo* runtimeCallInfo);
};
} // namespace OHOS::Ace::NG
#endif // FRAMEWORKS_BRIDGE_DECLARATIVE_FRONTEND_ENGINE_JSI_NATIVEMODULE_ARKTS_NATIVE_SHAPE_BRIDGE_H

View File

@ -1130,6 +1130,9 @@ void JSCanvasRenderer::JsGetPixelMap(const JSCallbackInfo& info)
napi_create_int32(env, 0, &temp);
napi_set_named_property(env, napiValue, "index", temp);
#endif
#else
TAG_LOGD(
AceLogTag::ACE_CANVAS, "[Engine Log] The function 'getPixelMap' is not supported on the current platform.");
#endif
}

View File

@ -818,10 +818,12 @@ void JSDatePickerDialog::Show(const JSCallbackInfo& info)
if (alignment >= 0 && alignment <= static_cast<int32_t>(DIALOG_ALIGNMENT.size())) {
pickerDialog.alignment = DIALOG_ALIGNMENT[alignment];
}
if (alignment == static_cast<int32_t>(DialogAlignment::TOP) ||
alignment == static_cast<int32_t>(DialogAlignment::TOP_START) ||
alignment == static_cast<int32_t>(DialogAlignment::TOP_END)) {
pickerDialog.offset = DATEPICKER_OFFSET_DEFAULT_TOP;
if (Container::LessThanAPIVersion(PlatformVersion::VERSION_ELEVEN)) {
if (alignment == static_cast<int32_t>(DialogAlignment::TOP) ||
alignment == static_cast<int32_t>(DialogAlignment::TOP_START) ||
alignment == static_cast<int32_t>(DialogAlignment::TOP_END)) {
pickerDialog.offset = DATEPICKER_OFFSET_DEFAULT_TOP;
}
}
}
@ -889,11 +891,16 @@ void JSDatePickerDialog::DatePickerDialogShow(const JSRef<JSObject>& paramObj,
DialogProperties properties;
if (SystemProperties::GetDeviceType() == DeviceType::PHONE) {
properties.alignment = DialogAlignment::BOTTOM;
if (Container::GreatOrEqualAPIVersion(PlatformVersion::VERSION_ELEVEN)) {
properties.offset = DimensionOffset(Offset(0, -theme->GetMarginBottom().ConvertToPx()));
}
} else {
properties.alignment = DialogAlignment::CENTER;
}
properties.customStyle = false;
properties.offset = DimensionOffset(Offset(0, -theme->GetMarginBottom().ConvertToPx()));
if (Container::LessThanAPIVersion(PlatformVersion::VERSION_ELEVEN)) {
properties.offset = DimensionOffset(Offset(0, -theme->GetMarginBottom().ConvertToPx()));
}
std::map<std::string, PickerDate> datePickerProperty;
std::map<std::string, PickerTime> timePickerProperty;
@ -1266,10 +1273,12 @@ void JSTimePickerDialog::Show(const JSCallbackInfo& info)
if (alignment >= 0 && alignment <= static_cast<int32_t>(DIALOG_ALIGNMENT.size())) {
pickerDialog.alignment = DIALOG_ALIGNMENT[alignment];
}
if (alignment == static_cast<int32_t>(DialogAlignment::TOP) ||
alignment == static_cast<int32_t>(DialogAlignment::TOP_START) ||
alignment == static_cast<int32_t>(DialogAlignment::TOP_END)) {
pickerDialog.offset = DATEPICKER_OFFSET_DEFAULT_TOP;
if (Container::LessThanAPIVersion(PlatformVersion::VERSION_ELEVEN)) {
if (alignment == static_cast<int32_t>(DialogAlignment::TOP) ||
alignment == static_cast<int32_t>(DialogAlignment::TOP_START) ||
alignment == static_cast<int32_t>(DialogAlignment::TOP_END)) {
pickerDialog.offset = DATEPICKER_OFFSET_DEFAULT_TOP;
}
}
}
@ -1327,11 +1336,16 @@ void JSTimePickerDialog::TimePickerDialogShow(const JSRef<JSObject>& paramObj,
DialogProperties properties;
if (SystemProperties::GetDeviceType() == DeviceType::PHONE) {
properties.alignment = DialogAlignment::BOTTOM;
if (Container::GreatOrEqualAPIVersion(PlatformVersion::VERSION_ELEVEN)) {
properties.offset = DimensionOffset(Offset(0, -theme->GetMarginBottom().ConvertToPx()));
}
} else {
properties.alignment = DialogAlignment::CENTER;
}
properties.customStyle = false;
properties.offset = DimensionOffset(Offset(0, -theme->GetMarginBottom().ConvertToPx()));
if (Container::LessThanAPIVersion(PlatformVersion::VERSION_ELEVEN)) {
properties.offset = DimensionOffset(Offset(0, -theme->GetMarginBottom().ConvertToPx()));
}
std::map<std::string, PickerTime> timePickerProperty;
if (selectedTime->IsObject()) {

View File

@ -1133,10 +1133,12 @@ void JSTextPickerDialog::Show(const JSCallbackInfo& info)
if (alignment >= 0 && alignment <= static_cast<int32_t>(DIALOG_ALIGNMENT.size())) {
textPickerDialog.alignment = DIALOG_ALIGNMENT[alignment];
}
if (alignment == static_cast<int32_t>(DialogAlignment::TOP) ||
alignment == static_cast<int32_t>(DialogAlignment::TOP_START) ||
alignment == static_cast<int32_t>(DialogAlignment::TOP_END)) {
textPickerDialog.offset = TEXT_PICKER_OFFSET_DEFAULT_TOP;
if (Container::LessThanAPIVersion(PlatformVersion::VERSION_ELEVEN)) {
if (alignment == static_cast<int32_t>(DialogAlignment::TOP) ||
alignment == static_cast<int32_t>(DialogAlignment::TOP_START) ||
alignment == static_cast<int32_t>(DialogAlignment::TOP_END)) {
textPickerDialog.offset = TEXT_PICKER_OFFSET_DEFAULT_TOP;
}
}
}
@ -1194,11 +1196,16 @@ void JSTextPickerDialog::TextPickerDialogShow(const JSRef<JSObject>& paramObj,
ButtonInfo buttonInfo;
if (SystemProperties::GetDeviceType() == DeviceType::PHONE) {
properties.alignment = DialogAlignment::BOTTOM;
if (Container::GreatOrEqualAPIVersion(PlatformVersion::VERSION_ELEVEN)) {
properties.offset = DimensionOffset(Offset(0, -theme->GetMarginBottom().ConvertToPx()));
}
} else {
properties.alignment = DialogAlignment::CENTER;
}
properties.customStyle = false;
properties.offset = DimensionOffset(Offset(0, -theme->GetMarginBottom().ConvertToPx()));
if (Container::LessThanAPIVersion(PlatformVersion::VERSION_ELEVEN)) {
properties.offset = DimensionOffset(Offset(0, -theme->GetMarginBottom().ConvertToPx()));
}
auto context = AccessibilityManager::DynamicCast<NG::PipelineContext>(pipelineContext);
auto overlayManager = context ? context->GetOverlayManager() : nullptr;

View File

@ -143,7 +143,8 @@ void DatePickerDialogModelImpl::SetDatePickerDialogShow(PickerDialogInfo& picker
}
auto datePicker = AceType::DynamicCast<PickerBaseComponent>(component);
DialogProperties properties {};
properties.alignment = DialogAlignment::CENTER;
properties.alignment = Container::LessThanAPIVersion(PlatformVersion::VERSION_ELEVEN) ? DialogAlignment::CENTER
: DialogAlignment::DEFAULT;
properties.customComponent = datePicker;
properties.customStyle = true;
auto acceptId = EventMarker(std::move(onAccept));

View File

@ -98,7 +98,8 @@ void TextPickerDialogModelImpl::SetTextPickerDialogShow(RefPtr<AceType>& PickerT
pickerText->SetRange(textPickerDialog.getRangeVector);
DialogProperties properties {};
properties.alignment = DialogAlignment::CENTER;
properties.alignment = Container::LessThanAPIVersion(PlatformVersion::VERSION_ELEVEN) ? DialogAlignment::CENTER
: DialogAlignment::DEFAULT;
properties.customComponent = pickerText;
properties.customStyle = true;
auto acceptId = EventMarker(std::move(onAccept));

View File

@ -74,7 +74,8 @@ void TimePickerDialogModelImpl::SetTimePickerDialogShow(PickerDialogInfo& picker
auto datePicker = AceType::DynamicCast<PickerBaseComponent>(component);
DialogProperties properties {};
properties.alignment = DialogAlignment::CENTER;
properties.alignment = Container::LessThanAPIVersion(PlatformVersion::VERSION_ELEVEN) ? DialogAlignment::CENTER
: DialogAlignment::DEFAULT;
properties.customComponent = datePicker;
properties.customStyle = true;
auto acceptId = EventMarker(std::move(onAccept));

View File

@ -17,6 +17,7 @@
#define FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_QRCODE_QRCODE_THEME_H
#include "core/common/ace_application_info.h"
#include "core/common/container.h"
#include "core/components/common/layout/constants.h"
#include "core/components/common/properties/color.h"
#include "core/components/theme/theme.h"
@ -26,6 +27,9 @@
#include "core/pipeline/pipeline_base.h"
namespace OHOS::Ace {
namespace {
constexpr double QRCODE_SIZE = 200.0;
} // namespace
class QrcodeTheme : public virtual Theme {
DECLARE_ACE_TYPE(QrcodeTheme, Theme);
@ -42,11 +46,7 @@ public:
if (!themeConstants) {
return theme;
}
auto pipeline = PipelineBase::GetCurrentContext();
CHECK_NULL_RETURN(pipeline, theme);
if (pipeline->GetMinPlatformVersion() > static_cast<int32_t>(PlatformVersion::VERSION_TEN)) {
ParsePattern(themeConstants->GetThemeStyle(), theme);
}
ParsePattern(themeConstants->GetThemeStyle(), theme);
return theme;
}
@ -59,8 +59,15 @@ public:
if (!pattern) {
return;
}
theme->qrcodeColor_ = pattern->GetAttr<Color>("qrcode_foreground_color", Color::RED);
theme->backgroundColor_ = pattern->GetAttr<Color>("qrcode_background_color", Color::RED);
if (Container::LessThanAPIVersion(PlatformVersion::VERSION_ELEVEN)) {
theme->qrcodeColor_ = Color(0xff000000);
theme->qrcodeType_ = QrcodeType::RECT;
theme->qrcodeWidth_ = Dimension(QRCODE_SIZE, DimensionUnit::PX);
theme->qrcodeHeight_ = Dimension(QRCODE_SIZE, DimensionUnit::PX);
return;
}
theme->qrcodeColor_ = pattern->GetAttr<Color>("qrcode_foreground_color", Color::RED);
theme->focusedColor_ = pattern->GetAttr<Color>("qrcode_focused_color", Color::RED);
theme->qrcodeType_ = QrcodeType(pattern->GetAttr<int>("qrcode_type", 0));
theme->qrcodeWidth_ = pattern->GetAttr<Dimension>("qrcode_size", 200.0_px);

View File

@ -313,17 +313,30 @@ void DatePickerDialogModelNG::SetDatePickerDialogShow(PickerDialogInfo& pickerDi
dialogCancelEvent["cancelId"] = func;
ButtonInfo buttonInfo;
DialogProperties properties;
if (SystemProperties::GetDeviceType() == DeviceType::PHONE) {
properties.alignment = DialogAlignment::BOTTOM;
} else {
properties.alignment = DialogAlignment::CENTER;
if (Container::LessThanAPIVersion(PlatformVersion::VERSION_ELEVEN)) {
if (SystemProperties::GetDeviceType() == DeviceType::PHONE) {
properties.alignment = DialogAlignment::BOTTOM;
} else {
properties.alignment = DialogAlignment::CENTER;
}
}
if (pickerDialog.alignment.has_value()) {
properties.alignment = pickerDialog.alignment.value();
}
properties.customStyle = false;
properties.offset = DimensionOffset(Offset(0, -theme->GetMarginBottom().ConvertToPx()));
if (Container::LessThanAPIVersion(PlatformVersion::VERSION_ELEVEN)) {
properties.offset = DimensionOffset(Offset(0, -theme->GetMarginBottom().ConvertToPx()));
} else {
if (properties.alignment == DialogAlignment::DEFAULT) {
if (SystemProperties::GetDeviceType() == DeviceType::PHONE) {
properties.alignment = DialogAlignment::BOTTOM;
properties.offset = DimensionOffset(Offset(0, -theme->GetMarginBottom().ConvertToPx()));
} else {
properties.alignment = DialogAlignment::CENTER;
}
}
}
if (pickerDialog.offset.has_value()) {
properties.offset = pickerDialog.offset.value();
}

View File

@ -4556,16 +4556,21 @@ std::string RichEditorPattern::GetPositionSpansText(int32_t position, int32_t& s
}
void RichEditorPattern::CheckHandles(SelectHandleInfo& handleInfo)
{
handleInfo.isShow = CheckHandleVisible(handleInfo.paintRect);
}
bool RichEditorPattern::CheckHandleVisible(const RectF& paintRect)
{
auto host = GetHost();
CHECK_NULL_VOID(host);
auto pipeline = PipelineContext::GetCurrentContext();
CHECK_NULL_VOID(pipeline);
auto offset = host->GetPaintRectOffset() + contentRect_.GetOffset() - pipeline->GetRootRect().GetOffset();
RectF contentGlobalRect(offset, contentRect_.GetSize());
contentGlobalRect = GetVisibleContentRect(host->GetAncestorNodeOfFrame(), contentGlobalRect);
auto handleOffset = handleInfo.paintRect.GetOffset();
handleInfo.isShow = contentGlobalRect.IsInRegion(PointF(handleOffset.GetX(), handleOffset.GetY() + BOX_EPSILON));
CHECK_NULL_RETURN(host, false);
// use global offset.
RectF visibleContentRect(contentRect_.GetOffset() + parentGlobalOffset_, contentRect_.GetSize());
auto parent = host->GetAncestorNodeOfFrame();
visibleContentRect = GetVisibleContentRect(parent, visibleContentRect);
PointF bottomPoint = { paintRect.Left(), paintRect.Bottom() - BOX_EPSILON };
PointF topPoint = { paintRect.Left(), paintRect.Top() + BOX_EPSILON };
return visibleContentRect.IsInRegion(bottomPoint) && visibleContentRect.IsInRegion(topPoint);
}
bool RichEditorPattern::IsShowSelectMenuUsingMouse()

View File

@ -325,6 +325,8 @@ public:
void CheckHandles(SelectHandleInfo& handleInfo) override;
bool CheckHandleVisible(const RectF& paintRect) override;
bool IsShowSelectMenuUsingMouse();
private:

View File

@ -126,5 +126,72 @@ void RectModelNG::SetShapeRectRadius(
}
}
void RectModelNG::SetRadiusValue(
FrameNode* frameNode, const Dimension& radiusX, const Dimension& radiusY, int32_t index)
{
NG::Radius radius = NG::Radius(radiusX, radiusY);
switch (index) {
case TOP_LEFT_RADIUS:
RectModelNG::SetTopLeftRadius(frameNode, radius);
break;
case TOP_RIGHT_RADIUS:
RectModelNG::SetTopRightRadius(frameNode, radius);
break;
case BOTTOM_RIGHT_RADIUS:
RectModelNG::SetBottomRightRadius(frameNode, radius);
break;
case BOTTOM_LEFT_RADIUS:
RectModelNG::SetBottomLeftRadius(frameNode, radius);
break;
}
}
void RectModelNG::SetTopLeftRadius(FrameNode* frameNode, const Radius& topLeftRadius)
{
ACE_UPDATE_NODE_PAINT_PROPERTY(RectPaintProperty, TopLeftRadius, topLeftRadius, frameNode);
}
void RectModelNG::SetTopRightRadius(FrameNode* frameNode, const Radius& topRightRadius)
{
ACE_UPDATE_NODE_PAINT_PROPERTY(RectPaintProperty, TopRightRadius, topRightRadius, frameNode);
}
void RectModelNG::SetBottomLeftRadius(FrameNode* frameNode, const Radius& bottomLeftRadius)
{
ACE_UPDATE_NODE_PAINT_PROPERTY(RectPaintProperty, BottomLeftRadius, bottomLeftRadius, frameNode);
}
void RectModelNG::SetBottomRightRadius(FrameNode* frameNode, const Radius& bottomRightRadius)
{
ACE_UPDATE_NODE_PAINT_PROPERTY(RectPaintProperty, BottomRightRadius, bottomRightRadius, frameNode);
}
void RectModelNG::SetRadiusWidth(FrameNode* frameNode, const Dimension& value)
{
Radius radius;
value.IsNegative() ? radius.SetX(Dimension(DEFAULT_RADIUS_VALUE)) : radius.SetX(value);
radius.SetY(DEFAULT_RADIUS_INVALID);
RectModelNG::UpdateRadius(frameNode, radius);
}
void RectModelNG::SetRadiusHeight(FrameNode* frameNode, const Dimension& value)
{
Radius radius;
value.IsNegative() ? radius.SetY(Dimension(DEFAULT_RADIUS_VALUE)) : radius.SetY(value);
radius.SetX(DEFAULT_RADIUS_INVALID);
RectModelNG::UpdateRadius(frameNode, radius);
}
void RectModelNG::UpdateRadius(FrameNode* frameNode, const Radius& radius)
{
CHECK_NULL_VOID(frameNode);
auto castRectPaintProperty = frameNode->GetPaintProperty<RectPaintProperty>();
if (castRectPaintProperty) {
castRectPaintProperty->UpdateTopLeftRadius(radius);
castRectPaintProperty->UpdateTopRightRadius(radius);
castRectPaintProperty->UpdateBottomLeftRadius(radius);
castRectPaintProperty->UpdateBottomRightRadius(radius);
}
}
} // namespace OHOS::Ace::NG
#endif // FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_PATTERNS_SHAPE_RECT_MODEL_NG_CPP

View File

@ -31,6 +31,9 @@ public:
void SetShapeRectRadius(
const RefPtr<ShapeRect>& shapeRect, const Dimension& radiusX, const Dimension& radiusY, int32_t index) override;
static void SetRadiusWidth(FrameNode* frameNode, const Dimension& value);
static void SetRadiusHeight(FrameNode* frameNode, const Dimension& value);
static void SetRadiusValue(FrameNode* frameNode, const Dimension& radiusX, const Dimension& radiusY, int32_t index);
private:
static void SetTopLeftRadius(const Radius& topLeftRadius);
@ -38,6 +41,11 @@ private:
static void SetBottomRightRadius(const Radius& bottomRightRadius);
static void SetBottomLeftRadius(const Radius& bottomLeftRadius);
static void UpdateRadius(const Radius& radius);
static void SetTopLeftRadius(FrameNode* frameNode, const Radius& topLeftRadius);
static void SetTopRightRadius(FrameNode* frameNode, const Radius& topRightRadius);
static void SetBottomRightRadius(FrameNode* frameNode, const Radius& bottomRightRadius);
static void SetBottomLeftRadius(FrameNode* frameNode, const Radius& bottomLeftRadius);
static void UpdateRadius(FrameNode* frameNode, const Radius& radius);
};
} // namespace OHOS::Ace::NG

View File

@ -22,6 +22,8 @@
#include "core/components_v2/inspector/inspector_constants.h"
namespace OHOS::Ace::NG {
constexpr double FILL_OPACITY_MIN = 0.0f;
constexpr double FILL_OPACITY_MAX = 1.0f;
void ShapeModelNG::Create()
{
@ -104,4 +106,76 @@ void ShapeModelNG::SetAntiAlias(bool antiAlias)
ShapeAbstractModelNG().SetAntiAlias(antiAlias);
}
void ShapeModelNG::SetStrokeDashArray(FrameNode* frameNode, const std::vector<Ace::Dimension>& segments)
{
ACE_UPDATE_NODE_PAINT_PROPERTY(ShapePaintProperty, StrokeDashArray, segments, frameNode);
}
void ShapeModelNG::SetStroke(FrameNode* frameNode, const Color& color)
{
ACE_UPDATE_NODE_PAINT_PROPERTY(ShapePaintProperty, Stroke, color, frameNode);
}
void ShapeModelNG::SetFill(FrameNode* frameNode, const Color& color)
{
ACE_UPDATE_NODE_PAINT_PROPERTY(ShapePaintProperty, Fill, color, frameNode);
}
void ShapeModelNG::SetStrokeDashOffset(FrameNode* frameNode, const Ace::Dimension& dashOffset)
{
ACE_UPDATE_NODE_PAINT_PROPERTY(ShapePaintProperty, StrokeDashOffset, dashOffset, frameNode);
}
void ShapeModelNG::SetStrokeLineCap(FrameNode* frameNode, int lineCapStyle)
{
ACE_UPDATE_NODE_PAINT_PROPERTY(ShapePaintProperty, StrokeLineCap, lineCapStyle, frameNode);
}
void ShapeModelNG::SetStrokeLineJoin(FrameNode* frameNode, int lineJoinStyle)
{
ACE_UPDATE_NODE_PAINT_PROPERTY(ShapePaintProperty, StrokeLineJoin, lineJoinStyle, frameNode);
}
void ShapeModelNG::SetStrokeMiterLimit(FrameNode* frameNode, double miterLimit)
{
ACE_UPDATE_NODE_PAINT_PROPERTY(ShapePaintProperty, StrokeMiterLimit, miterLimit, frameNode);
}
void ShapeModelNG::SetFillOpacity(FrameNode* frameNode, double fillOpacity)
{
ACE_UPDATE_NODE_PAINT_PROPERTY(
ShapePaintProperty, FillOpacity, std::clamp(fillOpacity, FILL_OPACITY_MIN, FILL_OPACITY_MAX), frameNode);
}
void ShapeModelNG::SetStrokeOpacity(FrameNode* frameNode, double strokeOpacity)
{
ACE_UPDATE_NODE_PAINT_PROPERTY(ShapePaintProperty, StrokeOpacity, strokeOpacity, frameNode);
}
void ShapeModelNG::SetStrokeWidth(FrameNode* frameNode, const Ace::Dimension& strokeWidth)
{
ACE_UPDATE_NODE_PAINT_PROPERTY(ShapePaintProperty, StrokeWidth, strokeWidth, frameNode);
}
void ShapeModelNG::SetAntiAlias(FrameNode* frameNode, bool antiAlias)
{
ACE_UPDATE_NODE_PAINT_PROPERTY(ShapePaintProperty, AntiAlias, antiAlias, frameNode);
}
void ShapeModelNG::SetViewPort(FrameNode* frameNode, const Dimension& dimLeft, const Dimension& dimTop,
const Dimension& dimWidth, const Dimension& dimHeight)
{
ShapeViewBox shapeViewBox;
shapeViewBox.SetLeft(dimLeft);
shapeViewBox.SetTop(dimTop);
shapeViewBox.SetWidth(dimWidth);
shapeViewBox.SetHeight(dimHeight);
ACE_UPDATE_NODE_PAINT_PROPERTY(ShapeContainerPaintProperty, ShapeViewBox, shapeViewBox, frameNode);
}
void ShapeModelNG::SetBitmapMesh(FrameNode* frameNode, std::vector<double>& mesh, int32_t column, int32_t row)
{
ACE_UPDATE_NODE_PAINT_PROPERTY(
ShapeContainerPaintProperty, ImageMesh, ImageMesh(mesh, (int32_t)column, (int32_t)row), frameNode);
}
} // namespace OHOS::Ace::NG

View File

@ -18,6 +18,7 @@
#include "base/geometry/dimension.h"
#include "base/utils/macros.h"
#include "core/components_ng/base/frame_node.h"
#include "core/components_ng/pattern/shape/shape_model.h"
namespace OHOS::Ace::NG {
@ -42,6 +43,20 @@ public:
void SetAntiAlias(bool antiAlias) override;
void SetWidth() override {}
void SetHeight() override {}
static void SetStrokeDashArray(FrameNode* frameNode, const std::vector<Ace::Dimension>& segments);
static void SetStrokeMiterLimit(FrameNode* frameNode, double miterLimit);
static void SetFillOpacity(FrameNode* frameNode, double fillOpacity);
static void SetStrokeOpacity(FrameNode* frameNode, double strokeOpacity);
static void SetStrokeWidth(FrameNode* frameNode, const Ace::Dimension& strokeWidth);
static void SetAntiAlias(FrameNode* frameNode, bool antiAlias);
static void SetStroke(FrameNode* frameNode, const Color& color);
static void SetFill(FrameNode* frameNode, const Color& color);
static void SetStrokeDashOffset(FrameNode* frameNode, const Ace::Dimension& dashOffset);
static void SetStrokeLineCap(FrameNode* frameNode, int lineCapStyle);
static void SetStrokeLineJoin(FrameNode* frameNode, int lineJoinStyle);
static void SetViewPort(FrameNode* frameNode, const Dimension& dimLeft, const Dimension& dimTop,
const Dimension& dimWidth, const Dimension& dimHeight);
static void SetBitmapMesh(FrameNode* frameNode, std::vector<double>& mesh, int32_t column, int32_t row);
};
} // namespace OHOS::Ace::NG

View File

@ -121,13 +121,6 @@ void TabBarPattern::InitScrollable(const RefPtr<GestureEventHub>& gestureHub)
if (!pattern) {
return false;
}
if (pattern->controller_ && pattern->controller_->IsRunning()) {
auto scrollable = pattern->scrollableEvent_->GetScrollable();
if (scrollable) {
scrollable->StopScrollable();
}
return true;
}
if (pattern->tabBarStyle_ == TabBarStyle::SUBTABBATSTYLE && pattern->axis_ == Axis::HORIZONTAL &&
pattern->IsOutOfBoundary()) {
// over scroll in drag update from normal to over scroll.
@ -449,7 +442,6 @@ void TabBarPattern::GetInnerFocusPaintRect(RoundRect& paintRect)
} else {
indicator = focusIndicator_;
}
AdjustFocusPosition();
}
auto childNode = AceType::DynamicCast<FrameNode>(host->GetChildAtIndex(indicator));
CHECK_NULL_VOID(childNode);
@ -1322,57 +1314,79 @@ bool TabBarPattern::IsContainsBuilder()
void TabBarPattern::PlayTranslateAnimation(float startPos, float endPos, float targetCurrentOffset)
{
auto curve = DurationCubicCurve;
isAnimating_ = true;
// If animation is still running, stop it before play new animation.
StopTranslateAnimation();
SetSwiperCurve(curve);
auto translate = AceType::MakeRefPtr<CurveAnimation<double>>(startPos, endPos, curve);
auto weak = AceType::WeakClaim(this);
translate->AddListener(Animation<double>::ValueCallback([weak, startPos, endPos](double value) {
auto tabBarPattern = weak.Upgrade();
CHECK_NULL_VOID(tabBarPattern);
tabBarPattern->UpdateIndicatorCurrentOffset(static_cast<float>(value - tabBarPattern->currentIndicatorOffset_));
}));
auto startCurrentOffset = currentOffset_;
auto tabBarTranslate = AceType::MakeRefPtr<CurveAnimation<double>>(startCurrentOffset, targetCurrentOffset, curve);
tabBarTranslate->AddListener(
Animation<double>::ValueCallback([weak, startCurrentOffset, targetCurrentOffset](double value) {
auto tabBarPattern = weak.Upgrade();
CHECK_NULL_VOID(tabBarPattern);
tabBarPattern->currentOffset_ = value;
auto host = tabBarPattern->GetHost();
host->MarkDirtyNode(PROPERTY_UPDATE_LAYOUT);
}));
if (!controller_) {
auto pipeline = PipelineBase::GetCurrentContext();
CHECK_NULL_VOID(pipeline);
controller_ = CREATE_ANIMATOR(pipeline);
}
controller_->ClearStopListeners();
controller_->ClearInterpolators();
auto pipelineContext = PipelineContext::GetCurrentContext();
CHECK_NULL_VOID(pipelineContext);
auto tabTheme = pipelineContext->GetTheme<TabTheme>();
CHECK_NULL_VOID(tabTheme);
controller_->SetDuration(
static_cast<int32_t>(animationDuration_.value_or(tabTheme->GetTabContentAnimationDuration())));
controller_->AddInterpolator(translate);
controller_->AddInterpolator(tabBarTranslate);
controller_->Play();
AnimationOption option = AnimationOption();
option.SetDuration(static_cast<int32_t>(animationDuration_.value_or(tabTheme->GetTabContentAnimationDuration())));
option.SetCurve(curve);
option.SetFillMode(FillMode::FORWARDS);
auto weak = AceType::WeakClaim(this);
const auto& pattern = weak.Upgrade();
auto host = pattern->GetHost();
host->CreateAnimatablePropertyFloat("tabbarindicator", 0, [weak](float value) {
auto tabBarPattern = weak.Upgrade();
CHECK_NULL_VOID(tabBarPattern);
tabBarPattern->UpdateIndicatorCurrentOffset(static_cast<float>(value - tabBarPattern->currentIndicatorOffset_));
});
host->UpdateAnimatablePropertyFloat("tabbarindicator", startPos);
auto delta = endPos;
indicatorAnimationIsRunning_ = true;
tabbarIndicatorAnimation_ = AnimationUtils::StartAnimation(option,
[host, delta]() {
host->UpdateAnimatablePropertyFloat("tabbarindicator", delta);
},
[weak]() {
auto tabBarPattern = weak.Upgrade();
CHECK_NULL_VOID(tabBarPattern);
tabBarPattern->indicatorAnimationIsRunning_ = false;
});
auto startCurrentOffset = currentOffset_;
host->CreateAnimatablePropertyFloat("tabbar", 0, [weak](float value) {
auto tabBarPattern = weak.Upgrade();
CHECK_NULL_VOID(tabBarPattern);
tabBarPattern->currentOffset_ = value;
auto host = tabBarPattern->GetHost();
host->MarkDirtyNode(PROPERTY_UPDATE_LAYOUT);
});
host->UpdateAnimatablePropertyFloat("tabbar", startCurrentOffset);
delta = targetCurrentOffset;
translateAnimationIsRunning_ = true;
translateAnimation_ = AnimationUtils::StartAnimation(option,
[host, delta]() {
host->UpdateAnimatablePropertyFloat("tabbar", delta);
},
[weak]() {
auto tabBarPattern = weak.Upgrade();
CHECK_NULL_VOID(tabBarPattern);
tabBarPattern->translateAnimationIsRunning_ = false;
});
}
void TabBarPattern::StopTranslateAnimation()
{
if (controller_ && !controller_->IsStopped()) {
controller_->Stop();
}
if (translateAnimation_)
AnimationUtils::StopAnimation(translateAnimation_);
if (tabbarIndicatorAnimation_)
AnimationUtils::StopAnimation(tabbarIndicatorAnimation_);
if (indicatorAnimationIsRunning_)
indicatorAnimationIsRunning_ = false;
if (translateAnimationIsRunning_)
translateAnimationIsRunning_ = false;
}
void TabBarPattern::PlayTabBarTranslateAnimation(int32_t targetIndex)
{
StopTabBarTranslateAnimation();
auto host = GetHost();
CHECK_NULL_VOID(host);
if (host->GetGeometryNode()->GetPaddingSize().Width() >= childrenMainSize_) {
@ -1387,49 +1401,45 @@ void TabBarPattern::PlayTabBarTranslateAnimation(int32_t targetIndex)
? host->GetGeometryNode()->GetPaddingSize().Width() - childrenMainSize_
: space - frontChildrenMainSize;
auto startOffset = currentOffset_;
auto curve = DurationCubicCurve;
// If animation is still running, stop it before play new animation.
StopTabBarTranslateAnimation();
auto weak = AceType::WeakClaim(this);
auto tabBarTranslate = AceType::MakeRefPtr<CurveAnimation<double>>(startOffset, targetOffset, curve);
tabBarTranslate->AddListener(Animation<double>::ValueCallback([weak, startOffset, targetOffset](double value) {
auto tabBarPattern = weak.Upgrade();
CHECK_NULL_VOID(tabBarPattern);
if (!NearEqual(value, startOffset) && !NearEqual(value, targetOffset) &&
!NearEqual(startOffset, targetOffset)) {
float moveRate = Curves::EASE_OUT->MoveInternal(
static_cast<float>((value - startOffset) / (targetOffset - startOffset)));
value = startOffset + (targetOffset - startOffset) * moveRate;
}
tabBarPattern->currentOffset_ = value;
auto host = tabBarPattern->GetHost();
host->MarkDirtyNode(PROPERTY_UPDATE_LAYOUT);
}));
if (!controller_) {
auto pipeline = PipelineBase::GetCurrentContext();
CHECK_NULL_VOID(pipeline);
controller_ = CREATE_ANIMATOR(pipeline);
}
controller_->ClearStopListeners();
controller_->ClearInterpolators();
auto pipelineContext = PipelineContext::GetCurrentContext();
CHECK_NULL_VOID(pipelineContext);
auto tabTheme = pipelineContext->GetTheme<TabTheme>();
CHECK_NULL_VOID(tabTheme);
controller_->SetDuration(
static_cast<int32_t>(animationDuration_.value_or(tabTheme->GetTabContentAnimationDuration())));
controller_->AddInterpolator(tabBarTranslate);
controller_->Play();
auto curve = DurationCubicCurve;
AnimationOption option = AnimationOption();
option.SetDuration(static_cast<int32_t>(animationDuration_.value_or(tabTheme->GetTabContentAnimationDuration())));
option.SetCurve(curve);
auto weak = AceType::WeakClaim(this);
host->CreateAnimatablePropertyFloat("tabbar", 0, [weak, startOffset, targetOffset](float value) {
auto tabBarPattern = weak.Upgrade();
CHECK_NULL_VOID(tabBarPattern);
tabBarPattern->currentOffset_ = value;
auto host = tabBarPattern->GetHost();
host->MarkDirtyNode(PROPERTY_UPDATE_LAYOUT);
});
host->UpdateAnimatablePropertyFloat("tabbar", startOffset);
auto delta = targetOffset;
tabBarTranslateAnimationIsRunning_ = true;
tabBarTranslateAnimation_ = AnimationUtils::StartAnimation(option,
[host, delta]() {
host->UpdateAnimatablePropertyFloat("tabbar", delta);
},
[weak]() {
auto tabBarPattern = weak.Upgrade();
CHECK_NULL_VOID(tabBarPattern);
tabBarPattern->tabBarTranslateAnimationIsRunning_ = false;
});
}
void TabBarPattern::StopTabBarTranslateAnimation()
{
if (tabBarTranslateController_ && !tabBarTranslateController_->IsStopped()) {
tabBarTranslateController_->Stop();
}
if (tabBarTranslateAnimation_)
AnimationUtils::StopAnimation(tabBarTranslateAnimation_);
if (tabBarTranslateAnimationIsRunning_)
tabBarTranslateAnimationIsRunning_ = false;
}
void TabBarPattern::UpdateIndicatorCurrentOffset(float offset)
@ -1677,7 +1687,6 @@ void TabBarPattern::SetAccessibilityAction()
if (tabBarLayoutProperty->GetTabBarMode().value_or(TabBarMode::FIXED) == TabBarMode::SCROLLABLE &&
frameNode->TotalChildCount() - MASK_COUNT > 1) {
auto index = pattern->GetIndicator() + 1;
pattern->PlayTabBarTranslateAnimation(index);
pattern->FocusIndexChange(index);
frameNode->OnAccessibilityEvent(AccessibilityEventType::SCROLL_END);
}
@ -1693,7 +1702,6 @@ void TabBarPattern::SetAccessibilityAction()
if (tabBarLayoutProperty->GetTabBarMode().value_or(TabBarMode::FIXED) == TabBarMode::SCROLLABLE &&
frameNode->TotalChildCount() - MASK_COUNT > 1) {
auto index = pattern->GetIndicator() - 1;
pattern->PlayTabBarTranslateAnimation(index);
pattern->FocusIndexChange(index);
frameNode->OnAccessibilityEvent(AccessibilityEventType::SCROLL_END);
}

View File

@ -407,6 +407,14 @@ private:
std::unordered_map<int32_t, bool> tabBarType_;
std::optional<int32_t> animationDuration_;
std::shared_ptr<AnimationUtils::Animation> tabbarIndicatorAnimation_;
std::shared_ptr<AnimationUtils::Animation> translateAnimation_;
std::shared_ptr<AnimationUtils::Animation> tabBarTranslateAnimation_;
bool indicatorAnimationIsRunning_ = false;
bool translateAnimationIsRunning_ = false;
bool tabBarTranslateAnimationIsRunning_ = false;
bool isRTL_ = false; // TODO Adapt RTL.
bool touching_ = false; // whether the item is in touching
@ -415,8 +423,6 @@ private:
std::optional<int32_t> touchingIndex_;
std::optional<int32_t> hoverIndex_;
TabBarStyle tabBarStyle_;
RefPtr<Animator> controller_;
RefPtr<Animator> tabBarTranslateController_;
float currentIndicatorOffset_ = 0.0f;
std::vector<SelectedMode> selectedModes_;
std::vector<IndicatorStyle> indicatorStyles_;

View File

@ -39,16 +39,29 @@ const int32_t BUFFER_NODE_NUMBER = 2;
void SetDialogProperties(DialogProperties& properties, TextPickerDialog& textPickerDialog,
const RefPtr<DialogTheme>& theme)
{
if (SystemProperties::GetDeviceType() == DeviceType::PHONE) {
properties.alignment = DialogAlignment::BOTTOM;
} else {
properties.alignment = DialogAlignment::CENTER;
if (Container::LessThanAPIVersion(PlatformVersion::VERSION_ELEVEN)) {
if (SystemProperties::GetDeviceType() == DeviceType::PHONE) {
properties.alignment = DialogAlignment::BOTTOM;
} else {
properties.alignment = DialogAlignment::CENTER;
}
}
if (textPickerDialog.alignment.has_value()) {
properties.alignment = textPickerDialog.alignment.value();
}
properties.customStyle = false;
properties.offset = DimensionOffset(Offset(0, -theme->GetMarginBottom().ConvertToPx()));
if (Container::LessThanAPIVersion(PlatformVersion::VERSION_ELEVEN)) {
properties.offset = DimensionOffset(Offset(0, -theme->GetMarginBottom().ConvertToPx()));
} else {
if (properties.alignment == DialogAlignment::DEFAULT) {
if (SystemProperties::GetDeviceType() == DeviceType::PHONE) {
properties.alignment = DialogAlignment::BOTTOM;
properties.offset = DimensionOffset(Offset(0, -theme->GetMarginBottom().ConvertToPx()));
} else {
properties.alignment = DialogAlignment::CENTER;
}
}
}
if (textPickerDialog.offset.has_value()) {
properties.offset = textPickerDialog.offset.value();
}

View File

@ -255,16 +255,29 @@ void TimePickerDialogModelNG::SetTimePickerDialogShow(PickerDialogInfo& pickerDi
};
dialogCancelEvent["cancelId"] = func;
DialogProperties properties;
if (SystemProperties::GetDeviceType() == DeviceType::PHONE) {
properties.alignment = DialogAlignment::BOTTOM;
} else {
properties.alignment = DialogAlignment::CENTER;
if (Container::LessThanAPIVersion(PlatformVersion::VERSION_ELEVEN)) {
if (SystemProperties::GetDeviceType() == DeviceType::PHONE) {
properties.alignment = DialogAlignment::BOTTOM;
} else {
properties.alignment = DialogAlignment::CENTER;
}
}
if (pickerDialog.alignment.has_value()) {
properties.alignment = pickerDialog.alignment.value();
}
properties.customStyle = false;
properties.offset = DimensionOffset(Offset(0, -theme->GetMarginBottom().ConvertToPx()));
if (Container::LessThanAPIVersion(PlatformVersion::VERSION_ELEVEN)) {
properties.offset = DimensionOffset(Offset(0, -theme->GetMarginBottom().ConvertToPx()));
} else {
if (properties.alignment == DialogAlignment::DEFAULT) {
if (SystemProperties::GetDeviceType() == DeviceType::PHONE) {
properties.alignment = DialogAlignment::BOTTOM;
properties.offset = DimensionOffset(Offset(0, -theme->GetMarginBottom().ConvertToPx()));
} else {
properties.alignment = DialogAlignment::CENTER;
}
}
}
if (pickerDialog.offset.has_value()) {
properties.offset = pickerDialog.offset.value();
}

View File

@ -1638,8 +1638,12 @@ void WebPattern::OfflineMode()
Size drawSize = Size(width, height);
Offset offset = Offset(0, 0);
delegate_->SetBoundsOrResize(drawSize, offset);
if (webSrc_) {
delegate_->LoadUrl();
} else if (webData_) {
delegate_->LoadDataWithRichText();
}
isUrlLoaded_ = true;
delegate_->LoadUrl();
OnWindowHide();
}

View File

@ -315,9 +315,9 @@ std::shared_ptr<RSData> FileImageLoader::LoadImageData(
auto result = SkData::MakeFromFileName(realPath);
if (!result) {
TAG_LOGW(AceLogTag::ACE_IMAGE,
"read data failed, filePath: %{public}s, src: %{public}s, skData size: %{public}zu, fail reason: "
"read data failed, filePath: %{public}s, src: %{public}s, fail reason: "
"%{public}s",
filePath.c_str(), src.c_str(), result->size(), strerror(errno));
filePath.c_str(), src.c_str(), strerror(errno));
}
#ifndef USE_ROSEN_DRAWING
#ifdef PREVIEW

View File

@ -5054,8 +5054,6 @@ HWTEST_F(TabsTestNg, TabBarPatternStopTabBarTranslateAnimation001, TestSize.Leve
tabBarNode->GetLayoutProperty<TabBarLayoutProperty>()->UpdateTabBarMode(TabBarMode::SCROLLABLE);
auto tabBarPattern = tabBarNode->GetPattern<TabBarPattern>();
ASSERT_NE(tabBarPattern, nullptr);
tabBarPattern->tabBarTranslateController_ = AceType::MakeRefPtr<Animator>();
tabBarPattern->tabBarTranslateController_->status_ = Animator::Status::RUNNING;
/**
* @tc.steps: step2. Test function StopTabBarTranslateAnimation.
@ -5063,8 +5061,8 @@ HWTEST_F(TabsTestNg, TabBarPatternStopTabBarTranslateAnimation001, TestSize.Leve
*/
for (int i = 0; i <= 1; i++) {
tabBarPattern->StopTabBarTranslateAnimation();
tabBarPattern->tabBarTranslateController_->status_ = Animator::Status::STOPPED;
}
EXPECT_FALSE(tabBarPattern->tabBarTranslateAnimation_);
}
/**
@ -5831,53 +5829,11 @@ HWTEST_F(TabsTestNg, TabBarPatternPlayTranslateAnimation001, TestSize.Level1)
float startPos = 0.1f;
float endPos = 0.2f;
float targetCurrentOffset = 0.3f;
double value = 0;
auto offset = 0.1f;
for (int i = 0; i <= 1; i++) {
for (int j = 0; j <= 1; j++) {
for (int k = 0; k <= 1; k++) {
tabBarPattern->currentOffset_ = offset;
tabBarPattern->PlayTranslateAnimation(startPos, endPos, targetCurrentOffset);
ASSERT_NE(tabBarPattern->controller_, nullptr);
auto interpolator = tabBarPattern->controller_->interpolators_.front();
ASSERT_NE(interpolator, nullptr);
auto* translate = static_cast<CurveAnimation<double>*>(AceType::RawPtr(interpolator));
ASSERT_NE(translate, nullptr);
Animation<double>::ValueCallback valueCallback = translate->callbacks_.begin()->second;
valueCallback.callback_(value);
tabBarPattern->controller_->ClearInterpolators();
value = 0;
startPos = 0.0f;
endPos = 0.0f;
}
endPos = 0.1f;
}
endPos = 0.0f;
startPos = 0.1f;
}
for (int i = 0; i <= 1; i++) {
for (int j = 0; j <= 1; j++) {
for (int k = 0; k <= 1; k++) {
tabBarPattern->currentOffset_ = offset;
tabBarPattern->PlayTranslateAnimation(startPos, endPos, targetCurrentOffset);
ASSERT_NE(tabBarPattern->controller_, nullptr);
auto interpolator = tabBarPattern->controller_->interpolators_.back();
ASSERT_NE(interpolator, nullptr);
auto* tabBarTranslate = static_cast<CurveAnimation<double>*>(AceType::RawPtr(interpolator));
ASSERT_NE(tabBarTranslate, nullptr);
Animation<double>::ValueCallback valueCallback = tabBarTranslate->callbacks_.begin()->second;
valueCallback.callback_(value);
tabBarPattern->controller_->ClearInterpolators();
value = 0;
offset = 0.0f;
targetCurrentOffset = 0.0f;
}
offset = 0.1f;
}
offset = 0.0f;
targetCurrentOffset = 0.1f;
}
tabBarPattern->currentOffset_ = offset;
tabBarPattern->PlayTranslateAnimation(startPos, endPos, targetCurrentOffset);
EXPECT_FALSE(tabBarPattern->indicatorAnimationIsRunning_);
EXPECT_FALSE(tabBarPattern->translateAnimationIsRunning_);
}
/**
@ -5960,47 +5916,9 @@ HWTEST_F(TabsTestNg, TabBarPatternPlayTabBarTranslateAnimation001, TestSize.Leve
* @tc.steps: step2. Test function PlayTabBarTranslateAnimation.
* @tc.expected: Related function runs ok.
*/
for (int i = 0; i <= 1; i++) {
for (int j = 0; j <= 1; j++) {
for (int k = 0; k <= 1; k++) {
tabBarPattern->PlayTabBarTranslateAnimation(targetIndex);
tabBarPattern->childrenMainSize_ = 2.0f;
}
AceType::DynamicCast<FrameNode>(tabBarNode->GetChildAtIndex(targetIndex - 1))
->GetGeometryNode()
->SetFrameSize(SizeF(2.0f, 2.0f));
}
AceType::DynamicCast<FrameNode>(tabBarNode->GetChildAtIndex(targetIndex + 1))
->GetGeometryNode()
->SetFrameSize(SizeF(2.0f, 2.0f));
}
double value = 0.0;
float offset = 0.0f;
AceType::DynamicCast<FrameNode>(tabBarNode->GetChildAtIndex(targetIndex - 1))
->GetGeometryNode()
->SetFrameSize(SizeF(0.0f, 0.0f));
for (int i = 0; i <= 1; i++) {
for (int j = 0; j <= 1; j++) {
for (int k = 0; k <= 1; k++) {
tabBarPattern->currentOffset_ = offset;
tabBarPattern->PlayTabBarTranslateAnimation(targetIndex);
ASSERT_NE(tabBarPattern->controller_, nullptr);
auto interpolator = tabBarPattern->controller_->interpolators_.front();
ASSERT_NE(interpolator, nullptr);
auto* tabBarTranslate = static_cast<CurveAnimation<double>*>(AceType::RawPtr(interpolator));
ASSERT_NE(tabBarTranslate, nullptr);
Animation<double>::ValueCallback valueCallback = tabBarTranslate->callbacks_.begin()->second;
valueCallback.callback_(value);
tabBarPattern->controller_->ClearInterpolators();
value = 1.0;
offset = 2.0f;
}
offset = 0.0f;
}
offset = 2.0f;
value = 0.0;
}
tabBarPattern->PlayTabBarTranslateAnimation(targetIndex);
EXPECT_FALSE(tabBarPattern->tabBarTranslateAnimationIsRunning_);
}
void FocusTest(const RefPtr<TabBarLayoutProperty>& tabBarLayoutProperty, const RefPtr<TabBarPattern>& tabBarPattern)
@ -9050,12 +8968,9 @@ HWTEST_F(TabsTestNg, TabBarPatternInitScrollable005, TestSize.Level1)
ASSERT_NE(tabBarPattern->scrollableEvent_, nullptr);
auto scrollable = tabBarPattern->scrollableEvent_->GetScrollable();
scrollable->callback_(0.1, SCROLL_FROM_NONE);
tabBarPattern->controller_ = AceType::MakeRefPtr<Animator>();
scrollable->callback_(0.1, SCROLL_FROM_NONE);
ASSERT_NE(tabBarPattern->scrollableEvent_, nullptr);
tabBarPattern->controller_->status_ = Animator::Status::RUNNING;
scrollable->callback_(0.1, SCROLL_FROM_NONE);
EXPECT_EQ(tabBarPattern->controller_->IsRunning(), true);
tabBarPattern->scrollableEvent_->scrollable_ = nullptr;
scrollable->callback_(0.1, SCROLL_FROM_NONE);
EXPECT_EQ(tabBarPattern->scrollableEvent_->scrollable_, nullptr);