Skip to content

Commit

Permalink
Fix RefreshView specificity on IsRefreshing (#17062)
Browse files Browse the repository at this point in the history
* [Controls]Fix specificity on RefreshView IsRefreshing

* [tests] Add RefreshView specificity test

* Add more refreshview tsts

* Update RefreshViewTests.cs
  • Loading branch information
rmarinho authored Aug 30, 2023
1 parent b420f50 commit 63e945c
Show file tree
Hide file tree
Showing 2 changed files with 171 additions and 2 deletions.
6 changes: 6 additions & 0 deletions src/Controls/src/Core/RefreshView/RefreshView.cs
Original file line number Diff line number Diff line change
Expand Up @@ -150,5 +150,11 @@ protected override void OnPropertyChanged([CallerMemberName] string propertyName
Paint IRefreshView.RefreshColor => RefreshColor?.AsPaint();

IView IRefreshView.Content => base.Content;

bool IRefreshView.IsRefreshing
{
get => IsRefreshing;
set { SetValue(IsRefreshingProperty, value, SetterSpecificity.FromHandler); }
}
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
using System;
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.ComponentModel;
using System.Runtime.CompilerServices;
using System.Threading.Tasks;
using Microsoft.Maui.Controls;
using Microsoft.Maui.Controls.Handlers.Items;
using Microsoft.Maui.Handlers;
using Microsoft.Maui.Hosting;
using Xunit;
Expand All @@ -20,6 +25,164 @@ void SetupBuilder()
});
});
}


// [Fact(DisplayName = "IsRefreshing binding works")]
// public async Task IsRefreshingBindingWorks()
// {
// SetupBuilder();

// var vm = new RefreshPageViewModel();
// var refreshView = new RefreshView() { BindingContext = vm };

// refreshView.SetBinding(RefreshView.IsRefreshingProperty, nameof(vm.IsRefreshing), BindingMode.TwoWay);

// await CreateHandlerAndAddToWindow<RefreshViewHandler>(refreshView, async handler =>
// {
// var platformControl = handler.PlatformView;
// Assert.NotNull(platformControl);
// bool? platformIsRefreshing = null;
// #if WINDOWS
// Deferral refreshCompletionDeferral = null;
// platformControl.RefreshRequested += (s, e) =>
// {
// refreshCompletionDeferral = e.GetDeferral();
// platformIsRefreshing = true;
// };
// #endif
// vm.IsRefreshing = true;
// #if ANDROID
// platformIsRefreshing = platformControl.Refreshing;
// #elif IOS
// platformIsRefreshing = platformControl.IsRefreshing;
// #elif WINDOWS

// #endif
// Assert.NotNull(platformIsRefreshing);
// Assert.Equal(vm.IsRefreshing, platformIsRefreshing);
// await Task.Delay(300);
// vm.IsRefreshing = false;
// #if ANDROID
// platformIsRefreshing = platformControl.Refreshing;
// #elif IOS
// platformIsRefreshing = platformControl.IsRefreshing;
// #elif WINDOWS
// if(refreshCompletionDeferral != null)
// {
// refreshCompletionDeferral.Complete();
// refreshCompletionDeferral = null;
// platformIsRefreshing = false;
// }
// #endif
// Assert.Equal(vm.IsRefreshing, platformIsRefreshing);
// await Task.Delay(1000);
// });
// }

// [Fact(DisplayName = "IsRefreshing binding works when started on platform")]
// public async Task IsRefreshingBindingWorksFromPlatform()
// {
// SetupBuilder();

// var vm = new RefreshPageViewModel();
// var refreshView = new RefreshView() { BindingContext = vm };

// refreshView.SetBinding(RefreshView.IsRefreshingProperty, nameof(vm.IsRefreshing), BindingMode.TwoWay);

// await CreateHandlerAndAddToWindow<RefreshViewHandler>(refreshView, async handler =>
// {
// var platformControl = handler.PlatformView;
// Assert.NotNull(platformControl);
// bool? platformIsRefreshing = null;
// #if WINDOWS
// Deferral refreshCompletionDeferral = null;
// platformControl.RefreshRequested += (s, e) =>
// {
// refreshCompletionDeferral = e.GetDeferral();
// platformIsRefreshing = true;
// };
// platformControl.RequestRefresh();
// #endif

// #if ANDROID
// platformIsRefreshing = platformControl.Refreshing = true;
// #elif IOS
// platformIsRefreshing = platformControl.IsRefreshing = true;
// #elif WINDOWS

// #endif
// Assert.NotNull(platformIsRefreshing);
// Assert.Equal(platformIsRefreshing, vm.IsRefreshing);
// await Task.Delay(300);
// vm.IsRefreshing = false;
// #if ANDROID
// platformIsRefreshing = platformControl.Refreshing;
// #elif IOS
// platformIsRefreshing = platformControl.IsRefreshing;
// #elif WINDOWS
// if (refreshCompletionDeferral != null)
// {
// refreshCompletionDeferral.Complete();
// refreshCompletionDeferral = null;
// platformIsRefreshing = false;
// }
// #endif
// Assert.Equal(vm.IsRefreshing, platformIsRefreshing);
// await Task.Delay(1000);
// });
// }

// class RefreshPageViewModel : BaseViewModel
// {
// public RefreshPageViewModel()
// {
// Data = new ObservableCollection<string>()
// {
// "Item 1",
// "Item 2",
// "Item 3"
// };
// }
// bool _isRefreshing;
// ObservableCollection<string> _data;

// public bool IsRefreshing
// {
// get => _isRefreshing;
// set => SetProperty(ref _isRefreshing, value);
// }

// public ObservableCollection<string> Data
// {
// get => _data;
// set => SetProperty(ref _data, value);
// }
// }

// public abstract class BaseViewModel : INotifyPropertyChanged
// {
// protected bool SetProperty<T>(ref T backingStore, T value,
// [CallerMemberName] string propertyName = "",
// Action onChanged = null)
// {
// if (EqualityComparer<T>.Default.Equals(backingStore, value))
// return false;

// backingStore = value;
// onChanged?.Invoke();
// OnPropertyChanged(propertyName);
// return true;
// }

// #region INotifyPropertyChanged

// public event PropertyChangedEventHandler PropertyChanged;
// protected void OnPropertyChanged([CallerMemberName] string propertyName = "")
// {
// PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
// }

// #endregion
// }
}
}

0 comments on commit 63e945c

Please sign in to comment.