diff --git a/Xamarin.Forms.Core/BindableObject.cs b/Xamarin.Forms.Core/BindableObject.cs index 551d67a0cb6..a60c9629b84 100644 --- a/Xamarin.Forms.Core/BindableObject.cs +++ b/Xamarin.Forms.Core/BindableObject.cs @@ -407,7 +407,7 @@ internal void SetValueCore(BindableProperty property, object value, SetValueFlag if (!converted && !property.TryConvert(ref value)) { - Log.Warning("SetValue", $"Cannot convert {value} to type '{property.ReturnType}'"); + Log.Warning("SetValue", $"Cannot convert {value} to type '{property.ReturnType}' for {this.GetType().Name}.{property.PropertyName}"); return; } diff --git a/Xamarin.Forms.Platform.Android/PlatformRenderer.cs b/Xamarin.Forms.Platform.Android/PlatformRenderer.cs index 59523aca88f..3f5917cb4cc 100644 --- a/Xamarin.Forms.Platform.Android/PlatformRenderer.cs +++ b/Xamarin.Forms.Platform.Android/PlatformRenderer.cs @@ -10,9 +10,6 @@ namespace Xamarin.Forms.Platform.Android internal class PlatformRenderer : ViewGroup { readonly IPlatformLayout _canvas; - Point _downPosition; - - DateTime _downTime; public PlatformRenderer(Context context, IPlatformLayout canvas) : base(context) { @@ -24,53 +21,6 @@ public PlatformRenderer(Context context, IPlatformLayout canvas) : base(context) } } - public override bool DispatchTouchEvent(MotionEvent e) - { - if (e.Action == MotionEventActions.Down) - { - _downTime = DateTime.UtcNow; - _downPosition = new Point(e.RawX, e.RawY); - } - - if (e.Action != MotionEventActions.Up) - return base.DispatchTouchEvent(e); - - global::Android.Views.View currentView = Context.GetActivity().CurrentFocus; - bool result = base.DispatchTouchEvent(e); - - do - { - if (!(currentView is EditText)) - break; - - global::Android.Views.View newCurrentView = Context.GetActivity().CurrentFocus; - - if (currentView != newCurrentView) - break; - - double distance = _downPosition.Distance(new Point(e.RawX, e.RawY)); - - if (distance > Context.ToPixels(20) || DateTime.UtcNow - _downTime > TimeSpan.FromMilliseconds(200)) - break; - - var location = new int[2]; - currentView.GetLocationOnScreen(location); - - float x = e.RawX + currentView.Left - location[0]; - float y = e.RawY + currentView.Top - location[1]; - - var rect = new Rectangle(currentView.Left, currentView.Top, currentView.Width, currentView.Height); - - if (rect.Contains(x, y)) - break; - - Context.HideKeyboard(currentView); - Context.GetActivity().Window.DecorView.ClearFocus(); - } while (false); - - return result; - } - protected override void OnLayout(bool changed, int l, int t, int r, int b) { Profile.FrameBegin(); diff --git a/Xamarin.Forms.Platform.Android/Renderers/IShellSearchView.cs b/Xamarin.Forms.Platform.Android/Renderers/IShellSearchView.cs index 90cc87f3ac1..6ac2506d59a 100644 --- a/Xamarin.Forms.Platform.Android/Renderers/IShellSearchView.cs +++ b/Xamarin.Forms.Platform.Android/Renderers/IShellSearchView.cs @@ -12,7 +12,5 @@ public interface IShellSearchView : IDisposable void LoadView(); event EventHandler SearchConfirmed; - - bool ShowKeyboardOnAttached { get; set; } } } \ No newline at end of file diff --git a/Xamarin.Forms.Platform.Android/Renderers/SearchBarRenderer.cs b/Xamarin.Forms.Platform.Android/Renderers/SearchBarRenderer.cs index aa470ddd04d..56882b752a6 100644 --- a/Xamarin.Forms.Platform.Android/Renderers/SearchBarRenderer.cs +++ b/Xamarin.Forms.Platform.Android/Renderers/SearchBarRenderer.cs @@ -46,7 +46,6 @@ bool SearchView.IOnQueryTextListener.OnQueryTextChange(string newText) bool SearchView.IOnQueryTextListener.OnQueryTextSubmit(string query) { ((ISearchBarController)Element).OnSearchButtonPressed(); - ClearFocus(Control); return true; } @@ -225,7 +224,6 @@ void UpdateEnabled() SearchView control = Control; if (!model.IsEnabled) { - ClearFocus(control); // removes cursor in SearchView control.SetInputType(InputTypes.Null); } diff --git a/Xamarin.Forms.Platform.Android/Renderers/SearchHandlerAppearanceTracker.cs b/Xamarin.Forms.Platform.Android/Renderers/SearchHandlerAppearanceTracker.cs index 62b7a962826..64b2cb8fcd4 100644 --- a/Xamarin.Forms.Platform.Android/Renderers/SearchHandlerAppearanceTracker.cs +++ b/Xamarin.Forms.Platform.Android/Renderers/SearchHandlerAppearanceTracker.cs @@ -32,7 +32,6 @@ public SearchHandlerAppearanceTracker(IShellSearchView searchView) _searchHandler = searchView.SearchHandler; _control = searchView.View; _searchHandler.PropertyChanged += SearchHandlerPropertyChanged; - _searchHandler.FocusChangeRequested += SearchHandlerFocusChangeRequested; _editText = (_control as ViewGroup).GetChildrenOfType().FirstOrDefault(); _textColorSwitcher = new TextColorSwitcher(_editText.TextColors, false); _hintColorSwitcher = new TextColorSwitcher(_editText.HintTextColors, false); @@ -43,22 +42,6 @@ public SearchHandlerAppearanceTracker(IShellSearchView searchView) UpdateInputType(); } - protected virtual void SearchHandlerFocusChangeRequested(object sender, VisualElement.FocusRequestArgs e) - { - e.Result = true; - - if (e.Focus) - { - _control?.RequestFocus(); - _control?.PostShowKeyboard(); - } - else - { - _control.ClearFocus(); - _control.HideKeyboard(); - } - } - protected virtual void SearchHandlerPropertyChanged(object sender, System.ComponentModel.PropertyChangedEventArgs e) { if (e.Is(SearchHandler.BackgroundColorProperty)) @@ -235,7 +218,6 @@ protected virtual void Dispose(bool disposing) { if (_searchHandler != null) { - _searchHandler.FocusChangeRequested -= SearchHandlerFocusChangeRequested; _searchHandler.PropertyChanged -= SearchHandlerPropertyChanged; } _searchHandler = null; diff --git a/Xamarin.Forms.Platform.Android/Renderers/ShellFlyoutRecyclerAdapter.cs b/Xamarin.Forms.Platform.Android/Renderers/ShellFlyoutRecyclerAdapter.cs index c664cf953b4..921f87eb665 100644 --- a/Xamarin.Forms.Platform.Android/Renderers/ShellFlyoutRecyclerAdapter.cs +++ b/Xamarin.Forms.Platform.Android/Renderers/ShellFlyoutRecyclerAdapter.cs @@ -105,14 +105,12 @@ public override void OnBindViewHolder(RecyclerView.ViewHolder holder, int positi elementHolder.Element = item.Element; } - class LinearLayoutWithFocus : LinearLayout, ITabStop, IVisualElementRenderer + class ShellLinearLayout : LinearLayout, IVisualElementRenderer { - public LinearLayoutWithFocus(global::Android.Content.Context context) : base(context) + public ShellLinearLayout(global::Android.Content.Context context) : base(context) { } - AView ITabStop.TabStop => this; - #region IVisualElementRenderer VisualElement IVisualElementRenderer.Element => Content?.BindingContext as VisualElement; @@ -180,7 +178,7 @@ public override RecyclerView.ViewHolder OnCreateViewHolder(ViewGroup parent, int var content = (View)template.CreateContent(); - var linearLayout = new LinearLayoutWithFocus(parent.Context) + var linearLayout = new ShellLinearLayout(parent.Context) { Orientation = Orientation.Vertical, LayoutParameters = new RecyclerView.LayoutParams(LP.MatchParent, LP.WrapContent), diff --git a/Xamarin.Forms.Platform.Android/Renderers/ShellSearchView.cs b/Xamarin.Forms.Platform.Android/Renderers/ShellSearchView.cs index 1be8af742fc..25abb8ea1fd 100644 --- a/Xamarin.Forms.Platform.Android/Renderers/ShellSearchView.cs +++ b/Xamarin.Forms.Platform.Android/Renderers/ShellSearchView.cs @@ -28,8 +28,6 @@ public class ShellSearchView : FrameLayout, IShellSearchView, TextView.IOnEditor public SearchHandler SearchHandler { get; set; } - public bool ShowKeyboardOnAttached { get; set; } - AView IShellSearchView.View { get @@ -113,8 +111,6 @@ bool TextView.IOnEditorActionListener.OnEditorAction(TextView v, ImeAction actio // Fire Completed and dismiss keyboard for hardware / physical keyboards if (actionId == ImeAction.Done || (actionId == ImeAction.ImeNull && e.KeyCode == Keycode.Enter && e.Action == KeyEventActions.Up)) { - _textBlock.ClearFocus(); - v.HideKeyboard(); SearchConfirmed?.Invoke(this, EventArgs.Empty); Controller.QueryConfirmed(); } @@ -248,9 +244,6 @@ protected override async void OnAttachedToWindow() { base.OnAttachedToWindow(); - if (!ShowKeyboardOnAttached) - return; - Alpha = 0; Animate().Alpha(1).SetDuration(200).SetListener(null); @@ -259,9 +252,6 @@ protected override async void OnAttachedToWindow() if (_disposed) return; - - _textBlock.RequestFocus(); - Context.ShowKeyboard(_textBlock); } protected virtual void OnClearButtonClicked(object sender, EventArgs e) @@ -343,7 +333,6 @@ void OnTextBlockItemClicked(object sender, AdapterView.ItemClickEventArgs e) var item = Controller.ListProxy[index]; _textBlock.Text = ""; - _textBlock.HideKeyboard(); SearchConfirmed?.Invoke(this, EventArgs.Empty); Controller.ItemSelected(item); } diff --git a/Xamarin.Forms.Platform.Android/Renderers/ShellToolbarTracker.cs b/Xamarin.Forms.Platform.Android/Renderers/ShellToolbarTracker.cs index 606525d25f8..abc7e059258 100644 --- a/Xamarin.Forms.Platform.Android/Renderers/ShellToolbarTracker.cs +++ b/Xamarin.Forms.Platform.Android/Renderers/ShellToolbarTracker.cs @@ -595,13 +595,11 @@ protected virtual void UpdateToolbarItems(Toolbar toolbar, Page page) if (_searchView.View.Parent != null) _searchView.View.RemoveFromParent(); - _searchView.ShowKeyboardOnAttached = true; item.SetActionView(_searchView.View); item.Dispose(); } else if (SearchHandler.SearchBoxVisibility == SearchBoxVisibility.Expanded) { - _searchView.ShowKeyboardOnAttached = false; if (_searchView.View.Parent != _toolbar) _toolbar.AddView(_searchView.View); }