From 1c0701d443b774f3aabc7d292ed66510ebbac653 Mon Sep 17 00:00:00 2001 From: tsj_2020 Date: Mon, 24 Feb 2025 17:28:20 +0800 Subject: [PATCH] add animation/animateTo support Signed-off-by: tsj_2020 --- arkoala-arkts/arkui/src/ComponentBase.ts | 14 ++++++ .../arkui/src/handwritten/ArkAnimation.ts | 49 +++++++++++++++++++ arkoala-arkts/arkui/src/handwritten/index.ts | 1 + 3 files changed, 64 insertions(+) create mode 100644 arkoala-arkts/arkui/src/handwritten/ArkAnimation.ts diff --git a/arkoala-arkts/arkui/src/ComponentBase.ts b/arkoala-arkts/arkui/src/ComponentBase.ts index 41a2658e65..97553e69c4 100644 --- a/arkoala-arkts/arkui/src/ComponentBase.ts +++ b/arkoala-arkts/arkui/src/ComponentBase.ts @@ -15,9 +15,12 @@ import { PeerNode } from './PeerNode' import { ArkUINativeModule } from "#components" +import { AnimateParam, DoubleAnimationParam } from './generated' +import { _animationEnd, _animationStart } from './handwritten' export class ComponentBase { protected peer?: PeerNode + protected isFirstBuild: boolean = true setPeer(peer: PeerNode) { this.peer = peer } @@ -27,4 +30,15 @@ export class ComponentBase { public applyAttributesFinish(): void { ArkUINativeModule._ApplyModifierFinish(this.peer!.peer.ptr) } + public animationStart(param: AnimateParam): this { + _animationStart(param, this.isFirstBuild); + return this + } + + public animationEnd(): this { + _animationEnd(this.isFirstBuild, () => { + this.isFirstBuild = false; + }) + return this; + } } diff --git a/arkoala-arkts/arkui/src/handwritten/ArkAnimation.ts b/arkoala-arkts/arkui/src/handwritten/ArkAnimation.ts new file mode 100644 index 0000000000..a81f84ebd0 --- /dev/null +++ b/arkoala-arkts/arkui/src/handwritten/ArkAnimation.ts @@ -0,0 +1,49 @@ +/* + * 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. + */ + +import {addPartialUpdate} from '../Application' +import {AnimationExtender, AnimateParam} from '../generated' + +export function animateTo(param: AnimateParam, event: (() => void)): void { + if (!event) { + return; + } + AnimationExtender.OpenImplicitAnimation(param); + event(); + addPartialUpdate(event, param, (before: boolean) => { + if (!before) { + AnimationExtender.CloseImplicitAnimation(); + } + }) +} + +export function _animationStart(param: AnimateParam, isFirstBuild: boolean) { + if (isFirstBuild) { + return + } + AnimationExtender.OpenImplicitAnimation(param); + return +} + +export function _animationEnd(isFirstBuild: boolean, update: (() => void)): void { + let param: AnimateParam = {} + addPartialUpdate(() => {}, param, (before: boolean) => { + if (before) { + return; + } + AnimationExtender.CloseImplicitAnimation() + }) + return this +} \ No newline at end of file diff --git a/arkoala-arkts/arkui/src/handwritten/index.ts b/arkoala-arkts/arkui/src/handwritten/index.ts index 9b1107584c..eeb6fe2981 100644 --- a/arkoala-arkts/arkui/src/handwritten/index.ts +++ b/arkoala-arkts/arkui/src/handwritten/index.ts @@ -1,3 +1,4 @@ +export * from "./ArkAnimation" export * from "./ArkPageTransition" export * from "./ArkPageTransitionData" export * from "./Router" -- Gitee