picoe / Eto

Cross platform GUI framework for desktop and mobile applications in .NET
Other
3.52k stars 319 forks source link

Mac: Fix some events not firing properly #2665

Closed cwensley closed 3 weeks ago

cwensley commented 3 weeks ago

In some cases, especially when the object being attached such as an NSScrollView.ContentView gets GC'd before it gets a chance to register, it would fail causing scroll events to not fire. This is because we were (incorrectly) using Runtime.TryGetNSObject() which will only return an object if it still has a managed instance.

Additionally if we were to add an event after the control is loaded it wouldn't register it properly so we only delay registration before it has been loaded.

Now we use Runtime.GetNSObject() so it'll create an instance if necessary.

This issue was caused by #2654 as now we only add notification centre observers when the control is loaded, giving more time for the .NET instance to be GC'd if it isn't referenced anywhere.