-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathLottie.uno
426 lines (310 loc) · 8.96 KB
/
Lottie.uno
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
using Uno;
using Uno.UX;
using Uno.Compiler.ExportTargetInterop;
using Fuse;
using Fuse.Controls.Native;
using Fuse.Scripting;
namespace RBT.Animation
{
using Fuse.Controls.Native.iOS;
using Fuse.Controls.Native.Android;
interface ILottieView
{
string File { set; }
string AndroidImagesFolder { set; }
string ContentMode { set; }
bool IsAnimationPlaying { get; set; }
bool LoopAnimation { set; }
bool AutoReverseAnimation { set; }
bool Play { set; }
bool Pause { set; }
bool Stop { set; }
float Progress { set; }
void OnRooted();
void OnUnrooted();
}
interface ILottieEvents
{
void onAnimationComplete(bool isCompleted);
}
public abstract partial class LottieBase : Fuse.Controls.Panel, ILottieEvents
{
/** EVENTS **/
void ILottieEvents.onAnimationComplete(bool isComplete)
{
SetAnimationCompletedValue(isComplete, null);
}
/** EVENT PROPERTIES **/
//AnimationCompleted - Animation Completed
bool _AnimationCompletedValue = false;
static Selector _AnimationCompletedProperty = "AnimationCompleted";
[UXOriginSetter("SetAnimationCompletedValue")]
public bool AnimationCompleted
{
get { return _AnimationCompletedValue; }
set { SetAnimationCompletedValue(value, this); }
}
public void SetAnimationCompletedValue(bool value, IPropertyListener origin)
{
_AnimationCompletedValue = value;
OnPropertyChanged(_AnimationCompletedProperty, origin);
}
//EndAnimationCompleted
/** PROPERTIES **/
//AndroidImagesFolder - Sets the images animation folder for android
string _AndroidImagesFolderValue = "/";
static Selector _AndroidImagesFolderProperty = "AndroidImagesFolder";
[UXOriginSetter("SetAndroidImagesFolderValue")]
public string AndroidImagesFolder
{
get { return _AndroidImagesFolderValue; }
set { SetAndroidImagesFolderValue(value, this); }
}
public void SetAndroidImagesFolderValue(string value, IPropertyListener origin)
{
if (value != _AndroidImagesFolderValue)
{
_AndroidImagesFolderValue = value;
OnPropertyChanged(_AndroidImagesFolderProperty, origin);
}
var lv = LottieView;
if (lv != null)
lv.AndroidImagesFolder = value;
}
//EndAndroidImagesFolder
//File - Load animation from a bundled .json file
string _UrlToJSONValue = "";
static Selector _UrlToJSONProperty = "File";
[UXOriginSetter("SetUrlToJSONValue")]
public string File
{
get { return _UrlToJSONValue; }
set { SetUrlToJSONValue(value, this); }
}
public void SetUrlToJSONValue(string value, IPropertyListener origin)
{
if (value != _UrlToJSONValue)
{
_UrlToJSONValue = value;
OnPropertyChanged(_UrlToJSONProperty, origin);
}
var lv = LottieView;
if (lv != null)
lv.File = value;
}
//EndFile
//ContentMode - iOS + Set Only - sets visual mode of content such as: Scale Aspect Fit
string _ContentModeValue = "";
static Selector _ContentModeProperty = "ContentMode";
[UXOriginSetter("SetContentModeValue")]
public string ContentMode
{
get { return _ContentModeValue; }
set { SetContentModeValue(value, this); }
}
public void SetContentModeValue(string value, IPropertyListener origin)
{
if (value != _ContentModeValue)
{
_ContentModeValue = value;
OnPropertyChanged(_ContentModeProperty, origin);
}
var lv = LottieView;
if (lv != null)
lv.ContentMode = value;
}
//EndContentMode
//IsAnimationPlaying - Read Only - true/false if animation is playing
bool _IsAnimationPlayingValue = false;
static Selector _IsAnimationPlayingProperty = "LoopAnimation";
public bool IsAnimationPlaying
{
get {
var lv = LottieView;
if (lv != null)
return lv.IsAnimationPlaying;
return false;
}
set { }
}
//EndIsAnimationPlaying
//LoopAnimation - Tells the animation to loop indefinitely. Defaults to false.
bool _LoopAnimationValue = false;
static Selector _LoopAnimationProperty = "LoopAnimation";
[UXOriginSetter("SetLoopAnimationValue")]
public bool LoopAnimation
{
get { return _LoopAnimationValue; }
set { SetLoopAnimationValue(value, this); }
}
public void SetLoopAnimationValue(bool value, IPropertyListener origin)
{
if (value != _LoopAnimationValue)
{
_LoopAnimationValue = value;
OnPropertyChanged(_LoopAnimationProperty, origin);
}
var lv = LottieView;
if (lv != null)
lv.LoopAnimation = value;
}
//EndLoopAnimation
//AutoReverseAnimation - The animation will play forward and then backwards if loopAnimation is also true
bool _AutoReverseAnimationValue = false;
static Selector _AutoReverseAnimationProperty = "AutoReverseAnimation";
[UXOriginSetter("SetAutoReverseAnimationValue")]
public bool AutoReverseAnimation
{
get { return _AutoReverseAnimationValue; }
set { SetAutoReverseAnimationValue(value, this); }
}
public void SetAutoReverseAnimationValue(bool value, IPropertyListener origin)
{
if (value != _AutoReverseAnimationValue)
{
_AutoReverseAnimationValue = value;
OnPropertyChanged(_AutoReverseAnimationProperty, origin);
}
var lv = LottieView;
if (lv != null)
lv.AutoReverseAnimation = value;
}
//EndAutoReverseAnimation
/*
Plays the animation from its current position to the end of the animation.
The animation will start from its current position.
If loopAnimation is true the animation will loop from beginning to end indefinitely.
If loopAnimation is false the animation will stop and the completion event will be called.
*/
bool _PlayValue = false;
static Selector _PlayProperty = "Play";
[UXOriginSetter("SetPlayValue")]
public bool Play
{
get { return _PlayValue; }
set { SetPlayValue(value, this); }
}
public void SetPlayValue(bool value, IPropertyListener origin)
{
if (value != _PlayValue)
{
_PlayValue = value;
OnPropertyChanged(_PlayProperty, origin);
//reset stop, play & progress
_StopValue = false;
OnPropertyChanged(_StopProperty, origin);
_PauseValue = false;
OnPropertyChanged(_PauseProperty, origin);
_ProgressValue = 0f;
OnPropertyChanged(_ProgressProperty, origin);
}
var lv = LottieView;
if (lv != null)
lv.Play = value;
}
//EndPlay
//Pause - Stops the animation at the current frame.
bool _PauseValue = false;
static Selector _PauseProperty = "Pause";
[UXOriginSetter("SetPauseValue")]
public bool Pause
{
get { return _PauseValue; }
set { SetPauseValue(value, this); }
}
public void SetPauseValue(bool value, IPropertyListener origin)
{
if (value != _PauseValue)
{
_PauseValue = value;
OnPropertyChanged(_PauseProperty, origin);
//reset play & stop
_PlayValue = false;
OnPropertyChanged(_PlayProperty, origin);
_StopValue = false;
OnPropertyChanged(_StopProperty, origin);
}
var lv = LottieView;
if (lv != null)
lv.Pause = value;
}
//EndPause
//Stop - Stops the animation and rewinds to the beginning.
bool _StopValue = false;
static Selector _StopProperty = "Stop";
[UXOriginSetter("SetStopValue")]
public bool Stop
{
get { return _StopValue; }
set { SetStopValue(value, this); }
}
public void SetStopValue(bool value, IPropertyListener origin)
{
if (value != _StopValue)
{
_StopValue = value;
OnPropertyChanged(_StopProperty, origin);
//reset play & pause
_PlayValue = false;
OnPropertyChanged(_PlayProperty, origin);
_PauseValue = false;
OnPropertyChanged(_PauseProperty, origin);
}
var lv = LottieView;
if (lv != null)
lv.Stop = value;
}
//EndStop
/* Sets a progress from 0 - 1 of the animation. If the animation is playing it will stop.
The current progress of the animation in absolute time.
e.g. a value of 0.75 always represents the same point in the animation, regardless of positive
or negative speed.
*/
float _ProgressValue = 0f;
static Selector _ProgressProperty = "Progress";
[UXOriginSetter("SetProgressValue")]
public float Progress
{
get { return _ProgressValue; }
set { SetProgressValue(value, this); }
}
public void SetProgressValue(float value, IPropertyListener origin)
{
if (value != _ProgressValue)
{
_ProgressValue = value;
OnPropertyChanged(_ProgressProperty, origin);
//reset play, pause & stop
_PlayValue = false;
OnPropertyChanged(_PlayProperty, origin);
_PauseValue = false;
OnPropertyChanged(_PauseProperty, origin);
_StopValue = false;
OnPropertyChanged(_StopProperty, origin);
}
var lv = LottieView;
if (lv != null)
lv.Progress = value;
}
//EndProgress
/** ENDPROPERTIES **/
protected override void OnRooted()
{
base.OnRooted();
var lv = LottieView;
if (lv != null)
lv.OnRooted();
}
protected override void OnUnrooted()
{
var lv = LottieView;
if (lv != null)
lv.OnUnrooted();
base.OnUnrooted();
}
ILottieView LottieView
{
get { return (ILottieView)NativeView; }
}
}
}