Quantcast
Channel: Xamarin.Forms — Xamarin Community Forums
Viewing all articles
Browse latest Browse all 77050

ScrollView ScrollToAsync resulting in blank screen on iOS

$
0
0

Background
We have a page where we have a bound RepeaterView within a ScrollView. We're adding Questions to the bound collection as the user answers questions (the aim is to give a series of questions, scrolling off the top as the user progresses).

We want the ScrollView to scroll to the bottom as we add Questions.

To do this, I've created an Event which we raise when we add a Question, and added a handler in the Page. I'm subscribing/unsubscribing on the Appearing/Disappearing events for the page to avoid memory leaks etc.

The Problem
On Android this works fine. But on iOS, the ScrollView goes blank. However, if I background the app and bring it back to the foreground (by tapping the Home button and then the app icon, the screen then refreshes.

Therefore it appears that the Page isn't being refreshed properly by my code.

My XAML code:

using System;
using System.Collections.Generic;
using System.Threading.Tasks;
using MvvmCross.Forms.Presenters.Attributes;
using MyApp.Mobile.PageModels.Claims.Medical;
using MyApp.Mobile.Pages.Base;
using Xamarin.Forms;

namespace MyApp.Mobile.Pages.Claims.Medical
{
    [MvxContentPagePresentation(NoHistory = true)]
    public partial class ClaimConditionPage : BaseContentPage<ClaimConditionPageModel>
    {
        public ClaimConditionPage()
        {
            InitializeComponent();
        }

        protected override void OnAppearing()
        {
            if (BindingContext != null)
            {
                ClaimConditionPageModel model = (ClaimConditionPageModel)this.BindingContext.DataContext;

                model.QuestionAdded += Model_QuestionAdded;
            }

            base.OnAppearing();
        }

        protected override void OnDisappearing()
        {
            ClaimConditionPageModel model = (ClaimConditionPageModel)this.BindingContext.DataContext;

            model.QuestionAdded -= Model_QuestionAdded;
            base.OnDisappearing();
        }

        void Model_QuestionAdded(object sender, EventArgs e)
        {
            Device.BeginInvokeOnMainThread(async () =>
            {
                await QuestionScrollView.ScrollToAsync(0, QuestionScrollView.Content.Height, false);
            });

        }

    }
}

I've seen suggestions of adding a Task.Delay() to allow the UI to catch up - but this didn't work.

Note that this is only on iOS.

I note that there is this bug, but I don't think this is my problem. The ScrollView does scroll, but the display goes blank.

Versions
Xamarin.Forms 3.4.0.1029999

=== Visual Studio Community 2017 for Mac ===

Version 7.8.2 (build 1)
Installation UUID: 650b4c91-c7f5-4ee5-ad70-6f178f314906
GTK+ 2.24.23 (Raleigh theme)
Xamarin.Mac 5.0.0.0 ( / b40230c0)

Package version: 516000221

=== Mono Framework MDK ===

Runtime:
Mono 5.16.0.221 (2018-06/b63e5378e38) (64-bit)
Package version: 516000221

=== NuGet ===

Version: 4.8.0.5385

=== .NET Core ===

Runtime: /usr/local/share/dotnet/dotnet
Runtime Versions:
2.1.8
2.1.5
2.1.2
2.1.1
2.0.5
SDK: /usr/local/share/dotnet/sdk/2.1.504/Sdks
SDK Versions:
2.1.504
2.1.403
2.1.302
2.1.301
2.1.4
MSBuild SDKs: /Library/Frameworks/Mono.framework/Versions/5.16.0/lib/mono/msbuild/15.0/bin/Sdks

=== Xamarin.Profiler ===

Version: 1.6.4
Location: /Applications/Xamarin Profiler.app/Contents/MacOS/Xamarin Profiler

=== Updater ===

Version: 11

=== Apple Developer Tools ===

Xcode 10.1 (14460.46)
Build 10B61

=== Xamarin.Mac ===

Version: 5.2.1.15 (Visual Studio Community)
Hash: d60abd198
Branch:
Build date: 2019-02-01 12:23:30-0500

=== Xamarin.iOS ===

Version: 12.2.1.15 (Visual Studio Community)
Hash: d60abd198
Branch: d15-9
Build date: 2019-02-01 12:23:29-0500

=== Xamarin.Android ===

Version: 9.1.8.0 (Visual Studio Community)
Android SDK: /Users/jameslavery/Library/Developer/Xamarin/android-sdk-macosx
Supported Android versions:
2.3 (API level 10)
4.0.3 (API level 15)
4.1 (API level 16)
4.3 (API level 18)
4.4 (API level 19)
5.0 (API level 21)
5.1 (API level 22)
6.0 (API level 23)
7.0 (API level 24)
7.1 (API level 25)
8.0 (API level 26)
8.1 (API level 27)

SDK Tools Version: 26.1.1
SDK Platform Tools Version: 28.0.0
SDK Build Tools Version: 26.0.2

=== Microsoft Mobile OpenJDK ===

Java SDK: /Users/jameslavery/Library/Developer/Xamarin/jdk/microsoft_dist_openjdk_8.0.25
1.8.0-25
Android Designer EPL code available here:
https://github.com/xamarin/AndroidDesigner.EPL

=== Android Device Manager ===

Version: 7.8.1.0
Hash: 8924ea4a

=== Xamarin Inspector ===

Version: 1.4.3
Hash: db27525
Branch: 1.4-release
Build date: Mon, 09 Jul 2018 21:20:18 GMT
Client compatibility: 1

=== Build Information ===

Release ID: 708020001
Git revision: 13e0e5b7e85ffe742957e6f204bab5c06c644f0e
Build date: 2019-02-27 19:33:14+00
Build branch: release-7.8
Xamarin extensions: 23eaa7c9cdc9a3f55be7bb87b485a790ec82ef25

=== Operating System ===

Mac OS X 10.13.6
Darwin 17.7.0 Darwin Kernel Version 17.7.0
Fri Nov 2 20:43:16 PDT 2018
root:xnu-4570.71.17~1/RELEASE_X86_64 x86_64

=== Enabled user installed extensions ===

LiveXAML 1.3.31
MFractor 3.7.10
MvvmCross Template pack 2.0.1
NuGet Package Management Extensions 0.15
Template Creator 0.4
Redth's Addins 1.0.9
Internet of Things (IoT) development (Preview) 7.5


Viewing all articles
Browse latest Browse all 77050

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>