Skip to content

Commit

Permalink
fix bug while set composition
Browse files Browse the repository at this point in the history
  • Loading branch information
Hparty committed Sep 5, 2024
1 parent ebc88e0 commit 89db32c
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 5 deletions.
10 changes: 5 additions & 5 deletions ohos/libpag/src/main/ets/PAGView.ets
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ export class PAGViewController {
* already added to another PAGView, it will be removed from the previous PAGView.
*/
setComposition(composition: PAGComposition | null) {
this.filePath = null;
this.composition = composition;
this.jView.setComposition(composition?.getNativeComposition());
}
Expand All @@ -79,7 +80,7 @@ export class PAGViewController {
* The path string of a pag file set by setPath() or setPathAsync().
* @returns
*/
getPath(): string {
getPath(): string | null {
return this.filePath;
}

Expand All @@ -92,6 +93,7 @@ export class PAGViewController {
this.filePath = path;
let file = PAGFile.LoadFromPath(path);
this.composition = file;
this.jView.setComposition(file?.getNativeComposition());
return file != null;
}

Expand All @@ -105,6 +107,7 @@ export class PAGViewController {
return new Promise<PAGFile | null>((resolve) => {
PAGFile.LoadFromPathAsync(path).then((pagFile) => {
this.composition = pagFile;
this.jView.setComposition(pagFile?.getNativeComposition());
resolve(pagFile)
})
})
Expand Down Expand Up @@ -442,7 +445,7 @@ export class PAGViewController {
}
}
private composition: PAGComposition | null = null;
private filePath: string = "";
private filePath: string | null = null;
private listeners: Array<WeakRef<PAGViewListener>> = [];
private jView: JPAGView = new JPAGView();
private view: WeakRef<PAGView> | null = null;
Expand All @@ -458,9 +461,6 @@ export struct PAGView {
type: XComponentType.SURFACE,
libraryname: "pag",
})
.onLoad(() => {
this.controller.update();
})
.backgroundColor(Color.Transparent)
}

Expand Down
1 change: 1 addition & 0 deletions src/platform/ohos/JPAGView.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -221,6 +221,7 @@ static napi_value SetComposition(napi_env env, napi_callback_info info) {
if (layer != nullptr) {
if (layer->layerType() == LayerType::PreCompose) {
player->setComposition(std::static_pointer_cast<PAGComposition>(layer));
animator->setProgress(player->getProgress());
animator->setDuration(layer->duration());
}
} else {
Expand Down

0 comments on commit 89db32c

Please sign in to comment.