mirror of
https://gitee.com/openharmony/arkui_ace_engine
synced 2024-11-23 15:10:30 +00:00
[NDK] animateTo
Signed-off-by:lisitaolisitao3@huawei.com Signed-off-by: lisitao <lisitao3@huawei.com> Change-Id: I86f052e43df2405aaa35ce7991b8a363350502a8
This commit is contained in:
parent
645823ce15
commit
664514e746
@ -31,7 +31,7 @@ extern "C" {
|
||||
// increased as well.
|
||||
#define ARKUI_NODE_API_VERSION 90
|
||||
|
||||
#define ARKUI_BASIC_API_VERSION 7
|
||||
#define ARKUI_BASIC_API_VERSION 8
|
||||
#define ARKUI_EXTENDED_API_VERSION 7
|
||||
#define ARKUI_NODE_GRAPHICS_API_VERSION 5
|
||||
#define ARKUI_NODE_MODIFIERS_API_VERSION 7
|
||||
@ -852,6 +852,29 @@ struct ArkUICustomNodeEvent {
|
||||
ArkUI_Int32 data[8];
|
||||
};
|
||||
|
||||
struct ArkUIExpectedFrameRateRange {
|
||||
ArkUI_Uint32 min;
|
||||
ArkUI_Uint32 max;
|
||||
ArkUI_Uint32 expected;
|
||||
};
|
||||
|
||||
struct ArkUIAnimateOption {
|
||||
ArkUI_Uint32 duration;
|
||||
ArkUI_Float32 tempo;
|
||||
ArkUI_Int32 curve;
|
||||
ArkUI_Int32 delay;
|
||||
ArkUI_Int32 iterations;
|
||||
ArkUI_Int32 playMode;
|
||||
ArkUIExpectedFrameRateRange* expectedFrameRateRange;
|
||||
void* onFinishCallback;
|
||||
void* user;
|
||||
ArkUI_Int32 finishCallbackType;
|
||||
};
|
||||
|
||||
struct ArkUIContext {
|
||||
ArkUI_Int32 id;
|
||||
};
|
||||
|
||||
struct ArkUICommonModifier {
|
||||
void (*setBackgroundColor)(ArkUINodeHandle node, ArkUI_Uint32 color);
|
||||
void (*resetBackgroundColor)(ArkUINodeHandle node);
|
||||
@ -3180,6 +3203,7 @@ struct ArkUIAnimation {
|
||||
void (*openImplicitAnimation)(
|
||||
ArkUIVMContext vmContext, ArkUI_Int32 curve, ArkUI_Float32* options, ArkUI_Int32 callbackId);
|
||||
void (*closeImplicitAnimation)();
|
||||
void (*animateTo)(ArkUIContext* context, ArkUIAnimateOption option, void* event, void* userData);
|
||||
};
|
||||
|
||||
struct ArkUINavigation {
|
||||
|
@ -59,6 +59,7 @@ template("ace_core_interfaces_native_node") {
|
||||
"node/navigation_modifier.cpp",
|
||||
"node/navigator_modifier.cpp",
|
||||
"node/node_adapter_impl.cpp",
|
||||
"node/node_animate.cpp",
|
||||
"node/node_api.cpp",
|
||||
"node/node_canvas_modifier.cpp",
|
||||
"node/node_checkbox_modifier.cpp",
|
||||
|
146
frameworks/core/interfaces/native/node/node_animate.cpp
Normal file
146
frameworks/core/interfaces/native/node/node_animate.cpp
Normal file
@ -0,0 +1,146 @@
|
||||
/*
|
||||
* 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/node_animate.h"
|
||||
|
||||
#include "base/utils/utils.h"
|
||||
#include "core/common/ace_engine.h"
|
||||
#include "core/common/container.h"
|
||||
|
||||
namespace OHOS::Ace::NG::ViewAnimate {
|
||||
namespace {
|
||||
const std::vector<OHOS::Ace::RefPtr<OHOS::Ace::Curve>> CURVES_LIST = {
|
||||
OHOS::Ace::Curves::LINEAR,
|
||||
OHOS::Ace::Curves::EASE,
|
||||
OHOS::Ace::Curves::EASE_IN,
|
||||
OHOS::Ace::Curves::EASE_OUT,
|
||||
OHOS::Ace::Curves::EASE_IN_OUT,
|
||||
OHOS::Ace::Curves::FAST_OUT_SLOW_IN,
|
||||
OHOS::Ace::Curves::LINEAR_OUT_SLOW_IN,
|
||||
OHOS::Ace::Curves::FAST_OUT_LINEAR_IN,
|
||||
OHOS::Ace::Curves::EXTREME_DECELERATION,
|
||||
OHOS::Ace::Curves::SHARP,
|
||||
OHOS::Ace::Curves::RHYTHM,
|
||||
OHOS::Ace::Curves::SMOOTH,
|
||||
OHOS::Ace::Curves::FRICTION,
|
||||
};
|
||||
|
||||
const std::vector<AnimationDirection> DIRECTION_LIST = {
|
||||
AnimationDirection::NORMAL,
|
||||
AnimationDirection::REVERSE,
|
||||
AnimationDirection::ALTERNATE,
|
||||
AnimationDirection::ALTERNATE_REVERSE,
|
||||
};
|
||||
} // namespace
|
||||
|
||||
void AnimateToInner(ArkUIContext* context, AnimationOption& option, const std::function<void()>& animateToFunc,
|
||||
const std::function<void()>& onFinishFunc, bool immediately)
|
||||
{
|
||||
CHECK_NULL_VOID(context);
|
||||
auto containerSafely = Container::GetContainer(context->id);
|
||||
CHECK_NULL_VOID(containerSafely);
|
||||
auto pipelineContext = containerSafely->GetPipelineContext();
|
||||
CHECK_NULL_VOID(pipelineContext);
|
||||
|
||||
ACE_SCOPED_TRACE("duration:%d, curve:%s, iteration:%d", option.GetDuration(), option.GetCurve()->ToString().c_str(),
|
||||
option.GetIteration());
|
||||
auto triggerId = context->id;
|
||||
AceEngine::Get().NotifyContainers([triggerId, option](const RefPtr<Container>& container) {
|
||||
auto context = container->GetPipelineContext();
|
||||
if (!context) {
|
||||
// pa container do not have pipeline context.
|
||||
return;
|
||||
}
|
||||
if (!container->GetSettings().usingSharedRuntime) {
|
||||
return;
|
||||
}
|
||||
if (!container->IsFRSCardContainer() && !container->WindowIsShow()) {
|
||||
return;
|
||||
}
|
||||
ContainerScope scope(container->GetInstanceId());
|
||||
context->FlushBuild();
|
||||
if (context->GetInstanceId() == triggerId) {
|
||||
return;
|
||||
}
|
||||
context->PrepareOpenImplicitAnimation();
|
||||
});
|
||||
pipelineContext->OpenImplicitAnimation(option, option.GetCurve(), onFinishFunc);
|
||||
pipelineContext->SetSyncAnimationOption(option);
|
||||
// Execute the function.
|
||||
animateToFunc();
|
||||
pipelineContext->FlushOnceVsyncTask();
|
||||
AceEngine::Get().NotifyContainers([triggerId](const RefPtr<Container>& container) {
|
||||
auto context = container->GetPipelineContext();
|
||||
if (!context) {
|
||||
// pa container do not have pipeline context.
|
||||
return;
|
||||
}
|
||||
if (!container->GetSettings().usingSharedRuntime) {
|
||||
return;
|
||||
}
|
||||
if (!container->IsFRSCardContainer() && !container->WindowIsShow()) {
|
||||
return;
|
||||
}
|
||||
ContainerScope scope(container->GetInstanceId());
|
||||
context->FlushBuild();
|
||||
if (context->GetInstanceId() == triggerId) {
|
||||
return;
|
||||
}
|
||||
context->PrepareCloseImplicitAnimation();
|
||||
});
|
||||
pipelineContext->CloseImplicitAnimation();
|
||||
pipelineContext->SetSyncAnimationOption(AnimationOption());
|
||||
if (immediately) {
|
||||
pipelineContext->FlushMessages();
|
||||
} else {
|
||||
pipelineContext->RequestFrame();
|
||||
}
|
||||
}
|
||||
|
||||
void AnimateTo(ArkUIContext* context, ArkUIAnimateOption option, void (*event)(void* userData), void* user)
|
||||
{
|
||||
AnimationOption animationOption;
|
||||
animationOption.SetDuration(NearZero(static_cast<double>(option.tempo)) ? 0 : option.duration);
|
||||
animationOption.SetTempo(option.tempo);
|
||||
animationOption.SetCurve(CURVES_LIST[option.curve > CURVES_LIST.size() ? 0 : option.curve]);
|
||||
animationOption.SetDelay(option.delay);
|
||||
animationOption.SetIteration(option.iterations);
|
||||
animationOption.SetAnimationDirection(
|
||||
DIRECTION_LIST[option.playMode > DIRECTION_LIST.size() ? 0 : option.playMode]);
|
||||
animationOption.SetFinishCallbackType(static_cast<FinishCallbackType>(option.finishCallbackType));
|
||||
|
||||
if (option.expectedFrameRateRange) {
|
||||
RefPtr<FrameRateRange> frameRateRange = AceType::MakeRefPtr<FrameRateRange>(option.expectedFrameRateRange->min,
|
||||
option.expectedFrameRateRange->max, option.expectedFrameRateRange->expected);
|
||||
animationOption.SetFrameRateRange(frameRateRange);
|
||||
}
|
||||
|
||||
auto onEvent = [event, user]() {
|
||||
if (event) {
|
||||
event(user);
|
||||
}
|
||||
};
|
||||
|
||||
auto onFinishEvent = [option]() {
|
||||
if (option.onFinishCallback) {
|
||||
auto* onFinishFunc = reinterpret_cast<void (*)(void*)>(option.onFinishCallback);
|
||||
onFinishFunc(option.user);
|
||||
}
|
||||
};
|
||||
|
||||
AnimateToInner(context, animationOption, onEvent, onFinishEvent, false);
|
||||
}
|
||||
|
||||
} // namespace OHOS::Ace::NG::ViewAnimate
|
31
frameworks/core/interfaces/native/node/node_animate.h
Normal file
31
frameworks/core/interfaces/native/node/node_animate.h
Normal file
@ -0,0 +1,31 @@
|
||||
/*
|
||||
* 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_NODE_ANIMATE_H
|
||||
#define FOUNDATION_ACE_FRAMEWORKS_CORE_INTERFACES_NODE_ANIMATE_H
|
||||
|
||||
#include "core/interfaces/arkoala/arkoala_api.h"
|
||||
#include "core/interfaces/native/node/node_utils.h"
|
||||
|
||||
namespace OHOS::Ace::NG::ViewAnimate {
|
||||
|
||||
void AnimateToInner(AnimationOption& option, const std::function<void()>& animateToFunc,
|
||||
const std::function<void()>& onFinishFunc, bool immediately);
|
||||
|
||||
void AnimateTo(ArkUIContext* context, ArkUIAnimateOption option, void (*event)(void* userData), void* user);
|
||||
|
||||
} // namespace OHOS::Ace::NG::ViewAnimate
|
||||
|
||||
#endif // FOUNDATION_ACE_FRAMEWORKS_CORE_INTERFACES_NODE_ANIMATE_H
|
@ -29,6 +29,7 @@
|
||||
#include "core/interfaces/native/node/calendar_picker_modifier.h"
|
||||
#include "core/interfaces/native/node/canvas_rendering_context_2d_modifier.h"
|
||||
#include "core/interfaces/native/node/custom_dialog_model.h"
|
||||
#include "core/interfaces/native/node/node_animate.h"
|
||||
#include "core/interfaces/native/node/node_canvas_modifier.h"
|
||||
#include "core/interfaces/native/node/node_adapter_impl.h"
|
||||
#include "core/interfaces/native/node/node_checkbox_modifier.h"
|
||||
@ -1006,12 +1007,18 @@ const ArkUIGraphicsAPI* GetGraphicsAPI()
|
||||
return &api;
|
||||
}
|
||||
|
||||
void AnimateTo(ArkUIContext* context, ArkUIAnimateOption option, void* event, void* user)
|
||||
{
|
||||
ViewAnimate::AnimateTo(context, option, reinterpret_cast<void (*)(void*)>(event), user);
|
||||
}
|
||||
|
||||
const ArkUIAnimation* GetAnimationAPI()
|
||||
{
|
||||
static const ArkUIAnimation modifier = {
|
||||
nullptr,
|
||||
nullptr,
|
||||
nullptr,
|
||||
AnimateTo,
|
||||
};
|
||||
return &modifier;
|
||||
}
|
||||
|
@ -49,6 +49,7 @@ ohos_shared_library("ace_ndk") {
|
||||
"//foundation/arkui/ace_engine/frameworks/core/components/xcomponent/native_interface_xcomponent_impl.cpp",
|
||||
"event/ui_input_event.cpp",
|
||||
"native_interface_xcomponent.cpp",
|
||||
"node/animate_impl.cpp",
|
||||
"node/dialog_model.cpp",
|
||||
"node/event_converter.cpp",
|
||||
"node/gesture_impl.cpp",
|
||||
@ -56,6 +57,7 @@ ohos_shared_library("ace_ndk") {
|
||||
"node/native_node_extented.cpp",
|
||||
"node/native_node_napi.cpp",
|
||||
"node/node_adapter_impl.cpp",
|
||||
"node/node_animate.cpp",
|
||||
"node/node_extened.cpp",
|
||||
"node/node_model.cpp",
|
||||
"node/style_modifier.cpp",
|
||||
|
@ -562,5 +562,73 @@
|
||||
{
|
||||
"first_introduced": "12",
|
||||
"name": "OH_ArkUI_NodeAdapterEvent_SetNodeId"
|
||||
}
|
||||
},
|
||||
{
|
||||
"first_introduced": "12",
|
||||
"name": "OH_ArkUI_AnimateOption_Create"
|
||||
},
|
||||
{
|
||||
"first_introduced": "12",
|
||||
"name": "OH_ArkUI_AnimateOption_Dispose"
|
||||
},
|
||||
{
|
||||
"first_introduced": "12",
|
||||
"name": "OH_ArkUI_AnimateOption_GetDuration"
|
||||
},
|
||||
{
|
||||
"first_introduced": "12",
|
||||
"name": "OH_ArkUI_AnimateOption_GetTempo"
|
||||
},
|
||||
{
|
||||
"first_introduced": "12",
|
||||
"name": "OH_ArkUI_AnimateOption_GetCurve"
|
||||
},
|
||||
{
|
||||
"first_introduced": "12",
|
||||
"name": "OH_ArkUI_AnimateOption_GetDelay"
|
||||
},
|
||||
{
|
||||
"first_introduced": "12",
|
||||
"name": "OH_ArkUI_AnimateOption_GetIterations"
|
||||
},
|
||||
{
|
||||
"first_introduced": "12",
|
||||
"name": "OH_ArkUI_AnimateOption_GetPlayMode"
|
||||
},
|
||||
{
|
||||
"first_introduced": "12",
|
||||
"name": "OH_ArkUI_AnimateOption_GetExpectedFrameRateRange"
|
||||
},
|
||||
{
|
||||
"first_introduced": "12",
|
||||
"name": "OH_ArkUI_AnimateOption_SetDuration"
|
||||
},
|
||||
{
|
||||
"first_introduced": "12",
|
||||
"name": "OH_ArkUI_AnimateOption_SetTempo"
|
||||
},
|
||||
{
|
||||
"first_introduced": "12",
|
||||
"name": "OH_ArkUI_AnimateOption_SetCurve"
|
||||
},
|
||||
{
|
||||
"first_introduced": "12",
|
||||
"name": "OH_ArkUI_AnimateOption_SetDelay"
|
||||
},
|
||||
{
|
||||
"first_introduced": "12",
|
||||
"name": "OH_ArkUI_AnimateOption_SetIterations"
|
||||
},
|
||||
{
|
||||
"first_introduced": "12",
|
||||
"name": "OH_ArkUI_AnimateOption_SetPlayMode"
|
||||
},
|
||||
{
|
||||
"first_introduced": "12",
|
||||
"name": "OH_ArkUI_AnimateOption_SetExpectedFrameRateRange"
|
||||
},
|
||||
{
|
||||
"first_introduced": "12",
|
||||
"name": "OH_ArkUI_GetContextFromNapiValue"
|
||||
}
|
||||
]
|
||||
|
237
interfaces/native/native_animate.h
Normal file
237
interfaces/native/native_animate.h
Normal file
@ -0,0 +1,237 @@
|
||||
/*
|
||||
* 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 ARKUI_NATIVE_ANIMATE_H
|
||||
#define ARKUI_NATIVE_ANIMATE_H
|
||||
|
||||
#include <cstdint>
|
||||
|
||||
#include "native_type.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/**
|
||||
* @brief Defines the expected frame rate range of the animation.
|
||||
*
|
||||
* @since 12
|
||||
*/
|
||||
typedef struct {
|
||||
/** Expected minimum frame rate. */
|
||||
uint32_t min;
|
||||
/** Expected maximum frame rate. */
|
||||
uint32_t max;
|
||||
/** Expected optimal frame rate. */
|
||||
uint32_t expected;
|
||||
} ArkUI_ExpectedFrameRateRange;
|
||||
|
||||
/**
|
||||
* @brief Defines the callback type for when the animation playback is complete.
|
||||
*
|
||||
* @since 12
|
||||
*/
|
||||
typedef struct {
|
||||
/** Type of the <b>onFinish</b> callback. */
|
||||
ArkUI_FinishCallbackType type;
|
||||
/** Callback invoked when the animation playback is complete. */
|
||||
void (*callback)(void* userData);
|
||||
/** Custom type. */
|
||||
void* userData;
|
||||
} ArkUI_AnimateCompleteCallback;
|
||||
|
||||
/**
|
||||
* @brief Defines the animation configuration.
|
||||
*
|
||||
* @since 12
|
||||
*/
|
||||
typedef struct ArkUI_AnimateOption ArkUI_AnimateOption;
|
||||
|
||||
/**
|
||||
* @brief Implements the native animation APIs provided by ArkUI.
|
||||
*
|
||||
* @version 1
|
||||
* @since 12
|
||||
*/
|
||||
typedef struct {
|
||||
/**
|
||||
* @brief Defines an explicit animation.
|
||||
*
|
||||
* @note Make sure the component attributes to be set in the event closure have been set before.
|
||||
*
|
||||
* @param context UIContext。
|
||||
* @param option Indicates the pointer to an animation configuration.
|
||||
* @param update Indicates the animation closure. The system automatically inserts a transition animation
|
||||
* for the state change caused by the closure.
|
||||
* @param complete Indicates the callback to be invoked when the animation playback is complete.
|
||||
* @return Returns <b>0</b> if the operation is successful; returns <b>401</b> if a parameter error occurs.
|
||||
*/
|
||||
int32_t (*animateTo)(ArkUI_ContextHandle context, ArkUI_AnimateOption* option, ArkUI_ContextCallback* update,
|
||||
ArkUI_AnimateCompleteCallback* complete);
|
||||
} ArkUI_NativeAnimateAPI_1;
|
||||
|
||||
/**
|
||||
* @brief Defines the animation configuration.
|
||||
*
|
||||
* @since 12
|
||||
*/
|
||||
typedef struct ArkUI_AnimateOption ArkUI_AnimateOption;
|
||||
|
||||
/**
|
||||
* @brief Creates an animation configuration.
|
||||
*
|
||||
* @return Returns the pointer to the created animation configuration.
|
||||
* @since 12
|
||||
*/
|
||||
ArkUI_AnimateOption* OH_ArkUI_AnimateOption_Create();
|
||||
|
||||
/**
|
||||
* @brief Destroys an animation configuration.
|
||||
*
|
||||
* @since 12
|
||||
*/
|
||||
void OH_ArkUI_AnimateOption_Dispose(ArkUI_AnimateOption* option);
|
||||
|
||||
/**
|
||||
* @brief Obtains the animation duration, in milliseconds.
|
||||
*
|
||||
* @param option Indicates the pointer to an animation configuration.
|
||||
* @return Returns the duration.
|
||||
* @since 12
|
||||
*/
|
||||
uint32_t OH_ArkUI_AnimateOption_GetDuration(ArkUI_AnimateOption* option);
|
||||
|
||||
/**
|
||||
* @brief Obtains the animation playback speed.
|
||||
*
|
||||
* @param option Indicates the pointer to an animation configuration.
|
||||
* @return Returns the animation playback speed.
|
||||
* @since 12
|
||||
*/
|
||||
float OH_ArkUI_AnimateOption_GetTempo(ArkUI_AnimateOption* option);
|
||||
|
||||
/**
|
||||
* @brief Obtains the animation curve.
|
||||
*
|
||||
* @param option Indicates the pointer to an animation configuration.
|
||||
* @return Returns the animated curve.
|
||||
* @since 12
|
||||
*/
|
||||
ArkUI_AnimationCurve OH_ArkUI_AnimateOption_GetCurve(ArkUI_AnimateOption* option);
|
||||
|
||||
/**
|
||||
* @brief Obtains the animation delay, in milliseconds.
|
||||
*
|
||||
* @param option Indicates the pointer to an animation configuration.
|
||||
* @return Returns the animation delay.
|
||||
* @since 12
|
||||
*/
|
||||
int32_t OH_ArkUI_AnimateOption_GetDelay(ArkUI_AnimateOption* option);
|
||||
|
||||
/**
|
||||
* @brief Obtains the number of times that an animation is played.
|
||||
*
|
||||
* @param option Indicates the pointer to an animation configuration.
|
||||
* @return Returns the number of times that the animation is played.
|
||||
* @since 12
|
||||
*/
|
||||
int32_t OH_ArkUI_AnimateOption_GetIterations(ArkUI_AnimateOption* option);
|
||||
|
||||
/**
|
||||
* @brief Obtains the animation playback mode.
|
||||
*
|
||||
* @param option Indicates the pointer to an animation configuration.
|
||||
* @return Returns the animation playback mode.
|
||||
* @since 12
|
||||
*/
|
||||
ArkUI_AnimationPlayMode OH_ArkUI_AnimateOption_GetPlayMode(ArkUI_AnimateOption* option);
|
||||
|
||||
/**
|
||||
* @brief Obtains the expected frame rate range of an animation.
|
||||
*
|
||||
* @param option Indicates the pointer to an animation configuration.
|
||||
* @return Returns the expected frame rate range.
|
||||
* @since 12
|
||||
*/
|
||||
ArkUI_ExpectedFrameRateRange* OH_ArkUI_AnimateOption_GetExpectedFrameRateRange(ArkUI_AnimateOption* option);
|
||||
|
||||
/**
|
||||
* @brief Sets the animation duration.
|
||||
*
|
||||
* @param option Indicates the pointer to an animation configuration.
|
||||
* @param value Indicates the duration, in milliseconds.
|
||||
* @since 12
|
||||
*/
|
||||
void OH_ArkUI_AnimateOption_SetDuration(ArkUI_AnimateOption* option, int32_t value);
|
||||
|
||||
/**
|
||||
* @brief Sets the animation playback speed.
|
||||
*
|
||||
* @param option Indicates the pointer to an animation configuration.
|
||||
* @param value Indicates the animation playback speed.
|
||||
* @since 12
|
||||
*/
|
||||
void OH_ArkUI_AnimateOption_SetTempo(ArkUI_AnimateOption* option, float value);
|
||||
|
||||
/**
|
||||
* @brief Sets the animation curve.
|
||||
*
|
||||
* @param option Indicates the pointer to an animation configuration.
|
||||
* @param value Indicates the animated curve.
|
||||
* @since 12
|
||||
*/
|
||||
void OH_ArkUI_AnimateOption_SetCurve(ArkUI_AnimateOption* option, ArkUI_AnimationCurve value);
|
||||
|
||||
/**
|
||||
* @brief Sets the animation delay.
|
||||
*
|
||||
* @param option Indicates the pointer to an animation configuration.
|
||||
* @param value Indicates the animation delay.
|
||||
* @since 12
|
||||
*/
|
||||
void OH_ArkUI_AnimateOption_SetDelay(ArkUI_AnimateOption* option, int32_t value);
|
||||
|
||||
/**
|
||||
* @brief Sets the number of times that an animation is played.
|
||||
*
|
||||
* @param option Indicates the pointer to an animation configuration.
|
||||
* @param value Indicates the number of times that the animation is played.
|
||||
* @since 12
|
||||
*/
|
||||
void OH_ArkUI_AnimateOption_SetIterations(ArkUI_AnimateOption* option, int32_t value);
|
||||
|
||||
/**
|
||||
* @brief Sets the animation playback mode.
|
||||
*
|
||||
* @param option Indicates the pointer to an animation configuration.
|
||||
* @param value Indicates the animation playback mode.
|
||||
* @since 12
|
||||
*/
|
||||
void OH_ArkUI_AnimateOption_SetPlayMode(ArkUI_AnimateOption* option, ArkUI_AnimationPlayMode value);
|
||||
|
||||
/**
|
||||
* @brief Sets the expected frame rate range of an animation.
|
||||
*
|
||||
* @param option Indicates the pointer to an animation configuration.
|
||||
* @param value Indicates the expected frame rate range.
|
||||
* @since 12
|
||||
*/
|
||||
void OH_ArkUI_AnimateOption_SetExpectedFrameRateRange(ArkUI_AnimateOption* option, ArkUI_ExpectedFrameRateRange* value);
|
||||
|
||||
#ifdef __cplusplus
|
||||
};
|
||||
#endif
|
||||
|
||||
#endif // ARKUI_NATIVE_ANIMATE_H
|
@ -54,6 +54,8 @@ typedef enum {
|
||||
ARKUI_NATIVE_DIALOG,
|
||||
/** API related to gestures. For details, see the struct definition in <arkui/native_gesture.h>. */
|
||||
ARKUI_NATIVE_GESTURE,
|
||||
/** API related to animations. For details, see the struct definition in <arkui/native_animate.h>.*/
|
||||
ARKUI_NATIVE_ANIMATE,
|
||||
} ArkUI_NativeAPIVariantKind;
|
||||
|
||||
/**
|
||||
|
@ -45,6 +45,18 @@ extern "C" {
|
||||
|
||||
int32_t OH_ArkUI_GetNodeHandleFromNapiValue(napi_env env, napi_value value, ArkUI_NodeHandle* handle);
|
||||
|
||||
/**
|
||||
* @brief 获取ArkTS侧创建的UIContext对象映射到native侧的ArkUI_ContextHandle。
|
||||
*
|
||||
* @param env napi的环境指针。
|
||||
* @param value ArkTS侧创建的context对象。
|
||||
* @param context ArkUI_ContextHandle指针。
|
||||
* @return 0 - 成功。
|
||||
* 401 - 函数参数异常。
|
||||
* @since 12
|
||||
*/
|
||||
int32_t OH_ArkUI_GetContextFromNapiValue(napi_env env, napi_value value, ArkUI_ContextHandle* context);
|
||||
|
||||
#ifdef __cplusplus
|
||||
};
|
||||
#endif
|
||||
|
@ -83,6 +83,33 @@ typedef struct ArkUI_Node* ArkUI_NodeHandle;
|
||||
*/
|
||||
typedef struct ArkUI_NativeDialog* ArkUI_NativeDialogHandle;
|
||||
|
||||
/**
|
||||
* @brief 提供ArkUI native UI的上下文实例对象定义。
|
||||
*
|
||||
* @since 12
|
||||
*/
|
||||
|
||||
struct ArkUI_Context;
|
||||
|
||||
/**
|
||||
* @brief 定义ArkUI native UI的上下文实例对象指针定义。
|
||||
*
|
||||
* @since 12
|
||||
*/
|
||||
typedef struct ArkUI_Context* ArkUI_ContextHandle;
|
||||
|
||||
/**
|
||||
* @brief Defines the event callback type.
|
||||
*
|
||||
* @since 12
|
||||
*/
|
||||
typedef struct {
|
||||
/** Custom type. */
|
||||
void* userData;
|
||||
/** Event callback. */
|
||||
void (*callback)(void* userData);
|
||||
} ArkUI_ContextCallback;
|
||||
|
||||
/**
|
||||
* @brief Defines the water flow section configuration.
|
||||
*
|
||||
@ -1406,6 +1433,19 @@ typedef struct {
|
||||
float left;
|
||||
} ArkUI_Margin;
|
||||
|
||||
/**
|
||||
* @brief Enumerates the animation onFinish callback types.
|
||||
*
|
||||
* @since 12
|
||||
*/
|
||||
typedef enum {
|
||||
/** The callback is invoked when the entire animation is removed once it has finished. */
|
||||
ARKUI_FINISH_CALLBACK_REMOVED = 0,
|
||||
/** The callback is invoked when the animation logically enters the falling state, though it may still be in its
|
||||
* long tail state. */
|
||||
ARKUI_FINISH_CALLBACK_LOGICALLY,
|
||||
} ArkUI_FinishCallbackType;
|
||||
|
||||
/**
|
||||
* @brief Creates a size constraint.
|
||||
*
|
||||
|
62
interfaces/native/node/animate_impl.cpp
Normal file
62
interfaces/native/node/animate_impl.cpp
Normal file
@ -0,0 +1,62 @@
|
||||
/*
|
||||
* 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/animate_impl.h"
|
||||
|
||||
#include "node/node_model.h"
|
||||
|
||||
#include "base/error/error_code.h"
|
||||
|
||||
namespace OHOS::Ace::AnimateModel {
|
||||
|
||||
int32_t AnimateTo(ArkUI_ContextHandle context, ArkUI_AnimateOption* option, ArkUI_ContextCallback* update,
|
||||
ArkUI_AnimateCompleteCallback* complete)
|
||||
{
|
||||
auto* impl = OHOS::Ace::NodeModel::GetFullImpl();
|
||||
if (!impl || !context || !option || !update || !update->callback) {
|
||||
return ERROR_CODE_PARAM_INVALID;
|
||||
}
|
||||
|
||||
ArkUIAnimateOption animateOption {};
|
||||
animateOption.duration = option->duration;
|
||||
animateOption.tempo = option->tempo;
|
||||
animateOption.curve = static_cast<ArkUI_Int32>(option->curve);
|
||||
animateOption.delay = option->delay;
|
||||
animateOption.iterations = option->iterations;
|
||||
animateOption.playMode = static_cast<ArkUI_Int32>(option->playMode);
|
||||
if (option->expectedFrameRateRange) {
|
||||
animateOption.expectedFrameRateRange =
|
||||
reinterpret_cast<ArkUIExpectedFrameRateRange*>(option->expectedFrameRateRange);
|
||||
}
|
||||
|
||||
if (complete && complete->callback) {
|
||||
animateOption.onFinishCallback = reinterpret_cast<void*>(complete->callback);
|
||||
}
|
||||
|
||||
if (complete && complete->userData) {
|
||||
animateOption.user = complete->userData;
|
||||
}
|
||||
auto finishCallbackType = static_cast<ArkUI_Int32>(ARKUI_FINISH_CALLBACK_REMOVED);
|
||||
if (complete && complete->type == ARKUI_FINISH_CALLBACK_LOGICALLY) {
|
||||
finishCallbackType = static_cast<ArkUI_Int32>(ARKUI_FINISH_CALLBACK_LOGICALLY);
|
||||
}
|
||||
animateOption.finishCallbackType = finishCallbackType;
|
||||
|
||||
impl->getAnimation()->animateTo(reinterpret_cast<ArkUIContext*>(context), animateOption,
|
||||
reinterpret_cast<void*>(update->callback), update->userData);
|
||||
return ERROR_CODE_NO_ERROR;
|
||||
}
|
||||
|
||||
} // namespace OHOS::Ace::AnimateModel
|
46
interfaces/native/node/animate_impl.h
Normal file
46
interfaces/native/node/animate_impl.h
Normal file
@ -0,0 +1,46 @@
|
||||
/*
|
||||
* 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 ARKUI_NATIVE_ANIMATE_IMPL_H
|
||||
#define ARKUI_NATIVE_ANIMATE_IMPL_H
|
||||
|
||||
#include <cstdint>
|
||||
|
||||
#include "native_animate.h"
|
||||
#include "native_type.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
struct ArkUI_AnimateOption {
|
||||
uint32_t duration;
|
||||
float tempo;
|
||||
ArkUI_AnimationCurve curve;
|
||||
int32_t delay;
|
||||
int32_t iterations;
|
||||
ArkUI_AnimationPlayMode playMode;
|
||||
ArkUI_ExpectedFrameRateRange* expectedFrameRateRange;
|
||||
};
|
||||
|
||||
#ifdef __cplusplus
|
||||
};
|
||||
#endif
|
||||
|
||||
namespace OHOS::Ace::AnimateModel {
|
||||
|
||||
int32_t AnimateTo(ArkUI_ContextHandle context, ArkUI_AnimateOption* option, ArkUI_ContextCallback* update,
|
||||
ArkUI_AnimateCompleteCallback* complete);
|
||||
}; // namespace OHOS::Ace::AnimateModel
|
||||
#endif
|
@ -15,6 +15,8 @@
|
||||
|
||||
#include "native_interface.h"
|
||||
#include "native_node.h"
|
||||
#include "native_animate.h"
|
||||
#include "node/animate_impl.h"
|
||||
#include "node/dialog_model.h"
|
||||
#include "node/gesture_impl.h"
|
||||
#include "node/native_compatible.h"
|
||||
@ -121,6 +123,10 @@ ArkUI_NativeGestureAPI_1 gestureImpl_1 = {
|
||||
OHOS::Ace::GestureModel::GetGestureType,
|
||||
};
|
||||
|
||||
ArkUI_NativeAnimateAPI_1 animateImpl_1 = {
|
||||
OHOS::Ace::AnimateModel::AnimateTo,
|
||||
};
|
||||
|
||||
} // namespace
|
||||
|
||||
#ifdef __cplusplus
|
||||
@ -209,6 +215,11 @@ void* OH_ArkUI_QueryModuleInterfaceByName(ArkUI_NativeAPIVariantKind type, const
|
||||
return &gestureImpl_1;
|
||||
}
|
||||
break;
|
||||
case ARKUI_NATIVE_ANIMATE:
|
||||
if (strcmp(structName, "ArkUI_NativeAnimateAPI_1") == 0) {
|
||||
return &animateImpl_1;
|
||||
}
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
@ -100,4 +100,34 @@ int32_t OH_ArkUI_GetNodeHandleFromNapiValue(napi_env env, napi_value value, ArkU
|
||||
return OHOS::Ace::ERROR_CODE_PARAM_INVALID;
|
||||
}
|
||||
|
||||
int32_t OH_ArkUI_GetContextFromNapiValue(napi_env env, napi_value value, ArkUI_ContextHandle* context)
|
||||
{
|
||||
bool hasProperty = false;
|
||||
auto result = napi_has_named_property(env, value, "instanceId_", &hasProperty);
|
||||
if (result != napi_ok || !hasProperty) {
|
||||
LOGE("fail to get Context value");
|
||||
return OHOS::Ace::ERROR_CODE_PARAM_INVALID;
|
||||
}
|
||||
|
||||
napi_value contextPtr = nullptr;
|
||||
result = napi_get_named_property(env, value, "instanceId_", &contextPtr);
|
||||
if (result != napi_ok) {
|
||||
return OHOS::Ace::ERROR_CODE_PARAM_INVALID;
|
||||
}
|
||||
|
||||
napi_valuetype valuetype;
|
||||
if (napi_typeof(env, contextPtr, &valuetype) != napi_ok) {
|
||||
return OHOS::Ace::ERROR_CODE_PARAM_INVALID;
|
||||
}
|
||||
if (valuetype != napi_number) {
|
||||
return OHOS::Ace::ERROR_CODE_PARAM_INVALID;
|
||||
}
|
||||
int32_t instanceId = -1;
|
||||
result = napi_get_value_int32(env, contextPtr, &instanceId);
|
||||
if (result != napi_ok) {
|
||||
return OHOS::Ace::ERROR_CODE_PARAM_INVALID;
|
||||
}
|
||||
*context = new ArkUI_Context({ .id = instanceId });
|
||||
return OHOS::Ace::ERROR_CODE_NO_ERROR;
|
||||
}
|
||||
}
|
||||
|
157
interfaces/native/node/node_animate.cpp
Normal file
157
interfaces/native/node/node_animate.cpp
Normal file
@ -0,0 +1,157 @@
|
||||
/*
|
||||
* 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 "animate_impl.h"
|
||||
#include "native_type.h"
|
||||
|
||||
#include "base/utils/utils.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
ArkUI_AnimateOption* OH_ArkUI_AnimateOption_Create()
|
||||
{
|
||||
ArkUI_AnimateOption* option = new ArkUI_AnimateOption;
|
||||
//duration default 1000
|
||||
option->duration = 1000;
|
||||
//tempo default 1.0
|
||||
option->tempo = 1.0f;
|
||||
option->curve = ArkUI_AnimationCurve::ARKUI_CURVE_EASE_IN_OUT;
|
||||
//delay default 0
|
||||
option->delay = 0;
|
||||
//iterations default 1
|
||||
option->iterations = 1;
|
||||
option->playMode = ArkUI_AnimationPlayMode::ARKUI_ANIMATION_PLAY_MODE_NORMAL;
|
||||
option->expectedFrameRateRange = nullptr;
|
||||
return option;
|
||||
}
|
||||
|
||||
void OH_ArkUI_AnimateOption_Dispose(ArkUI_AnimateOption* option)
|
||||
{
|
||||
if (option == nullptr) {
|
||||
return;
|
||||
}
|
||||
if (option->expectedFrameRateRange != nullptr) {
|
||||
delete option->expectedFrameRateRange;
|
||||
option->expectedFrameRateRange = nullptr;
|
||||
}
|
||||
delete option;
|
||||
}
|
||||
|
||||
uint32_t OH_ArkUI_AnimateOption_GetDuration(ArkUI_AnimateOption* option)
|
||||
{
|
||||
CHECK_NULL_RETURN(option, 0);
|
||||
return option->duration;
|
||||
}
|
||||
|
||||
float OH_ArkUI_AnimateOption_GetTempo(ArkUI_AnimateOption* option)
|
||||
{
|
||||
CHECK_NULL_RETURN(option, 0.0f);
|
||||
return option->tempo;
|
||||
}
|
||||
|
||||
ArkUI_AnimationCurve OH_ArkUI_AnimateOption_GetCurve(ArkUI_AnimateOption* option)
|
||||
{
|
||||
CHECK_NULL_RETURN(option, static_cast<ArkUI_AnimationCurve>(-1));
|
||||
return option->curve;
|
||||
}
|
||||
|
||||
int32_t OH_ArkUI_AnimateOption_GetDelay(ArkUI_AnimateOption* option)
|
||||
{
|
||||
CHECK_NULL_RETURN(option, 0);
|
||||
return option->delay;
|
||||
}
|
||||
|
||||
int32_t OH_ArkUI_AnimateOption_GetIterations(ArkUI_AnimateOption* option)
|
||||
{
|
||||
CHECK_NULL_RETURN(option, 0);
|
||||
return option->iterations;
|
||||
}
|
||||
|
||||
ArkUI_AnimationPlayMode OH_ArkUI_AnimateOption_GetPlayMode(ArkUI_AnimateOption* option)
|
||||
{
|
||||
CHECK_NULL_RETURN(option, static_cast<ArkUI_AnimationPlayMode>(-1));
|
||||
return option->playMode;
|
||||
}
|
||||
|
||||
ArkUI_ExpectedFrameRateRange* OH_ArkUI_AnimateOption_GetExpectedFrameRateRange(ArkUI_AnimateOption* option)
|
||||
{
|
||||
CHECK_NULL_RETURN(option, nullptr);
|
||||
return option->expectedFrameRateRange;
|
||||
}
|
||||
|
||||
void OH_ArkUI_AnimateOption_SetDuration(ArkUI_AnimateOption* option, int32_t value)
|
||||
{
|
||||
CHECK_NULL_VOID(option);
|
||||
// 设置小于0的值时按0处理
|
||||
if (value < 0) {
|
||||
value = 0;
|
||||
}
|
||||
option->duration = value;
|
||||
}
|
||||
|
||||
void OH_ArkUI_AnimateOption_SetTempo(ArkUI_AnimateOption* option, float value)
|
||||
{
|
||||
CHECK_NULL_VOID(option);
|
||||
// 小于0的值时按值为1处理
|
||||
if (value < 0) {
|
||||
value = 1;
|
||||
}
|
||||
option->tempo = value;
|
||||
}
|
||||
|
||||
void OH_ArkUI_AnimateOption_SetCurve(ArkUI_AnimateOption* option, ArkUI_AnimationCurve value)
|
||||
{
|
||||
CHECK_NULL_VOID(option);
|
||||
if (value >= ARKUI_CURVE_LINEAR && value <= ARKUI_CURVE_FRICTION) {
|
||||
option->curve = value;
|
||||
}
|
||||
}
|
||||
|
||||
void OH_ArkUI_AnimateOption_SetDelay(ArkUI_AnimateOption* option, int32_t value)
|
||||
{
|
||||
CHECK_NULL_VOID(option);
|
||||
option->delay = value;
|
||||
}
|
||||
|
||||
void OH_ArkUI_AnimateOption_SetIterations(ArkUI_AnimateOption* option, int32_t value)
|
||||
{
|
||||
CHECK_NULL_VOID(option);
|
||||
//取值范围:[-1, +∞)
|
||||
if (value < -1) {
|
||||
return;
|
||||
}
|
||||
option->iterations = value;
|
||||
}
|
||||
|
||||
void OH_ArkUI_AnimateOption_SetPlayMode(ArkUI_AnimateOption* option, ArkUI_AnimationPlayMode value)
|
||||
{
|
||||
CHECK_NULL_VOID(option);
|
||||
if (value >= ARKUI_ANIMATION_PLAY_MODE_NORMAL && value <= ARKUI_ANIMATION_PLAY_MODE_ALTERNATE_REVERSE) {
|
||||
option->playMode = value;
|
||||
}
|
||||
}
|
||||
|
||||
void OH_ArkUI_AnimateOption_SetExpectedFrameRateRange(ArkUI_AnimateOption* option, ArkUI_ExpectedFrameRateRange* value)
|
||||
{
|
||||
CHECK_NULL_VOID(option);
|
||||
CHECK_NULL_VOID(value);
|
||||
option->expectedFrameRateRange = new ArkUI_ExpectedFrameRateRange { value->min, value->max, value->expected };
|
||||
}
|
||||
|
||||
#ifdef __cplusplus
|
||||
};
|
||||
#endif
|
@ -34,6 +34,10 @@ struct ArkUI_Node {
|
||||
void* extraCustomData = nullptr;
|
||||
};
|
||||
|
||||
struct ArkUI_Context {
|
||||
int32_t id;
|
||||
};
|
||||
|
||||
constexpr int BASIC_COMPONENT_NUM = 18;
|
||||
|
||||
#ifdef __cplusplus
|
||||
|
Loading…
Reference in New Issue
Block a user