Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix RefreshView specificity on IsRefreshing #17062

Merged
merged 4 commits into from
Aug 30, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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")]
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We need to track this in an issue and get it working to RC 2

// 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
// }
}
}