Skip to content

Commit a2f9b8b

Browse files
authored
Expose the PAGLayer::setAlpha() method as a public API for iOS and Android. (#2783)
Co-authored-by: thunderllei <thunderllei@tencent.com>
1 parent 6c308db commit a2f9b8b

File tree

6 files changed

+60
-0
lines changed

6 files changed

+60
-0
lines changed

android/libpag/src/main/java/org/libpag/PAGLayer.java

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -172,6 +172,17 @@ public Matrix getTotalMatrix() {
172172
*/
173173
public native void setExcludedFromTimeline(boolean value);
174174

175+
/**
176+
* Returns the current alpha of the layer if previously set.
177+
*/
178+
public native float alpha();
179+
180+
/**
181+
* Set the alpha of the layer, which will be concatenated to the current animation opacity for
182+
* displaying.
183+
*/
184+
public native void setAlpha(float value);
185+
175186
private native void nativeRelease();
176187

177188
protected long nativeContext;

src/platform/android/JPAGLayer.cpp

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -297,4 +297,22 @@ PAG_API void Java_org_libpag_PAGLayer_setExcludedFromTimeline(JNIEnv* env, jobje
297297

298298
pagLayer->setExcludedFromTimeline(value);
299299
}
300+
301+
PAG_API jfloat Java_org_libpag_PAGLayer_alpha(JNIEnv* env, jobject thiz) {
302+
auto pagLayer = GetPAGLayer(env, thiz);
303+
if (pagLayer == nullptr) {
304+
return 0.0f;
305+
}
306+
307+
return pagLayer->alpha();
308+
}
309+
310+
PAG_API void Java_org_libpag_PAGLayer_setAlpha(JNIEnv* env, jobject thiz, jfloat value) {
311+
auto pagLayer = GetPAGLayer(env, thiz);
312+
if (pagLayer == nullptr) {
313+
return;
314+
}
315+
316+
pagLayer->setAlpha(value);
317+
}
300318
}

src/platform/cocoa/PAGLayer.h

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -165,4 +165,15 @@ PAG_API @interface PAGLayer : NSObject
165165
*/
166166
- (void)setExcludedFromTimeline:(BOOL)value;
167167

168+
/**
169+
* Returns the current alpha of the layer if previously set.
170+
*/
171+
- (float)alpha;
172+
173+
/**
174+
* Set the alpha of the layer, which will be concatenated to the current animation opacity for
175+
* displaying.
176+
*/
177+
- (void)setAlpha:(float)value;
178+
168179
@end

src/platform/cocoa/PAGLayer.m

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,14 @@ - (void)setExcludedFromTimeline:(BOOL)value {
133133
[(PAGLayerImpl*)_impl setExcludedFromTimeline:value];
134134
}
135135

136+
- (float)alpha {
137+
return [(PAGLayerImpl*)_impl alpha];
138+
}
139+
140+
- (void)setAlpha:(float)value {
141+
[(PAGLayerImpl*)_impl setAlpha:value];
142+
}
143+
136144
- (void)dealloc {
137145
[_impl release];
138146
[super dealloc];

src/platform/cocoa/private/PAGLayerImpl.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,4 +72,8 @@
7272

7373
- (void)setExcludedFromTimeline:(BOOL)value;
7474

75+
- (float)alpha;
76+
77+
- (void)setAlpha:(float)value;
78+
7579
@end

src/platform/cocoa/private/PAGLayerImpl.mm

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -254,4 +254,12 @@ - (void)setExcludedFromTimeline:(BOOL)value {
254254
_pagLayer->setExcludedFromTimeline(value);
255255
}
256256

257+
- (float)alpha {
258+
return _pagLayer->alpha();
259+
}
260+
261+
- (void)setAlpha:(float)value {
262+
_pagLayer->setAlpha(value);
263+
}
264+
257265
@end

0 commit comments

Comments
 (0)