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!: Remove load actions #12287

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
104 changes: 104 additions & 0 deletions build/PackageDiffIgnore.xml
Original file line number Diff line number Diff line change
Expand Up @@ -1243,6 +1243,110 @@
<Member fullName="System.Void Windows.UI.Xaml.Media.Animation.RepeatBehavior.set_Type(Windows.UI.Xaml.Media.Animation.RepeatBehaviorType value)" reason="Api alignments" />
<Member fullName="System.Void Windows.Media.Playback.MediaPlayer.set_Position(System.TimeSpan value)" reason="Api alignments" />
<Member fullName="System.TimeSpan Windows.Media.Playback.MediaPlayer.get_Position()" reason="Api alignments" />

<Member
fullName="System.IDisposable Uno.UI.Xaml.Controls.NativeRefreshControl.RegisterLoadActions(System.Action loaded, System.Action unloaded)"
reason="Remove LoadActions" />
<Member
fullName="System.IDisposable Windows.UI.Xaml.Controls.NativeListViewBase.RegisterLoadActions(System.Action loaded, System.Action unloaded)"
reason="Remove LoadActions" />
<Member
fullName="System.IDisposable Windows.UI.Xaml.Controls.NativePagedView.RegisterLoadActions(System.Action loaded, System.Action unloaded)"
reason="Remove LoadActions" />
<Member
fullName="System.IDisposable Uno.UI.Controls.BindableButton.RegisterLoadActions(System.Action loaded, System.Action unloaded)"
reason="Remove LoadActions" />
<Member
fullName="System.IDisposable Uno.UI.Controls.BindableCheckBox.RegisterLoadActions(System.Action loaded, System.Action unloaded)"
reason="Remove LoadActions" />
<Member
fullName="System.IDisposable Uno.UI.Controls.BindableDrawerLayout.RegisterLoadActions(System.Action loaded, System.Action unloaded)"
reason="Remove LoadActions" />
<Member
fullName="System.IDisposable Uno.UI.Controls.BindableListView.RegisterLoadActions(System.Action loaded, System.Action unloaded)"
reason="Remove LoadActions" />
<Member
fullName="System.IDisposable Uno.UI.Controls.BindableProgressBar.RegisterLoadActions(System.Action loaded, System.Action unloaded)"
reason="Remove LoadActions" />
<Member
fullName="System.IDisposable Uno.UI.Controls.BindableRadioButton.RegisterLoadActions(System.Action loaded, System.Action unloaded)"
reason="Remove LoadActions" />
<Member
fullName="System.IDisposable Uno.UI.Controls.BindableSeekBar.RegisterLoadActions(System.Action loaded, System.Action unloaded)"
reason="Remove LoadActions" />
<Member
fullName="System.IDisposable Uno.UI.Controls.BindableSwitchCompat.RegisterLoadActions(System.Action loaded, System.Action unloaded)"
reason="Remove LoadActions" />
<Member
fullName="System.IDisposable Uno.UI.Controls.BindableToggleButton.RegisterLoadActions(System.Action loaded, System.Action unloaded)"
reason="Remove LoadActions" />
<Member
fullName="System.IDisposable Uno.UI.Controls.BindableView.RegisterLoadActions(System.Action loaded, System.Action unloaded)"
reason="Remove LoadActions" />
<Member
fullName="System.IDisposable Uno.UI.Controls.Legacy.GridView.RegisterLoadActions(System.Action loaded, System.Action unloaded)"
reason="Remove LoadActions" />
<Member
fullName="System.IDisposable Uno.UI.Controls.Legacy.HorizontalGridView.RegisterLoadActions(System.Action loaded, System.Action unloaded)"
reason="Remove LoadActions" />
<Member
fullName="System.IDisposable Uno.UI.Controls.Legacy.HorizontalListView.RegisterLoadActions(System.Action loaded, System.Action unloaded)"
reason="Remove LoadActions" />
<Member
fullName="System.IDisposable Uno.UI.Controls.Legacy.ListView.RegisterLoadActions(System.Action loaded, System.Action unloaded)"
reason="Remove LoadActions" />
<Member
fullName="System.IDisposable Windows.UI.Xaml.Controls.Picker.RegisterLoadActions(System.Action loaded, System.Action unloaded)"
reason="Remove LoadActions" />
<Member
fullName="System.IDisposable Windows.UI.Xaml.Controls.MultilineTextBoxView.RegisterLoadActions(System.Action loaded, System.Action unloaded)"
reason="Remove LoadActions" />
<Member
fullName="System.IDisposable Windows.UI.Xaml.Controls.SinglelineTextBoxView.RegisterLoadActions(System.Action loaded, System.Action unloaded)"
reason="Remove LoadActions" />
<Member
fullName="System.IDisposable Uno.UI.Views.Controls.BindableUIActivityIndicatorView.RegisterLoadActions(System.Action loaded, System.Action unloaded)"
reason="Remove LoadActions" />
<Member
fullName="System.IDisposable Uno.UI.Views.Controls.BindableUIAlertView.RegisterLoadActions(System.Action loaded, System.Action unloaded)"
reason="Remove LoadActions" />
<Member
fullName="System.IDisposable Uno.UI.Views.Controls.BindableUIButton.RegisterLoadActions(System.Action loaded, System.Action unloaded)"
reason="Remove LoadActions" />
<Member
fullName="System.IDisposable Uno.UI.Views.Controls.BindableUIProgressView.RegisterLoadActions(System.Action loaded, System.Action unloaded)"
reason="Remove LoadActions" />
<Member
fullName="System.IDisposable Uno.UI.Views.Controls.BindableUIScrollView.RegisterLoadActions(System.Action loaded, System.Action unloaded)"
reason="Remove LoadActions" />
<Member
fullName="System.IDisposable Uno.UI.Views.Controls.BindableUISwitch.RegisterLoadActions(System.Action loaded, System.Action unloaded)"
reason="Remove LoadActions" />
<Member
fullName="System.IDisposable Uno.UI.Views.Controls.BindableUICollectionView.RegisterLoadActions(System.Action loaded, System.Action unloaded)"
reason="Remove LoadActions" />
<Member
fullName="System.IDisposable Uno.UI.Controls.BindableSearchBar.RegisterLoadActions(System.Action loaded, System.Action unloaded)"
reason="Remove LoadActions" />
<Member
fullName="System.IDisposable Uno.UI.Controls.BindableUISlider.RegisterLoadActions(System.Action loaded, System.Action unloaded)"
reason="Remove LoadActions" />
<Member
fullName="System.IDisposable Uno.UI.Controls.BindableUIView.RegisterLoadActions(System.Action loaded, System.Action unloaded)"
reason="Remove LoadActions" />
<Member
fullName="System.IDisposable Uno.UI.Controls.StatePresenter.RegisterLoadActions(System.Action loaded, System.Action unloaded)"
reason="Remove LoadActions" />
<Member
fullName="System.IDisposable Uno.UI.Controls.UnoNavigationBar.RegisterLoadActions(System.Action loaded, System.Action unloaded)"
reason="Remove LoadActions" />
<Member
fullName="System.IDisposable Windows.UI.Xaml.Controls.SecureTextBoxView.RegisterLoadActions(System.Action loaded, System.Action unloaded)"
reason="Remove LoadActions" />
<Member
fullName="System.IDisposable Uno.UI.Controls.BindableNSView.RegisterLoadActions(System.Action loaded, System.Action unloaded)"
reason="Remove LoadActions" />

<Member fullName="System.Void Windows.UI.Xaml.Controls.Primitives.ToggleButton.OnIsCheckedChanged(System.Nullable`1&lt;System.Boolean&gt; oldValue, System.Nullable`1&lt;System.Boolean&gt; newValue)" reason="Api alignments" />
<Member fullName="System.Void Windows.UI.Xaml.Media.Animation.Timeline.Dispose(System.Boolean disposing)" reason="Api alignments" />
<Member fullName="System.Void Windows.UI.Xaml.Media.Animation.Timeline.Dispose()" reason="Api alignments" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -307,11 +307,6 @@ private void WriteAndroidAttachedToWindow(INamedTypeSymbol typeSymbol, IndentedS

if (isAndroidView || isAndroidActivity || isAndroidFragment)
{
if (!isAndroidActivity && !isAndroidFragment)
{
WriteRegisterLoadActions(typeSymbol, builder);
}

builder.AppendMultiLineIndented($@"
#if {hasOverridesAttachedToWindowAndroid} //Is Android view (that doesn't already override OnAttachedToWindow)

Expand All @@ -321,15 +316,11 @@ private void WriteAndroidAttachedToWindow(INamedTypeSymbol typeSymbol, IndentedS

protected override void OnNativeLoaded()
{{
_loadActions.ForEach(a => a.Item1());

BinderAttachedToWindow();
}}

protected override void OnNativeUnloaded()
{{
_loadActions.ForEach(a => a.Item2());

BinderDetachedFromWindow();
}}
#else //Not UnoViewGroup
Expand All @@ -341,15 +332,13 @@ protected override void OnAttachedToWindow()
OnLoading();
OnLoaded();
#endif
_loadActions.ForEach(a => a.Item1());
BinderAttachedToWindow();
}}


protected override void OnDetachedFromWindow()
{{
base.OnDetachedFromWindow();
_loadActions.ForEach(a => a.Item2());
#if {implementsIFrameworkElement} //Is IFrameworkElement
OnUnloaded();
#endif
Expand Down Expand Up @@ -387,41 +376,6 @@ private void BinderDetachedFromWindow()
}
}

private static void WriteRegisterLoadActions(INamedTypeSymbol typeSymbol, IndentedStringBuilder builder)
{
builder.AppendMultiLineIndented($@"
// A list of actions to be executed on Load and Unload
private List<(Action loaded, Action unloaded)> _loadActions = new List<(Action loaded, Action unloaded)>(2);

/// <summary>
/// Registers actions to be executed when the control is Loaded and Unloaded.
/// </summary>
/// <param name=""loaded""></param>
/// <param name=""unloaded""></param>
/// <returns></returns>
/// <remarks>The loaded action may be executed immediately if the control is already loaded.</remarks>
public IDisposable RegisterLoadActions(Action loaded, Action unloaded)
{{
var actions = (loaded, unloaded);

_loadActions.Add(actions);

#if __ANDROID__
if(this.IsLoaded())
#elif __IOS__ || __MACOS__
if(Window != null)
#else
#error Unsupported platform
#endif
{{
loaded();
}}

return Disposable.Create(() => _loadActions.Remove(actions));
}}
");
}

private void WriteAttachToWindow(INamedTypeSymbol typeSymbol, IndentedStringBuilder builder)
{
var hasOverridesAttachedToWindowiOS = typeSymbol.Is(_iosViewSymbol) &&
Expand All @@ -431,21 +385,17 @@ private void WriteAttachToWindow(INamedTypeSymbol typeSymbol, IndentedStringBuil

if (hasOverridesAttachedToWindowiOS)
{
WriteRegisterLoadActions(typeSymbol, builder);

builder.AppendMultiLineIndented($@"
public override void MovedToWindow()
{{
base.MovedToWindow();

if(Window != null)
{{
_loadActions.ForEach(a => a.loaded());
OnAttachedToWindowPartial();
}}
else
{{
_loadActions.ForEach(a => a.unloaded());
OnDetachedFromWindowPartial();
}}
}}
Expand Down Expand Up @@ -477,21 +427,17 @@ private void WriteViewDidMoveToWindow(INamedTypeSymbol typeSymbol, IndentedStrin

if (hasOverridesAttachedToWindowiOS)
{
WriteRegisterLoadActions(typeSymbol, builder);

builder.AppendMultiLineIndented($@"
public override void ViewDidMoveToWindow()
{{
base.ViewDidMoveToWindow();

if(Window != null)
{{
_loadActions.ForEach(a => a.loaded());
OnAttachedToWindowPartial();
}}
else
{{
_loadActions.ForEach(a => a.unloaded());
OnDetachedFromWindowPartial();
}}
}}
Expand Down
24 changes: 0 additions & 24 deletions src/Uno.UI/Controls/StatePresenter.iOS.cs
Original file line number Diff line number Diff line change
Expand Up @@ -48,40 +48,16 @@ public StatePresenter()
InitializeBinder();
}

#region RegisterLoadActions

private List<(Action loaded, Action unloaded)> _loadActions = new List<(Action loaded, Action unloaded)>(2);

public IDisposable RegisterLoadActions(Action loaded, Action unloaded)
{
var actions = (loaded, unloaded);

_loadActions.Add(actions);

if (Window != null)
{
loaded();
}

return Disposable.Create(() => _loadActions.Remove(actions));
}

#endregion

public override void MovedToWindow()
{
base.MovedToWindow();

if (this.Window != null)
{
_loadActions.ForEach(a => a.loaded());

Loaded?.Invoke();
}
else
{
_loadActions.ForEach(a => a.unloaded());

Unloaded?.Invoke();
}
}
Expand Down