Skip to content
This repository has been archived by the owner on May 1, 2024. It is now read-only.

[Bug] iOS - ListView and CollectionView - Editor - Focus is not cleared when Editor gets out of View #10942

Open
BrayanKhosravian opened this issue Jun 3, 2020 · 2 comments

Comments

@BrayanKhosravian
Copy link
Contributor

BrayanKhosravian commented Jun 3, 2020

Description

When a Editor is placed inside a ViewCell and the Editor is currently focused while getting out of View, then the ViewCell.OnDisappearing is not called and the focus of the Editor is not cleared.

There are a few issues with this behavior:
1.) there is not always a "Done" button for an editor (f.e. NumberKeyboard)
2.) When he user scrolls down in a listview/collectionview the user can edit still the field even when it is not visible anymore
3.) i cant even workaround it as the OnDisappearing is not called at all when the editor is located inside a viewcell (The workaround would be to unfocus the editor in the ondisappearing)
4.) It causes weird rendering issues.

  • For the listview the editor is visible at an index where it shouldnt.
  • for the collectionView the editor is white or transparent and cant be used anymore.

Steps to Reproduce

ListView:

  1. Copy and paste the snippet
  2. Make sure that u use the ListView (Content = CreateListView();)
  3. Start the app
  4. Click the first editor
  5. Set the Breakpoint in the OnDisappearing
  6. Scroll
    => Editor is not unfocused
    => OnDisappearing is not called where the currently focused editor is located

CollectionView:

  1. Copy and paste the snippet
  2. Make sure that u use the CollectionView (Content = CreateCollectionView();) (It is commented, please uncomment it)
  3. Start the app
  4. Click the first editor
  5. Scroll
    => Editor is not unfocused
    => OnDisappearing is not called where the currently focused editor is located

Code is added to "Repro Link"

Expected Behavior

The Editor should unfocus when its not visible anymore.
ListView: The OnDisappearing of the viewcell should be called when getting out of view even when a focused Editor is locaed inside.

Actual Behavior

Editor is not unfocused
ListView: OnDisappearing is not called

Basic Information

  • Version with issue: master
  • Last known good version: -
  • IDE: VS 2019
  • Platform Target Frameworks:
    • iOS: tested on xamarin forms master branch

Screenshots

ios-editor-unfocus

Reproduction Link

using System.Collections.ObjectModel;
using System.Linq;
using Xamarin.Forms.CustomAttributes;

namespace Xamarin.Forms.Controls.Issues
{
	[Issue(IssueTracker.Github, 10942, "iOS - ListView and CollectionView - Editor - Focus is not cleared when Editor gets out of View", PlatformAffected.iOS)]
	public class IosEntryOnDisappearing : TestContentPage
	{
		private class EditorContentView : ContentView
		{
			public EditorContentView()
			{
				var editor = new Editor();
				editor.SetBinding(Editor.TextProperty, ".");
				Content = editor;
			}
		}

		private class EditorViewCell : ViewCell
		{
			public EditorViewCell()
			{
				var editor = new Editor();
				editor.SetBinding(Editor.TextProperty, ".");
				View = editor;
			}

			// Click on the first Cell/View and then scroll down
			// You notice that the OnDisappearing is not called for the cell where the editor is located
			protected override void OnDisappearing()
			{
				var text = (View as Editor)?.Text;
				base.OnDisappearing(); // breakpoint here

			}
		}

		protected override void Init()
		{
			// comment one of the 2 lines out // use either listview or collectionview
			// Content = CreateCollectionView();
			Content = CreateListView();
		}

		ListView CreateListView()
		{
			var listView = new ListView();
			listView.ItemTemplate = new DataTemplate(typeof(EditorViewCell));
			listView.ItemsSource = GetSource();
			return listView;
		}

		CollectionView CreateCollectionView()
		{
			var collectionView = new CollectionView();
			collectionView.ItemTemplate = new DataTemplate(typeof(EditorContentView));
			collectionView.ItemsSource = GetSource();
			return collectionView;
		}

		ObservableCollection<int> GetSource() => 
			new ObservableCollection<int>(Enumerable.Range(0, 75));
	}
}

Workaround

none

@BrayanKhosravian BrayanKhosravian added s/unverified New report that has yet to be verified t/bug 🐛 labels Jun 3, 2020
@pauldipietro pauldipietro added this to New in Triage Jun 3, 2020
@BrayanKhosravian
Copy link
Contributor Author

@gentledepp @bruzkovsky fyi

@jsuarezruiz jsuarezruiz added a/collectionview a/editor a/listview Problems with the ListView/TableView labels Jun 4, 2020
@rmarinho rmarinho removed the s/unverified New report that has yet to be verified label Jun 30, 2020
rmarinho added a commit that referenced this issue Jun 30, 2020
@rmarinho
Copy link
Member

Can confirm this issue on iOS, on Android the Keyboard is hidden when we scroll, so we should make the same on iOS. At the same time is weird that only the cell that is focused doesn't call Disappearing, the others the Disappearing is being called.

@rmarinho rmarinho moved this from New to Ready For Work in Triage Jun 30, 2020
@rmarinho rmarinho added the e/3 🕒 3 label Jun 30, 2020
@samhouts samhouts added this to To do in Other Ready For Work Jul 1, 2020
@samhouts samhouts removed this from Ready For Work in Triage Jul 1, 2020
@samhouts samhouts added this to Backlog in CollectionView Jul 13, 2020
@samhouts samhouts added this to the 5.0.0 milestone Aug 13, 2020
@samhouts samhouts added this to To do in vNext+1 (5.0.0) Aug 13, 2020
@samhouts samhouts removed this from the 5.0.0 milestone Nov 2, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
CollectionView
  
Review Backlog
Development

No branches or pull requests

4 participants