Skip to content

Commit

Permalink
[NUI] DO NOT use BindableProperty in Style.
Browse files Browse the repository at this point in the history
This patch is cherry-picked from repo of Ms. Yang:
rabbitfor@f451a96
rabbitfor@432de16
  • Loading branch information
huayongxu authored and dongsug-song committed Feb 17, 2025
1 parent 764b0a4 commit abd9693
Show file tree
Hide file tree
Showing 19 changed files with 831 additions and 7,658 deletions.
419 changes: 28 additions & 391 deletions src/Tizen.NUI.Components/Style/ButtonStyle.cs

Large diffs are not rendered by default.

193 changes: 15 additions & 178 deletions src/Tizen.NUI.Components/Style/LoadingStyle.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,86 +27,14 @@ namespace Tizen.NUI.Components
/// <since_tizen> 8 </since_tizen>
public class LoadingStyle : ControlStyle
{
/// <summary>The FrameRateSelector bindable property.</summary>
[EditorBrowsable(EditorBrowsableState.Never)]
public static readonly BindableProperty FrameRateSelectorProperty = null;
internal static void SetInternalFrameRateSelectorProperty(BindableObject bindable, object oldValue, object newValue)
{
((LoadingStyle)bindable).frameRate = ((Selector<int?>)newValue)?.Clone();
}
internal static object GetInternalFrameRateSelectorProperty(BindableObject bindable)
{
return ((LoadingStyle)bindable).frameRate;
}

/// <summary>The LoadingSize bindable property.</summary>
[EditorBrowsable(EditorBrowsableState.Never)]
public static readonly BindableProperty LoadingSizeProperty = null;
internal static void SetInternalLoadingSizeProperty(BindableObject bindable, object oldValue, object newValue)
{
((LoadingStyle)bindable).Size = (Size)newValue;
}
internal static object GetInternalLoadingSizeProperty(BindableObject bindable)
{
return ((LoadingStyle)bindable).Size;
}

/// <summary>The Images bindable property.</summary>
[EditorBrowsable(EditorBrowsableState.Never)]
public static readonly BindableProperty ImagesProperty = null;
internal static void SetInternalImagesProperty(BindableObject bindable, object oldValue, object newValue)
{
((LoadingStyle)bindable).images = newValue == null ? null : new List<string>((string[])newValue);
}
internal static object GetInternalImagesProperty(BindableObject bindable)
{
return ((LoadingStyle)bindable).images?.ToArray();
}

/// <summary>The Images bindable property.</summary>
[EditorBrowsable(EditorBrowsableState.Never)]
public static readonly BindableProperty ImageListProperty = null;
internal static void SetInternalImageListProperty(BindableObject bindable, object oldValue, object newValue)
{
((LoadingStyle)bindable).images = newValue == null ? null : newValue as List<string>;
}
internal static object GetInternalImageListProperty(BindableObject bindable)
{
return ((LoadingStyle)bindable).images;
}

/// <summary>The lottie resource url bindable property.</summary>
[EditorBrowsable(EditorBrowsableState.Never)]
public static readonly BindableProperty LottieResourceUrlProperty = null;
internal static void SetInternalLottieResourceUrlProperty(BindableObject bindable, object oldValue, object newValue)
{
((LoadingStyle)bindable).lottieResourceUrl = newValue as string;
}
internal static object GetInternalLottieResourceUrlProperty(BindableObject bindable)
{
return ((LoadingStyle)bindable).lottieResourceUrl;
}
// NOTE framerate selector does not work.
static readonly IStyleProperty FrameRateProperty = new StyleProperty<Loading, Selector<int?>>((v, o) => v.FrameRate = (int)o.Normal);
static readonly IStyleProperty ImageListProperty = new StyleProperty<Loading, IList<string>>((v, o) => Loading.SetInternalImageListProperty(v, null, o));
static readonly IStyleProperty LottieResourceUrlProperty = new StyleProperty<Loading, string>((v, o) => v.LottieResourceUrl = o);

private Selector<int?> frameRate;
private List<string> images;
private string lottieResourceUrl;
private Size loadingSize;

static LoadingStyle()
{
if (NUIApplication.IsUsingXaml)
{
FrameRateSelectorProperty = BindableProperty.Create("FrameRateSelector", typeof(Selector<int?>), typeof(LoadingStyle), null,
propertyChanged: SetInternalFrameRateSelectorProperty, defaultValueCreator: GetInternalFrameRateSelectorProperty);
LoadingSizeProperty = BindableProperty.Create(nameof(LoadingSize), typeof(Size), typeof(LoadingStyle), null,
propertyChanged: SetInternalLoadingSizeProperty, defaultValueCreator: GetInternalLoadingSizeProperty);
ImagesProperty = BindableProperty.Create(nameof(Images), typeof(string[]), typeof(LoadingStyle), null,
propertyChanged: SetInternalImagesProperty, defaultValueCreator: GetInternalImagesProperty);
ImageListProperty = BindableProperty.Create(nameof(ImageList), typeof(IList<string>), typeof(LoadingStyle), null,
propertyChanged: SetInternalImageListProperty, defaultValueCreator: GetInternalImageListProperty);
LottieResourceUrlProperty = BindableProperty.Create(nameof(LottieResourceUrl), typeof(string), typeof(LoadingStyle), null,
propertyChanged: SetInternalLottieResourceUrlProperty, defaultValueCreator: GetInternalLottieResourceUrlProperty);
}
}
static LoadingStyle() { }

/// <summary>
/// Creates a new instance of a LoadingStyle.
Expand All @@ -127,24 +55,7 @@ public LoadingStyle(LoadingStyle style) : base(style)
/// Gets or sets loading image resources.
/// </summary>
/// <since_tizen> 8 </since_tizen>
public string[] Images
{
get
{
return (ImageList as List<string>)?.ToArray();
}
set
{
if (NUIApplication.IsUsingXaml)
{
SetValue(ImagesProperty, value);
}
else
{
SetInternalImagesProperty(this, null, value);
}
}
}
public string[] Images { get; set; }

/// <summary>
/// Gets loading image resources.
Expand All @@ -154,26 +65,9 @@ public IList<string> ImageList
{
get
{
if (NUIApplication.IsUsingXaml)
{
return GetValue(ImageListProperty) as List<string>;
}
else
{
return GetInternalImageListProperty(this) as IList<string>;
}
}
internal set
{
if (NUIApplication.IsUsingXaml)
{
SetValue(ImageListProperty, value);
}
else
{
SetInternalImageListProperty(this, null, value);
}
return GetValue(ImageListProperty) as List<string>;
}
internal set => SetValue(ImageListProperty, value);
}

/// <summary>
Expand All @@ -183,28 +77,8 @@ internal set
[EditorBrowsable(EditorBrowsableState.Never)]
public string LottieResourceUrl
{
get
{
if (NUIApplication.IsUsingXaml)
{
return GetValue(LottieResourceUrlProperty) as string;
}
else
{
return GetInternalLottieResourceUrlProperty(this) as string;
}
}
set
{
if (NUIApplication.IsUsingXaml)
{
SetValue(LottieResourceUrlProperty, value);
}
else
{
SetInternalLottieResourceUrlProperty(this, null, value);
}
}
get => GetValue(LottieResourceUrlProperty) as string;
set => SetValue(LottieResourceUrlProperty, value);
}

/// <summary>
Expand All @@ -213,27 +87,10 @@ public string LottieResourceUrl
/// <since_tizen> 8 </since_tizen>
public Size LoadingSize
{
get
{
if (NUIApplication.IsUsingXaml)
{
return (Size)GetValue(LoadingSizeProperty);
}
else
{
return (Size)GetInternalLoadingSizeProperty(this);
}
}
get => loadingSize;
set
{
if (NUIApplication.IsUsingXaml)
{
SetValue(LoadingSizeProperty, value);
}
else
{
SetInternalLoadingSizeProperty(this, null, value);
}
loadingSize = value;
}
}

Expand All @@ -243,28 +100,8 @@ public Size LoadingSize
/// <since_tizen> 8 </since_tizen>
public Selector<int?> FrameRate
{
get
{
if (NUIApplication.IsUsingXaml)
{
return (Selector<int?>)GetValue(FrameRateSelectorProperty);
}
else
{
return (Selector<int?>)GetInternalFrameRateSelectorProperty(this);
}
}
set
{
if (NUIApplication.IsUsingXaml)
{
SetValue(FrameRateSelectorProperty, value);
}
else
{
SetInternalFrameRateSelectorProperty(this, null, value);
}
}
get => (Selector<int?>)GetValue(FrameRateProperty);
set => SetValue(FrameRateProperty, value);
}

/// <inheritdoc/>
Expand Down
127 changes: 10 additions & 117 deletions src/Tizen.NUI.Components/Style/PaginationStyle.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,58 +26,11 @@ namespace Tizen.NUI.Components
/// <since_tizen> 8 </since_tizen>
public class PaginationStyle : ControlStyle
{
/// <summary>The IndicatorSize bindable property.</summary>
[EditorBrowsable(EditorBrowsableState.Never)]
public static readonly BindableProperty IndicatorSizeProperty = null;
internal static void SetInternalIndicatorSizeProperty(BindableObject bindable, object oldValue, object newValue)
{
((PaginationStyle)bindable).indicatorSize = newValue == null ? null : new Size((Size)newValue);
}
internal static object GetInternalIndicatorSizeProperty(BindableObject bindable)
{
return ((PaginationStyle)bindable).indicatorSize;
}

/// <summary>The IndicatorImageUrlSelector bindable property.</summary>
[EditorBrowsable(EditorBrowsableState.Never)]
public static readonly BindableProperty IndicatorImageUrlSelectorProperty = null;
internal static void SetInternalIndicatorImageUrlSelectorProperty(BindableObject bindable, object oldValue, object newValue)
{
((PaginationStyle)bindable).indicatorImageUrl = (Selector<string>)newValue;
}
internal static object GetInternalIndicatorImageUrlSelectorProperty(BindableObject bindable)
{
return ((PaginationStyle)bindable).indicatorImageUrl;
}
static readonly IStyleProperty IndicatorSizeProperty = new StyleProperty<Pagination, Size>((v, o) => v.IndicatorSize = o);
static readonly IStyleProperty IndicatorImageUrlProperty = new StyleProperty<Pagination, Selector<string>>((v, o) => v.IndicatorImageUrl = o);
static readonly IStyleProperty IndicatorSpacingProperty = new StyleProperty<Pagination, int>((v, o) => v.IndicatorSpacing = o);

/// <summary>The IndicatorSpacing bindable property.</summary>
[EditorBrowsable(EditorBrowsableState.Never)]
public static readonly BindableProperty IndicatorSpacingProperty = null;
internal static void SetInternalIndicatorSpacingProperty(BindableObject bindable, object oldValue, object newValue)
{
((PaginationStyle)bindable).indicatorSpacing = (int?)newValue;
}
internal static object GetInternalIndicatorSpacingProperty(BindableObject bindable)
{
return ((PaginationStyle)bindable).indicatorSpacing;
}

private Size indicatorSize;
private Selector<string> indicatorImageUrl;
private int? indicatorSpacing;

static PaginationStyle()
{
if (NUIApplication.IsUsingXaml)
{
IndicatorSizeProperty = BindableProperty.Create(nameof(IndicatorSize), typeof(Size), typeof(PaginationStyle), null,
propertyChanged: SetInternalIndicatorSizeProperty, defaultValueCreator: GetInternalIndicatorSizeProperty);
IndicatorImageUrlSelectorProperty = BindableProperty.Create("IndicatorImageUrl", typeof(Selector<string>), typeof(PaginationStyle), null,
propertyChanged: SetInternalIndicatorImageUrlSelectorProperty, defaultValueCreator: GetInternalIndicatorImageUrlSelectorProperty);
IndicatorSpacingProperty = BindableProperty.Create(nameof(IndicatorSpacing), typeof(int?), typeof(PaginationStyle), null,
propertyChanged: SetInternalIndicatorSpacingProperty, defaultValueCreator: GetInternalIndicatorSpacingProperty);
}
}
static PaginationStyle() { }

/// <summary>
/// Creates a new instance of a PaginationStyle.
Expand All @@ -100,28 +53,8 @@ public PaginationStyle(PaginationStyle style) : base(style)
/// <since_tizen> 8 </since_tizen>
public Size IndicatorSize
{
get
{
if (NUIApplication.IsUsingXaml)
{
return (Size)GetValue(IndicatorSizeProperty);
}
else
{
return (Size)GetInternalIndicatorSizeProperty(this);
}
}
set
{
if (NUIApplication.IsUsingXaml)
{
SetValue(IndicatorSizeProperty, value);
}
else
{
SetInternalIndicatorSizeProperty(this, null, value);
}
}
get => (Size)GetValue(IndicatorSizeProperty);
set => SetValue(IndicatorSizeProperty, value);
}

/// <summary>
Expand All @@ -130,28 +63,8 @@ public Size IndicatorSize
/// <since_tizen> 8 </since_tizen>
public Selector<string> IndicatorImageUrl
{
get
{
if (NUIApplication.IsUsingXaml)
{
return (Selector<string>)GetValue(IndicatorImageUrlSelectorProperty);
}
else
{
return (Selector<string>)GetInternalIndicatorImageUrlSelectorProperty(this);
}
}
set
{
if (NUIApplication.IsUsingXaml)
{
SetValue(IndicatorImageUrlSelectorProperty, value);
}
else
{
SetInternalIndicatorImageUrlSelectorProperty(this, null, value);
}
}
get => (Selector<string>)GetValue(IndicatorImageUrlProperty);
set => SetValue(IndicatorImageUrlProperty, value);
}

/// <summary>
Expand All @@ -160,28 +73,8 @@ public Selector<string> IndicatorImageUrl
/// <since_tizen> 8 </since_tizen>
public int IndicatorSpacing
{
get
{
if (NUIApplication.IsUsingXaml)
{
return ((int?)GetValue(IndicatorSpacingProperty)) ?? 0;
}
else
{
return ((int?)GetInternalIndicatorSpacingProperty(this)) ?? 0;
}
}
set
{
if (NUIApplication.IsUsingXaml)
{
SetValue(IndicatorSpacingProperty, value);
}
else
{
SetInternalIndicatorSpacingProperty(this, null, value);
}
}
get => ((int?)GetValue(IndicatorSpacingProperty)) ?? 0;
set => SetValue(IndicatorSpacingProperty, value);
}

/// <inheritdoc/>
Expand Down
Loading

0 comments on commit abd9693

Please sign in to comment.