From fe49e3a1127dcd89a3315453c6d58e37074d4b71 Mon Sep 17 00:00:00 2001 From: Sebastien Pouliot Date: Wed, 9 Jun 2021 08:50:14 -0400 Subject: [PATCH] [uikit] More linker-friendly `UIControl` (#11872) The `RemoveTarget` method already checked if `allTargets` was `null`, even if it was not possible (might have been at some point in time) It makes some apps, like the one we track for the minimal size, able to eliminate a few more types (for both _dotnet_ and _legacy_) ```diff --- a.cs 2021-06-08 17:41:00.000000000 -0400 +++ b.cs 2021-06-08 17:41:02.000000000 -0400 @@ -3216,21 +3216,9 @@ NSString.ReleaseNative(intPtr); } } - [Register] - internal class UIControlEventProxy : NSObject - { - [MethodImpl(8)] - [Export("BridgeSelector")] - public void Activated() - { - throw new NotSupportedException("Linked away"); - } - } [Register("UIControl", true)] public class UIControl : UIView, INativeObject, IDisposable { - private static ConditionalWeakTable>> allTargets = new ConditionalWeakTable>>(); - private static readonly IntPtr class_ptr = Class.GetHandle("UIControl"); public override IntPtr ClassHandle => class_ptr; @@ -3523,32 +3511,6 @@ } [Flags] [Native] - public enum UIControlEvent : ulong - { - TouchDown = 0x1, - TouchDownRepeat = 0x2, - TouchDragInside = 0x4, - TouchDragOutside = 0x8, - TouchDragEnter = 0x10, - TouchDragExit = 0x20, - TouchUpInside = 0x40, - TouchUpOutside = 0x80, - TouchCancel = 0x100, - ValueChanged = 0x1000, - PrimaryActionTriggered = 0x2000, - MenuActionTriggered = 0x4000, - EditingDidBegin = 0x10000, - EditingChanged = 0x20000, - EditingDidEnd = 0x40000, - EditingDidEndOnExit = 0x80000, - AllTouchEvents = 0xFFF, - AllEditingEvents = 0xF0000, - ApplicationReserved = 0xF000000, - SystemReserved = 0xF0000000, - AllEvents = 0xFFFFFFFF - } - [Flags] - [Native] public enum UIControlState : ulong { Normal = 0x0, @@ -4737,10 +4699,6 @@ public bool IsWrapper => is_wrapper; - public RegisterAttribute() - { - } - public RegisterAttribute(string P_0) { name = P_0; ``` --- src/UIKit/UIControl.cs | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/UIKit/UIControl.cs b/src/UIKit/UIControl.cs index e4fc1e47b5..bd9141d2a2 100644 --- a/src/UIKit/UIControl.cs +++ b/src/UIKit/UIControl.cs @@ -47,10 +47,12 @@ namespace UIKit { } public partial class UIControl { - static ConditionalWeakTable>> allTargets = new - ConditionalWeakTable>> (); + static ConditionalWeakTable>> allTargets; public void AddTarget (EventHandler notification, UIControlEvent events) { + if (allTargets == null) + allTargets = new (); + var targets = allTargets.GetValue (this, k => { MarkDirty ();