@@ -19,7 +19,7 @@ public class ItemsViewRenderer : RecyclerView, IVisualElementRenderer, IEffectCo
19
19
readonly EffectControlProvider _effectControlProvider ;
20
20
21
21
protected ItemsViewAdapter ItemsViewAdapter ;
22
-
22
+
23
23
int ? _defaultLabelFor ;
24
24
bool _disposed ;
25
25
@@ -139,7 +139,10 @@ protected override void Dispose(bool disposing)
139
139
if ( Element != null )
140
140
{
141
141
TearDownOldElement ( Element as ItemsView ) ;
142
+ }
142
143
144
+ if ( Element != null )
145
+ {
143
146
if ( Platform . GetRenderer ( Element ) == this )
144
147
{
145
148
Element . ClearValue ( Platform . RendererProperty ) ;
@@ -215,18 +218,23 @@ protected virtual void UpdateItemsSource()
215
218
return ;
216
219
}
217
220
218
- // Stop watching the old adapter to see if it's empty (if we _are_ watching)
219
- Unwatch ( ItemsViewAdapter ?? GetAdapter ( ) ) ;
220
-
221
221
UpdateAdapter ( ) ;
222
222
223
223
UpdateEmptyView ( ) ;
224
224
}
225
225
226
226
protected virtual void UpdateAdapter ( )
227
227
{
228
+ var oldItemViewAdapter = ItemsViewAdapter ;
229
+
230
+ // Stop watching the old adapter to see if it's empty (if we are watching)
231
+ Unwatch ( oldItemViewAdapter ) ;
232
+
228
233
ItemsViewAdapter = new ItemsViewAdapter ( ItemsView ) ;
234
+
229
235
SwapAdapter ( ItemsViewAdapter , true ) ;
236
+
237
+ oldItemViewAdapter ? . Dispose ( ) ;
230
238
}
231
239
232
240
void Unwatch ( Adapter adapter )
@@ -281,7 +289,7 @@ protected virtual void SetUpNewElement(ItemsView newElement)
281
289
282
290
_layout = ItemsView . ItemsLayout ;
283
291
SetLayoutManager ( SelectLayoutManager ( _layout ) ) ;
284
-
292
+
285
293
UpdateSnapBehavior ( ) ;
286
294
UpdateBackgroundColor ( ) ;
287
295
UpdateFlowDirection ( ) ;
@@ -296,7 +304,7 @@ protected virtual void SetUpNewElement(ItemsView newElement)
296
304
// Listen for ScrollTo requests
297
305
ItemsView . ScrollToRequested += ScrollToRequested ;
298
306
}
299
-
307
+
300
308
protected virtual void TearDownOldElement ( ItemsView oldElement )
301
309
{
302
310
if ( oldElement == null )
@@ -316,12 +324,13 @@ protected virtual void TearDownOldElement(ItemsView oldElement)
316
324
// Stop listening for ScrollTo requests
317
325
oldElement . ScrollToRequested -= ScrollToRequested ;
318
326
319
- var adapter = GetAdapter ( ) ;
320
-
321
- if ( adapter != null )
327
+ if ( ItemsViewAdapter != null )
322
328
{
329
+ Unwatch ( ItemsViewAdapter ) ;
330
+
323
331
SetAdapter ( null ) ;
324
- adapter . Dispose ( ) ;
332
+
333
+ ItemsViewAdapter . Dispose ( ) ;
325
334
}
326
335
327
336
if ( _snapManager != null )
@@ -349,7 +358,7 @@ protected virtual void LayoutOnPropertyChanged(object sender, PropertyChangedEve
349
358
{
350
359
UpdateSnapBehavior ( ) ;
351
360
}
352
- else if ( propertyChanged . IsOneOf ( ListItemsLayout . ItemSpacingProperty ,
361
+ else if ( propertyChanged . IsOneOf ( ListItemsLayout . ItemSpacingProperty ,
353
362
GridItemsLayout . HorizontalItemSpacingProperty , GridItemsLayout . VerticalItemSpacingProperty ) )
354
363
{
355
364
UpdateItemSpacing ( ) ;
@@ -408,6 +417,7 @@ protected virtual void UpdateEmptyView()
408
417
409
418
_emptyViewAdapter . EmptyView = emptyView ;
410
419
_emptyViewAdapter . EmptyViewTemplate = emptyViewTemplate ;
420
+
411
421
Watch ( ItemsViewAdapter ) ;
412
422
}
413
423
else
@@ -479,7 +489,7 @@ void ScrollToRequested(object sender, ScrollToRequestEventArgs args)
479
489
protected virtual void ScrollTo ( ScrollToRequestEventArgs args )
480
490
{
481
491
var position = DeterminePosition ( args ) ;
482
-
492
+
483
493
if ( args . IsAnimated )
484
494
{
485
495
ScrollHelper . AnimateScrollToPosition ( position , args . ScrollToPosition ) ;
0 commit comments