Skip to content

Commit 927a64f

Browse files
committed
fix: BREAKING CHANGE renamed setOpacityValueDelegateForKeyPath to setOpacity and setColorValueDelegateForKeyPath to setColor
1 parent 592c2a7 commit 927a64f

File tree

3 files changed

+26
-12
lines changed

3 files changed

+26
-12
lines changed

src/index.d.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -75,12 +75,12 @@ export class LottieView extends View {
7575
/**
7676
* Sets the provided color value on each property that matches the specified keyPath.
7777
*/
78-
setColorValueDelegateForKeyPath(value: Color, keyPath: string[]): void;
78+
setColor(value: Color, keyPath: string[]): void;
7979

8080
/**
8181
* Sets the provided opacity value on each property that matches the specified keyPath.
8282
*/
83-
setOpacityValueDelegateForKeyPath(value: number, keyPath: string[]): void;
83+
setOpacity(value: number, keyPath: string[]): void;
8484

8585
/**
8686
* Plays the animation from the beginning.

src/lottie.android.ts

Lines changed: 21 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -168,18 +168,20 @@ export class LottieView extends LottieViewBase {
168168
}
169169
}
170170

171-
public setColorValueDelegateForKeyPath(value: Color, keyPath: string[]): void {
172-
if (this.nativeViewProtected && value && keyPath && keyPath.length) {
171+
public setColor(value: Color, keyPath: string[]): void {
172+
const nativeView = this.nativeViewProtected;
173+
if (nativeView && value && keyPath && keyPath.length) {
173174
if (keyPath[keyPath.length - 1].toLowerCase() === 'color') {
175+
keyPath = [...keyPath];
174176
keyPath.pop(); // android specifies the property as an enum parameter.
175177
if (keyPath.length === 0) {
176178
return;
177179
}
178180
}
179-
const nativeKeyPath: java.lang.String[] = Array.create(java.lang.String, keyPath.length);
180-
keyPath.forEach((key, index) => {
181-
nativeKeyPath[index] = new java.lang.String(key);
182-
});
181+
const nativeKeyPath: any[] = Array.create(java.lang.String, keyPath.length);
182+
for (let index = 0; index < keyPath.length; index++) {
183+
nativeKeyPath[index] = keyPath[index];
184+
}
183185
if (!LottieProperty) {
184186
LottieProperty = com.airbnb.lottie.LottieProperty;
185187
}
@@ -191,16 +193,27 @@ export class LottieView extends LottieViewBase {
191193
LottieKeyPath = com.airbnb.lottie.model.KeyPath;
192194
}
193195
// by using color filter we change all colors (STROKE_COLOR and COLOR)
196+
// const colorFilter = new android.graphics.PorterDuffColorFilter(value.android, android.graphics.PorterDuff.Mode.SRC_ATOP) ;
194197
const colorFilter = new com.airbnb.lottie.SimpleColorFilter(value.android);
195-
this.nativeViewProtected.addValueCallback(
198+
nativeView.addValueCallback(
196199
new LottieKeyPath(nativeKeyPath as any),
197200
LottieProperty.COLOR_FILTER,
198201
new LottieValueCallback(colorFilter)
199202
);
203+
// nativeView.addValueCallback(
204+
// new LottieKeyPath(nativeKeyPath as any),
205+
// LottieProperty.COLOR,
206+
// new LottieValueCallback(java.lang.Integer.valueOf(value.android))
207+
// );
208+
nativeView.addValueCallback(
209+
new LottieKeyPath(nativeKeyPath as any),
210+
LottieProperty.COLOR,
211+
new LottieValueCallback(java.lang.Integer.valueOf(value.android))
212+
);
200213
}
201214
}
202215

203-
public setOpacityValueDelegateForKeyPath(value: number, keyPath: string[]): void {
216+
public setOpacity(value: number, keyPath: string[]): void {
204217
if (this.nativeViewProtected && value && keyPath && keyPath.length) {
205218
if (keyPath[keyPath.length - 1].toLowerCase() === 'opacity') {
206219
keyPath.pop();

src/lottie.ios.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -91,9 +91,10 @@ export class LottieView extends LottieViewBase {
9191
}
9292
}
9393

94-
public setColorValueDelegateForKeyPath(value: Color, keyPath: string[]): void {
94+
public setColor(value: Color, keyPath: string[]): void {
9595
if (this.nativeView && value && keyPath && keyPath.length) {
9696
if (keyPath[keyPath.length - 1].toLowerCase() !== 'color') {
97+
keyPath = [...keyPath];
9798
keyPath.push('Color'); // ios expects the property as the last item in the keyPath
9899
}
99100

@@ -104,7 +105,7 @@ export class LottieView extends LottieViewBase {
104105
}
105106
}
106107

107-
public setOpacityValueDelegateForKeyPath(value: number, keyPath: string[]): void {
108+
public setOpacity(value: number, keyPath: string[]): void {
108109
if (this.nativeView && value && keyPath && keyPath.length) {
109110
if (keyPath[keyPath.length - 1].toLowerCase() !== 'opacity') {
110111
keyPath.push('Opacity'); // ios expects the property as the last item in the keyPath

0 commit comments

Comments
 (0)