Skip to content

Commit

Permalink
feat: Add refresh indication support for non-mobile platforms
Browse files Browse the repository at this point in the history
  • Loading branch information
MartinZikmund committed Aug 8, 2022
1 parent d7494e5 commit 7aeee51
Show file tree
Hide file tree
Showing 4 changed files with 87 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

namespace Uno.UI.Xaml.Controls;

public partial class NativeRefreshVisualizer : RefreshVisualizer
internal partial class NativeRefreshVisualizer : RefreshVisualizer
{
}
#endif
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
using Microsoft.UI.Private.Controls;
using Microsoft.UI.Xaml.Controls;
using Windows.Foundation;
using Windows.UI.Xaml;

namespace Uno.UI.Xaml.Controls;

internal class ProgressRingRefreshInfoProviderAdapter : IRefreshInfoProviderAdapter
{
private readonly RefreshContainer _refreshContainer;
private IRefreshInfoProvider _refreshInfoProvider;
private ProgressRingRefreshVisualizer _progressRingVisualizer;

public ProgressRingRefreshInfoProviderAdapter(RefreshContainer refreshContainer)
{
_refreshContainer = refreshContainer;
}

public IRefreshInfoProvider AdaptFromTree(UIElement root, Size visualizerSize)
{
_refreshInfoProvider = new RefreshInfoProviderImpl();
_refreshInfoProvider.RefreshStarted += OnRefreshStarted;
_refreshInfoProvider.RefreshCompleted += OnRefreshCompleted;
return _refreshInfoProvider;
}

private void OnRefreshStarted(IRefreshInfoProvider sender, object args)
{
_progressRingVisualizer.Visibility = Visibility.Visible;
_progressRingVisualizer.ProgressRing.Visibility = Visibility.Visible;
_progressRingVisualizer.ProgressRing.IsActive = true;
}

private void OnRefreshCompleted(IRefreshInfoProvider sender, object args)
{
_progressRingVisualizer.Visibility = Visibility.Collapsed;
_progressRingVisualizer.ProgressRing.Visibility = Visibility.Collapsed;
_progressRingVisualizer.ProgressRing.IsActive = false;
}

public void SetAnimations(UIElement refreshVisualizerAnimatableContainer)
{
if (refreshVisualizerAnimatableContainer is ProgressRingRefreshVisualizer progressRingVisualizer)
{
if (_progressRingVisualizer != progressRingVisualizer)
{
progressRingVisualizer.Visibility = Visibility.Collapsed;
progressRingVisualizer.ProgressRing.IsActive = false;
_progressRingVisualizer = progressRingVisualizer;
}
}
else
{
_progressRingVisualizer = null;
}
}

public void Dispose()
{
// Unsubscribe events.
if (_refreshInfoProvider != null)
{
_refreshInfoProvider.RefreshStarted -= OnRefreshStarted;
_refreshInfoProvider.RefreshCompleted -= OnRefreshCompleted;
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
using Microsoft.UI.Xaml.Controls;

using WUXProgressRing = Windows.UI.Xaml.Controls.ProgressRing;

namespace Uno.UI.Xaml.Controls;

internal class ProgressRingRefreshVisualizer : RefreshVisualizer
{
public ProgressRingRefreshVisualizer()
{
Content = ProgressRing;
}

internal WUXProgressRing ProgressRing { get; } = new WUXProgressRing();
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,12 @@ private void SetDefaultRefreshInfoProviderAdapter()
{
if (m_refreshInfoProviderAdapter is not null)
{
m_refreshInfoProviderAdapter.Dispose();
// TODO Uno specific: We currently don't need to switch refresh info provider adapter.
return;
}

#if !__ANDROID__ && !__IOS__
m_refreshInfoProviderAdapter = new StubIRefreshInfoProviderAdapter();
m_refreshInfoProviderAdapter = new ProgressRingRefreshInfoProviderAdapter(this);
#else
m_refreshInfoProviderAdapter = new NativeRefreshInfoProviderAdapter(this);
#endif
Expand All @@ -26,7 +27,7 @@ private void SetDefaultRefreshInfoProviderAdapter()
private void SetDefaultRefreshVisualizer()
{
#if !__ANDROID__ && !__IOS__
Visualizer = new RefreshVisualizer();
Visualizer = new ProgressRingRefreshVisualizer();
#else
Visualizer = new NativeRefreshVisualizer();
#endif
Expand Down

0 comments on commit 7aeee51

Please sign in to comment.