Xamarin.forms: [iOS] Layout and Styling Issues when reloading page

Created on 6 Apr 2019  路  12Comments  路  Source: xamarin/Xamarin.Forms

Description

Item from CollectionView is left over or out of place. Title styling is lost.

https://www.screencast.com/t/zB074v71xe

2019-04-06_11-54-00

Android doesn't exhibit these problems, but the scrolling is very choppy and slow on the emulator, even after the images are all loaded.

https://www.screencast.com/t/wm7OZVLWW

Details

  • Version with issue: 4.0-pre8

Reproduction Link

https://github.com/davidortinau/Gastropods

collectionview blocker 3 in-progress iOS 馃崕 bug

All 12 comments

Android doesn't exhibit these problems, but the scrolling is very choppy and slow on the emulator, even after the images are all loaded.

@davidortinau If you're seeing choppy scrolling on Android, please open another issue so we can keep track of both.

Is there an ETA on fix for this? It seems that when you navigate away from a page then return, the last item in the collection is now stuck on top of the first item in the view...

I ran into this today too. Navigating off of a flyout page with a collectionview to another flyout page does this behavior. I'm not seeing it if I switch between tabs or use GoToAsync.

I found that doing the following on my page eliminates the weird floating item: (assuming your BindingContext is driving the CollectionView):

IMyViewModel _viewModel;

MyPage(IMyViewModel viewModel) {
 BindingContext = _viewModel;
}

protected override void OnAppearing() {
 Device.BeginInvokeOnMainThread(() => {
  BindingContext = _viewModel;
 });
}

protected override void OnDisappearing() {
 BindingContext = null;
}

I verified via SychronizationContext.Current that OnAppearing is indeed being executed on the main thread, which would make DeviceBeginInvokeOnMainThread seem redundant here... but it doesn't work without it, which suggests a timing issue.

It seems like OnAppearing is firing just a hair before the UI is ready to properly bind or something and that creating this delegate gives it enough time to do whatever it needs to do before proceeding.

@samhouts @hartez hopefully these findings help the team with this one.

Actually, this also works (no need to do anything in OnAppearing)

protected override void OnDisappearing() {
 BindingContext = null;
 Device.BeginInvokeOnMainThread(() => {
  BindingContext = _viewModel;
 });
}

@alanag13 thanks! Your OnDissapearing() override fixes the issue on my end.

Another observation: When the unwanted item hangs around as in the screencast, the flyout is blocked. Swipe gestures no longer work.

Actually, this also works (no need to do anything in OnAppearing)

protected override void OnDisappearing() {
 BindingContext = null;
 Device.BeginInvokeOnMainThread(() => {
  BindingContext = _viewModel;
 });
}

I tried this one but it doesn't work for me :( Sadly i am just using just native MVVM straight from the Documentation and i also used Xamarin Version 4.3 as of now

Actually, this also works (no need to do anything in OnAppearing)

protected override void OnDisappearing() {
 BindingContext = null;
 Device.BeginInvokeOnMainThread(() => {
  BindingContext = _viewModel;
 });
}

Screen Shot 2019-10-29 at 9 09 23 AM

I Already Fix it on my Case I Used the Nightly Builds

Here: https://github.com/alanag13/Xamarin.Forms/tree/fix-collectionview

You can browse there on how to Work on it both Mac or Windows version of VS 2019 or lower

And NOTE: Upon Updating your Xamarin.Forms to 4.5 with Nightly Make Sure you also Download the Xamarin.Visual.Material JUST IN CASE YOU USED That on your Projects But if not You're Good To Go :)

Thank You So Much to @alanag13 Author from the link and all of the Contributors :) More Power

The fix should be in the Nightly package and the fix was made in this PR: https://github.com/xamarin/Xamarin.Forms/pull/8189

For some reason this was never closed while the associated PR seems merged and has fixed the issue. Closing this for now.

Was this page helpful?
0 / 5 - 0 ratings