xamarin / Xamarin.Forms

Xamarin.Forms is no longer supported. Migrate your apps to .NET MAUI.
https://aka.ms/xamarin-upgrade
Other
5.64k stars 1.88k forks source link

[Bug] iOS 14 ScrollView when you tap in the editor first line will scroll to go to the bottom #13040

Open tcerdaj opened 3 years ago

tcerdaj commented 3 years ago

Description

iOS 14 ScrollView when you tap in the editor first line will scroll to go to the bottom, this is happening when you add editor or entry content type to a ScrollView.

Steps to Reproduce

  1. Enter some text in the first editor or entry line
  2. Press enter to go to the next line
  3. Enter some text
  4. Tap to go to the first line

Expected Behavior

keep the scroll position in the first line and not go to the bottom

Actual Behavior

The screen will scroll to go to the bottom

Basic Information

Xamarin forms 8.

Environment

Xamarin forms 4.8 Xcode 11.6

Build Logs

Reproduction Link

Workaround

PureWeen commented 3 years ago

@tcerdaj Can you attach a repro or the XAML you are using for this issue?

tcerdaj commented 3 years ago

Sorry @PureWeen for the delay: Note: This was working fine in iOS 13. XAML:

    <!-- Note Editor -->
    <!--*************-->
        <AbsoluteLayout HorizontalOptions="FillAndExpand"
                        VerticalOptions="FillAndExpand">
            <StackLayout AbsoluteLayout.LayoutBounds="0, 0, 1, 1"
                         AbsoluteLayout.LayoutFlags="All">
                <ScrollView x:Name="myScrollView"
                            HorizontalOptions="FillAndExpand"
                            VerticalOptions="FillAndExpand">
                    <ScrollView.Triggers>
                        <DataTrigger TargetType="ScrollView"
                                     Binding="{Binding Source={Reference textNoteEditor}, Path=IsFocused}"
                                     Value="True">
                            <DataTrigger.EnterActions>
                                <act:ScrollOnFocusTriggerAction />
                            </DataTrigger.EnterActions>
                        </DataTrigger>
                        <DataTrigger TargetType="ScrollView"
                                     Binding="{Binding Source={Reference textNoteEditor}, Path=IsFocused}"
                                     Value="False">
                            <DataTrigger.EnterActions>
                                <act:ScrollOnUnfocusTriggerAction />
                            </DataTrigger.EnterActions>
                        </DataTrigger>
                    </ScrollView.Triggers>
                    <mycc:AdjustableEditor x:Name="textNoteEditor"
                                           BackgroundColor="White"
                                           HorizontalOptions="FillAndExpand"
                                           VerticalOptions="FillAndExpand"
                                           Text="{Binding Note}"
                                           IsEnabled="{Binding CanEditNote}"
                                           AutoSize="TextChanges"
                                           AutomationId="user_note_entry" />
                </ScrollView>
            </StackLayout>
            <AbsoluteLayout AbsoluteLayout.LayoutBounds="0, 0, 1, 1"
                            AbsoluteLayout.LayoutFlags="All"
                            BackgroundColor="White"
                            Opacity="0.5"
                            IsVisible="{Binding IsBusy}">
                <ActivityIndicator AbsoluteLayout.LayoutBounds="0.5, 0.5, -1, -1"
                                   AbsoluteLayout.LayoutFlags="PositionProportional"
                                   IsRunning="{Binding IsBusy}" />
            </AbsoluteLayout>
        </AbsoluteLayout>

AdjustableEditor:

 public class AdjustableEditor : Editor
    {
        public bool HasBorder { get; set; } = false;
        // This is used for locking the scrolling ability of the Editor in iOS 
        public bool ScrollEnabled { get; set; } = false;
    }

ScrollOnFocusTriggerAction:

public class ScrollOnFocusTriggerAction : TriggerAction<ScrollView>
    {
        protected override async void Invoke(ScrollView scrollView)
        {
            try
            {
                if (scrollView == null || Device.RuntimePlatform != Device.iOS)
                    return;

                await Task.Delay(50);
                await scrollView.ScrollToAsync(scrollView, ScrollToPosition.Start, false);
            }
            catch (Exception ex)
            {
                Crashes.TrackError(ex);
            }
        }
    }

ScrollOnUnfocusTriggerAction

 public class ScrollOnUnfocusTriggerAction : TriggerAction<ScrollView>
    {
        protected override void Invoke(ScrollView scrollView)
        {
            try
            {
                if (scrollView == null || Device.RuntimePlatform != Device.iOS)
                    return;

                _ = scrollView.ScrollToAsync(scrollView, ScrollToPosition.Start, false);
                scrollView.Focus();
            }
            catch (Exception ex)
            {
                Crashes.TrackError(ex);
            }
        }
    }
jsuarezruiz commented 3 years ago

Attach a sample trying to reproduce the issue with the previous comment code: Issue13040.zip

Tested with Xamarin.Forms 4.8 and 5.0.

@tcerdaj Cannot reproduce the issue, probably I am missing something in the sample, could you take a look?

tcerdaj commented 3 years ago

Trying using iPhone 7 iOS 14

Teofilo Cerda Sent from my iPhone

On Feb 11, 2021, at 12:13 PM, Javier Suárez notifications@github.com wrote:



Attach a sample trying to reproduce the issue with the previous comment code: Issue13040.ziphttps://github.com/xamarin/Xamarin.Forms/files/5967185/Issue13040.zip

@tcerdajhttps://github.com/tcerdaj Cannot reproduce the issue, probably I am missing something in the sample, could you take a look?

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHubhttps://github.com/xamarin/Xamarin.Forms/issues/13040#issuecomment-777650933, or unsubscribehttps://github.com/notifications/unsubscribe-auth/AAZHSY7UNBXRWNFT3T3IXM3S6QF33ANCNFSM4UMETDWQ.

tcerdaj commented 3 years ago

IOS 14 o last er

Teofilo Cerda Sent from my iPhone

On Feb 11, 2021, at 12:33 PM, Teófilo Cerda tcerdaj@hotmail.com wrote:

 Trying using iPhone 7 iOS 14

Teofilo Cerda Sent from my iPhone

On Feb 11, 2021, at 12:13 PM, Javier Suárez notifications@github.com wrote:



Attach a sample trying to reproduce the issue with the previous comment code: Issue13040.ziphttps://github.com/xamarin/Xamarin.Forms/files/5967185/Issue13040.zip

@tcerdajhttps://github.com/tcerdaj Cannot reproduce the issue, probably I am missing something in the sample, could you take a look?

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHubhttps://github.com/xamarin/Xamarin.Forms/issues/13040#issuecomment-777650933, or unsubscribehttps://github.com/notifications/unsubscribe-auth/AAZHSY7UNBXRWNFT3T3IXM3S6QF33ANCNFSM4UMETDWQ.

tcerdaj commented 3 years ago

Hi, @jsuarezruiz I was able to reproduce within https://github.com/xamarin/Xamarin.Forms/files/5967185/Issue13040.zip iPhone 7 iOS 14.2 Simulator.

singhwong commented 3 years ago

I think,If the Text attribute uses binding, the built-in Scroll of the editor will not work in iOS 14+. If you add a ScrollView outside, this issue will occur.