Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[iOS/MacCatalyst] Fix SearchBar TextChanged event not working issue #5462

Merged
merged 4 commits into from
Mar 30, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,11 @@
Style="{StaticResource Headline}"/>
<SearchBar
IsTextPredictionEnabled="False"/>
<Label
Text="TextChanged"
Style="{StaticResource Headline}"/>
<SearchBar
TextChanged="OnSearchBarTextChanged"/>
<Label
Text="Background color"
Style="{StaticResource Headline}"/>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,19 @@
namespace Maui.Controls.Sample.Pages
using System.Diagnostics;
using Microsoft.Maui.Controls;

namespace Maui.Controls.Sample.Pages
{
public partial class SearchBarPage
{
public SearchBarPage()
{
InitializeComponent();
}

void OnSearchBarTextChanged(object sender, TextChangedEventArgs args)
{
var text = ((SearchBar)sender).Text;
Debug.WriteLine($"SearchBar Text changed: {text}");
}
}
}
15 changes: 14 additions & 1 deletion src/Core/src/Handlers/SearchBar/SearchBarHandler.iOS.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,10 @@ protected override void ConnectHandler(MauiSearchBar platformView)

platformView.OnEditingStarted += OnEditingStarted;
platformView.OnEditingStopped += OnEditingEnded;


if (_editor != null)
_editor.EditingChanged += OnEditingChanged;

base.ConnectHandler(platformView);
}

Expand All @@ -45,6 +48,8 @@ protected override void DisconnectHandler(MauiSearchBar platformView)
platformView.OnEditingStarted -= OnEditingStarted;
platformView.OnEditingStopped -= OnEditingEnded;

if (_editor != null)
_editor.EditingChanged -= OnEditingChanged;

base.DisconnectHandler(platformView);
}
Expand Down Expand Up @@ -171,5 +176,13 @@ void OnEditingStarted(object? sender, EventArgs e)
if (VirtualView != null)
VirtualView.IsFocused = true;
}

void OnEditingChanged(object? sender, EventArgs e)
{
if (VirtualView == null || _editor == null)
return;

VirtualView.UpdateText(_editor.Text);
}
}
}