Skip to content

Commit

Permalink
Code cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
jonathanpeppers committed Nov 15, 2023
1 parent cd27412 commit cdf2ffb
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions src/Core/src/Handlers/SearchBar/SearchBarHandler.iOS.cs
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,8 @@ class MauiSearchBarProxy

ISearchBar? VirtualView => _virtualView is not null && _virtualView.TryGetTarget(out var v) ? v : null;

SearchBarHandler? Handler => _handler is not null && _handler.TryGetTarget(out var h) ? h : null;

public void Connect(SearchBarHandler handler, ISearchBar virtualView, MauiSearchBar platformView)
{
_handler = new(handler);
Expand All @@ -179,6 +181,7 @@ public void Connect(SearchBarHandler handler, ISearchBar virtualView, MauiSearch
public void Disconnect(MauiSearchBar platformView, UITextField? editor)
{
_virtualView = null;
_handler = null;

platformView.CancelButtonClicked -= OnCancelClicked;
platformView.SearchButtonClicked -= OnSearchButtonClicked;
Expand All @@ -196,7 +199,7 @@ void OnMovedToWindow(object? sender, EventArgs e)
{
// The cancel button doesn't exist until the control has moved to the window
// so we fire this off again so it can set the color
if (_handler is not null && _handler.TryGetTarget(out var handler))
if (Handler is SearchBarHandler handler)
{
handler.UpdateValue(nameof(ISearchBar.CancelButtonColor));
}
Expand All @@ -219,7 +222,7 @@ void OnTextPropertySet(object? sender, UISearchBarTextChangedEventArgs a)
{
virtualView.UpdateText(a.SearchText);

if (_handler is not null && _handler.TryGetTarget(out var handler))
if (Handler is SearchBarHandler handler)
{
handler.UpdateCancelButtonVisibility();
}
Expand All @@ -240,7 +243,7 @@ void OnEditingStarted(object? sender, EventArgs e)

void OnEditingChanged(object? sender, EventArgs e)
{
if (_handler is not null && _handler.TryGetTarget(out var handler))
if (Handler is SearchBarHandler handler)
{
handler.UpdateCancelButtonVisibility();
}
Expand Down

0 comments on commit cdf2ffb

Please sign in to comment.