线性导航条modifer功能

Signed-off-by: 张全超 <zhangquanchao@huawei.com>
This commit is contained in:
张全超 2024-08-06 20:45:00 +08:00
parent 8d772c3fac
commit b100933b73
19 changed files with 723 additions and 6 deletions

View File

@ -507,6 +507,7 @@ frameworks/bridge/declarative_frontend/ark_component/src/ArkImageAnimator.ts @ar
frameworks/bridge/declarative_frontend/ark_component/src/ArkImageSpan.ts @arkui_image
frameworks/bridge/declarative_frontend/ark_component/src/ArkImage.ts @arkui_image
frameworks/bridge/declarative_frontend/ark_component/src/ArkLine.ts @arkuilayout
frameworks/bridge/declarative_frontend/ark_component/src/ArkLinearIndicator.ts @arkuiscroll
frameworks/bridge/declarative_frontend/ark_component/src/ArkListItemGroup.ts @arkuiscroll
frameworks/bridge/declarative_frontend/ark_component/src/ArkListItem.ts @arkuiscroll
frameworks/bridge/declarative_frontend/ark_component/src/ArkList.ts @arkuiscroll
@ -599,6 +600,7 @@ frameworks/bridge/declarative_frontend/ark_modifier/src/image_modifier.ts @arkui
frameworks/bridge/declarative_frontend/ark_modifier/src/image_span_modifier.ts @huawei_g_five
frameworks/bridge/declarative_frontend/ark_modifier/src/import.ts @arkuievent
frameworks/bridge/declarative_frontend/ark_modifier/src/line_modifier.ts @arkuilayout
frameworks/bridge/declarative_frontend/ark_modifier/src/linear_indicator_modifier.ts @arkuiscroll
frameworks/bridge/declarative_frontend/ark_modifier/src/list_item_group_modifier.ts @arkuiscroll
frameworks/bridge/declarative_frontend/ark_modifier/src/list_item_modifier.ts @arkuiscroll
frameworks/bridge/declarative_frontend/ark_modifier/src/list_modifier.ts @arkuiscroll
@ -828,6 +830,8 @@ frameworks/bridge/declarative_frontend/engine/jsi/nativeModule/arkts_native_imag
frameworks/bridge/declarative_frontend/engine/jsi/nativeModule/arkts_native_image_span_bridge.h @huawei_g_five
frameworks/bridge/declarative_frontend/engine/jsi/nativeModule/arkts_native_line_bridge.cpp @arkuilayout
frameworks/bridge/declarative_frontend/engine/jsi/nativeModule/arkts_native_line_bridge.h @arkuilayout
frameworks/bridge/declarative_frontend/engine/jsi/nativeModule/arkts_native_linear_indicator.cpp @arkuiscroll
frameworks/bridge/declarative_frontend/engine/jsi/nativeModule/arkts_native_linear_indicator.h @arkuiscroll
frameworks/bridge/declarative_frontend/engine/jsi/nativeModule/arkts_native_list_bridge.cpp @arkuilayout
frameworks/bridge/declarative_frontend/engine/jsi/nativeModule/arkts_native_list_bridge.h @arkuilayout
frameworks/bridge/declarative_frontend/engine/jsi/nativeModule/arkts_native_list_item_bridge.cpp @arkuilayout
@ -2669,6 +2673,8 @@ frameworks/core/interfaces/native/node/image_animator_modifier.cpp @arkui_image
frameworks/core/interfaces/native/node/image_animator_modifier.h @arkui_image
frameworks/core/interfaces/native/node/line_modifier.cpp @arkuilayout
frameworks/core/interfaces/native/node/line_modifier.h @arkuilayout
frameworks/core/interfaces/native/node/linear_indicator_modifier.cpp @arkuiscroll
frameworks/core/interfaces/native/node/linear_indicator_modifier.h @arkuiscroll
frameworks/core/interfaces/native/node/marquee_modifier.cpp @huawei_g_five
frameworks/core/interfaces/native/node/marquee_modifier.h @huawei_g_five
frameworks/core/interfaces/native/node/menu_item_modifier.cpp @arkuipopupwindow

View File

@ -102,6 +102,7 @@ declare class ModifierJS {
SymbolSpanModifier(nativePtr: KNode, classType: ModifierType): void;
Component3DModifier(nativePtr: KNode, classType: ModifierType): void;
ContainerSpanModifier(nativePtr: KNode, classType: ModifierType): void;
LinearIndicatorModifier(nativePtr: KNode, classType: ModifierType): void;
}
declare class aceConsole {

View File

@ -0,0 +1,102 @@
/*
* Copyright (c) 2024 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/// <reference path='./import.ts' />
class LinearIndicatorIndicatorStyleModifier extends ModifierWithKey<LinearIndicatorStyle> {
constructor(value: LinearIndicatorStyle) {
super(value);
}
static identity = Symbol('linearIndicatorIndicatorStyle');
applyPeer(node: KNode, reset: boolean): void {
if (reset) {
getUINativeModule().linearIndicator.resetIndicatorStyle(node);
} else {
getUINativeModule().linearIndicator.setIndicatorStyle(node,
this.value.space, this.value.strokeWidth, this.value.strokeRadius
, this.value.trackBackgroundColor, this.value.trackColor);
}
}
checkObjectDiff(): boolean {
return
this.stageValue.space !== this.value.space
|| this.stageValue.strokeWidth !== this.value.strokeWidth
|| this.stageValue.strokeRadius !== this.value.strokeRadius
|| this.stageValue.trackBackgroundColor !== this.value.trackBackgroundColor
|| this.stageValue.trackColor !== this.value.trackColor
;
}
}
class LinearIndicatorIndicatorLoopModifier extends ModifierWithKey<boolean> {
constructor(value: boolean) {
super(value);
}
static identity = Symbol('linearIndicatorIndicatorLoop');
applyPeer(node: KNode, reset: boolean): void {
if (reset) {
getUINativeModule().linearIndicator.resetIndicatorLoop(node);
} else {
getUINativeModule().linearIndicator.setIndicatorLoop(node, this.value);
}
}
checkObjectDiff(): boolean {
return this.stageValue !== this.value;
}
}
class LinearIndicatorOnChangeModifier extends ModifierWithKey<OnLinearIndicatorChangeCallback> {
constructor(value: OnLinearIndicatorChangeCallback) {
super(value);
}
static identity = Symbol('linearIndicatorOnChange');
applyPeer(node: KNode, reset: boolean): void {
if (reset) {
getUINativeModule().linearIndicator.resetOnChange(node);
} else {
getUINativeModule().linearIndicator.setOnChange(node, this.value);
}
}
}
class ArkLinearIndicatorComponent extends ArkComponent implements CommonMethod<LinearIndicatorAttribute> {
constructor(nativePtr: KNode, classType?: ModifierType) {
super(nativePtr, classType);
}
indicatorStyle(value: LinearIndicatorStyle) {
modifierWithKey(this._modifiersWithKeys, LinearIndicatorIndicatorStyleModifier.identity, LinearIndicatorIndicatorStyleModifier, value);
return this;
}
indicatorLoop(value: boolean) {
modifierWithKey(this._modifiersWithKeys, LinearIndicatorIndicatorLoopModifier.identity, LinearIndicatorIndicatorLoopModifier, value);
return this;
}
onChange(value: OnLinearIndicatorChangeCallback) {
modifierWithKey(this._modifiersWithKeys, LinearIndicatorOnChangeModifier.identity, LinearIndicatorOnChangeModifier, value);
return this;
}
}
// @ts-ignore
globalThis.LinearIndicator.attributeModifier = function (modifier: ArkComponent): void {
attributeModifierFunc.call(this, modifier, (nativePtr: KNode) => {
return new ArkLinearIndicatorComponent(nativePtr);
}, (nativePtr: KNode, classType: ModifierType, modifierJS: ModifierJS) => {
return new modifierJS.LinearIndicatorModifier(nativePtr, classType);
});
};

View File

@ -99,7 +99,8 @@
"src/ArkSymbolGlyph.ts",
"src/ArkSymbolSpan.ts",
"src/ArkComponent3D.ts",
"src/ArkContainerSpan.ts"
"src/ArkContainerSpan.ts",
"src/ArkLinearIndicator.ts"
],
"compilerOptions": {
"module": "none",

View File

@ -0,0 +1,28 @@
/*
* Copyright (c) 2024 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/// <reference path='./import.ts' />
class LinearIndicatorModifier extends ArkLinearIndicatorComponent implements AttributeModifier<LinearIndicatorAttribute> {
constructor(nativePtr: KNode, classType: ModifierType) {
super(nativePtr, classType);
this._modifiersWithKeys = new ModifierMap();
}
applyNormalAttribute(instance: LinearIndicatorAttribute): void {
ModifierUtils.applySetOnChange(this);
ModifierUtils.applyAndMergeModifier<LinearIndicatorAttribute, ArkLinearIndicatorComponent, ArkComponent>(instance, this);
}
}

View File

@ -82,7 +82,8 @@
"src/water_flow_modifier.ts",
"src/symbol_glyph_modifier.ts",
"src/symbol_span_modifier.ts",
"src/container_span_modifier.ts"
"src/container_span_modifier.ts",
"src/linear_indicator_modifitr.ts"
],
"compilerOptions": {
"module": "none",

View File

@ -7947,6 +7947,95 @@ class RowSpaceModifier extends ModifierWithKey {
}
RowSpaceModifier.identity = Symbol('rowSpace');
class LinearIndicatorIndicatorStyleModifier extends ModifierWithKey {
constructor(value) {
super(value);
}
applyPeer(node, reset) {
if (reset) {
getUINativeModule().linearIndicator.resetIndicatorStyle(node);
}
else {
getUINativeModule().linearIndicator.setIndicatorStyle(node,
this.value.space, this.value.strokeWidth, this.value.strokeRadius
, this.value.trackBackgroundColor, this.value.trackColor);
}
}
checkObjectDiff() {
return
this.stageValue.space !== this.value.space
|| this.stageValue.strokeWidth !== this.value.strokeWidth
|| this.stageValue.strokeRadius !== this.value.strokeRadius
|| this.stageValue.trackBackgroundColor !== this.value.trackBackgroundColor
|| this.stageValue.trackColor !== this.value.trackColor
;
}
}
LinearIndicatorIndicatorStyleModifier.identity = Symbol('linearIndicatorIndicatorStyle');
class LinearIndicatorIndicatorLoopModifier extends ModifierWithKey {
constructor(value) {
super(value);
}
applyPeer(node, reset) {
if (reset) {
getUINativeModule().linearIndicator.resetIndicatorLoop(node);
}
else {
getUINativeModule().linearIndicator.setIndicatorLoop(node, this.value);
}
}
checkObjectDiff() {
return this.stageValue !== this.value;
}
}
LinearIndicatorIndicatorLoopModifier.identity = Symbol('linearIndicatorIndicatorLoop');
class LinearIndicatorOnChangeModifier extends ModifierWithKey {
constructor(value) {
super(value);
}
applyPeer(node, reset) {
if (reset) {
getUINativeModule().linearIndicator.resetOnChange(node);
} else {
getUINativeModule().linearIndicator.setOnChange(node, this.value);
}
}
}
LinearIndicatorOnChangeModifier.identity = Symbol('linearIndicatorOnChange');
class ArkLinearIndicatorComponent extends ArkComponent {
constructor(nativePtr, classType) {
super(nativePtr, classType);
}
indicatorStyle(value) {
modifierWithKey(this._modifiersWithKeys, LinearIndicatorIndicatorStyleModifier.identity, LinearIndicatorIndicatorStyleModifier, value);
return this;
}
indicatorLoop(value) {
modifierWithKey(this._modifiersWithKeys, LinearIndicatorIndicatorLoopModifier.identity, LinearIndicatorIndicatorLoopModifier, value);
return this;
}
onChange(value) {
modifierWithKey(this._modifiersWithKeys, LinearIndicatorOnChangeModifier.identity, LinearIndicatorOnChangeModifier, value);
return this;
}
}
// @ts-ignore
if (globalThis.LinearIndicator !== undefined) {
globalThis.LinearIndicator.attributeModifier = function (modifier) {
attributeModifierFunc.call(this, modifier, (nativePtr) => {
return new ArkLinearIndicatorComponent(nativePtr);
}, (nativePtr, classType, modifierJS) => {
return new modifierJS.LinearIndicatorModifier(nativePtr, classType);
});
};
}
class RowPointLightModifier extends ModifierWithKey {
constructor(value) {
super(value);

View File

@ -1064,7 +1064,19 @@ class ContainerSpanModifier extends ArkContainerSpanComponent {
}
}
export default { CommonModifier, AlphabetIndexerModifier, BlankModifier, ButtonModifier, CalendarPickerModifier, CheckboxModifier, CheckboxGroupModifier, CircleModifier,
class LinearIndicatorModifier extends ArkLinearIndicatorComponent {
constructor(nativePtr, classType) {
super(nativePtr, classType);
this._modifiersWithKeys = new ModifierMap();
}
applyNormalAttribute(instance) {
ModifierUtils.applySetOnChange(this);
ModifierUtils.applyAndMergeModifier(instance, this);
}
}
export default {
CommonModifier, AlphabetIndexerModifier, BlankModifier, ButtonModifier, CalendarPickerModifier, CheckboxModifier, CheckboxGroupModifier, CircleModifier,
ColumnModifier, ColumnSplitModifier, CounterModifier, DataPanelModifier, DatePickerModifier, DividerModifier, FormComponentModifier, GaugeModifier,
GridModifier, GridColModifier, GridItemModifier, GridRowModifier, HyperlinkModifier, ImageAnimatorModifier, ImageModifier, ImageSpanModifier, LineModifier,
ListModifier, ListItemModifier, ListItemGroupModifier, LoadingProgressModifier, MarqueeModifier, MenuModifier, MenuItemModifier, NavDestinationModifier,
@ -1073,4 +1085,5 @@ export default { CommonModifier, AlphabetIndexerModifier, BlankModifier, ButtonM
ScrollModifier, SearchModifier, SelectModifier, ShapeModifier, SideBarContainerModifier, SliderModifier, SpanModifier, StackModifier, StepperItemModifier,
SwiperModifier, TabsModifier, TextAreaModifier, TextModifier, TextClockModifier, TextInputModifier, TextPickerModifier, TextTimerModifier, TimePickerModifier,
ToggleModifier, VideoModifier, WaterFlowModifier, FlexModifier, PluginComponentModifier, RefreshModifier, TabContentModifier, ModifierUtils, AttributeUpdater,
ParticleModifier, MediaCachedImageModifier, SymbolGlyphModifier, SymbolSpanModifier, Component3DModifier, ContainerSpanModifier };
ParticleModifier, MediaCachedImageModifier, SymbolGlyphModifier, SymbolSpanModifier, Component3DModifier, ContainerSpanModifier, LinearIndicatorModifier
};

View File

@ -226,6 +226,7 @@ template("declarative_js_engine_ark") {
"nativeModule/arkts_native_image_bridge.cpp",
"nativeModule/arkts_native_image_span_bridge.cpp",
"nativeModule/arkts_native_line_bridge.cpp",
"nativeModule/arkts_native_linear_indicator.cpp",
"nativeModule/arkts_native_list_bridge.cpp",
"nativeModule/arkts_native_list_item_bridge.cpp",
"nativeModule/arkts_native_list_item_group_bridge.cpp",

View File

@ -108,6 +108,7 @@
#include "bridge/declarative_frontend/engine/jsi/nativeModule/arkts_native_refresh_bridge.h"
#include "bridge/declarative_frontend/engine/jsi/nativeModule/arkts_native_relative_container_bridge.h"
#include "bridge/declarative_frontend/engine/jsi/nativeModule/arkts_native_container_span_bridge.h"
#include "bridge/declarative_frontend/engine/jsi/nativeModule/arkts_native_linear_indicator.h"
#include "bridge/declarative_frontend/engine/js_converter.h"
#include "bridge/declarative_frontend/jsview/js_navigation_stack.h"
#ifdef PLUGIN_COMPONENT_SUPPORTED
@ -1677,6 +1678,21 @@ ArkUINativeModuleValue ArkUINativeModule::GetArkUINativeModule(ArkUIRuntimeCallI
panda::FunctionRef::New(const_cast<panda::EcmaVM*>(vm), RichEditorBridge::ResetOnCopy));
object->Set(vm, panda::StringRef::NewFromUtf8(vm, "richEditor"), richEditor);
auto linearIndicator = panda::ObjectRef::New(vm);
linearIndicator->Set(vm, panda::StringRef::NewFromUtf8(vm, "setIndicatorStyle"),
panda::FunctionRef::New(const_cast<panda::EcmaVM*>(vm), LinearIndicatorBridge::SetIndicatorStyle));
linearIndicator->Set(vm, panda::StringRef::NewFromUtf8(vm, "resetIndicatorStyle"),
panda::FunctionRef::New(const_cast<panda::EcmaVM*>(vm), LinearIndicatorBridge::ResetIndicatorStyle));
linearIndicator->Set(vm, panda::StringRef::NewFromUtf8(vm, "setIndicatorLoop"),
panda::FunctionRef::New(const_cast<panda::EcmaVM*>(vm), LinearIndicatorBridge::SetIndicatorLoop));
linearIndicator->Set(vm, panda::StringRef::NewFromUtf8(vm, "resetIndicatorLoop"),
panda::FunctionRef::New(const_cast<panda::EcmaVM*>(vm), LinearIndicatorBridge::ResetIndicatorLoop));
linearIndicator->Set(vm, panda::StringRef::NewFromUtf8(vm, "setOnChange"),
panda::FunctionRef::New(const_cast<panda::EcmaVM*>(vm), LinearIndicatorBridge::SetOnChange));
linearIndicator->Set(vm, panda::StringRef::NewFromUtf8(vm, "resetOnChange"),
panda::FunctionRef::New(const_cast<panda::EcmaVM*>(vm), LinearIndicatorBridge::ResetOnChange));
object->Set(vm, panda::StringRef::NewFromUtf8(vm, "linearIndicator"), linearIndicator);
auto textArea = panda::ObjectRef::New(vm);
textArea->Set(vm, panda::StringRef::NewFromUtf8(vm, "setStyle"),
panda::FunctionRef::New(const_cast<panda::EcmaVM*>(vm), TextAreaBridge::SetStyle));

View File

@ -0,0 +1,184 @@
/*
* Copyright (c) 2024 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include "bridge/declarative_frontend/engine/jsi/nativeModule/arkts_native_linear_indicator.h"
#include <string>
#include "base/geometry/dimension.h"
#include "bridge/declarative_frontend/engine/jsi/nativeModule/arkts_native_button_bridge.h"
#include "bridge/declarative_frontend/engine/jsi/nativeModule/arkts_native_common_bridge.h"
#include "bridge/declarative_frontend/engine/jsi/nativeModule/arkts_utils.h"
#include "core/components/common/properties/text_style.h"
#include "core/components_ng/base/frame_node.h"
#include "core/components_ng/pattern/button/button_model_ng.h"
#include "core/components_ng/pattern/button/button_request_data.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;
void LinearIndicatorBridge::SetIndicatorStyleSize(
EcmaVM* vm, ArkUINodeHandle nativeNode, const Local<panda::ObjectRef>& obj)
{
auto jsSpace = obj->Get(vm, panda::StringRef::NewFromUtf8(vm, "space"));
auto jsStrokeWidth = obj->Get(vm, panda::StringRef::NewFromUtf8(vm, "strokeWidth"));
auto jsStrokeRadius = obj->Get(vm, panda::StringRef::NewFromUtf8(vm, "strokeRadius"));
ArkUI_Float32 space = .0f;
if (jsSpace->IsNumber()) {
space = jsSpace->ToNumber(vm)->Value();
}
ArkUI_Float32 strokeWidth = .0f;
if (jsStrokeWidth->IsNumber()) {
strokeWidth = jsStrokeWidth->ToNumber(vm)->Value();
}
ArkUI_Float32 strokeRadius = .0f;
if (jsStrokeRadius->IsNumber()) {
strokeRadius = jsStrokeRadius->ToNumber(vm)->Value();
}
GetArkUINodeModifiers()->getLinearIndicatorModifier()->setLinearIndicatorIndicatorStyleSpace(nativeNode, space);
GetArkUINodeModifiers()->getLinearIndicatorModifier()->setLinearIndicatorIndicatorStyleStrokeWidth(
nativeNode, strokeWidth);
GetArkUINodeModifiers()->getLinearIndicatorModifier()->setLinearIndicatorIndicatorStyleStrokeRadius(
nativeNode, strokeRadius);
}
void LinearIndicatorBridge::SetIndicatorStyleColor(
EcmaVM* vm, ArkUINodeHandle nativeNode, const Local<panda::ObjectRef>& obj)
{
auto jsTrackBackgroundColor = obj->Get(vm, panda::StringRef::NewFromUtf8(vm, "trackBackgroundColor"));
auto jsTrackColor = obj->Get(vm, panda::StringRef::NewFromUtf8(vm, "trackColor"));
ArkUI_Uint32 trackBackgroundColor = 0;
if (jsTrackBackgroundColor->IsNumber()) {
trackBackgroundColor = jsTrackBackgroundColor->ToNumber(vm)->Value();
}
ArkUI_Uint32 trackColor = 0;
if (jsTrackColor->IsNumber()) {
trackColor = jsTrackColor->ToNumber(vm)->Value();
}
GetArkUINodeModifiers()->getLinearIndicatorModifier()->setLinearIndicatorIndicatorStyleTrackBackgroundColor(
nativeNode, trackBackgroundColor);
GetArkUINodeModifiers()->getLinearIndicatorModifier()->setLinearIndicatorIndicatorStyleTrackColor(
nativeNode, trackColor);
}
ArkUINativeModuleValue LinearIndicatorBridge::SetIndicatorStyle(ArkUIRuntimeCallInfo* runtimeCallInfo)
{
EcmaVM* vm = runtimeCallInfo->GetVM();
CHECK_NULL_RETURN(vm, panda::JSValueRef::Undefined(vm));
Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(NUM_0);
Local<JSValueRef> secondArg = runtimeCallInfo->GetCallArgRef(NUM_1);
auto nativeNode = nodePtr(firstArg->ToNativePointer(vm)->Value());
if (secondArg->IsObject(vm)) {
Local<panda::ObjectRef> obj = secondArg->ToObject(vm);
SetIndicatorStyleSize(vm, nativeNode, obj);
SetIndicatorStyleColor(vm, nativeNode, obj);
} else {
GetArkUINodeModifiers()->getLinearIndicatorModifier()->resetLinearIndicatorIndicatorStyleSpace(nativeNode);
GetArkUINodeModifiers()->getLinearIndicatorModifier()->resetLinearIndicatorIndicatorStyleStrokeWidth(
nativeNode);
GetArkUINodeModifiers()->getLinearIndicatorModifier()->resetLinearIndicatorIndicatorStyleStrokeRadius(
nativeNode);
GetArkUINodeModifiers()->getLinearIndicatorModifier()->resetLinearIndicatorIndicatorStyleTrackBackgroundColor(
nativeNode);
GetArkUINodeModifiers()->getLinearIndicatorModifier()->resetLinearIndicatorIndicatorStyleTrackColor(nativeNode);
}
return panda::JSValueRef::Undefined(vm);
}
ArkUINativeModuleValue LinearIndicatorBridge::ResetIndicatorStyle(ArkUIRuntimeCallInfo* runtimeCallInfo)
{
EcmaVM* vm = runtimeCallInfo->GetVM();
CHECK_NULL_RETURN(vm, panda::JSValueRef::Undefined(vm));
Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(NUM_0);
auto nativeNode = nodePtr(firstArg->ToNativePointer(vm)->Value());
GetArkUINodeModifiers()->getLinearIndicatorModifier()->resetLinearIndicatorIndicatorStyleSpace(nativeNode);
GetArkUINodeModifiers()->getLinearIndicatorModifier()->resetLinearIndicatorIndicatorStyleStrokeWidth(nativeNode);
GetArkUINodeModifiers()->getLinearIndicatorModifier()->resetLinearIndicatorIndicatorStyleStrokeRadius(nativeNode);
GetArkUINodeModifiers()->getLinearIndicatorModifier()->resetLinearIndicatorIndicatorStyleTrackBackgroundColor(
nativeNode);
GetArkUINodeModifiers()->getLinearIndicatorModifier()->resetLinearIndicatorIndicatorStyleTrackColor(nativeNode);
return panda::JSValueRef::Undefined(vm);
}
ArkUINativeModuleValue LinearIndicatorBridge::SetIndicatorLoop(ArkUIRuntimeCallInfo* runtimeCallInfo)
{
EcmaVM* vm = runtimeCallInfo->GetVM();
CHECK_NULL_RETURN(vm, panda::JSValueRef::Undefined(vm));
Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(NUM_0);
Local<JSValueRef> secondArg = runtimeCallInfo->GetCallArgRef(NUM_1);
auto nativeNode = nodePtr(firstArg->ToNativePointer(vm)->Value());
bool SetIndicatorLoop = true;
if (secondArg->IsBoolean()) {
SetIndicatorLoop = secondArg->ToBoolean(vm)->Value();
GetArkUINodeModifiers()->getLinearIndicatorModifier()->setLinearIndicatorIndicatorLoop(
nativeNode, SetIndicatorLoop);
} else {
GetArkUINodeModifiers()->getLinearIndicatorModifier()->resetLinearIndicatorIndicatorLoop(nativeNode);
}
return panda::JSValueRef::Undefined(vm);
}
ArkUINativeModuleValue LinearIndicatorBridge::ResetIndicatorLoop(ArkUIRuntimeCallInfo* runtimeCallInfo)
{
EcmaVM* vm = runtimeCallInfo->GetVM();
CHECK_NULL_RETURN(vm, panda::JSValueRef::Undefined(vm));
Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(NUM_0);
auto nativeNode = nodePtr(firstArg->ToNativePointer(vm)->Value());
GetArkUINodeModifiers()->getLinearIndicatorModifier()->resetLinearIndicatorIndicatorLoop(nativeNode);
return panda::JSValueRef::Undefined(vm);
}
ArkUINativeModuleValue LinearIndicatorBridge::SetOnChange(ArkUIRuntimeCallInfo* runtimeCallInfo)
{
EcmaVM* vm = runtimeCallInfo->GetVM();
CHECK_NULL_RETURN(vm, panda::JSValueRef::Undefined(vm));
Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(NUM_0);
Local<JSValueRef> callbackArg = runtimeCallInfo->GetCallArgRef(NUM_1);
auto nativeNode = nodePtr(firstArg->ToNativePointer(vm)->Value());
auto frameNode = reinterpret_cast<FrameNode*>(nativeNode);
CHECK_NULL_RETURN(frameNode, panda::JSValueRef::Undefined(vm));
if (callbackArg->IsUndefined() || callbackArg->IsNull() || !callbackArg->IsFunction(vm)) {
GetArkUINodeModifiers()->getLinearIndicatorModifier()->resetLinearIndicatorOnChange(nativeNode);
return panda::JSValueRef::Undefined(vm);
}
panda::Local<panda::FunctionRef> func = callbackArg->ToObject(vm);
std::function<void(int index, float progress)> callback = [vm, frameNode, func = panda::CopyableGlobal(vm, func)](
int index, float progress) {
panda::LocalScope pandaScope(vm);
panda::TryCatch trycatch(vm);
PipelineContext::SetCallBackNode(AceType::WeakClaim(frameNode));
panda::Local<panda::JSValueRef> params[NUM_2] = { panda::NumberRef::New(vm, index),
panda::NumberRef::New(vm, progress) };
func->Call(vm, func.ToLocal(), params, NUM_2);
};
GetArkUINodeModifiers()->getLinearIndicatorModifier()->setLinearIndicatorOnChange(
nativeNode, reinterpret_cast<void*>(&callback));
return panda::JSValueRef::Undefined(vm);
}
ArkUINativeModuleValue LinearIndicatorBridge::ResetOnChange(ArkUIRuntimeCallInfo* runtimeCallInfo)
{
EcmaVM* vm = runtimeCallInfo->GetVM();
CHECK_NULL_RETURN(vm, panda::JSValueRef::Undefined(vm));
Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(NUM_0);
auto nativeNode = nodePtr(firstArg->ToNativePointer(vm)->Value());
GetArkUINodeModifiers()->getLinearIndicatorModifier()->resetLinearIndicatorOnChange(nativeNode);
return panda::JSValueRef::Undefined(vm);
}
} // namespace OHOS::Ace::NG

View File

@ -0,0 +1,38 @@
/*
* Copyright (c) 2024 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#ifndef FRAMEWORKS_BRIDGE_DECLARATIVE_FRONTEND_ENGINE_JSI_NATIVEMODULE_ARKTS_NATIVE_LINEAR_INDICATOR_H
#define FRAMEWORKS_BRIDGE_DECLARATIVE_FRONTEND_ENGINE_JSI_NATIVEMODULE_ARKTS_NATIVE_LINEAR_INDICATOR_H
#include "bridge/declarative_frontend/engine/jsi/nativeModule/arkts_native_api_bridge.h"
#include "bridge/declarative_frontend/jsview/js_xcomponent.h"
namespace OHOS::Ace::NG {
class LinearIndicatorBridge {
public:
static ArkUINativeModuleValue SetIndicatorStyle(ArkUIRuntimeCallInfo* runtimeCallInfo);
static ArkUINativeModuleValue ResetIndicatorStyle(ArkUIRuntimeCallInfo* runtimeCallInfo);
static ArkUINativeModuleValue SetIndicatorLoop(ArkUIRuntimeCallInfo* runtimeCallInfo);
static ArkUINativeModuleValue ResetIndicatorLoop(ArkUIRuntimeCallInfo* runtimeCallInfo);
static ArkUINativeModuleValue SetOnChange(ArkUIRuntimeCallInfo* runtimeCallInfo);
static ArkUINativeModuleValue ResetOnChange(ArkUIRuntimeCallInfo* runtimeCallInfo);
private:
static void SetIndicatorStyleSize(EcmaVM* vm, ArkUINodeHandle nativeNode, const Local<panda::ObjectRef>& obj);
static void SetIndicatorStyleColor(EcmaVM* vm, ArkUINodeHandle nativeNode, const Local<panda::ObjectRef>& obj);
};
} // namespace OHOS::Ace::NG
#endif // FRAMEWORKS_BRIDGE_DECLARATIVE_FRONTEND_ENGINE_JSI_NATIVEMODULE_ARKTS_NATIVE_LINEAR_INDICATOR_H

View File

@ -77,6 +77,7 @@ void LinearIndicatorModelNG::SetTrackBackgroundColor(const Color& value)
void LinearIndicatorModelNG::SetTrackColor(const Color& value)
{
auto frameNode = ViewStackProcessor::GetInstance()->GetMainFrameNode();
CHECK_NULL_VOID(frameNode);
ACE_UPDATE_NODE_LAYOUT_PROPERTY(LinearIndicatorLayoutProperty, TrackColor, value, frameNode);
}
@ -96,4 +97,43 @@ void LinearIndicatorModelNG::OnChange(std::function<void(int index, float progre
pattern->GetController()->OnChange(std::move(event));
}
void LinearIndicatorModelNG::SetIndicatorStyleSpace(FrameNode* frameNode, const Dimension& space)
{
ACE_UPDATE_NODE_LAYOUT_PROPERTY(LinearIndicatorLayoutProperty, Space, space, frameNode);
}
void LinearIndicatorModelNG::SetIndicatorStyleStrokeWidth(FrameNode* frameNode, const Dimension& strokeWidth)
{
ACE_UPDATE_NODE_LAYOUT_PROPERTY(LinearIndicatorLayoutProperty, StrokeWidth, strokeWidth, frameNode);
}
void LinearIndicatorModelNG::SetIndicatorStyleStrokeRadius(FrameNode* frameNode, const Dimension& strokeRadius)
{
ACE_UPDATE_NODE_LAYOUT_PROPERTY(LinearIndicatorLayoutProperty, StrokeRadius, strokeRadius, frameNode);
}
void LinearIndicatorModelNG::SetIndicatorStyleTrackBackgroundColor(
FrameNode* frameNode, const Color& trackBackgroundColor)
{
ACE_UPDATE_NODE_LAYOUT_PROPERTY(
LinearIndicatorLayoutProperty, TrackBackgroundColor, trackBackgroundColor, frameNode);
}
void LinearIndicatorModelNG::SetIndicatorStyleTrackColor(FrameNode* frameNode, const Color& trackColor)
{
ACE_UPDATE_NODE_LAYOUT_PROPERTY(LinearIndicatorLayoutProperty, TrackColor, trackColor, frameNode);
}
void LinearIndicatorModelNG::SetLoop(FrameNode* frameNode, bool value)
{
ACE_UPDATE_NODE_LAYOUT_PROPERTY(LinearIndicatorLayoutProperty, Loop, value, frameNode);
}
void LinearIndicatorModelNG::SetOnChange(FrameNode* frameNode, std::function<void(int index, float progress)>&& event)
{
auto pattern = frameNode->GetPattern<LinearIndicatorPattern>();
CHECK_NULL_VOID(pattern);
pattern->GetController()->OnChange(std::move(event));
}
} // namespace OHOS::Ace::NG

View File

@ -31,6 +31,14 @@ public:
void Loop(bool value) override;
void OnChange(std::function<void(int index, float progress)>&& event) override;
static void SetIndicatorStyleSpace(FrameNode* frameNode, const Dimension& space);
static void SetIndicatorStyleStrokeWidth(FrameNode* frameNode, const Dimension& strokeWidth);
static void SetIndicatorStyleStrokeRadius(FrameNode* frameNode, const Dimension& strokeRadius);
static void SetIndicatorStyleTrackBackgroundColor(FrameNode* frameNode, const Color& trackBackgroundColor);
static void SetIndicatorStyleTrackColor(FrameNode* frameNode, const Color& trackColor);
static void SetLoop(FrameNode* frameNode, bool value);
static void SetOnChange(FrameNode* frameNode, std::function<void(int index, float progress)>&& event);
private:
void SetProgressCount(OHOS::Ace::RefPtr<OHOS::Ace::NG::FrameNode> frameNode, std::size_t progressCount);
};

View File

@ -26,10 +26,10 @@
extern "C" {
#endif
#define ARKUI_FULL_API_VERSION 121
#define ARKUI_FULL_API_VERSION 122
// When changing ARKUI_BASIC_API_VERSION, ARKUI_FULL_API_VERSION must be
// increased as well.
#define ARKUI_NODE_API_VERSION 121
#define ARKUI_NODE_API_VERSION 122
#define ARKUI_BASIC_API_VERSION 8
#define ARKUI_EXTENDED_API_VERSION 8
@ -4227,6 +4227,24 @@ struct ArkUIRichEditorControllerModifier {
ArkUINodeHandle (*getRichEditorController)(ArkUINodeHandle node);
};
struct ArkUILinearIndicatorModifier {
void (*setLinearIndicatorIndicatorStyleSpace)(ArkUINodeHandle node, ArkUI_Float32 space);
void (*resetLinearIndicatorIndicatorStyleSpace)(ArkUINodeHandle node);
void (*setLinearIndicatorIndicatorStyleStrokeWidth)(ArkUINodeHandle node, ArkUI_Float32 strokeWidth);
void (*resetLinearIndicatorIndicatorStyleStrokeWidth)(ArkUINodeHandle node);
void (*setLinearIndicatorIndicatorStyleStrokeRadius)(ArkUINodeHandle node, ArkUI_Float32 strokeRadius);
void (*resetLinearIndicatorIndicatorStyleStrokeRadius)(ArkUINodeHandle node);
void (*setLinearIndicatorIndicatorStyleTrackBackgroundColor)(
ArkUINodeHandle node, ArkUI_Uint32 trackBackgroundColor);
void (*resetLinearIndicatorIndicatorStyleTrackBackgroundColor)(ArkUINodeHandle node);
void (*setLinearIndicatorIndicatorStyleTrackColor)(ArkUINodeHandle node, ArkUI_Uint32 trackColor);
void (*resetLinearIndicatorIndicatorStyleTrackColor)(ArkUINodeHandle node);
void (*setLinearIndicatorIndicatorLoop)(ArkUINodeHandle node, ArkUI_Bool value);
void (*resetLinearIndicatorIndicatorLoop)(ArkUINodeHandle node);
void (*setLinearIndicatorOnChange)(ArkUINodeHandle node, void* callback);
void (*resetLinearIndicatorOnChange)(ArkUINodeHandle node);
};
struct ArkUIDataPanelModifier {
void (*setCloseEffect)(ArkUINodeHandle node, ArkUI_Bool value);
void (*resetCloseEffect)(ArkUINodeHandle node);
@ -4695,6 +4713,7 @@ struct ArkUINodeModifiers {
const ArkUISymbolSpanModifier* (*getSymbolSpanModifier)();
const ArkUIComponent3DModifier* (*getComponent3DModifier)();
const ArkUIContainerSpanModifier* (*getContainerSpanModifier)();
const ArkUILinearIndicatorModifier* (*getLinearIndicatorModifier)();
};
// same as inner defines in property.h

View File

@ -56,6 +56,7 @@ template("ace_core_interfaces_native_node") {
"node/hyperlink_modifier.cpp",
"node/image_animator_modifier.cpp",
"node/line_modifier.cpp",
"node/linear_indicator_modifier.cpp",
"node/marquee_modifier.cpp",
"node/menu_item_modifier.cpp",
"node/menu_modifier.cpp",

View File

@ -0,0 +1,143 @@
/*
* Copyright (c) 2024 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include "core/interfaces/native/node/linear_indicator_modifier.h"
#include "core/components/common/layout/constants.h"
#include "core/components_ng/base/frame_node.h"
#include "core/components_ng/base/view_abstract.h"
#include "core/components_ng/pattern/linear_indicator/linear_indicator_model_ng.h"
#include "core/components_ng/pattern/linear_indicator/linear_indicator_theme.h"
#include "core/interfaces/native/node/node_api.h"
#include "core/pipeline/base/element_register.h"
namespace OHOS::Ace::NG {
void SetLinearIndicatorIndicatorStyleSpace(ArkUINodeHandle node, ArkUI_Float32 space)
{
auto frameNode = reinterpret_cast<FrameNode*>(node);
CHECK_NULL_VOID(frameNode);
LinearIndicatorModelNG::SetIndicatorStyleSpace(frameNode, Dimension(space));
}
void ResetLinearIndicatorIndicatorStyleSpace(ArkUINodeHandle node)
{
auto frameNode = reinterpret_cast<FrameNode*>(node);
CHECK_NULL_VOID(frameNode);
LinearIndicatorModelNG::SetIndicatorStyleSpace(frameNode, Dimension(.0f));
}
void SetLinearIndicatorIndicatorStyleStrokeWidth(ArkUINodeHandle node, ArkUI_Float32 strokeWidth)
{
auto frameNode = reinterpret_cast<FrameNode*>(node);
CHECK_NULL_VOID(frameNode);
LinearIndicatorModelNG::SetIndicatorStyleStrokeWidth(frameNode, Dimension(strokeWidth));
}
void ResetLinearIndicatorIndicatorStyleStrokeWidth(ArkUINodeHandle node)
{
auto frameNode = reinterpret_cast<FrameNode*>(node);
CHECK_NULL_VOID(frameNode);
LinearIndicatorModelNG::SetIndicatorStyleStrokeWidth(frameNode, Dimension(.0f));
}
void SetLinearIndicatorIndicatorStyleStrokeRadius(ArkUINodeHandle node, ArkUI_Float32 strokeRadius)
{
auto frameNode = reinterpret_cast<FrameNode*>(node);
CHECK_NULL_VOID(frameNode);
LinearIndicatorModelNG::SetIndicatorStyleStrokeWidth(frameNode, Dimension(strokeRadius));
}
void ResetLinearIndicatorIndicatorStyleStrokeRadius(ArkUINodeHandle node)
{
auto frameNode = reinterpret_cast<FrameNode*>(node);
CHECK_NULL_VOID(frameNode);
LinearIndicatorModelNG::SetIndicatorStyleStrokeWidth(frameNode, Dimension(.0f));
}
void SetLinearIndicatorIndicatorStyleTrackBackgroundColor(ArkUINodeHandle node, ArkUI_Uint32 trackBackgroundColor)
{
auto frameNode = reinterpret_cast<FrameNode*>(node);
CHECK_NULL_VOID(frameNode);
LinearIndicatorModelNG::SetIndicatorStyleTrackBackgroundColor(frameNode, Color(trackBackgroundColor));
}
void ResetLinearIndicatorIndicatorStyleTrackBackgroundColor(ArkUINodeHandle node)
{
auto frameNode = reinterpret_cast<FrameNode*>(node);
CHECK_NULL_VOID(frameNode);
LinearIndicatorModelNG::SetIndicatorStyleTrackBackgroundColor(frameNode, Color(0));
}
void SetLinearIndicatorIndicatorStyleTrackColor(ArkUINodeHandle node, ArkUI_Uint32 trackColor)
{
auto frameNode = reinterpret_cast<FrameNode*>(node);
CHECK_NULL_VOID(frameNode);
LinearIndicatorModelNG::SetIndicatorStyleTrackColor(frameNode, Color(trackColor));
}
void ResetLinearIndicatorIndicatorStyleTrackColor(ArkUINodeHandle node)
{
auto frameNode = reinterpret_cast<FrameNode*>(node);
CHECK_NULL_VOID(frameNode);
LinearIndicatorModelNG::SetIndicatorStyleTrackColor(frameNode, Color(0));
}
void SetLinearIndicatorIndicatorLoop(ArkUINodeHandle node, ArkUI_Bool value)
{
auto frameNode = reinterpret_cast<FrameNode*>(node);
CHECK_NULL_VOID(frameNode);
LinearIndicatorModelNG::SetLoop(frameNode, static_cast<bool>(value));
}
void ResetLinearIndicatorIndicatorLoop(ArkUINodeHandle node)
{
auto frameNode = reinterpret_cast<FrameNode*>(node);
CHECK_NULL_VOID(frameNode);
LinearIndicatorModelNG::SetLoop(frameNode, true);
}
void SetLinearIndicatorOnChange(ArkUINodeHandle node, void* callback)
{
auto* frameNode = reinterpret_cast<FrameNode*>(node);
CHECK_NULL_VOID(frameNode);
if (callback) {
auto onChange = reinterpret_cast<std::function<void(int index, float progress)>*>(callback);
LinearIndicatorModelNG::SetOnChange(frameNode, std::move(*onChange));
} else {
LinearIndicatorModelNG::SetOnChange(frameNode, nullptr);
}
}
void ResetLinearIndicatorOnChange(ArkUINodeHandle node)
{
auto* frameNode = reinterpret_cast<FrameNode*>(node);
CHECK_NULL_VOID(frameNode);
LinearIndicatorModelNG::SetOnChange(frameNode, nullptr);
}
namespace NodeModifier {
const ArkUILinearIndicatorModifier* GetLinearIndicatorModifier()
{
static const ArkUILinearIndicatorModifier modifier = { SetLinearIndicatorIndicatorStyleSpace,
ResetLinearIndicatorIndicatorStyleSpace, SetLinearIndicatorIndicatorStyleStrokeWidth,
ResetLinearIndicatorIndicatorStyleStrokeWidth, SetLinearIndicatorIndicatorStyleStrokeRadius,
ResetLinearIndicatorIndicatorStyleStrokeRadius, SetLinearIndicatorIndicatorStyleTrackBackgroundColor,
ResetLinearIndicatorIndicatorStyleTrackBackgroundColor, SetLinearIndicatorIndicatorStyleTrackColor,
ResetLinearIndicatorIndicatorStyleTrackColor, SetLinearIndicatorIndicatorLoop,
ResetLinearIndicatorIndicatorLoop, SetLinearIndicatorOnChange, ResetLinearIndicatorOnChange };
return &modifier;
}
} // namespace NodeModifier
} // namespace OHOS::Ace::NG

View File

@ -0,0 +1,24 @@
/*
* Copyright (c) 2024 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#ifndef FOUNDATION_ACE_FRAMEWORKS_CORE_INTERFACES_NATIVE_NODE_LINEAR_INDICATOR_MODIFIER_H
#define FOUNDATION_ACE_FRAMEWORKS_CORE_INTERFACES_NATIVE_NODE_LINEAR_INDICATOR_MODIFIER_H
#include "core/interfaces/native/node/node_api.h"
namespace OHOS::Ace::NG::NodeModifier {
const ArkUILinearIndicatorModifier* GetLinearIndicatorModifier();
}
#endif // FOUNDATION_ACE_FRAMEWORKS_CORE_INTERFACES_NATIVE_NODE_LINEAR_INDICATOR_MODIFIER_H

View File

@ -103,6 +103,7 @@
#include "core/interfaces/native/node/video_modifier.h"
#include "core/interfaces/native/node/water_flow_modifier.h"
#include "core/interfaces/native/node/node_container_span_modifier.h"
#include "core/interfaces/native/node/linear_indicator_modifier.h"
#ifdef MODEL_COMPONENT_SUPPORTED
#include "core/interfaces/native/node/node_component3d_modifier.h"
@ -249,6 +250,7 @@ const ArkUINodeModifiers impl = {
#endif
NodeModifier::GetContainerSpanModifier,
NodeModifier::GetLinearIndicatorModifier,
};
} // namespace