From 0d4f46762608cfe10fe04e1bec7c80c20b3e6300 Mon Sep 17 00:00:00 2001 From: Brandon Minnick <13558917+brminnick@users.noreply.github.com> Date: Tue, 14 Mar 2023 12:28:14 -0700 Subject: [PATCH 1/3] Update TypedBindings --- .../CommunityToolkit.Maui.Markup.Sample/App.cs | 6 +----- .../TypedBindingExtensions.cs | 18 +++++++++--------- .../TypedBindingsExtensions.Handlers.cs | 14 +++++++------- 3 files changed, 17 insertions(+), 21 deletions(-) diff --git a/samples/CommunityToolkit.Maui.Markup.Sample/App.cs b/samples/CommunityToolkit.Maui.Markup.Sample/App.cs index b68d1290..38e27194 100644 --- a/samples/CommunityToolkit.Maui.Markup.Sample/App.cs +++ b/samples/CommunityToolkit.Maui.Markup.Sample/App.cs @@ -1,6 +1,4 @@ -using CommunityToolkit.Maui.Markup.Sample.Resources; - -namespace CommunityToolkit.Maui.Markup.Sample; +namespace CommunityToolkit.Maui.Markup.Sample; class App : Application { @@ -10,6 +8,4 @@ public App(AppShell shell) MainPage = shell; } - - } \ No newline at end of file diff --git a/src/CommunityToolkit.Maui.Markup/TypedBindingExtensions.cs b/src/CommunityToolkit.Maui.Markup/TypedBindingExtensions.cs index 5dd2cdd0..e6f32136 100644 --- a/src/CommunityToolkit.Maui.Markup/TypedBindingExtensions.cs +++ b/src/CommunityToolkit.Maui.Markup/TypedBindingExtensions.cs @@ -15,7 +15,7 @@ public static TBindable BindCommand( Expression> getter, Action? setter = null, BindingMode mode = BindingMode.Default, - TCommandBindingContext? source = default) where TBindable : BindableObject + object? source = null) where TBindable : BindableObject { return BindCommand( bindable, @@ -30,12 +30,12 @@ public static TBindable BindCommand> getter, Action? setter = null, - TCommandBindingContext? source = default, + object? source = null, BindingMode commandBindingMode = BindingMode.Default, Expression>? parameterGetter = null, Action? parameterSetter = null, BindingMode parameterBindingMode = BindingMode.Default, - TParameterBindingContext? parameterSource = default) where TBindable : BindableObject + object? parameterSource = null) where TBindable : BindableObject { (var commandProperty, var parameterProperty) = DefaultBindableProperties.GetCommandAndCommandParameterProperty(); @@ -68,7 +68,7 @@ public static TBindable Bind( Action? setter = null, BindingMode mode = BindingMode.Default, string? stringFormat = null, - TBindingContext? source = default) where TBindable : BindableObject + object? source = null) where TBindable : BindableObject { return Bind( bindable, @@ -95,7 +95,7 @@ public static TBindable Bind( Func? convert = null, Func? convertBack = null, string? stringFormat = null, - TBindingContext? source = default, + object? source = null, TDest? targetNullValue = default, TDest? fallbackValue = default) where TBindable : BindableObject { @@ -123,7 +123,7 @@ public static TBindable Bind( BindingMode mode = BindingMode.Default, IValueConverter? converter = null, string? stringFormat = null, - TBindingContext? source = default, + object? source = null, TDest? targetNullValue = default, TDest? fallbackValue = default) where TBindable : BindableObject { @@ -151,7 +151,7 @@ public static TBindable Bind( BindingMode mode = BindingMode.Default, IValueConverter? converter = null, string? stringFormat = null, - TBindingContext? source = default, + object? source = null, TDest? targetNullValue = default, TDest? fallbackValue = default) where TBindable : BindableObject { @@ -181,7 +181,7 @@ public static TBindable Bind Func? convertBack = null, TParam? converterParameter = default, string? stringFormat = null, - TBindingContext? source = default, + object? source = null, TDest? targetNullValue = default, TDest? fallbackValue = default) where TBindable : BindableObject { @@ -213,7 +213,7 @@ public static TBindable Bind IValueConverter? converter = null, TParam? converterParameter = default, string? stringFormat = null, - TBindingContext? source = default, + object? source = null, TDest? targetNullValue = default, TDest? fallbackValue = default) where TBindable : BindableObject { diff --git a/src/CommunityToolkit.Maui.Markup/TypedBindingsExtensions.Handlers.cs b/src/CommunityToolkit.Maui.Markup/TypedBindingsExtensions.Handlers.cs index ac6366c4..736d63bd 100644 --- a/src/CommunityToolkit.Maui.Markup/TypedBindingsExtensions.Handlers.cs +++ b/src/CommunityToolkit.Maui.Markup/TypedBindingsExtensions.Handlers.cs @@ -15,7 +15,7 @@ public static TBindable BindCommand( (Func, string)[] handlers, Action? setter = null, BindingMode mode = BindingMode.Default, - TCommandBindingContext? source = default) where TBindable : BindableObject + object? source = null) where TBindable : BindableObject { return BindCommand( bindable, @@ -32,12 +32,12 @@ public static TBindable BindCommand getter, (Func, string)[] handlers, Action? setter = null, - TCommandBindingContext? source = default, + object? source = null, BindingMode commandBindingMode = BindingMode.Default, Func? parameterGetter = null, (Func, string)[]? parameterHandlers = null, Action? parameterSetter = null, - TParameterBindingContext? parameterSource = default, + object? parameterSource = null, BindingMode parameterBindingMode = BindingMode.Default) where TBindable : BindableObject { (var commandProperty, var parameterProperty) = DefaultBindableProperties.GetCommandAndCommandParameterProperty(); @@ -76,7 +76,7 @@ public static TBindable Bind( Action? setter = null, BindingMode mode = BindingMode.Default, string? stringFormat = null, - TBindingContext? source = default) where TBindable : BindableObject + object? source = null) where TBindable : BindableObject { return Bind( bindable, @@ -105,7 +105,7 @@ public static TBindable Bind( Func? convert = null, Func? convertBack = null, string? stringFormat = null, - TBindingContext? source = default, + object? source = null, TDest? targetNullValue = default, TDest? fallbackValue = default) where TBindable : BindableObject { @@ -137,7 +137,7 @@ public static TBindable Bind Func? convertBack = null, TParam? converterParameter = default, string? stringFormat = null, - TBindingContext? source = default, + object? source = null, TDest? targetNullValue = default, TDest? fallbackValue = default) where TBindable : BindableObject { @@ -172,7 +172,7 @@ public static TBindable Bind IValueConverter? converter = null, TParam? converterParameter = default, string? stringFormat = null, - TBindingContext? source = default, + object? source = null, TDest? targetNullValue = default, TDest? fallbackValue = default) where TBindable : BindableObject { From 9e8474d54d1c02cb7d63aa2680b64a72dfa0a3c3 Mon Sep 17 00:00:00 2001 From: Brandon Minnick <13558917+brminnick@users.noreply.github.com> Date: Tue, 14 Mar 2023 12:45:45 -0700 Subject: [PATCH 2/3] Update MauiProgram.cs --- samples/CommunityToolkit.Maui.Markup.Sample/MauiProgram.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/samples/CommunityToolkit.Maui.Markup.Sample/MauiProgram.cs b/samples/CommunityToolkit.Maui.Markup.Sample/MauiProgram.cs index 5358ed3c..55e09b8c 100644 --- a/samples/CommunityToolkit.Maui.Markup.Sample/MauiProgram.cs +++ b/samples/CommunityToolkit.Maui.Markup.Sample/MauiProgram.cs @@ -26,7 +26,7 @@ public static MauiApp CreateMauiApp() builder.Services.AddSingleton(); builder.Services.AddRefitClient() .ConfigureHttpClient(client => client.BaseAddress = new Uri("https://hacker-news.firebaseio.com/v0")) - .AddTransientHttpErrorPolicy(builder => builder.WaitAndRetryAsync(3, sleepDurationProvider)); + .AddTransientHttpErrorPolicy(builder => builder.WaitAndRetryAsync(3, ExponentialBackoff)); // Pages + View Models builder.Services.AddTransient(); @@ -35,6 +35,6 @@ public static MauiApp CreateMauiApp() return builder.Build(); - static TimeSpan sleepDurationProvider(int attemptNumber) => TimeSpan.FromSeconds(Math.Pow(2, attemptNumber)); + static TimeSpan ExponentialBackoff(int attemptNumber) => TimeSpan.FromSeconds(Math.Pow(2, attemptNumber)); } } \ No newline at end of file From 2821fb7e9391d4702563bb20ffee823a7fa695e8 Mon Sep 17 00:00:00 2001 From: Brandon Minnick <13558917+brminnick@users.noreply.github.com> Date: Tue, 14 Mar 2023 13:32:33 -0700 Subject: [PATCH 3/3] Update TypedBindingExtensionsTests.cs --- .../TypedBindingExtensionsTests.cs | 32 +++++++++++++++++++ 1 file changed, 32 insertions(+) diff --git a/src/CommunityToolkit.Maui.Markup.UnitTests/TypedBindingExtensionsTests.cs b/src/CommunityToolkit.Maui.Markup.UnitTests/TypedBindingExtensionsTests.cs index cc4660b2..bdfd93dd 100644 --- a/src/CommunityToolkit.Maui.Markup.UnitTests/TypedBindingExtensionsTests.cs +++ b/src/CommunityToolkit.Maui.Markup.UnitTests/TypedBindingExtensionsTests.cs @@ -87,6 +87,38 @@ public void BindCommandWithParameters() Assert.AreEqual(textCell.CommandParameter, viewModel.Id); } + [Test] + public async Task BindUsingRelativeBindingSourceSelf() + { + const int heightRequest = 200; + bool didPropertyChangeFire = false; + TaskCompletionSource propertyChangedEventArgsTCS = new(); + + var label = new Label().Bind(Label.TextProperty, static (Label view) => view.HeightRequest, source: RelativeBindingSource.Self); + label.PropertyChanged += HandlePropertyChanged; + + Assert.AreEqual(label.HeightRequest.ToString(), label.Text); + + label.HeightRequest = heightRequest; + + var propertyName = await propertyChangedEventArgsTCS.Task.WaitAsync(TimeSpan.FromSeconds(3)).ConfigureAwait(false); + + Assert.True(didPropertyChangeFire); + Assert.AreEqual(Label.TextProperty.PropertyName, propertyName); + Assert.AreEqual(heightRequest, label.HeightRequest); + Assert.AreEqual(label.HeightRequest.ToString(), label.Text); + + + void HandlePropertyChanged(object? sender, PropertyChangedEventArgs e) + { + if (e.PropertyName == Label.TextProperty.PropertyName) + { + didPropertyChangeFire = true; + propertyChangedEventArgsTCS.SetResult(e.PropertyName); + } + } + } + [Test] public async Task ConfirmStringFormat() {