11using CoreGraphics ;
22using Foundation ;
33using Microsoft . Maui . Platform ;
4+ using Microsoft . VisualBasic ;
45using System . Diagnostics . CodeAnalysis ;
56using UIKit ;
67
@@ -12,7 +13,7 @@ internal class CvCell : UICollectionViewCell
1213
1314 public WeakReference < NSIndexPath > IndexPath { get ; set ; }
1415
15- public PositionInfo PositionInfo { get ; set ; }
16+ public PositionInfo PositionInfo { get ; private set ; }
1617
1718 public WeakReference < Action < IView > > ReuseCallback { get ; set ; }
1819
@@ -91,7 +92,10 @@ public override UICollectionViewLayoutAttributes PreferredLayoutAttributesFittin
9192 }
9293
9394 public bool NeedsView
94- => NativeView == null || ! NativeView . TryGetTarget ( out var _ ) ;
95+ => NativeView == null
96+ || VirtualView is null
97+ || ! NativeView . TryGetTarget ( out var _ )
98+ || ! VirtualView . TryGetTarget ( out var _ ) ;
9599
96100 public WeakReference < IView > VirtualView { get ; set ; }
97101
@@ -109,31 +113,33 @@ public override void PrepareForReuse()
109113 }
110114 }
111115
112- public void SwapView ( IView newView )
116+ public void SetupView ( IView view )
113117 {
114118 // Create a new platform native view if we don't have one yet
115- if ( ! ( NativeView ? . TryGetTarget ( out var nativeView ) ?? false ) )
119+ if ( ! ( NativeView ? . TryGetTarget ( out var _ ) ?? false ) )
116120 {
117- nativeView = newView . ToPlatform ( this . Handler . MauiContext ) ;
121+ var nativeView = view . ToPlatform ( this . Handler . MauiContext ) ;
118122 nativeView . Frame = this . ContentView . Frame ;
119123 nativeView . AutoresizingMask = UIViewAutoresizing . FlexibleHeight | UIViewAutoresizing . FlexibleWidth ;
120- this . ContentView . AddSubview ( nativeView ) ;
121- NativeView = new WeakReference < UIView > ( nativeView ) ;
124+
125+ this . ContentView . AddSubview ( nativeView ) ;
126+
127+ NativeView = new WeakReference < UIView > ( nativeView ) ;
122128 }
123129
124- // Create a new virtual view if we don't have one yet
125- if ( ! ( VirtualView ? . TryGetTarget ( out var virtualView ) ?? false ) || ( virtualView ? . Handler is null ) )
126- {
127- virtualView = newView ;
128- VirtualView = new WeakReference < IView > ( virtualView ) ;
129- }
130- else
130+ if ( ! ( VirtualView ? . TryGetTarget ( out var virtualView ) ?? false ) || ( virtualView ? . Handler is null ) )
131+ {
132+ VirtualView = new WeakReference < IView > ( view ) ;
133+ }
134+ }
135+
136+ public void UpdatePosition ( PositionInfo positionInfo )
137+ {
138+ PositionInfo = positionInfo ;
139+ if ( VirtualView ? . TryGetTarget ( out var virtualView ) ?? false )
131140 {
132- var handler = virtualView . Handler ;
133- virtualView . Handler = null ;
134- newView . Handler = handler ;
135- handler . SetVirtualView ( newView ) ;
136- VirtualView . SetTarget ( newView ) ;
137- }
141+ if ( virtualView is IPositionInfo viewPositionInfo )
142+ viewPositionInfo . Update ( positionInfo ) ;
143+ }
138144 }
139145}
0 commit comments