|
6 | 6 | **********************************************************************************/ |
7 | 7 | /// <reference path="./node_modules/tns-platform-declarations/ios.d.ts" /> |
8 | 8 |
|
9 | | -import { layout } from 'tns-core-modules/ui/core/view'; |
10 | | -import { LottieViewBase, srcProperty, loopProperty, autoPlayProperty } from './nativescript-lottie.common'; |
| 9 | +import { Color, layout } from 'tns-core-modules/ui/core/view'; |
| 10 | +import { |
| 11 | + LottieViewBase, |
| 12 | + srcProperty, |
| 13 | + loopProperty, |
| 14 | + autoPlayProperty, |
| 15 | + themeProperty, |
| 16 | + Theme |
| 17 | +} from './nativescript-lottie.common'; |
11 | 18 | import { screen } from 'tns-core-modules/platform'; |
| 19 | + |
12 | 20 | declare var LOTAnimationView: any; |
| 21 | +declare var LOTKeypath: any; |
| 22 | +declare var LOTColorValueCallback: any; |
13 | 23 |
|
14 | 24 | export class LottieView extends LottieViewBase { |
15 | 25 | private _contentMode: any; |
@@ -88,6 +98,27 @@ export class LottieView extends LottieViewBase { |
88 | 98 | } |
89 | 99 | } |
90 | 100 |
|
| 101 | + // todo: add more dynamic properties |
| 102 | + public [themeProperty.setNative](value: Theme[]) { |
| 103 | + this.setTheme(value); |
| 104 | + } |
| 105 | + |
| 106 | + public setTheme(value: Theme[]) { |
| 107 | + if (!this._animationView) { |
| 108 | + setTimeout(() => this.setTheme(value), 50); |
| 109 | + return; |
| 110 | + } |
| 111 | + |
| 112 | + if (value && value.length) { |
| 113 | + value.forEach(dynamicValue => { |
| 114 | + const callBack = LOTColorValueCallback.withCGColor(new Color(dynamicValue.value).ios.CGColor); |
| 115 | + dynamicValue.keyPath.push('Color'); |
| 116 | + const keyPath = LOTKeypath.keypathWithString(dynamicValue.keyPath.join('.')); |
| 117 | + this._animationView.setValueDelegateForKeypath(callBack, keyPath); |
| 118 | + }); |
| 119 | + } |
| 120 | + } |
| 121 | + |
91 | 122 | public onLoaded() { |
92 | 123 | super.onLoaded(); // ensure 'loaded' event fires |
93 | 124 | } |
|
0 commit comments