This is Xamarin's bug tracking system. For product support, please use the support links listed in your Xamarin Account.
Bug 45924 - On UWP, SearchBar getting focus results in page scrolling unnecessarily
Summary: On UWP, SearchBar getting focus results in page scrolling unnecessarily
Status: RESOLVED FIXED
Alias: None
Product: Forms
Classification: Xamarin
Component: Forms (show other bugs)
Version: 2.3.2
Hardware: PC Windows
: Normal normal
Target Milestone: ---
Assignee: Bugzilla
URL:
Depends on:
Blocks:
 
Reported: 2016-10-26 14:52 UTC by John Hardman
Modified: 2017-03-07 10:45 UTC (History)
4 users (show)

See Also:
Tags: UWP SearchBar scrolling ac
Is this bug a regression?: ---
Last known good build:


Attachments

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 =
                {
                    entryLabel,
                    entry,
                    searchBarLabel,
                    searchBar
                }
            };

            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 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 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

Note You need to log in before you can comment on or make changes to this bug.