xamarin/Xamarin.Forms

[Bug] Unfocus method does not hide picker

開放

#8,367 建立於 2019年11月4日

 (4 則留言) (0 個反應) (0 位負責人)C# (1,926 個分叉)batch import
e/4 :clock4:help wantedinactivep/iOS 🍎t/bug :bug:up-for-grabs

倉庫指標

星標
 (5,644 顆星)
PR 合併指標
 (30 天內沒有已合併 PR)

描述

Description

When calling Unfocus (docs) on a picker, the picker is not hidden.

This only happens in a fairly specific scenario - the element that is clicked to cause the Unfocus is an Entry and it also does a Navigation.PushAsync following the Unfocus. The reasoning for this UX is that clicking the entry field opens a page where you can add or search for the record that populates that field (you never actually type anything into this field).

This occurs for me on the latest iOS, the latest Xamarin.Forms, and with a basic Picker. I have not tried other versions or other components (this method is inherited from VisualElement).

Steps to Reproduce

  1. Create a xaml page with a Picker named "MyPicker" with some items in it and an Entry
  2. Wire the Entry focused event to a method that calls MyPicker.Unfocus() and await Navigation.PushAsync
  3. Click the entry

Expected Behavior

The picker will be hidden when the entry is focused.

Actual Behavior

The picker remains open. Note that the picker's Unfocused event does fire.

Basic Information

  • Version with issue: 4.3.0.947036
  • Last known good version: Unknown
  • IDE: Visual Studio for Mac Professional 8.3.6 build 4
  • Platform Target Frameworks:
    • iOS: 13.2
    • Android: Did not check
    • UWP: Did not check
  • Android Support Library Version: N/A
  • Nuget Packages:
  • Affected Devices: iPhone 11 Pro Max, did not check others

Screenshots

Picker open on first page

Bug demonstration - picker should now be closed

Reproduction Sample Code

MyPage.xaml

<StackLayout>
  <Picker x:Name="MyPicker" Title="Pick" Unfocused="MyPickerUnfocused">
    <Picker.Items>
      <x:String>Item 1</x:String>
      <x:String>Item 2</x:String>
    </Picker.Items>
  </Picker>
  <Entry Placeholder="Hide Picker" Focused="HidePickerFocused" />
</StackLayout>

MyPage.xaml.cs

public async void HidePickerFocused(object sender, FocusEventArgs eventArgs)
{
    MyPicker.Unfocus();
    await Navigation.PushAsync(new ContentPage(), true);
}

public void MyPickerUnfocused(object sender, FocusEventArgs eventArgs)
{
    Console.WriteLine("MyPickerUnfocused"); // this is hit when debugging
}

貢獻者指南