Merge pull request #8820 from unoplatform/dev/eb/load-actions

fix: Temporarily restore LoadActions
This commit is contained in:
mergify[bot] 2022-05-19 07:26:10 +00:00 коммит произвёл GitHub
Родитель cf8ea2f00c 024c26de71
Коммит ac52b14d49
Не найден ключ, соответствующий данной подписи
Идентификатор ключа GPG: 4AEE18F83AFDEB23
3 изменённых файлов: 78 добавлений и 102 удалений

Просмотреть файл

@ -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" />

Просмотреть файл

@ -325,6 +325,11 @@ namespace Uno.UI.SourceGenerators.DependencyObject
if (isAndroidView || isAndroidActivity || isAndroidFragment)
{
if (!isAndroidActivity && !isAndroidFragment)
{
WriteRegisterLoadActions(typeSymbol, builder);
}
builder.AppendLine($@"
#if {hasOverridesAttachedToWindowAndroid} //Is Android view (that doesn't already override OnAttachedToWindow)
@ -334,11 +339,15 @@ namespace Uno.UI.SourceGenerators.DependencyObject
protected override void OnNativeLoaded()
{{
_loadActions.ForEach(a => a.Item1());
BinderAttachedToWindow();
}}
protected override void OnNativeUnloaded()
{{
_loadActions.ForEach(a => a.Item2());
BinderDetachedFromWindow();
}}
#else //Not UnoViewGroup
@ -350,6 +359,7 @@ namespace Uno.UI.SourceGenerators.DependencyObject
OnLoading();
OnLoaded();
#endif
_loadActions.ForEach(a => a.Item1());
BinderAttachedToWindow();
}}
@ -357,6 +367,7 @@ namespace Uno.UI.SourceGenerators.DependencyObject
protected override void OnDetachedFromWindow()
{{
base.OnDetachedFromWindow();
_loadActions.ForEach(a => a.Item2());
#if {implementsIFrameworkElement} //Is IFrameworkElement
OnUnloaded();
#endif
@ -394,6 +405,41 @@ namespace Uno.UI.SourceGenerators.DependencyObject
}
}
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) &&
@ -405,6 +451,8 @@ namespace Uno.UI.SourceGenerators.DependencyObject
if (hasOverridesAttachedToWindowiOS)
{
WriteRegisterLoadActions(typeSymbol, builder);
builder.AppendLine($@"
public override void MovedToWindow()
{{
@ -412,10 +460,12 @@ namespace Uno.UI.SourceGenerators.DependencyObject
if(Window != null)
{{
_loadActions.ForEach(a => a.loaded());
OnAttachedToWindowPartial();
}}
else
{{
_loadActions.ForEach(a => a.unloaded());
OnDetachedFromWindowPartial();
}}
}}
@ -448,6 +498,8 @@ namespace Uno.UI.SourceGenerators.DependencyObject
if (hasOverridesAttachedToWindowiOS)
{
WriteRegisterLoadActions(typeSymbol, builder);
builder.AppendLine($@"
public override void ViewDidMoveToWindow()
{{
@ -455,10 +507,12 @@ namespace Uno.UI.SourceGenerators.DependencyObject
if(Window != null)
{{
_loadActions.ForEach(a => a.loaded());
OnAttachedToWindowPartial();
}}
else
{{
_loadActions.ForEach(a => a.unloaded());
OnDetachedFromWindowPartial();
}}
}}

Просмотреть файл

@ -48,16 +48,40 @@ namespace Uno.UI.Controls
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();
}
}