Skip to content

Commit

Permalink
fix: Temporarily restore LoadActions
Browse files Browse the repository at this point in the history
  • Loading branch information
ebariche committed May 19, 2022
1 parent 3dbff07 commit 024c26d
Show file tree
Hide file tree
Showing 3 changed files with 78 additions and 102 deletions.
102 changes: 0 additions & 102 deletions build/PackageDiffIgnore.xml
Original file line number Diff line number Diff line change
Expand Up @@ -8787,108 +8787,6 @@
</Types>

<Methods>
<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.Devices.Power.BatteryReport..ctor()"
reason="Does not exist in UWP" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -325,6 +325,11 @@ private void WriteAndroidAttachedToWindow(INamedTypeSymbol typeSymbol, IndentedS

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

builder.AppendLine($@"
#if {hasOverridesAttachedToWindowAndroid} //Is Android view (that doesn't already override OnAttachedToWindow)
Expand All @@ -334,11 +339,15 @@ 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 @@ -350,13 +359,15 @@ 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 @@ -394,6 +405,41 @@ private void BinderDetachedFromWindow()
}
}

private static void WriteRegisterLoadActions(INamedTypeSymbol typeSymbol, IndentedStringBuilder builder)
{
builder.AppendLine($@"
// 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 @@ -405,17 +451,21 @@ private void WriteAttachToWindow(INamedTypeSymbol typeSymbol, IndentedStringBuil

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

builder.AppendLine($@"
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 @@ -448,17 +498,21 @@ private void WriteViewDidMoveToWindow(INamedTypeSymbol typeSymbol, IndentedStrin

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

builder.AppendLine($@"
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: 24 additions & 0 deletions src/Uno.UI/Controls/StatePresenter.iOS.cs
Original file line number Diff line number Diff line change
Expand Up @@ -48,16 +48,40 @@ 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

0 comments on commit 024c26d

Please sign in to comment.