Bug 45924

Summary: On UWP, SearchBar getting focus results in page scrolling unnecessarily
Product: Forms Reporter: John Hardman <jsh001guard-z659>
Component: FormsAssignee: Bugzilla <bugzilla>
Severity: normal CC: jas, jsh001guard-z659, paul.dipietro, rui.marinho, v-jawasw
Priority: Normal    
Version: 2.3.2   
Target Milestone: ---   
Hardware: PC   
OS: Windows   
Tags: UWP SearchBar scrolling ac Is this bug a regression?: ---
Last known good build:

Description John Hardman 2016-10-26 14:52:35 UTC
With a UWP build running on a phone, with a simple page containing a couple of Labels, an Entry and a SearchBar, when the SearchBar receives focus the page scrolls unnecessarily to put the SearchBar right at the top of the page. This creates an unpleasant user experience. Scrolling should only happen if the view receiving the focus would be hidden by the soft keyboard.

To reproduce, I have a simple view model:

    public class MyAppXamarinViewsPageViewModel
        public Color PageBackgroundColor { get; set; } = Color.White;

And then the following code creates the page content:

            MyAppXamarinViewsPageViewModel viewModel = new MyAppXamarinViewsPageViewModel();

            Label entryLabel = new Label {Text = "Entry"};
            Entry entry = new Entry
                Placeholder = "Placeholder for Entry"

            Label searchBarLabel = new Label {Text = "SearchBar"};
            SearchBar searchBar = new SearchBar
                Placeholder = "Placeholder for SearchBar"

            StackLayout vslOuterPage = new StackLayout
                BackgroundColor = viewModel.PageBackgroundColor,
                HorizontalOptions = LayoutOptions.FillAndExpand,
                VerticalOptions = LayoutOptions.FillAndExpand,
                Margin = new Thickness(0, 0, 0, 0),
                Padding = new Thickness(0, 10, 0, 10),
                Spacing = 0,
                Children =

            this.BackgroundColor = viewModel.PageBackgroundColor;
            this.Padding = new Thickness(5, 0, 5, 0);
            this.BindingContext = viewModel;
            this.Title = "Xamarin views";
            this.Content = vslOuterPage;

Run this, and tap on the SearchBar to move the focus to it. The page will scroll unnecessarily.
Comment 1 Paul DiPietro [MSFT] 2016-11-01 00:03:28 UTC
I apologize for marking this as confirmed too quickly. It seems as if this is regular AutoSuggestBox behavior. AutoSuggestBox is the standard control used in UWP (as explained at https://msdn.microsoft.com/windows/uwp/porting/w8x-to-uwp-porting-xaml-and-ui#searchbox-deprecated-in-favor-of-autosuggestbox) and is used for the Forms implementation of SearchBox, while the implementation in 8.1 uses the old SearchBox control, which would explain any differences in behavior. 

Why it jumps to the top of the screen, I can't explain, but if you set up a basic Universal app and place an AutoSuggestBox in the middle of the view, it'll do the same thing.
Comment 2 John Hardman 2016-11-01 09:55:43 UTC
@Paul DiPietro - Why it jumps to the top of the screen in UWP is probably because the native UWP implementation supports a drop-down list of suggestions. In Xamarin.Forms however, that drop-down list of suggestions is not present, so it would make sense for the default Xamarin.Forms SearchBar renderer to prevent the re-positioning to the top of the page when the view receives focus.

(I've re-opened this so that this message gets read)
Comment 3 Paul DiPietro [MSFT] 2016-11-01 19:01:08 UTC
You're correct on that part. In fact, this can fortunately be fixed. A concern would be that getting into the native behavior to prevent the scrolling might have been a bit of a task, but it appears that the AutoMaximizeSuggestionArea property on AutoSuggestBox can be utilized to prevent this. I think that there may be a potential case for platform specific functionality to be added here, so I'm in the middle of looking into it because I think it could be of help for Windows devs.
Comment 4 John Hardman 2016-11-01 23:09:54 UTC
@Paul DiPietro - yes, I've spent the day writing a custom ScrollBarRenderer that gives me control over the various features on UWP. Not quite finished, but happy to pass the code on if it might be useful.
Comment 5 Rui Marinho 2017-03-07 10:45:56 UTC
Should be fixed on 2.3.5-pre1
Comment 6 Jacky Waswani 2017-07-14 11:40:31 UTC
Tested. Bug appears fixed in version

Screencast : https://www.screencast.com/t/eNoqQhYwiGb

Build Info: https://gist.github.com/GLjackyvaswani/600433ce6f3b92544b42d0392001d326