Debug.Assert(((Loading)bindable).imageVisual != null);
return ((Loading)bindable).imageVisual.URLS;
});
+ /// <summary>The lottie resource url bindable property.</summary>
+ [EditorBrowsable(EditorBrowsableState.Never)]
+ public static readonly BindableProperty LottieResourceUrlProperty = BindableProperty.Create(nameof(LottieResourceUrl), typeof(string), typeof(Loading), null, propertyChanged: (bindable, oldValue, newValue) =>
+ {
+ var instance = (Loading)bindable;
+ instance.RemoveImageVisual();
+ instance.EnsureLottieView(newValue as string ?? string.Empty);
+ },
+ defaultValueCreator: (bindable) =>
+ {
+ var lottie = ((Loading)bindable).defaultLottieView;
+ return lottie == null ? string.Empty : lottie.URL;
+ });
/// <summary>The Size bindable property.</summary>
[EditorBrowsable(EditorBrowsableState.Never)]
public new static readonly BindableProperty SizeProperty = BindableProperty.Create(nameof(Size), typeof(Size), typeof(Loading), new Size(0, 0), propertyChanged: (bindable, oldValue, newValue) =>
return ((Loading)bindable).frameRate;
});
+ private const string ImageVisualName = "loadingImageVisual";
private AnimatedImageVisual imageVisual = null;
private LottieAnimationView defaultLottieView = null;
private int frameRate = (int)(1000 / 16.6f);
/// <summary>
/// Gets or sets loading image resource array.
+ /// The mutually exclusive with "LottieResourceUrl".
/// </summary>
/// <since_tizen> 6 </since_tizen>
public string[] ImageArray
}
set
{
- defaultLottieView?.Stop();
- defaultLottieView?.Dispose();
- defaultLottieView = null;
-
- CreateImageVisual();
+ RemoveLottieView();
+ EnsureImageVisual();
SetValue(ImageArrayProperty, value);
NotifyPropertyChanged();
}
}
+ /// <summary>
+ /// Gets or sets an lottie resource url.
+ /// The mutually exclusive with "ImageArray".
+ /// </summary>
+ [EditorBrowsable(EditorBrowsableState.Never)]
+ public string LottieResourceUrl
+ {
+ get => GetValue(LottieResourceUrlProperty) as string;
+ set => SetValue(LottieResourceUrlProperty, value);
+ }
+
/// <summary>
/// Gets or sets loading size.
/// </summary>
base.OnInitialize();
AccessibilityRole = Role.ProgressBar;
- defaultLottieView = new LottieAnimationView()
- {
- URL = lottieResource,
- LoopCount = -1,
- };
-
- Add(defaultLottieView);
- defaultLottieView.Play();
+ EnsureLottieView(lottieResource);
AccessibilityManager.Instance.SetAccessibilityAttribute(this, AccessibilityManager.AccessibilityAttribute.Trait, "Loading");
}
AccessibilityHighlightable = true;
}
- private void CreateImageVisual()
+ private void EnsureLottieView(string url)
+ {
+ if (defaultLottieView != null)
+ {
+ if (defaultLottieView.URL == url) return;
+ defaultLottieView.Stop();
+ }
+ else Add(defaultLottieView = new LottieAnimationView() { LoopCount = -1 });
+
+ defaultLottieView.URL = url;
+ defaultLottieView.Play();
+ }
+
+ private void RemoveLottieView()
+ {
+ if (defaultLottieView == null) return;
+ defaultLottieView.Stop();
+ defaultLottieView.Dispose();
+ defaultLottieView = null;
+ }
+
+ private void EnsureImageVisual()
{
if (imageVisual == null)
{
Size = new Size2D(1, 1)
};
- AddVisual("loadingImageVisual", imageVisual);
+ AddVisual(ImageVisualName, imageVisual);
}
}
+
+ private void RemoveImageVisual()
+ {
+ if (imageVisual == null) return;
+ RemoveVisual(ImageVisualName);
+ imageVisual.Dispose();
+ imageVisual = null;
+ }
}
}
/// <since_tizen> 6 </since_tizen>
public partial class Progress : Control, IAtspiValue
{
+ private const int IndeterminateAnimationDuration = 2000;
+
/// <summary>
/// MaxValueProperty
/// </summary>
this.size = new Vector2(size);
UpdateValue();
+
+ if (state == ProgressStatusType.Indeterminate) UpdateIndeterminateAnimation();
}
/// <summary>
[EditorBrowsable(EditorBrowsableState.Never)]
private void UpdateIndeterminateAnimation()
{
- indeterminateAnimation?.Stop();
+ if (indeterminateImage == null) return;
- if (null != indeterminateImage)
+ if (indeterminateAnimation == null)
{
- if (indeterminateAnimation == null)
- {
- indeterminateAnimation = new Animation(2000);
- }
+ indeterminateAnimation = new Animation(IndeterminateAnimationDuration);
+ }
+ else
+ {
+ indeterminateAnimation.Stop();
+ indeterminateAnimation.Clear();
+ }
- float destination = (this.SizeWidth - indeterminateImage.SizeWidth);
+ float destination = (this.SizeWidth - indeterminateImage.SizeWidth);
- KeyFrames keyFrames = new KeyFrames();
- keyFrames.Add(0.0f /* 0%*/, new Position(0, 0));
- AlphaFunction ease = new AlphaFunction(AlphaFunction.BuiltinFunctions.EaseInOut);
- keyFrames.Add(0.5f /* 50%*/, new Position(destination, 0), ease);
- keyFrames.Add(1.0f /*100%*/, new Position(0, 0), ease);
- ease.Dispose();
+ KeyFrames keyFrames = new KeyFrames();
+ keyFrames.Add(0.0f /* 0%*/, new Position(0, 0));
+ AlphaFunction ease = new AlphaFunction(AlphaFunction.BuiltinFunctions.EaseInOut);
+ keyFrames.Add(0.5f /* 50%*/, new Position(destination, 0), ease);
+ keyFrames.Add(1.0f /*100%*/, new Position(0, 0), ease);
+ ease.Dispose();
- indeterminateAnimation.AnimateBetween(indeterminateImage, "Position", keyFrames);
- indeterminateAnimation.Looping = true;
- indeterminateAnimation.Play();
- }
+ indeterminateAnimation.AnimateBetween(indeterminateImage, "Position", keyFrames);
+ indeterminateAnimation.Looping = true;
+ indeterminateAnimation.Play();
}
/// <summary>
defaultValueCreator: (bindable) => ((LoadingStyle)bindable).images
);
+ /// <summary>The lottie resource url bindable property.</summary>
+ [EditorBrowsable(EditorBrowsableState.Never)]
+ public static readonly BindableProperty LottieResourceUrlProperty = BindableProperty.Create(nameof(LottieResourceUrl), typeof(string), typeof(LoadingStyle), null, propertyChanged: (bindable, oldValue, newValue) =>
+ {
+ ((LoadingStyle)bindable).lottieResourceUrl = newValue as string;
+ },
+ defaultValueCreator: (bindable) => ((LoadingStyle)bindable).lottieResourceUrl
+ );
+
private Selector<int?> frameRate;
private List<string> images;
+ private string lottieResourceUrl;
static LoadingStyle() { }
internal set => SetValue(ImageListProperty, value);
}
+ /// <summary>
+ /// Gets or sets an lottie resource url.
+ /// The mutually exclusive with "ImageArray".
+ /// </summary>
+ [EditorBrowsable(EditorBrowsableState.Never)]
+ public string LottieResourceUrl
+ {
+ get => GetValue(LottieResourceUrlProperty) as string;
+ set => SetValue(LottieResourceUrlProperty, value);
+ }
+
/// <summary>
/// Gets or sets loading image size.
/// </summary>