Skip to content

Commit

Permalink
Add a PAGViewController class to manipulate the backing PAGView on th…
Browse files Browse the repository at this point in the history
…e HarmonyOS platform.(#2464)
  • Loading branch information
Hparty authored Sep 6, 2024
1 parent 956c12d commit 9d9841d
Show file tree
Hide file tree
Showing 6 changed files with 669 additions and 217 deletions.
45 changes: 23 additions & 22 deletions ohos/entry/src/main/ets/pages/Index.ets
Original file line number Diff line number Diff line change
Expand Up @@ -23,31 +23,32 @@ import * as pag from 'libpag';
struct Index {
@State message: string = "";
@State @Watch("updateMessage") stateString: string = "";
@State composition: pag.PAGComposition | null = null;
@State @Watch("updateMessage") progress: number = 0;
@State isPlaying: boolean = false;
@State repeatCount: number = 1;
@State viewController: pag.PAGViewController = new pag.PAGViewController();

aboutToAppear(): void {
let manager = getContext(this).resourceManager;
let file = pag.PAGFile.LoadFromAssets(manager, "PAG_LOGO.pag");
this.composition = file as pag.PAGComposition;
this.isPlaying = true;
this.viewController.setComposition(file);
this.viewController.setRepeatCount(1);
this.viewController.addListener(new WeakRef(this));
this.viewController.play();
}

onAnimationStart = (view: pag.PAGView) => {
this.stateString = 'PAG start';
onAnimationStart = (viewController: pag.PAGViewController) => {
this.stateString = viewController.uniqueID() + ` PAG start`;
}
onAnimationEnd = (view: pag.PAGView) => {
this.stateString = `PAG end`;
onAnimationEnd = (viewController: pag.PAGViewController) => {
this.stateString = viewController.uniqueID() + ` PAG end`;
}
onAnimationRepeat = (view: pag.PAGView) => {
this.stateString = `PAG repeat`;
onAnimationRepeat = (viewController: pag.PAGViewController) => {
this.stateString = viewController.uniqueID() + ` PAG repeat`;
}
onAnimationCancel = (view: pag.PAGView) => {
this.stateString = `PAG cancel`;
onAnimationCancel = (viewController: pag.PAGViewController) => {
this.stateString = viewController.uniqueID() + ` PAG cancel`;
}
onAnimationUpdate = (view: pag.PAGView) => {
onAnimationUpdate = (viewController: pag.PAGViewController) => {
this.progress = viewController.getProgress();
}

updateMessage() {
Expand All @@ -58,23 +59,23 @@ struct Index {
Row() {
Column() {
pag.PAGView({
composition: this.composition,
progress: this.progress,
isPlaying: this.isPlaying,
repeatCount: this.repeatCount,
listeners: [new WeakRef(this)]
controller: this.viewController
})
.height('50%')
.onClick(() => {
this.isPlaying = !this.isPlaying
if (this.viewController.isPlaying()) {
this.viewController.pause();
} else {
this.viewController.play();
}
})

Text(this.message)
.fontSize(50)
.fontWeight(FontWeight.Bold)
.onClick(() => {
this.progress = 0.5;
this.repeatCount = 0;
this.viewController.setProgress(0.5);
this.viewController.setRepeatCount(0);
})
.height('50%')
}
Expand Down
2 changes: 1 addition & 1 deletion ohos/libpag/Index.ets
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
//
/////////////////////////////////////////////////////////////////////////////////////////////////

export { PAGView, PAGViewListener } from './src/main/ets/PAGView'
export { PAGView, PAGViewListener, PAGViewController } from './src/main/ets/PAGView'

export { PAGPlayer } from './src/main/ets/PAGPlayer'

Expand Down
50 changes: 48 additions & 2 deletions ohos/libpag/src/main/cpp/types/libpag/Index.d.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,21 @@
/////////////////////////////////////////////////////////////////////////////////////////////////
//
// Tencent is pleased to support the open source community by making libpag available.
//
// Copyright (C) 2024 THL A29 Limited, a Tencent company. All rights reserved.
//
// 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 resourceManager from "@ohos.resourceManager";
import { image } from "@kit.ImageKit";

Expand Down Expand Up @@ -284,46 +302,74 @@ export declare class JPAGSurface {
}

export declare class JPAGView {
flush(): void;
flush(): boolean;

update(): void;

setProgress(progress: number): void;

getProgress(): number;

setComposition(composition: JPAGComposition | null): void;

setRepeatCount(repeatCount: number): void;

repeatCount(): number;

play(): void;

pause(): void;

isPlaying(): boolean;

setStateChangeCallback(callback: (number) => void): void;

setProgressUpdateCallback(callback: (double) => void): void;
setProgressUpdateCallback(callback: () => void): void;

uniqueID(): string;

setSync(isSync: boolean): void;

isSync(): boolean;

setVideoEnabled(videoEnabled: boolean): void;

videoEnabled(): boolean;

setCacheEnabled(cacheEnabled: boolean): void;

cacheEnabled(): boolean;

setCacheScale(cacheScale: number): void;

cacheScale(): number;

setMaxFrameRate(maxFrameRate: number): void;

maxFrameRate(): number;

setScaleMode(scaleMode: number): void;

scaleMode(): number;

setMatrix(matrix: Array<number>);

matrix(): Array<number>;

currentFrame(): number;

getLayersUnderPoint(x: number, y: number): Array<JPAGLayer>;

getBounds(pagLayer: JPAGLayer): Array<number>;

freeCache();

makeSnapshot(): image.PixelMap | null;

useDiskCache(): boolean;

setUseDiskCache(value: boolean);

release();
}

Expand Down
Loading

0 comments on commit 9d9841d

Please sign in to comment.