File tree Expand file tree Collapse file tree 2 files changed +41
-5
lines changed
SourceGenerators/Uno.UI.SourceGenerators/DependencyObject Expand file tree Collapse file tree 2 files changed +41
-5
lines changed Original file line number Diff line number Diff line change @@ -157,6 +157,9 @@ private void ProcessType(INamedTypeSymbol typeSymbol)
157
157
builder . AppendLineInvariant ( $ "using Windows.UI.Xaml;") ;
158
158
builder . AppendLineInvariant ( $ "using Windows.UI.Xaml.Data;") ;
159
159
builder . AppendLineInvariant ( $ "using Uno.Diagnostics.Eventing;") ;
160
+ builder . AppendLineInvariant ( "#if __MACOS__" ) ;
161
+ builder . AppendLineInvariant ( "using AppKit;" ) ;
162
+ builder . AppendLineInvariant ( "#endif" ) ;
160
163
161
164
using ( builder . BlockInvariant ( $ "namespace { typeSymbol . ContainingNamespace } ") )
162
165
{
@@ -667,21 +670,27 @@ protected sealed override void Dispose(bool disposing)
667
670
// a native representation via the IntPtr ctor, particularly on iOS.
668
671
__Store?.Dispose();
669
672
673
+ #if __IOS__
670
674
var subviews = Subviews;
671
675
672
676
if (subviews.Length > 0)
673
677
{{
674
678
BinderCollector.RequestCollect();
675
- #if __IOS__
676
679
foreach (var v in subviews)
677
680
{{
678
681
v.RemoveFromSuperview();
679
682
}}
683
+ }}
680
684
#elif __MACOS__
685
+ // avoids the managed array (and items) allocation(s) since we do not need them
686
+ if (this.GetSubviewsCount() > 0)
687
+ {{
688
+ BinderCollector.RequestCollect();
689
+
681
690
// avoids multiple native calls to remove subviews
682
- Subviews = Array.Empty<AppKit.NSView>();
683
- #endif
691
+ Subviews = Array.Empty<NSView>();
684
692
}}
693
+ #endif
685
694
686
695
base.Dispose(disposing);
687
696
Original file line number Diff line number Diff line change 4
4
using System ;
5
5
using System . Collections . Generic ;
6
6
using System . Linq ;
7
+ using System . Runtime . InteropServices ;
7
8
using System . Text ;
8
9
using Uno . UI . Extensions ;
9
10
using Windows . UI . Xaml ;
10
11
using Uno . Foundation . Logging ;
11
12
using Uno . UI . Controls ;
12
-
13
- #if NET6_0_OR_GREATER
14
13
using ObjCRuntime ;
14
+
15
+ #if ! NET6_0_OR_GREATER
16
+ using NativeHandle = System . IntPtr ;
15
17
#endif
16
18
17
19
#if XAMARIN_IOS_UNIFIED
@@ -687,5 +689,30 @@ public static void SetNeedsDisplay(this _View view)
687
689
view . NeedsDisplay = true ;
688
690
#endif
689
691
}
692
+
693
+ #if __MACOS__
694
+ static readonly NativeHandle selSubviewsHandle = Selector . GetHandle ( "subviews" ) ;
695
+ #endif
696
+
697
+ [ DllImport ( "/usr/lib/libobjc.dylib" , EntryPoint = "objc_msgSendSuper" ) ]
698
+ private extern static NativeHandle NativeHandle_objc_msgSendSuper ( NativeHandle receiver , IntPtr selector ) ;
699
+
700
+ private static NativeHandle GetSubviewsHandle ( this _View view )
701
+ {
702
+ #if __IOS__
703
+ return NativeHandle_objc_msgSendSuper ( view . SuperHandle , Selector . GetHandle ( "subviews" ) ) ;
704
+ #elif __MACOS__
705
+ return NativeHandle_objc_msgSendSuper ( view . SuperHandle , selSubviewsHandle ) ;
706
+ #endif
707
+ }
708
+
709
+ [ DllImport ( "/System/Library/Frameworks/CoreFoundation.framework/CoreFoundation" ) ]
710
+ private extern static /* CFIndex */ nint CFArrayGetCount ( /* CFArrayRef */ NativeHandle theArray ) ;
711
+
712
+ internal static nint GetSubviewsCount ( this _View view )
713
+ {
714
+ var handle = view . GetSubviewsHandle ( ) ;
715
+ return CFArrayGetCount ( handle ) ;
716
+ }
690
717
}
691
718
}
You can’t perform that action at this time.
0 commit comments