mirror of
https://gitee.com/openharmony/arkui_ace_engine
synced 2025-02-17 09:13:19 +00:00
!35999 [NDK] add transition api
Merge pull request !35999 from lisitao/i_1
This commit is contained in:
commit
23fe7944ee
@ -1204,6 +1204,45 @@ struct ArkUIAccessibilityValue {
|
||||
ArkUIOptionalCharPtr text;
|
||||
};
|
||||
|
||||
struct ArkUITranslateOption {
|
||||
ArkUI_Float32 x;
|
||||
ArkUI_Float32 y;
|
||||
ArkUI_Float32 z;
|
||||
};
|
||||
|
||||
struct ArkUIScaleOption {
|
||||
ArkUI_Float32 x;
|
||||
ArkUI_Float32 y;
|
||||
ArkUI_Float32 z;
|
||||
ArkUI_Float32 centerX;
|
||||
ArkUI_Float32 centerY;
|
||||
};
|
||||
|
||||
struct ArkUIRotateOption {
|
||||
ArkUI_Float32 x;
|
||||
ArkUI_Float32 y;
|
||||
ArkUI_Float32 z;
|
||||
ArkUI_Float32 angle;
|
||||
ArkUI_Float32 centerX;
|
||||
ArkUI_Float32 centerY;
|
||||
ArkUI_Float32 centerZ;
|
||||
ArkUI_Float32 perspective;
|
||||
};
|
||||
|
||||
struct ArkUITransitionEffectOption {
|
||||
ArkUI_Int32 type;
|
||||
ArkUI_Float32 opacity;
|
||||
ArkUITranslateOption translate;
|
||||
ArkUIScaleOption scale;
|
||||
ArkUIRotateOption rotate;
|
||||
ArkUI_Int32 move;
|
||||
ArkUITransitionEffectOption* appear;
|
||||
ArkUITransitionEffectOption* disappear;
|
||||
ArkUITransitionEffectOption* combine;
|
||||
ArkUI_Bool hasAnimation;
|
||||
ArkUIAnimateOption animation;
|
||||
};
|
||||
|
||||
struct ArkUIDragPreViewOptions {
|
||||
ArkUI_Int32 mode;
|
||||
ArkUI_Int32 modeArrayLength;
|
||||
@ -1651,6 +1690,7 @@ struct ArkUICommonModifier {
|
||||
void (*resetPixelRound)(ArkUINodeHandle node);
|
||||
void (*setBorderDashParams)(ArkUINodeHandle node, const ArkUI_Float32* values, ArkUI_Int32 valuesSize);
|
||||
void (*getExpandSafeArea)(ArkUINodeHandle node, ArkUI_Uint32 (*values)[2]);
|
||||
void (*setTransition)(ArkUINodeHandle node, ArkUITransitionEffectOption* option);
|
||||
};
|
||||
|
||||
struct ArkUICommonShapeModifier {
|
||||
|
@ -120,6 +120,23 @@ const std::vector<OHOS::Ace::RefPtr<OHOS::Ace::Curve>> CURVES = {
|
||||
OHOS::Ace::Curves::SMOOTH,
|
||||
OHOS::Ace::Curves::FRICTION,
|
||||
};
|
||||
|
||||
enum TransitionEffectType {
|
||||
TRANSITION_EFFECT_OPACITY = 0,
|
||||
TRANSITION_EFFECT_TRANSLATE,
|
||||
TRANSITION_EFFECT_SCALE,
|
||||
TRANSITION_EFFECT_ROTATE,
|
||||
TRANSITION_EFFECT_MOVE,
|
||||
TRANSITION_EFFECT_ASYMMETRIC,
|
||||
};
|
||||
|
||||
const std::vector<AnimationDirection> DIRECTION_LIST = {
|
||||
AnimationDirection::NORMAL,
|
||||
AnimationDirection::REVERSE,
|
||||
AnimationDirection::ALTERNATE,
|
||||
AnimationDirection::ALTERNATE_REVERSE,
|
||||
};
|
||||
|
||||
constexpr int32_t DEFAULT_DURATION = 1000;
|
||||
std::string g_strValue;
|
||||
|
||||
@ -5864,6 +5881,115 @@ void ResetPixelRound(ArkUINodeHandle node)
|
||||
ViewAbstract::SetPixelRound(frameNode, static_cast<uint8_t>(PixelRoundCalcPolicy::NO_FORCE_ROUND));
|
||||
}
|
||||
|
||||
RefPtr<NG::ChainedTransitionEffect> ParseTransition(ArkUITransitionEffectOption* option)
|
||||
{
|
||||
CHECK_NULL_RETURN(option, nullptr);
|
||||
auto type = static_cast<TransitionEffectType>(option->type);
|
||||
RefPtr<NG::ChainedTransitionEffect> transitionEffect;
|
||||
switch (type) {
|
||||
case TransitionEffectType::TRANSITION_EFFECT_OPACITY: {
|
||||
transitionEffect = AceType::MakeRefPtr<NG::ChainedOpacityEffect>(option->opacity);
|
||||
break;
|
||||
}
|
||||
|
||||
case TransitionEffectType::TRANSITION_EFFECT_TRANSLATE: {
|
||||
CalcDimension x(option->translate.x, DimensionUnit::VP);
|
||||
CalcDimension y(option->translate.y, DimensionUnit::VP);
|
||||
CalcDimension z(option->translate.z, DimensionUnit::VP);
|
||||
NG::TranslateOptions translate(x, y, z);
|
||||
transitionEffect = AceType::MakeRefPtr<NG::ChainedTranslateEffect>(translate);
|
||||
break;
|
||||
}
|
||||
|
||||
case TransitionEffectType::TRANSITION_EFFECT_SCALE: {
|
||||
CalcDimension centerX(option->scale.centerX, DimensionUnit::PERCENT);
|
||||
CalcDimension centerY(option->scale.centerY, DimensionUnit::PERCENT);
|
||||
NG::ScaleOptions scale(option->scale.x, option->scale.y, option->scale.z, centerX, centerY);
|
||||
transitionEffect = AceType::MakeRefPtr<NG::ChainedScaleEffect>(scale);
|
||||
break;
|
||||
}
|
||||
|
||||
case TransitionEffectType::TRANSITION_EFFECT_ROTATE: {
|
||||
CalcDimension centerX(option->rotate.centerX, DimensionUnit::PERCENT);
|
||||
CalcDimension centerY(option->rotate.centerY, DimensionUnit::PERCENT);
|
||||
CalcDimension centerZ(option->rotate.centerZ, DimensionUnit::PERCENT);
|
||||
NG::RotateOptions rotate(option->rotate.x, option->rotate.y, option->rotate.z, option->rotate.angle,
|
||||
centerX, centerY, centerZ, option->rotate.perspective);
|
||||
transitionEffect = AceType::MakeRefPtr<NG::ChainedRotateEffect>(rotate);
|
||||
break;
|
||||
}
|
||||
|
||||
case TransitionEffectType::TRANSITION_EFFECT_MOVE: {
|
||||
transitionEffect =
|
||||
AceType::MakeRefPtr<NG::ChainedMoveEffect>(static_cast<NG::TransitionEdge>(option->move));
|
||||
break;
|
||||
}
|
||||
|
||||
case TransitionEffectType::TRANSITION_EFFECT_ASYMMETRIC: {
|
||||
RefPtr<NG::ChainedTransitionEffect> appearEffect;
|
||||
RefPtr<NG::ChainedTransitionEffect> disappearEffect;
|
||||
if (option->appear) {
|
||||
appearEffect = ParseTransition(option->appear);
|
||||
}
|
||||
if (option->disappear) {
|
||||
disappearEffect = ParseTransition(option->disappear);
|
||||
}
|
||||
transitionEffect = AceType::MakeRefPtr<NG::ChainedAsymmetricEffect>(appearEffect, disappearEffect);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
CHECK_NULL_RETURN(transitionEffect, nullptr);
|
||||
|
||||
if (option->hasAnimation) {
|
||||
auto animation = option->animation;
|
||||
AnimationOption animationOption;
|
||||
animationOption.SetDuration(animation.duration);
|
||||
animationOption.SetDelay(animation.delay);
|
||||
animationOption.SetIteration(animation.iterations);
|
||||
animationOption.SetTempo(animation.tempo);
|
||||
animationOption.SetAnimationDirection(
|
||||
DIRECTION_LIST[animation.playMode > DIRECTION_LIST.size() ? 0 : animation.playMode]);
|
||||
|
||||
// curve
|
||||
if (animation.iCurve) {
|
||||
auto curve = reinterpret_cast<Curve*>(animation.iCurve);
|
||||
animationOption.SetCurve(AceType::Claim(curve));
|
||||
} else {
|
||||
if (animation.curve < 0 || animation.curve >= CURVES.size()) {
|
||||
animationOption.SetCurve(OHOS::Ace::Curves::EASE_IN_OUT);
|
||||
} else {
|
||||
animationOption.SetCurve(CURVES[animation.curve]);
|
||||
}
|
||||
}
|
||||
|
||||
if (animation.expectedFrameRateRange) {
|
||||
RefPtr<FrameRateRange> frameRateRange =
|
||||
AceType::MakeRefPtr<FrameRateRange>(animation.expectedFrameRateRange->min,
|
||||
animation.expectedFrameRateRange->max, animation.expectedFrameRateRange->expected);
|
||||
animationOption.SetFrameRateRange(frameRateRange);
|
||||
}
|
||||
auto animationOptionResult = std::make_shared<AnimationOption>(animationOption);
|
||||
transitionEffect->SetAnimationOption(animationOptionResult);
|
||||
}
|
||||
|
||||
if (option->combine) {
|
||||
transitionEffect->SetNext(ParseTransition(option->combine));
|
||||
}
|
||||
return transitionEffect;
|
||||
}
|
||||
|
||||
void SetTransition(ArkUINodeHandle node, ArkUITransitionEffectOption* option)
|
||||
{
|
||||
CHECK_NULL_VOID(option);
|
||||
auto* frameNode = reinterpret_cast<FrameNode*>(node);
|
||||
CHECK_NULL_VOID(frameNode);
|
||||
|
||||
auto transitionEffectOption = ParseTransition(option);
|
||||
CHECK_NULL_VOID(transitionEffectOption);
|
||||
ViewAbstract::SetChainedTransition(frameNode, transitionEffectOption);
|
||||
}
|
||||
|
||||
void GetExpandSafeArea(ArkUINodeHandle node, ArkUI_Uint32 (*values)[2])
|
||||
{
|
||||
auto* frameNode = reinterpret_cast<FrameNode*>(node);
|
||||
@ -5977,7 +6103,7 @@ const ArkUICommonModifier* GetCommonModifier()
|
||||
SetAccessibilityValue, GetAccessibilityValue, ResetAccessibilityValue, SetAccessibilityActions,
|
||||
ResetAccessibilityActions, GetAccessibilityActions, SetAccessibilityRole, ResetAccessibilityRole,
|
||||
GetAccessibilityRole, SetFocusScopeId, ResetFocusScopeId, SetFocusScopePriority, ResetFocusScopePriority,
|
||||
SetPixelRound, ResetPixelRound, SetBorderDashParams, GetExpandSafeArea };
|
||||
SetPixelRound, ResetPixelRound, SetBorderDashParams, GetExpandSafeArea, SetTransition };
|
||||
|
||||
return &modifier;
|
||||
}
|
||||
|
@ -71,6 +71,8 @@ ohos_shared_library("ace_ndk") {
|
||||
"node/node_extened.cpp",
|
||||
"node/node_model.cpp",
|
||||
"node/node_node_relative_container.cpp",
|
||||
"node/node_transition.cpp",
|
||||
"node/node_transition_imp.cpp",
|
||||
"node/node_utils.cpp",
|
||||
"node/style_modifier.cpp",
|
||||
"node/waterflow_section_option.cpp",
|
||||
|
@ -1650,5 +1650,41 @@
|
||||
{
|
||||
"first_introduced": "12",
|
||||
"name": "OH_ArkUI_PointerEvent_SetStopPropagation"
|
||||
},
|
||||
{
|
||||
"first_introduced": "12",
|
||||
"name": "OH_ArkUI_CreateOpacityTransitionEffect"
|
||||
},
|
||||
{
|
||||
"first_introduced": "12",
|
||||
"name": "OH_ArkUI_CreateTranslationTransitionEffect"
|
||||
},
|
||||
{
|
||||
"first_introduced": "12",
|
||||
"name": "OH_ArkUI_CreateScaleTransitionEffect"
|
||||
},
|
||||
{
|
||||
"first_introduced": "12",
|
||||
"name": "OH_ArkUI_CreateRotationTransitionEffect"
|
||||
},
|
||||
{
|
||||
"first_introduced": "12",
|
||||
"name": "OH_ArkUI_CreateMovementTransitionEffect"
|
||||
},
|
||||
{
|
||||
"first_introduced": "12",
|
||||
"name": "OH_ArkUI_CreateAsymmetricTransitionEffect"
|
||||
},
|
||||
{
|
||||
"first_introduced": "12",
|
||||
"name": "OH_ArkUI_TransitionEffect_Dispose"
|
||||
},
|
||||
{
|
||||
"first_introduced": "12",
|
||||
"name": "OH_ArkUI_TransitionEffect_Combine"
|
||||
},
|
||||
{
|
||||
"first_introduced": "12",
|
||||
"name": "OH_ArkUI_TransitionEffect_SetAnimation"
|
||||
}
|
||||
]
|
||||
|
@ -69,6 +69,9 @@ typedef struct ArkUI_Animator* ArkUI_AnimatorHandle;
|
||||
typedef struct ArkUI_AnimatorEvent ArkUI_AnimatorEvent;
|
||||
typedef struct ArkUI_AnimatorOnFrameEvent ArkUI_AnimatorOnFrameEvent;
|
||||
|
||||
|
||||
typedef struct ArkUI_TransitionEffect ArkUI_TransitionEffect;
|
||||
|
||||
/**
|
||||
* @brief Implements the native animation APIs provided by ArkUI.
|
||||
*
|
||||
@ -309,6 +312,17 @@ ArkUI_CurveHandle OH_ArkUI_Curve_CreateInterpolatingSpring(float velocity, float
|
||||
ArkUI_CurveHandle OH_ArkUI_Curve_CreateCustomCurve(
|
||||
void* userData, float (*interpolate)(float fraction, void* userdata));
|
||||
void OH_ArkUI_Curve_DisposeCurve(ArkUI_CurveHandle curveHandle);
|
||||
|
||||
ArkUI_TransitionEffect* OH_ArkUI_CreateOpacityTransitionEffect(float opacity);
|
||||
ArkUI_TransitionEffect* OH_ArkUI_CreateTranslationTransitionEffect(ArkUI_TranslationOptions* translate);
|
||||
ArkUI_TransitionEffect* OH_ArkUI_CreateScaleTransitionEffect(ArkUI_ScaleOptions* scale);
|
||||
ArkUI_TransitionEffect* OH_ArkUI_CreateRotationTransitionEffect(ArkUI_RotationOptions* rotate);
|
||||
ArkUI_TransitionEffect* OH_ArkUI_CreateMovementTransitionEffect(ArkUI_TransitionEdge move);
|
||||
ArkUI_TransitionEffect* OH_ArkUI_CreateAsymmetricTransitionEffect(
|
||||
ArkUI_TransitionEffect* appear, ArkUI_TransitionEffect* disappear);
|
||||
void OH_ArkUI_TransitionEffect_Dispose(ArkUI_TransitionEffect* effect);
|
||||
int32_t OH_ArkUI_TransitionEffect_Combine(ArkUI_TransitionEffect* effect, ArkUI_TransitionEffect* combine);
|
||||
int32_t OH_ArkUI_TransitionEffect_SetAnimation(ArkUI_TransitionEffect* effect, ArkUI_AnimateOption* animation);
|
||||
#ifdef __cplusplus
|
||||
};
|
||||
#endif
|
||||
|
@ -1597,6 +1597,8 @@ typedef enum {
|
||||
*
|
||||
*/
|
||||
NODE_ACCESSIBILITY_VALUE = 91,
|
||||
|
||||
|
||||
/**
|
||||
* @brief 定义控制组件扩展其安全区域,支持属性设置,属性重置和属性获取。
|
||||
*
|
||||
@ -1624,6 +1626,18 @@ typedef enum {
|
||||
*/
|
||||
NODE_VISIBLE_AREA_CHANGE_RADIO = 93,
|
||||
|
||||
/**
|
||||
* @brief 定义组件插入和删除时显示过渡动效,支持属性设置,属性获取。
|
||||
*
|
||||
* 属性设置方法{@link ArkUI_AttributeItem}参数格式: \n
|
||||
* .object:参数类型为{@link ArkUI_TransitionEffect}。 \n
|
||||
* \n
|
||||
* 属性获取方法返回值{@link ArkUI_AttributeItem}格式: \n
|
||||
* .object:参数类型为{@link ArkUI_TransitionEffect}。 \n
|
||||
*
|
||||
*/
|
||||
NODE_TRANSITION = 94,
|
||||
|
||||
/**
|
||||
* @brief Defines the text content attribute, which can be set, reset, and obtained as required through APIs.
|
||||
*
|
||||
@ -7093,6 +7107,7 @@ int32_t OH_ArkUI_NodeUtils_GetPositionWithTranslateInScreen(ArkUI_NodeHandle nod
|
||||
* @since 12
|
||||
*/
|
||||
int32_t OH_ArkUI_List_CloseAllSwipeActions(ArkUI_NodeHandle node, void* userData, void (*onFinish)(void* userData));
|
||||
|
||||
#ifdef __cplusplus
|
||||
};
|
||||
#endif
|
||||
|
@ -1947,6 +1947,31 @@ typedef enum {
|
||||
ARKUI_SAFE_AREA_EDGE_END = 1 << 3,
|
||||
} ArkUI_SafeAreaEdge;
|
||||
|
||||
typedef struct {
|
||||
float x;
|
||||
float y;
|
||||
float z;
|
||||
} ArkUI_TranslationOptions;
|
||||
|
||||
typedef struct {
|
||||
float x;
|
||||
float y;
|
||||
float z;
|
||||
float centerX;
|
||||
float centerY;
|
||||
} ArkUI_ScaleOptions;
|
||||
|
||||
typedef struct {
|
||||
float x;
|
||||
float y;
|
||||
float z;
|
||||
float angle;
|
||||
float centerX;
|
||||
float centerY;
|
||||
float centerZ;
|
||||
float perspective;
|
||||
} ArkUI_RotationOptions;
|
||||
|
||||
/**
|
||||
* @brief Creates a size constraint.
|
||||
*
|
||||
|
@ -47,6 +47,7 @@ struct ArkUI_Node {
|
||||
void* customEventListeners = nullptr;
|
||||
void* altDrawableDescriptor = nullptr;
|
||||
ArkUI_AttributeItem* areaChangeRadio = nullptr;
|
||||
void* transitionOption = nullptr;
|
||||
};
|
||||
|
||||
struct ArkUI_Context {
|
||||
|
112
interfaces/native/node/node_transition.cpp
Normal file
112
interfaces/native/node/node_transition.cpp
Normal file
@ -0,0 +1,112 @@
|
||||
/*
|
||||
* 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 "node_transition.h"
|
||||
|
||||
#include "native_type.h"
|
||||
|
||||
#include "base/utils/utils.h"
|
||||
|
||||
namespace OHOS::Ace::TransitionModel {
|
||||
|
||||
ArkUITransitionEffectOption* CreateEffectOption()
|
||||
{
|
||||
ArkUITransitionEffectOption* effectOption = new ArkUITransitionEffectOption;
|
||||
effectOption->appear = nullptr;
|
||||
effectOption->disappear = nullptr;
|
||||
effectOption->combine = nullptr;
|
||||
return effectOption;
|
||||
}
|
||||
|
||||
ArkUITransitionEffectOption* ConvertToEffectOption(ArkUI_TransitionEffect* effectOption)
|
||||
{
|
||||
CHECK_NULL_RETURN(effectOption, nullptr);
|
||||
auto* toEffectOption = CreateEffectOption();
|
||||
toEffectOption->type = effectOption->type;
|
||||
switch (effectOption->type) {
|
||||
case ARKUI_TRANSITION_EFFECT_OPACITY: {
|
||||
toEffectOption->opacity = effectOption->opacity;
|
||||
break;
|
||||
}
|
||||
case ARKUI_TRANSITION_EFFECT_TRANSLATE: {
|
||||
CHECK_NULL_RETURN(effectOption->translate, nullptr);
|
||||
toEffectOption->translate.x = effectOption->translate->x;
|
||||
toEffectOption->translate.y = effectOption->translate->y;
|
||||
toEffectOption->translate.z = effectOption->translate->z;
|
||||
break;
|
||||
}
|
||||
case ARKUI_TRANSITION_EFFECT_SCALE: {
|
||||
CHECK_NULL_RETURN(effectOption->scale, nullptr);
|
||||
toEffectOption->scale.x = effectOption->scale->x;
|
||||
toEffectOption->scale.y = effectOption->scale->y;
|
||||
toEffectOption->scale.z = effectOption->scale->z;
|
||||
toEffectOption->scale.centerX = effectOption->scale->centerX;
|
||||
toEffectOption->scale.centerY = effectOption->scale->centerY;
|
||||
break;
|
||||
}
|
||||
case ARKUI_TRANSITION_EFFECT_ROTATE: {
|
||||
CHECK_NULL_RETURN(effectOption->rotate, nullptr);
|
||||
toEffectOption->rotate.x = effectOption->rotate->x;
|
||||
toEffectOption->rotate.y = effectOption->rotate->y;
|
||||
toEffectOption->rotate.z = effectOption->rotate->z;
|
||||
toEffectOption->rotate.angle = effectOption->rotate->angle;
|
||||
toEffectOption->rotate.centerX = effectOption->rotate->centerX;
|
||||
toEffectOption->rotate.centerY = effectOption->rotate->centerY;
|
||||
toEffectOption->rotate.centerZ = effectOption->rotate->centerZ;
|
||||
toEffectOption->rotate.perspective = effectOption->rotate->perspective;
|
||||
break;
|
||||
}
|
||||
case ARKUI_TRANSITION_EFFECT_MOVE: {
|
||||
toEffectOption->move = effectOption->move;
|
||||
break;
|
||||
}
|
||||
case ARKUI_TRANSITION_EFFECT_ASYMMETRIC: {
|
||||
if (effectOption->appear) {
|
||||
auto* appear = ConvertToEffectOption(effectOption->appear);
|
||||
toEffectOption->appear = appear;
|
||||
}
|
||||
if (effectOption->disappear) {
|
||||
auto* disappear = ConvertToEffectOption(effectOption->disappear);
|
||||
toEffectOption->disappear = disappear;
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (effectOption->animation) {
|
||||
toEffectOption->hasAnimation = true;
|
||||
toEffectOption->animation.duration = effectOption->animation->duration;
|
||||
toEffectOption->animation.tempo = effectOption->animation->tempo;
|
||||
toEffectOption->animation.curve = effectOption->animation->curve;
|
||||
toEffectOption->animation.delay = effectOption->animation->delay;
|
||||
toEffectOption->animation.iterations = effectOption->animation->iterations;
|
||||
toEffectOption->animation.playMode = effectOption->animation->playMode;
|
||||
if (effectOption->animation->expectedFrameRateRange) {
|
||||
toEffectOption->animation.expectedFrameRateRange =
|
||||
reinterpret_cast<ArkUIExpectedFrameRateRange*>(effectOption->animation->expectedFrameRateRange);
|
||||
} else {
|
||||
toEffectOption->animation.expectedFrameRateRange = nullptr;
|
||||
}
|
||||
} else {
|
||||
toEffectOption->hasAnimation = false;
|
||||
}
|
||||
|
||||
if (effectOption->combine) {
|
||||
toEffectOption->combine = ConvertToEffectOption(effectOption->combine);
|
||||
}
|
||||
effectOption->toEffectOption = toEffectOption;
|
||||
return toEffectOption;
|
||||
}
|
||||
} // namespace OHOS::Ace::TransitionModel
|
59
interfaces/native/node/node_transition.h
Normal file
59
interfaces/native/node/node_transition.h
Normal file
@ -0,0 +1,59 @@
|
||||
/*
|
||||
* 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 NODE_TRANSITION_H
|
||||
#define NODE_TRANSITION_H
|
||||
|
||||
#include "animate_impl.h"
|
||||
#include "native_node.h"
|
||||
#include "native_type.h"
|
||||
|
||||
#include "frameworks/core/interfaces/arkoala/arkoala_api.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
typedef enum {
|
||||
ARKUI_TRANSITION_EFFECT_OPACITY = 0,
|
||||
ARKUI_TRANSITION_EFFECT_TRANSLATE,
|
||||
ARKUI_TRANSITION_EFFECT_SCALE,
|
||||
ARKUI_TRANSITION_EFFECT_ROTATE,
|
||||
ARKUI_TRANSITION_EFFECT_MOVE,
|
||||
ARKUI_TRANSITION_EFFECT_ASYMMETRIC,
|
||||
} ArkUI_TransitionEffectType;
|
||||
|
||||
struct ArkUI_TransitionEffect {
|
||||
ArkUI_TransitionEffectType type;
|
||||
float opacity;
|
||||
ArkUI_TranslationOptions* translate;
|
||||
ArkUI_ScaleOptions* scale;
|
||||
ArkUI_RotationOptions* rotate;
|
||||
ArkUI_TransitionEdge move;
|
||||
ArkUI_TransitionEffect* appear;
|
||||
ArkUI_TransitionEffect* disappear;
|
||||
ArkUI_TransitionEffect* combine;
|
||||
ArkUI_AnimateOption* animation;
|
||||
ArkUITransitionEffectOption* toEffectOption;
|
||||
};
|
||||
|
||||
#ifdef __cplusplus
|
||||
};
|
||||
#endif
|
||||
|
||||
namespace OHOS::Ace::TransitionModel {
|
||||
ArkUITransitionEffectOption* ConvertToEffectOption(ArkUI_TransitionEffect* effectOption);
|
||||
}; // namespace OHOS::Ace::TransitionModel
|
||||
|
||||
#endif
|
141
interfaces/native/node/node_transition_imp.cpp
Normal file
141
interfaces/native/node/node_transition_imp.cpp
Normal file
@ -0,0 +1,141 @@
|
||||
/*
|
||||
* 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 <algorithm>
|
||||
#include <cstddef>
|
||||
|
||||
#include "native_type.h"
|
||||
#include "node/node_transition.h"
|
||||
|
||||
#include "base/utils/utils.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
ArkUI_TransitionEffect* OH_ArkUI_CreateOpacityTransitionEffect(float opacity)
|
||||
{
|
||||
ArkUI_TransitionEffect* option = new ArkUI_TransitionEffect { ARKUI_TRANSITION_EFFECT_OPACITY };
|
||||
option->translate = nullptr;
|
||||
option->scale = nullptr;
|
||||
option->rotate = nullptr;
|
||||
option->appear = nullptr;
|
||||
option->disappear = nullptr;
|
||||
option->combine = nullptr;
|
||||
option->opacity = std::clamp(opacity, 0.0f, 1.0f);
|
||||
return option;
|
||||
}
|
||||
|
||||
ArkUI_TransitionEffect* OH_ArkUI_CreateTranslationTransitionEffect(ArkUI_TranslationOptions* translate)
|
||||
{
|
||||
CHECK_NULL_RETURN(translate, nullptr);
|
||||
ArkUI_TransitionEffect* option = new ArkUI_TransitionEffect { ARKUI_TRANSITION_EFFECT_TRANSLATE };
|
||||
option->scale = nullptr;
|
||||
option->rotate = nullptr;
|
||||
option->appear = nullptr;
|
||||
option->disappear = nullptr;
|
||||
option->combine = nullptr;
|
||||
option->translate = translate;
|
||||
return option;
|
||||
}
|
||||
|
||||
ArkUI_TransitionEffect* OH_ArkUI_CreateScaleTransitionEffect(ArkUI_ScaleOptions* scale)
|
||||
{
|
||||
CHECK_NULL_RETURN(scale, nullptr);
|
||||
ArkUI_TransitionEffect* option = new ArkUI_TransitionEffect { ARKUI_TRANSITION_EFFECT_SCALE };
|
||||
option->translate = nullptr;
|
||||
option->rotate = nullptr;
|
||||
option->appear = nullptr;
|
||||
option->disappear = nullptr;
|
||||
option->combine = nullptr;
|
||||
option->scale = scale;
|
||||
return option;
|
||||
}
|
||||
|
||||
ArkUI_TransitionEffect* OH_ArkUI_CreateRotationTransitionEffect(ArkUI_RotationOptions* rotate)
|
||||
{
|
||||
CHECK_NULL_RETURN(rotate, nullptr);
|
||||
ArkUI_TransitionEffect* option = new ArkUI_TransitionEffect { ARKUI_TRANSITION_EFFECT_ROTATE };
|
||||
option->translate = nullptr;
|
||||
option->scale = nullptr;
|
||||
option->appear = nullptr;
|
||||
option->disappear = nullptr;
|
||||
option->combine = nullptr;
|
||||
option->rotate = rotate;
|
||||
return option;
|
||||
}
|
||||
|
||||
ArkUI_TransitionEffect* OH_ArkUI_CreateMovementTransitionEffect(ArkUI_TransitionEdge move)
|
||||
{
|
||||
if (move < ARKUI_TRANSITION_EDGE_TOP || move > ARKUI_TRANSITION_EDGE_END) {
|
||||
move = ARKUI_TRANSITION_EDGE_START;
|
||||
}
|
||||
ArkUI_TransitionEffect* option = new ArkUI_TransitionEffect { ARKUI_TRANSITION_EFFECT_MOVE };
|
||||
option->translate = nullptr;
|
||||
option->scale = nullptr;
|
||||
option->rotate = nullptr;
|
||||
option->appear = nullptr;
|
||||
option->disappear = nullptr;
|
||||
option->combine = nullptr;
|
||||
option->move = move;
|
||||
return option;
|
||||
}
|
||||
|
||||
ArkUI_TransitionEffect* OH_ArkUI_CreateAsymmetricTransitionEffect(
|
||||
ArkUI_TransitionEffect* appear, ArkUI_TransitionEffect* disappear)
|
||||
{
|
||||
if (!appear && !disappear) {
|
||||
return nullptr;
|
||||
}
|
||||
ArkUI_TransitionEffect* option = new ArkUI_TransitionEffect { ARKUI_TRANSITION_EFFECT_ASYMMETRIC };
|
||||
option->translate = nullptr;
|
||||
option->scale = nullptr;
|
||||
option->rotate = nullptr;
|
||||
option->combine = nullptr;
|
||||
option->appear = appear;
|
||||
option->disappear = disappear;
|
||||
return option;
|
||||
}
|
||||
|
||||
void OH_ArkUI_TransitionEffect_Dispose(ArkUI_TransitionEffect* option)
|
||||
{
|
||||
CHECK_NULL_VOID(option);
|
||||
if (option->toEffectOption) {
|
||||
delete option->toEffectOption;
|
||||
option->toEffectOption = nullptr;
|
||||
}
|
||||
delete option;
|
||||
}
|
||||
|
||||
int32_t OH_ArkUI_TransitionEffect_Combine(ArkUI_TransitionEffect* option, ArkUI_TransitionEffect* combine)
|
||||
{
|
||||
CHECK_NULL_RETURN(option, ARKUI_ERROR_CODE_PARAM_INVALID);
|
||||
auto* currentOption = option;
|
||||
while (currentOption->combine) {
|
||||
currentOption = currentOption->combine;
|
||||
}
|
||||
currentOption->combine = combine;
|
||||
return ARKUI_ERROR_CODE_NO_ERROR;
|
||||
}
|
||||
|
||||
int32_t OH_ArkUI_TransitionEffect_SetAnimation(ArkUI_TransitionEffect* option, ArkUI_AnimateOption* animation)
|
||||
{
|
||||
CHECK_NULL_RETURN(option, ARKUI_ERROR_CODE_PARAM_INVALID);
|
||||
option->animation = animation;
|
||||
return ARKUI_ERROR_CODE_NO_ERROR;
|
||||
}
|
||||
#ifdef __cplusplus
|
||||
};
|
||||
#endif
|
@ -27,6 +27,7 @@
|
||||
#include "native_type.h"
|
||||
#include "node_extened.h"
|
||||
#include "node_model.h"
|
||||
#include "node_transition.h"
|
||||
#include "styled_string.h"
|
||||
#include "waterflow_section_option.h"
|
||||
#include "list_option.h"
|
||||
@ -3691,6 +3692,23 @@ const ArkUI_AttributeItem* GetExpandSafeArea(ArkUI_NodeHandle node)
|
||||
g_numberValues[NUM_1].u32 = values[NUM_1];
|
||||
return &g_attributeItem;
|
||||
}
|
||||
|
||||
int32_t SetTransition(ArkUI_NodeHandle node, const ArkUI_AttributeItem* item)
|
||||
{
|
||||
CHECK_NULL_RETURN(item->object, ERROR_CODE_PARAM_INVALID);
|
||||
auto fullImpl = GetFullImpl();
|
||||
node->transitionOption = item->object;
|
||||
auto effectOption = reinterpret_cast<ArkUI_TransitionEffect*>(item->object);
|
||||
auto toEffectOption = OHOS::Ace::TransitionModel::ConvertToEffectOption(effectOption);
|
||||
fullImpl->getNodeModifiers()->getCommonModifier()->setTransition(node->uiNodeHandle, toEffectOption);
|
||||
return ERROR_CODE_NO_ERROR;
|
||||
}
|
||||
|
||||
const ArkUI_AttributeItem* GetTransition(ArkUI_NodeHandle node)
|
||||
{
|
||||
g_attributeItem.object = node->transitionOption;
|
||||
return &g_attributeItem;
|
||||
}
|
||||
// Text
|
||||
int32_t SetFontColor(ArkUI_NodeHandle node, const ArkUI_AttributeItem* item)
|
||||
{
|
||||
@ -12519,6 +12537,7 @@ int32_t SetCommonAttribute(ArkUI_NodeHandle node, int32_t subTypeId, const ArkUI
|
||||
SetAccessibilityValue,
|
||||
SetExpandSafeArea,
|
||||
SetAreaChangeRatio,
|
||||
SetTransition,
|
||||
};
|
||||
if (subTypeId >= sizeof(setters) / sizeof(Setter*)) {
|
||||
TAG_LOGE(AceLogTag::ACE_NATIVE_NODE, "common node attribute: %{public}d NOT IMPLEMENT", subTypeId);
|
||||
@ -12624,6 +12643,7 @@ const ArkUI_AttributeItem* GetCommonAttribute(ArkUI_NodeHandle node, int32_t sub
|
||||
GetAccessibilityValue,
|
||||
GetExpandSafeArea,
|
||||
GetAreaChangeRatio,
|
||||
GetTransition,
|
||||
};
|
||||
if (subTypeId >= sizeof(getters) / sizeof(Getter*)) {
|
||||
TAG_LOGE(AceLogTag::ACE_NATIVE_NODE, "common node attribute: %{public}d NOT IMPLEMENT", subTypeId);
|
||||
@ -12733,6 +12753,7 @@ void ResetCommonAttribute(ArkUI_NodeHandle node, int32_t subTypeId)
|
||||
ResetAccessibilityValue,
|
||||
ResetExpandSafeArea,
|
||||
ResetAreaChangeRatio,
|
||||
nullptr,
|
||||
};
|
||||
if (subTypeId >= sizeof(resetters) / sizeof(Setter*)) {
|
||||
TAG_LOGE(AceLogTag::ACE_NATIVE_NODE, "common node attribute: %{public}d NOT IMPLEMENT", subTypeId);
|
||||
|
@ -486,6 +486,7 @@ ohos_unittest("native_node_napi_test") {
|
||||
"$ace_root/interfaces/native/node/native_node_napi.cpp",
|
||||
"$ace_root/interfaces/native/node/node_extened.cpp",
|
||||
"$ace_root/interfaces/native/node/node_model.cpp",
|
||||
"$ace_root/interfaces/native/node/node_transition.cpp",
|
||||
"$ace_root/interfaces/native/node/style_modifier.cpp",
|
||||
"$ace_root/test/mock/adapter/mock_log_wrapper.cpp",
|
||||
"native_node_napi_test.cpp",
|
||||
|
Loading…
x
Reference in New Issue
Block a user