2 * Copyright(c) 2020 Samsung Electronics Co., Ltd.
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
19 using global::System.Runtime.InteropServices;
20 using System.ComponentModel;
21 using System.Collections.Generic;
22 using System.Globalization;
24 namespace Tizen.NUI.BaseComponents
27 /// LottieAnimationView renders an animated vector image (Lottie file).
29 /// <since_tizen> 7 </since_tizen>
30 public partial class LottieAnimationView : ImageView
33 #region Constructor, Destructor, Dispose
35 /// LottieAnimationView constructor
37 /// <param name="scale">The factor of scaling image, default : 1.0f</param>
38 /// <param name="shown">false : not displayed (hidden), true : displayed (shown), default : true</param>
40 /// If the shown parameter is false, the animation is not visible even if the LottieAnimationView instance is created.
44 /// LottieAnimationView myLottie = new LottieAnimationView();
45 /// LottieAnimationView myLottie2 = new LottieAnimationView(2.0f);
46 /// LottieAnimationView myLottie3 = new LottieAnimationView(1.0f, false);
49 /// <since_tizen> 7 </since_tizen>
50 public LottieAnimationView(float scale = 1.0f, bool shown = true) : base()
52 ActionPlay = Interop.LottieAnimationView.AnimatedVectorImageVisualActionPlayGet();
53 ActionPause = Interop.LottieAnimationView.AnimatedVectorImageVisualActionPauseGet();
54 ActionStop = Interop.LottieAnimationView.AnimatedVectorImageVisualActionStopGet();
56 NUILog.Debug($"< constructor GetId={GetId()} >");
57 currentStates.url = "";
58 currentStates.loopCount = 1;
59 currentStates.loopMode = LoopingModeType.Restart;
60 currentStates.stopEndAction = StopBehaviorType.CurrentFrame;
61 currentStates.framePlayRangeMin = -1;
62 currentStates.framePlayRangeMax = -1;
63 currentStates.totalFrame = -1;
64 currentStates.scale = scale;
65 currentStates.redrawInScalingDown = true;
67 // Set changed flag as true when initalized state.
68 // After some properties change, LottieAnimationView.UpdateImage will apply these inital values.
69 currentStates.changed = true;
74 /// Dispose(DisposeTypes type)
76 /// <param name="type"></param>
77 // This will be public opened after ACR done. (Before ACR, need to be hidden as Inhouse API)
78 [EditorBrowsable(EditorBrowsableState.Never)]
79 protected override void Dispose(DisposeTypes type)
86 CleanCallbackDictionaries();
88 //Release your own unmanaged resources here.
89 //You should not access any managed member here except static instance.
90 //because the execution order of Finalizes is non-deterministic.
92 //disconnect event signal
93 if (finishedEventHandler != null && visualEventSignalCallback != null)
95 using VisualEventSignal visualEvent = VisualEventSignal();
96 visualEvent.Disconnect(visualEventSignalCallback);
97 finishedEventHandler = null;
98 NUILog.Debug($"disconnect event signal");
104 // This is used for internal purpose. hidden API.
105 [EditorBrowsable(EditorBrowsableState.Never)]
106 protected override void Dispose(bool disposing)
108 CleanCallbackDictionaries();
109 base.Dispose(disposing);
111 #endregion Constructor, Destructor, Dispose
116 /// Set or Get resource URL of Lottie file.
118 /// <since_tizen> 7 </since_tizen>
123 return GetValue(URLProperty) as string;
127 SetValue(URLProperty, value);
128 NotifyPropertyChanged();
132 private string InternalURL
136 // Reset cached infomations.
137 currentStates.contentInfo = null;
138 currentStates.mark1 = null;
139 currentStates.mark2 = null;
140 currentStates.framePlayRangeMin = -1;
141 currentStates.framePlayRangeMax = -1;
142 currentStates.totalFrame = -1;
144 string ret = (value == null ? "" : value);
145 currentStates.url = ret;
147 NUILog.Debug($"<[{GetId()}]SET url={currentStates.url}");
149 // TODO : Could create new Image without additional creation?
150 using PropertyMap map = new PropertyMap();
151 using PropertyValue type = new PropertyValue((int)Visual.Type.AnimatedVectorImage);
152 using PropertyValue url = new PropertyValue(currentStates.url);
153 using PropertyValue loopCnt = new PropertyValue(currentStates.loopCount);
154 using PropertyValue stopAction = new PropertyValue((int)currentStates.stopEndAction);
155 using PropertyValue loopMode = new PropertyValue((int)currentStates.loopMode);
156 using PropertyValue redrawInScalingDown = new PropertyValue(currentStates.redrawInScalingDown);
158 map.Add(Visual.Property.Type, type)
159 .Add(ImageVisualProperty.URL, url)
160 .Add(ImageVisualProperty.LoopCount, loopCnt)
161 .Add(ImageVisualProperty.StopBehavior, stopAction)
162 .Add(ImageVisualProperty.LoopingMode, loopMode)
163 .Add(ImageVisualProperty.RedrawInScalingDown, redrawInScalingDown);
166 // All states applied well.
167 currentStates.changed = false;
169 if (currentStates.scale != 1.0f)
171 Scale = new Vector3(currentStates.scale, currentStates.scale, currentStates.scale);
173 NUILog.Debug($"<[{GetId()}]>");
177 string ret = currentStates.url;
178 NUILog.Debug($"<[{GetId()}] GET");
179 NUILog.Debug($"gotten url={ret} >");
185 /// Gets the playing state
187 /// <since_tizen> 7 </since_tizen>
188 public PlayStateType PlayState
192 NUILog.Debug($"< Get!");
195 Interop.View.InternalRetrievingVisualPropertyInt(this.SwigCPtr, ImageView.Property.IMAGE, ImageVisualProperty.PlayState, out ret);
197 currentStates.playState = (PlayStateType)ret;
198 NUILog.Debug($"gotten play state={currentStates.playState} >");
200 return currentStates.playState;
205 /// Get the number of total frames
207 /// <since_tizen> 7 </since_tizen>
208 public int TotalFrame
212 int ret = currentStates.totalFrame;
215 Interop.View.InternalRetrievingVisualPropertyInt(this.SwigCPtr, ImageView.Property.IMAGE, ImageVisualProperty.TotalFrameNumber, out ret);
217 currentStates.totalFrame = ret;
218 NUILog.Debug($"TotalFrameNumber get! ret={ret}");
225 /// Set or get the current frame. When setting a specific frame, it is displayed as a still image.
228 /// Gets the value set by a user. If the setting value is out-ranged, it is reset as a minimum frame or a maximum frame.
231 /// We assume that the animation in myLottie.json file has 100 frames originally. If so, its frame index will be 0 - 99.
233 /// LottieAnimationView myLottie = new LottieAnimationView();
234 /// myLottie.URL = Tizen.Applications.Application.Current.DirectoryInfo.Resource + "myLottie.json"; //myLottie.json's total frame is 100 (frame: 0~99)
235 /// NUIApplication.GetDefaultWindow().GetDefaultLayer().Add(myLottie);
236 /// myLottie.CurrentFrame = 200; //display 99 frame
237 /// myLottie.SetMinMaxFrame(10, 20);
238 /// myLottie.CurrentFrame = 15; //display 15 frame
239 /// myLottie.CurrentFrame = 50; //display 20 frame, because the MinMax is set (10,20) above
242 /// <since_tizen> 7 </since_tizen>
243 public int CurrentFrame
247 return (int)GetValue(CurrentFrameProperty);
251 SetValue(CurrentFrameProperty, value);
252 NotifyPropertyChanged();
256 private int InternalCurrentFrame
260 NUILog.Debug($"<[{GetId()}]SET frame={value}>");
262 Interop.View.DoActionWithSingleIntAttributes(this.SwigCPtr, ImageView.Property.IMAGE, ActionJumpTo, value);
268 Interop.View.InternalRetrievingVisualPropertyInt(this.SwigCPtr, ImageView.Property.IMAGE, ImageVisualProperty.CurrentFrameNumber, out ret);
270 NUILog.Debug($"CurrentFrameNumber get! val={ret}");
276 /// Sets or gets the looping mode of Lottie animation.
278 /// <since_tizen> 7 </since_tizen>
279 public LoopingModeType LoopingMode
283 return (LoopingModeType)GetValue(LoopingModeProperty);
287 SetValue(LoopingModeProperty, value);
288 NotifyPropertyChanged();
292 private LoopingModeType InternalLoopingMode
296 if (currentStates.loopMode != (LoopingModeType)value)
298 currentStates.changed = true;
299 currentStates.loopMode = (LoopingModeType)value;
301 NUILog.Debug($"<[{GetId()}] SET loopMode={currentStates.loopMode}>");
303 Interop.View.InternalUpdateVisualPropertyInt(this.SwigCPtr, ImageView.Property.IMAGE, ImageVisualProperty.LoopingMode, (int)currentStates.loopMode);
308 NUILog.Debug($"LoopMode get! {currentStates.loopMode}");
309 return currentStates.loopMode;
314 /// Sets or gets the loop count.
317 /// The minus value means the infinite loop count.
321 /// LottieAnimationView myLottie = new LottieAnimationView();
322 /// myLottie.URL = Tizen.Applications.Application.Current.DirectoryInfo.Resource + "myLottie.json"; //myLottie.json's total frame is 100 (frame: 0~99)
323 /// NUIApplication.GetDefaultWindow().GetDefaultLayer().Add(myLottie);
324 /// myLottie.LoopCount = -1; //infinite loop
326 /// myLottie.Stop(); //it plays continuously unless Stop() is called
327 /// myLottie.LoopCount = 2;
328 /// myLottie.Play(); //it plays only 2 times and stops automatically
331 /// <since_tizen> 7 </since_tizen>
336 return (int)GetValue(LoopCountProperty);
340 SetValue(LoopCountProperty, value);
341 NotifyPropertyChanged();
345 private int InternalLoopCount
349 if (currentStates.loopCount != value)
351 currentStates.changed = true;
352 currentStates.loopCount = value;
354 NUILog.Debug($"<[{GetId()}]SET currentStates.loopCount={currentStates.loopCount}>");
356 Interop.View.InternalUpdateVisualPropertyInt(this.SwigCPtr, ImageView.Property.IMAGE, ImageVisualProperty.LoopCount, currentStates.loopCount);
361 NUILog.Debug($"LoopCount get! {currentStates.loopCount}");
362 return currentStates.loopCount;
367 /// Sets or gets the stop behavior.
369 /// <since_tizen> 7 </since_tizen>
370 public StopBehaviorType StopBehavior
374 return (StopBehaviorType)GetValue(StopBehaviorProperty);
378 SetValue(StopBehaviorProperty, value);
379 NotifyPropertyChanged();
383 private StopBehaviorType InternalStopBehavior
387 if (currentStates.stopEndAction != (StopBehaviorType)value)
389 currentStates.changed = true;
390 currentStates.stopEndAction = (StopBehaviorType)value;
392 NUILog.Debug($"<[{GetId()}]SET val={currentStates.stopEndAction}>");
394 Interop.View.InternalUpdateVisualPropertyInt(this.SwigCPtr, ImageView.Property.IMAGE, ImageVisualProperty.StopBehavior, (int)currentStates.stopEndAction);
399 NUILog.Debug($"StopBehavior get! {currentStates.stopEndAction}");
400 return currentStates.stopEndAction;
405 /// Whether to redraw the image when the visual is scaled down.
409 /// It is used in the AnimatedVectorImageVisual.The default is true.
411 [EditorBrowsable(EditorBrowsableState.Never)]
412 public bool RedrawInScalingDown
416 return (bool)GetValue(RedrawInScalingDownProperty);
420 SetValue(RedrawInScalingDownProperty, value);
421 NotifyPropertyChanged();
425 private bool InternalRedrawInScalingDown
429 if (currentStates.redrawInScalingDown != value)
431 currentStates.changed = true;
432 currentStates.redrawInScalingDown = value;
434 NUILog.Debug($"<[{GetId()}]SET currentStates.redrawInScalingDown={currentStates.redrawInScalingDown}>");
436 Interop.View.InternalUpdateVisualPropertyBool(this.SwigCPtr, ImageView.Property.IMAGE, ImageVisualProperty.RedrawInScalingDown, currentStates.redrawInScalingDown);
441 NUILog.Debug($"RedrawInScalingDown get! {currentStates.redrawInScalingDown}");
442 return currentStates.redrawInScalingDown;
448 /// Actions property value to Jump to the specified frame.
449 /// This property can be redefined by child class if it use different value.
451 [EditorBrowsable(EditorBrowsableState.Never)]
452 protected int ActionJumpTo { get; set; } = Interop.LottieAnimationView.AnimatedVectorImageVisualActionJumpToGet();
454 // This is used for internal purpose. hidden API.
455 [EditorBrowsable(EditorBrowsableState.Never)]
456 protected int SetDynamicProperty => ActionJumpTo + 1;
462 /// Set the minimum and the maximum frame.
464 /// <param name="minFrame">minimum frame</param>
465 /// <param name="maxFrame">maximum frame</param>
466 /// <since_tizen> 7 </since_tizen>
467 public void SetMinMaxFrame(int minFrame, int maxFrame)
469 if (currentStates.framePlayRangeMin != minFrame || currentStates.framePlayRangeMax != maxFrame)
471 NUILog.Debug($"< [{GetId()}] SetPlayRange({minFrame}, {maxFrame})");
472 currentStates.changed = true;
473 currentStates.framePlayRangeMin = minFrame;
474 currentStates.framePlayRangeMax = maxFrame;
476 Interop.View.InternalUpdateVisualPropertyIntPair(this.SwigCPtr, ImageView.Property.IMAGE, ImageVisualProperty.PlayRange, currentStates.framePlayRangeMin, currentStates.framePlayRangeMax);
478 NUILog.Debug($" [{GetId()}] currentStates.min:({currentStates.framePlayRangeMin}, max:{currentStates.framePlayRangeMax})>");
485 /// <since_tizen> 7 </since_tizen>
486 public new void Play()
488 NUILog.Debug($"<[{GetId()}] Play()");
491 NUILog.Debug($"[{GetId()}]>");
497 /// <since_tizen> 7 </since_tizen>
498 public new void Pause()
500 NUILog.Debug($"<[{GetId()}] Pause()>");
503 NUILog.Debug($"[{GetId()}]>");
509 /// <since_tizen> 7 </since_tizen>
510 public new void Stop()
512 NUILog.Debug($"<[{GetId()}] Stop()");
515 NUILog.Debug($"[{GetId()}]>");
519 /// Get the list of layers' information such as the start frame and the end frame in the Lottie file.
521 /// <returns>List of Tuple (string of layer name, integer of start frame, integer of end frame)</returns>
522 /// <since_tizen> 7 </since_tizen>
523 public List<Tuple<string, int, int>> GetContentInfo()
525 if (currentStates.contentInfo != null)
527 return currentStates.contentInfo;
532 PropertyMap imageMap = base.Image;
533 if (imageMap != null)
535 PropertyValue val = imageMap.Find(ImageVisualProperty.ContentInfo);
536 PropertyMap contentMap = new PropertyMap();
537 if (val?.Get(ref contentMap) == true)
539 currentStates.contentInfo = new List<Tuple<string, int, int>>();
540 for (uint i = 0; i < contentMap.Count(); i++)
542 using PropertyKey propertyKey = contentMap.GetKeyAt(i);
543 string key = propertyKey.StringKey;
545 using PropertyValue arrVal = contentMap.GetValue(i);
546 using PropertyArray arr = new PropertyArray();
550 using PropertyValue start = arr.GetElementAt(0);
551 start?.Get(out startFrame);
554 using PropertyValue end = arr.GetElementAt(1);
555 end?.Get(out endFrame);
557 NUILog.Debug($"[{i}] layer name={key}, startFrame={startFrame}, endFrame={endFrame}");
559 Tuple<string, int, int> item = new Tuple<string, int, int>(key, startFrame, endFrame);
561 currentStates.contentInfo?.Add(item);
565 contentMap.Dispose();
570 return currentStates.contentInfo;
574 /// A marker has its start frame and end frame.
575 /// Animation will play between the start frame and the end frame of the marker if one marker is specified.
576 /// Or animation will play between the start frame of the first marker and the end frame of the second marker if two markers are specified. *
578 /// <param name="marker1">First marker</param>
579 /// <param name="marker2">Second marker</param>
580 // This will be public opened after ACR done. (Before ACR, need to be hidden as Inhouse API)
581 [EditorBrowsable(EditorBrowsableState.Never)]
582 public void SetMinMaxFrameByMarker(string marker1, string marker2 = null)
584 if (currentStates.mark1 != marker1 || currentStates.mark2 != marker2)
586 NUILog.Debug($"< [{GetId()}] SetMinMaxFrameByMarker({marker1}, {marker2})");
588 currentStates.changed = true;
589 currentStates.mark1 = marker1;
590 currentStates.mark2 = marker2;
592 if (string.IsNullOrEmpty(currentStates.mark2))
594 Interop.View.InternalUpdateVisualPropertyString(this.SwigCPtr, ImageView.Property.IMAGE, ImageVisualProperty.PlayRange, currentStates.mark1);
598 Interop.View.InternalUpdateVisualPropertyStringPair(this.SwigCPtr, ImageView.Property.IMAGE, ImageVisualProperty.PlayRange, currentStates.mark1, currentStates.mark2);
601 NUILog.Debug($" [{GetId()}] currentStates.mark1:{currentStates.mark1}, mark2:{currentStates.mark2} >");
608 /// <returns>Tuple of Min and Max frames</returns>
609 // This will be public opened after ACR done. (Before ACR, need to be hidden as Inhouse API)
610 [EditorBrowsable(EditorBrowsableState.Never)]
611 public Tuple<int, int> GetMinMaxFrame()
613 NUILog.Debug($"< [{GetId()}] GetMinMaxFrame()! total frame={currentStates.totalFrame}");
615 using PropertyMap map = Image;
618 using PropertyValue val = map.Find(ImageVisualProperty.PlayRange);
621 using PropertyArray array = new PropertyArray();
624 uint cnt = array.Count();
625 int item1 = -1, item2 = -1;
626 for (uint i = 0; i < cnt; i++)
628 using PropertyValue v = array.GetElementAt(i);
630 if (v.Get(out intRet))
632 NUILog.Debug($"Got play range of string [{i}]: {intRet}");
644 Tizen.Log.Error("NUI", $"[ERR] fail to get play range from dali! case#1");
647 NUILog.Debug($" [{GetId()}] GetMinMaxFrame(min:{item1}, max:{item2})! >");
648 return new Tuple<int, int>(item1, item2);
652 Tizen.Log.Error("NUI", $"[ERR] fail to get play range from dali! case#2");
653 return new Tuple<int, int>(-1, -1);
656 // This will be public opened after ACR done. (Before ACR, need to be hidden as Inhouse API)
657 [EditorBrowsable(EditorBrowsableState.Never)]
658 public void DoActionExtension(LottieAnimationViewDynamicProperty info)
660 dynamicPropertyCallbackId++;
662 weakReferencesOfLottie?.Add(dynamicPropertyCallbackId, new WeakReference<LottieAnimationView>(this));
663 InternalSavedDynamicPropertyCallbacks?.Add(dynamicPropertyCallbackId, info.Callback);
665 Interop.View.DoActionExtension(SwigCPtr, ImageView.Property.IMAGE, SetDynamicProperty, dynamicPropertyCallbackId, info.KeyPath, (int)info.Property, Marshal.GetFunctionPointerForDelegate<System.Delegate>(rootCallback));
667 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
670 private void CleanCallbackDictionaries()
672 if (weakReferencesOfLottie?.Count > 0 && InternalSavedDynamicPropertyCallbacks != null)
674 foreach (var key in InternalSavedDynamicPropertyCallbacks?.Keys)
676 if (weakReferencesOfLottie.ContainsKey(key))
678 weakReferencesOfLottie.Remove(key);
682 InternalSavedDynamicPropertyCallbacks?.Clear();
683 InternalSavedDynamicPropertyCallbacks = null;
687 /// Update lottie-image-relative properties synchronously.
688 /// After call this API, All image properties updated.
690 [EditorBrowsable(EditorBrowsableState.Never)]
691 protected override void UpdateImage()
693 if (!imagePropertyUpdatedFlag) return;
695 // Update currentStates properties to cachedImagePropertyMap
696 if(currentStates.changed)
698 UpdateImage(ImageVisualProperty.LoopCount, new PropertyValue(currentStates.loopCount), false);
699 UpdateImage(ImageVisualProperty.StopBehavior, new PropertyValue((int)currentStates.stopEndAction), false);
700 UpdateImage(ImageVisualProperty.LoopingMode, new PropertyValue((int)currentStates.loopMode), false);
701 UpdateImage(ImageVisualProperty.RedrawInScalingDown, new PropertyValue(currentStates.redrawInScalingDown), false);
703 // Do not cache PlayRange and TotalFrameNumber into cachedImagePropertyMap.
704 // (To keep legacy implements behaviour)
705 currentStates.changed = false;
712 /// Update NUI cached animated image visual property map by inputed property map.
713 /// And call base.MergeCachedImageVisualProperty()
716 /// For performance issue, we will collect only "cachedLottieAnimationPropertyKeyList" hold in this class.
718 [EditorBrowsable(EditorBrowsableState.Never)]
719 protected override void MergeCachedImageVisualProperty(PropertyMap map)
721 if (map == null) return;
722 if (cachedImagePropertyMap == null)
724 cachedImagePropertyMap = new PropertyMap();
726 foreach (var key in cachedLottieAnimationPropertyKeyList)
728 PropertyValue value = map.Find(key);
731 // Update-or-Insert new value
732 cachedImagePropertyMap[key] = value;
735 base.MergeCachedImageVisualProperty(map);
740 #region Event, Enum, Struct, ETC
742 /// Animation finished event.
744 /// <since_tizen> 7 </since_tizen>
745 public event EventHandler Finished
749 if (finishedEventHandler == null)
751 NUILog.Debug($"<[{GetId()}] Finished eventhandler added>");
752 visualEventSignalCallback = onVisualEventSignal;
753 using VisualEventSignal visualEvent = VisualEventSignal();
754 visualEvent.Connect(visualEventSignalCallback);
756 finishedEventHandler += value;
760 NUILog.Debug($"<[{GetId()}] Finished eventhandler removed>");
761 finishedEventHandler -= value;
762 if (finishedEventHandler == null && visualEventSignalCallback != null)
764 using VisualEventSignal visualEvent = VisualEventSignal();
765 visualEvent.Disconnect(visualEventSignalCallback);
766 if (visualEvent?.Empty() == true)
768 visualEventSignalCallback = null;
775 /// Enumeration for what state the vector animation is in
777 /// <since_tizen> 7 </since_tizen>
778 public enum PlayStateType
783 /// <since_tizen> 7 </since_tizen>
786 /// Vector Animation has stopped
788 /// <since_tizen> 7 </since_tizen>
791 /// The vector animation is playing
793 /// <since_tizen> 7 </since_tizen>
796 /// The vector animation is paused
798 /// <since_tizen> 7 </since_tizen>
803 /// Enumeration for what to do when the animation is stopped.
805 /// <since_tizen> 7 </since_tizen>
806 public enum StopBehaviorType
809 /// When the animation is stopped, the current frame is shown.
811 /// <since_tizen> 7 </since_tizen>
814 /// When the animation is stopped, the min frame (first frame) is shown.
816 /// <since_tizen> 7 </since_tizen>
819 /// When the animation is stopped, the max frame (last frame) is shown.
821 /// <since_tizen> 7 </since_tizen>
826 /// Enumeration for what looping mode is in.
828 /// <since_tizen> 7 </since_tizen>
829 public enum LoopingModeType
832 /// When the animation arrives at the end in looping mode, the animation restarts from the beginning.
834 /// <since_tizen> 7 </since_tizen>
837 /// When the animation arrives at the end in looping mode, the animation reverses direction and runs backwards again.
839 /// <since_tizen> 7 </since_tizen>
846 // This will be public opened after ACR done. (Before ACR, need to be hidden as Inhouse API)
847 [EditorBrowsable(EditorBrowsableState.Never)]
848 public enum VectorProperty
851 /// Fill color of the object, Type of <see cref="Vector3"/>
853 [EditorBrowsable(EditorBrowsableState.Never)]
857 /// Fill opacity of the object, Type of float
859 [EditorBrowsable(EditorBrowsableState.Never)]
863 /// Stroke color of the object, Type of <see cref="Vector3"/>
865 [EditorBrowsable(EditorBrowsableState.Never)]
869 /// Stroke opacity of the object, Type of float
871 [EditorBrowsable(EditorBrowsableState.Never)]
875 /// Stroke width of the object, Type of float
877 [EditorBrowsable(EditorBrowsableState.Never)]
881 /// Transform anchor of the Layer and Group object, Type of <see cref="Vector2"/>
883 [EditorBrowsable(EditorBrowsableState.Never)]
887 /// Transform position of the Layer and Group object, Type of <see cref="Vector2"/>
889 [EditorBrowsable(EditorBrowsableState.Never)]
893 /// Transform scale of the Layer and Group object, Type of <see cref="Vector2"/>, Value range of [0..100]
895 [EditorBrowsable(EditorBrowsableState.Never)]
899 /// Transform rotation of the Layer and Group object, Type of float, Value range of [0..360] in degrees
901 [EditorBrowsable(EditorBrowsableState.Never)]
905 /// Transform opacity of the Layer and Group object, Type of float
907 [EditorBrowsable(EditorBrowsableState.Never)]
911 // This will be public opened after ACR done. (Before ACR, need to be hidden as Inhouse API)
912 [EditorBrowsable(EditorBrowsableState.Never)]
913 [UnmanagedFunctionPointer(CallingConvention.Cdecl)]
914 public delegate PropertyValue DynamicPropertyCallbackType(int returnType, uint frameNumber);
915 #endregion Event, Enum, Struct, ETC
919 internal class VisualEventSignalArgs : EventArgs
921 public int VisualIndex
933 internal event EventHandler<VisualEventSignalArgs> VisualEvent
937 if (visualEventSignalHandler == null)
939 visualEventSignalCallback = onVisualEventSignal;
940 using VisualEventSignal visualEvent = VisualEventSignal();
941 visualEvent?.Connect(visualEventSignalCallback);
943 visualEventSignalHandler += value;
947 visualEventSignalHandler -= value;
948 if (visualEventSignalHandler == null && visualEventSignalCallback != null)
950 using VisualEventSignal visualEvent = VisualEventSignal();
951 visualEvent?.Disconnect(visualEventSignalCallback);
952 if (visualEvent?.Empty() == true)
954 visualEventSignalCallback = null;
960 internal void EmitVisualEventSignal(int visualIndex, int signalId)
962 using VisualEventSignal visualEvent = VisualEventSignal();
963 visualEvent?.Emit(this, visualIndex, signalId);
966 internal VisualEventSignal VisualEventSignal()
968 VisualEventSignal ret = new VisualEventSignal(Interop.VisualEventSignal.NewWithView(View.getCPtr(this)), false);
969 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
973 internal Dictionary<int, DynamicPropertyCallbackType> InternalSavedDynamicPropertyCallbacks = new Dictionary<int, DynamicPropertyCallbackType>();
975 [UnmanagedFunctionPointer(CallingConvention.Cdecl)]
976 internal delegate void RootCallbackType(int id, int returnType, uint frameNumber, ref float val1, ref float val2, ref float val3);
978 internal RootCallbackType rootCallback = RootCallback;
980 static internal void RootCallback(int id, int returnType, uint frameNumber, ref float val1, ref float val2, ref float val3)
982 WeakReference<LottieAnimationView> current = null;
983 LottieAnimationView currentView = null;
984 DynamicPropertyCallbackType currentCallback = null;
985 PropertyValue ret = null;
987 if (weakReferencesOfLottie.TryGetValue(id, out current))
989 if (current.TryGetTarget(out currentView))
991 if (currentView != null && currentView.InternalSavedDynamicPropertyCallbacks != null &&
992 currentView.InternalSavedDynamicPropertyCallbacks.TryGetValue(id, out currentCallback))
994 ret = currentCallback?.Invoke(returnType, frameNumber);
998 Tizen.Log.Error("NUI", "can't find the callback in LottieAnimationView, just return here!");
1004 Tizen.Log.Error("NUI", "can't find the callback in LottieAnimationView, just return here!");
1010 Tizen.Log.Error("NUI", "can't find LottieAnimationView by id, just return here!");
1016 case (int)(VectorProperty.FillColor):
1017 case (int)(VectorProperty.StrokeColor):
1018 Vector3 tmpVector3 = new Vector3(-1, -1, -1);
1019 if ((ret != null) && ret.Get(tmpVector3))
1021 val1 = tmpVector3.X;
1022 val2 = tmpVector3.Y;
1023 val3 = tmpVector3.Z;
1025 tmpVector3.Dispose();
1028 case (int)(VectorProperty.TransformAnchor):
1029 case (int)(VectorProperty.TransformPosition):
1030 case (int)(VectorProperty.TransformScale):
1031 Vector2 tmpVector2 = new Vector2(-1, -1);
1032 if ((ret != null) && ret.Get(tmpVector2))
1034 val1 = tmpVector2.X;
1035 val2 = tmpVector2.Y;
1037 tmpVector2.Dispose();
1040 case (int)(VectorProperty.FillOpacity):
1041 case (int)(VectorProperty.StrokeOpacity):
1042 case (int)(VectorProperty.StrokeWidth):
1043 case (int)(VectorProperty.TransformRotation):
1044 case (int)(VectorProperty.TransformOpacity):
1045 float tmpFloat = -1;
1046 if ((ret != null) && ret.Get(out tmpFloat))
1062 // Collection of lottie-image-sensitive properties.
1063 private static readonly List<int> cachedLottieAnimationPropertyKeyList = new List<int> {
1064 ImageVisualProperty.LoopCount,
1065 ImageVisualProperty.StopBehavior,
1066 ImageVisualProperty.LoopingMode,
1067 ImageVisualProperty.RedrawInScalingDown,
1070 private struct states
1072 internal string url;
1073 internal int loopCount;
1074 internal LoopingModeType loopMode;
1075 internal StopBehaviorType stopEndAction;
1076 internal int framePlayRangeMin;
1077 internal int framePlayRangeMax;
1078 internal int totalFrame;
1079 internal float scale;
1080 internal PlayStateType playState;
1081 internal List<Tuple<string, int, int>> contentInfo;
1082 internal string mark1, mark2;
1083 internal bool redrawInScalingDown;
1084 internal bool changed;
1086 private states currentStates;
1088 private const string tag = "NUITEST";
1089 private event EventHandler finishedEventHandler;
1091 private void OnFinished()
1093 NUILog.Debug($"<[{GetId()}] OnFinished()>");
1094 finishedEventHandler?.Invoke(this, null);
1097 private void onVisualEventSignal(IntPtr targetView, int visualIndex, int signalId)
1101 if (targetView != IntPtr.Zero)
1103 View v = Registry.GetManagedBaseHandleFromNativePtr(targetView) as View;
1106 NUILog.Debug($"targetView is not null! name={v.Name}");
1110 NUILog.Debug($"target is something created from dali");
1113 VisualEventSignalArgs e = new VisualEventSignalArgs();
1114 e.VisualIndex = visualIndex;
1115 e.SignalId = signalId;
1116 visualEventSignalHandler?.Invoke(this, e);
1118 NUILog.Debug($"<[{GetId()}] onVisualEventSignal()! visualIndex={visualIndex}, signalId={signalId}>");
1121 [UnmanagedFunctionPointer(CallingConvention.StdCall)]
1122 private delegate void VisualEventSignalCallbackType(IntPtr targetView, int visualIndex, int signalId);
1124 private VisualEventSignalCallbackType visualEventSignalCallback;
1125 private EventHandler<VisualEventSignalArgs> visualEventSignalHandler;
1127 static private int dynamicPropertyCallbackId = 0;
1128 //static private Dictionary<int, DynamicPropertyCallbackType> dynamicPropertyCallbacks = new Dictionary<int, DynamicPropertyCallbackType>();
1129 static private Dictionary<int, WeakReference<LottieAnimationView>> weakReferencesOfLottie = new Dictionary<int, WeakReference<LottieAnimationView>>();
1131 private void debugPrint()
1133 NUILog.Debug($"===================================");
1134 NUILog.Debug($"<[{GetId()}] get currentStates : url={currentStates.url}, loopCount={currentStates.loopCount}, \nframePlayRangeMin/Max({currentStates.framePlayRangeMin},{currentStates.framePlayRangeMax}) ");
1135 NUILog.Debug($" get from Property : StopBehavior={StopBehavior}, LoopMode={LoopingMode}, LoopCount={LoopCount}, PlayState={PlayState}");
1136 NUILog.Debug($" RedrawInScalingDown={RedrawInScalingDown} >");
1137 NUILog.Debug($"===================================");
1144 /// A class containing frame informations for a LottieAnimationView.
1146 [EditorBrowsable(EditorBrowsableState.Never)]
1147 public class LottieFrameInfo : ICloneable
1150 /// Creates a new instance with a playing range.
1152 [EditorBrowsable(EditorBrowsableState.Never)]
1153 public LottieFrameInfo(int startFrame, int endFrame)
1155 StartFrame = startFrame;
1156 EndFrame = endFrame;
1160 /// Creates a new instance with a still image frame.
1162 [EditorBrowsable(EditorBrowsableState.Never)]
1163 public LottieFrameInfo(int stillImageFrame) : this(stillImageFrame, stillImageFrame)
1168 /// Create a new instance from a pair notation.
1170 [EditorBrowsable(EditorBrowsableState.Never)]
1171 public static implicit operator LottieFrameInfo((int, int) pair)
1173 return new LottieFrameInfo(pair.Item1, pair.Item2);
1177 /// Create a new instance from an int value.
1179 [EditorBrowsable(EditorBrowsableState.Never)]
1180 public static implicit operator LottieFrameInfo(int stillImageFrame)
1182 return new LottieFrameInfo(stillImageFrame);
1186 /// Create a new instance from string.
1187 /// Possible input : "0, 10", "10"
1189 [EditorBrowsable(EditorBrowsableState.Never)]
1190 public static implicit operator LottieFrameInfo(string pair)
1197 string[] parts = pair.Split(',');
1198 if (parts.Length == 1)
1200 return new LottieFrameInfo(Int32.Parse(parts[0].Trim(), CultureInfo.InvariantCulture));
1202 else if (parts.Length == 2)
1204 return new LottieFrameInfo(Int32.Parse(parts[0].Trim(), CultureInfo.InvariantCulture), Int32.Parse(parts[1].Trim(), CultureInfo.InvariantCulture));
1207 Tizen.Log.Error("NUI", $"Can not convert string {pair} to LottieFrameInfo");
1212 /// The start frame of the lottie animation.
1214 [EditorBrowsable(EditorBrowsableState.Never)]
1215 public int StartFrame { get; }
1218 /// The end frame of the lottie animation.
1220 [EditorBrowsable(EditorBrowsableState.Never)]
1221 public int EndFrame { get; }
1224 /// Create LottieFrameInfo struct with animation range information
1226 [EditorBrowsable(EditorBrowsableState.Never)]
1227 public static LottieFrameInfo CreateAnimationRange(int startFrame, int endFrame)
1229 return new LottieFrameInfo(startFrame, endFrame);
1233 /// Create LottieFrameInfo struct with still image information
1235 [EditorBrowsable(EditorBrowsableState.Never)]
1236 public static LottieFrameInfo CreateStillImage(int stillImageFrame)
1238 return new LottieFrameInfo(stillImageFrame, stillImageFrame);
1243 /// Whether this LottieFrameInfo represents one frame or more.
1245 [EditorBrowsable(EditorBrowsableState.Never)]
1246 public bool IsStillImage()
1248 return StartFrame == EndFrame;
1253 /// Play specified LottieAnimationView with this frame information.
1255 /// <param name="lottieView">The target LottieAnimationView to play.</param>
1256 /// <param name="noPlay">Whether go direct to the EndFrame. It is false by default.</param>
1257 [EditorBrowsable(EditorBrowsableState.Never)]
1258 [System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1062: Validate arguments of public methods", Justification = "The null checking is done by BeReadyToShow()")]
1259 public void Show(LottieAnimationView lottieView, bool noPlay = false)
1261 if (!BeReadyToShow(lottieView))
1266 lottieView.SetMinMaxFrame(StartFrame, Math.Min(EndFrame, lottieView.TotalFrame - 1));
1268 if (IsStillImage() || noPlay)
1270 lottieView.CurrentFrame = EndFrame;
1274 lottieView.CurrentFrame = StartFrame;
1280 [EditorBrowsable(EditorBrowsableState.Never)]
1281 public object Clone() => new LottieFrameInfo(StartFrame, EndFrame);
1283 private bool BeReadyToShow(LottieAnimationView lottieView)
1285 // Validate input lottieView
1286 if (null == lottieView || lottieView.PlayState == LottieAnimationView.PlayStateType.Invalid)
1291 // Stop if it was playing
1292 if (lottieView.PlayState == LottieAnimationView.PlayStateType.Playing)
1301 // This will be public opened after ACR done. (Before ACR, need to be hidden as Inhouse API)
1302 [EditorBrowsable(EditorBrowsableState.Never)]
1303 public struct LottieAnimationViewDynamicProperty : IEquatable<LottieAnimationViewDynamicProperty>
1305 [EditorBrowsable(EditorBrowsableState.Never)]
1306 public string KeyPath { get; set; }
1308 [EditorBrowsable(EditorBrowsableState.Never)]
1309 public LottieAnimationView.VectorProperty Property { get; set; }
1311 [EditorBrowsable(EditorBrowsableState.Never)]
1312 public LottieAnimationView.DynamicPropertyCallbackType Callback { get; set; }
1314 public override bool Equals(object obj)
1316 if (obj is LottieAnimationViewDynamicProperty target)
1318 if (KeyPath == target.KeyPath && Property == target.Property && Callback == target.Callback)
1326 public override int GetHashCode()
1328 return base.GetHashCode();
1331 public static bool operator ==(LottieAnimationViewDynamicProperty left, LottieAnimationViewDynamicProperty right)
1333 return left.Equals(right);
1336 public static bool operator !=(LottieAnimationViewDynamicProperty left, LottieAnimationViewDynamicProperty right)
1338 return !(left == right);
1341 public bool Equals(LottieAnimationViewDynamicProperty other)
1345 if (KeyPath == other.KeyPath && Property == other.Property && Callback == other.Callback)