diff --git a/android/libpag/src/main/java/org/libpag/PAGLayer.java b/android/libpag/src/main/java/org/libpag/PAGLayer.java index ef47178729..ae22e10d58 100644 --- a/android/libpag/src/main/java/org/libpag/PAGLayer.java +++ b/android/libpag/src/main/java/org/libpag/PAGLayer.java @@ -172,6 +172,17 @@ public Matrix getTotalMatrix() { */ public native void setExcludedFromTimeline(boolean value); + /** + * Returns the current alpha of the layer if previously set. + */ + public native float alpha(); + + /** + * Set the alpha of the layer, which will be concatenated to the current animation opacity for + * displaying. + */ + public native void setAlpha(float value); + private native void nativeRelease(); protected long nativeContext; diff --git a/src/platform/android/JPAGLayer.cpp b/src/platform/android/JPAGLayer.cpp index 9e26ee607d..8b99bc48f7 100644 --- a/src/platform/android/JPAGLayer.cpp +++ b/src/platform/android/JPAGLayer.cpp @@ -297,4 +297,22 @@ PAG_API void Java_org_libpag_PAGLayer_setExcludedFromTimeline(JNIEnv* env, jobje pagLayer->setExcludedFromTimeline(value); } + +PAG_API jfloat Java_org_libpag_PAGLayer_alpha(JNIEnv* env, jobject thiz) { + auto pagLayer = GetPAGLayer(env, thiz); + if (pagLayer == nullptr) { + return 0.0f; + } + + return pagLayer->alpha(); +} + +PAG_API void Java_org_libpag_PAGLayer_setAlpha(JNIEnv* env, jobject thiz, jfloat value) { + auto pagLayer = GetPAGLayer(env, thiz); + if (pagLayer == nullptr) { + return; + } + + pagLayer->setAlpha(value); +} } diff --git a/src/platform/cocoa/PAGLayer.h b/src/platform/cocoa/PAGLayer.h index 3cd4b8d71e..9283abdda6 100644 --- a/src/platform/cocoa/PAGLayer.h +++ b/src/platform/cocoa/PAGLayer.h @@ -165,4 +165,15 @@ PAG_API @interface PAGLayer : NSObject */ - (void)setExcludedFromTimeline:(BOOL)value; +/** + * Returns the current alpha of the layer if previously set. + */ +- (float)alpha; + +/** + * Set the alpha of the layer, which will be concatenated to the current animation opacity for + * displaying. + */ +- (void)setAlpha:(float)value; + @end diff --git a/src/platform/cocoa/PAGLayer.m b/src/platform/cocoa/PAGLayer.m index 6ea6409d97..e108fcf4af 100644 --- a/src/platform/cocoa/PAGLayer.m +++ b/src/platform/cocoa/PAGLayer.m @@ -133,6 +133,14 @@ - (void)setExcludedFromTimeline:(BOOL)value { [(PAGLayerImpl*)_impl setExcludedFromTimeline:value]; } +- (float)alpha { + return [(PAGLayerImpl*)_impl alpha]; +} + +- (void)setAlpha:(float)value { + [(PAGLayerImpl*)_impl setAlpha:value]; +} + - (void)dealloc { [_impl release]; [super dealloc]; diff --git a/src/platform/cocoa/private/PAGLayerImpl.h b/src/platform/cocoa/private/PAGLayerImpl.h index 3ed13448b4..bd15d6031b 100644 --- a/src/platform/cocoa/private/PAGLayerImpl.h +++ b/src/platform/cocoa/private/PAGLayerImpl.h @@ -72,4 +72,8 @@ - (void)setExcludedFromTimeline:(BOOL)value; +- (float)alpha; + +- (void)setAlpha:(float)value; + @end diff --git a/src/platform/cocoa/private/PAGLayerImpl.mm b/src/platform/cocoa/private/PAGLayerImpl.mm index 0931630925..1b4d1ba25e 100644 --- a/src/platform/cocoa/private/PAGLayerImpl.mm +++ b/src/platform/cocoa/private/PAGLayerImpl.mm @@ -254,4 +254,12 @@ - (void)setExcludedFromTimeline:(BOOL)value { _pagLayer->setExcludedFromTimeline(value); } +- (float)alpha { + return _pagLayer->alpha(); +} + +- (void)setAlpha:(float)value { + _pagLayer->setAlpha(value); +} + @end