xamarin/Xamarin.Forms

[Shell] Control loses focus after appearing

Open

#4,755 opened on Dec 15, 2018

 (1 comment) (0 reactions) (0 assignees)C# (1,926 forks)batch import
4.0.0a/shell :shell:e/4 :clock4:help wantedinactivet/bug :bug:up-for-grabs

Repository metrics

Stars
 (5,644 stars)
PR merge metrics
 (No merged PRs in 30d)

Description

Description

I have a page that sets focus to an Entry and then pre-selects text. This works fine in a TabbedPage, but within Shell it's losing focus.

Losing focus: https://www.screencast.com/t/Daq7XY40

protected override void OnAppearing()
        {
            base.OnAppearing();
            MakeSelection();
        }

        private void MakeSelection()
        {
            FirstEntry.Focus();
            FirstEntry.CursorPosition = 4;
            FirstEntry.SelectionLength = 11;
        }

If I set the ShellContent to be ShellSections (bottom tabs) and yet also displayed in the flyout, this is not a problem. It seems navigation from ShellItem to ShellItem introduces an animation that is causing this issue.

Not losing focus: https://www.screencast.com/t/GBJOIi9a

This is fine:

<Shell ...>
<ShellItem FlyoutDisplayOptions="AsMultipleItems" Title="Releases">
        <ShellContent Title="3.1.0" ContentTemplate="{DataTemplate views:ThreeOnePage}" Icon="iconXamagon"/>
        <ShellContent Title="3.2.0" ContentTemplate="{DataTemplate views:ThreeTwoPage}" Icon="iconXamagon"/>
        <ShellContent Title="3.3.0" ContentTemplate="{DataTemplate views:ThreeThreePage}" Icon="iconXamagon"/>
        <ShellContent Title="3.4.0" ContentTemplate="{DataTemplate views:ThreeFourPage}" Icon="iconXamagon"/>
        <ShellContent Title="3.5.0-pre" ContentTemplate="{DataTemplate views:ThreeFivePage}" Icon="iconXamagon"/>
    </ShellItem>
</Shell>

This is not:

<Shell ...>
        <ShellContent Title="3.1.0" ContentTemplate="{DataTemplate views:ThreeOnePage}" Icon="iconXamagon"/>
        <ShellContent Title="3.2.0" ContentTemplate="{DataTemplate views:ThreeTwoPage}" Icon="iconXamagon"/>
        <ShellContent Title="3.3.0" ContentTemplate="{DataTemplate views:ThreeThreePage}" Icon="iconXamagon"/>
        <ShellContent Title="3.4.0" ContentTemplate="{DataTemplate views:ThreeFourPage}" Icon="iconXamagon"/>
        <ShellContent Title="3.5.0-pre" ContentTemplate="{DataTemplate views:ThreeFivePage}" Icon="iconXamagon"/>
</Shell>

Steps to Reproduce

  1. Navigate to the 3.2.0 page from the flyout

Expected Behavior

Focus set in OnAppearing is not lost until the user changes focus..

Actual Behavior

Focus is lost a split second after appearing.

Basic Information

  • Version with issue: 4.0-pre1

Screenshots

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

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

Reproduction Link

Archive.zip

Parent: #2415

Contributor guide