Skip to content

Commit

Permalink
Adds IsLoading bindable property to pages and fixes SelectViewModelCo…
Browse files Browse the repository at this point in the history
…mmand (#45)

In Maui, the `IsBusy` property on pages now shows a loading indicator
with no way to override that behavior. Since implementing apps may want
their own loading indicator, this creates a new `IsLoading` property
which the implementing app can choose to forward to `IsBusy` if it
wants.

Also fixes the SelectViewModelCommand so it passes the model instead of
the view model to the `CanExecute` callback.
  • Loading branch information
mediabounds authored Jul 1, 2024
1 parent 8a9e0c8 commit 07558e4
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 4 deletions.
2 changes: 1 addition & 1 deletion Float.Core/Commands/SelectViewModelCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ public event EventHandler CanExecuteChanged
/// <inheritdoc />
public bool CanExecute(object parameter)
{
return parameter is ViewModel<T> && command.CanExecute(parameter);
return parameter is ViewModel<T> vm && command.CanExecute(vm.UnderlyingModel);
}

/// <summary>
Expand Down
21 changes: 18 additions & 3 deletions Float.Core/UI/BaseContentPage.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,21 @@ public abstract class BaseContentPage : ContentPage
/// </summary>
public static readonly BindableProperty ErrorProperty = BindableProperty.Create(nameof(Error), typeof(Exception), typeof(ContentPage), null);

/// <summary>
/// Binding for the IsLoading property.
/// </summary>
public static readonly BindableProperty IsLoadingProperty = BindableProperty.Create(nameof(IsLoading), typeof(bool), typeof(BaseContentPage));

/// <summary>
/// Gets or sets a value indicating whether the page should show a loading indicator.
/// </summary>
/// <value>Whether the page should show the loading indicator.</value>
public bool IsLoading
{
get => (bool)GetValue(IsLoadingProperty);
set => SetValue(IsLoadingProperty, value);
}

/// <summary>
/// Gets or sets the current error on the page.
/// </summary>
Expand Down Expand Up @@ -52,7 +67,7 @@ protected override void OnBindingContextChanged()
if (BindingContext is ViewModels.IPageViewModel viewModel)
{
this.SetBinding(TitleProperty, nameof(viewModel.Title));
this.SetBinding(IsBusyProperty, nameof(viewModel.IsLoading));
this.SetBinding(IsLoadingProperty, nameof(viewModel.IsLoading));
this.SetBinding(ErrorProperty, nameof(viewModel.Error), BindingMode.TwoWay);
}
}
Expand All @@ -73,8 +88,8 @@ protected override void OnPropertyChanged(string propertyName = null)
base.OnPropertyChanged(propertyName);
switch (propertyName)
{
case nameof(IsBusy):
if (IsBusy)
case nameof(IsLoading):
if (IsLoading)
{
OnStartLoading();
}
Expand Down

0 comments on commit 07558e4

Please sign in to comment.