Skip to content

Commit 645bb2f

Browse files
CopilotVetle444
andcommitted
Move SearchBar to bottom of page and make SearchView overlay full screen for proper M3 search mode transformation
Agent-Logs-Url: https://github.com/DIPSAS/DIPS.Mobile.UI/sessions/d733a50d-13be-4d3c-a600-48c2d2b930ef Co-authored-by: Vetle444 <35739538+Vetle444@users.noreply.github.com>
1 parent 7162a8b commit 645bb2f

2 files changed

Lines changed: 37 additions & 19 deletions

File tree

src/library/DIPS.Mobile.UI/Components/Pages/Search/Android/PageSearchField.cs

Lines changed: 24 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -12,34 +12,30 @@ namespace DIPS.Mobile.UI.Components.Pages.Search;
1212
/// <summary>
1313
/// A Material 3 search component for ContentPage using the actual
1414
/// <see cref="MaterialSearchBar"/> and <see cref="MaterialSearchView"/> components.
15-
/// The SearchBar provides the collapsed pill-shaped search trigger,
16-
/// while the SearchView provides the expanded search input with EditText.
15+
/// The SearchBar provides the collapsed pill-shaped search trigger at the bottom,
16+
/// while the SearchView provides the full-screen expanded search mode.
17+
/// The SearchView is attached to the root decor view so it can properly
18+
/// overlay the entire page when activated.
1719
/// </summary>
1820
internal class PageSearchField : Java.Lang.Object, ITextWatcher, MaterialSearchView.ITransitionListener
1921
{
2022
private readonly WeakReference<SearchBehavior> m_weakBehavior;
2123
private MaterialSearchBar? m_searchBar;
2224
private MaterialSearchView? m_searchView;
23-
private FrameLayout? m_container;
2425
private string m_previousText = string.Empty;
2526

2627
public PageSearchField(Context context, SearchBehavior behavior)
2728
{
2829
m_weakBehavior = new WeakReference<SearchBehavior>(behavior);
2930

30-
m_container = new FrameLayout(context);
31-
m_container.LayoutParameters = new Android.Widget.LinearLayout.LayoutParams(
32-
ViewGroup.LayoutParams.MatchParent,
33-
ViewGroup.LayoutParams.WrapContent);
34-
35-
// Material 3 SearchBar (pill-shaped search trigger)
31+
// Material 3 SearchBar (pill-shaped search trigger) — placed at bottom of page
3632
m_searchBar = new MaterialSearchBar(context);
3733
m_searchBar.LayoutParameters = new FrameLayout.LayoutParams(
3834
ViewGroup.LayoutParams.MatchParent,
3935
ViewGroup.LayoutParams.WrapContent);
40-
m_container.AddView(m_searchBar);
4136

42-
// Material 3 SearchView (expanded search with EditText)
37+
// Material 3 SearchView (full-screen expanded search mode)
38+
// Added to root decor view so it overlays the entire page
4339
m_searchView = new MaterialSearchView(context);
4440
m_searchView.LayoutParameters = new FrameLayout.LayoutParams(
4541
ViewGroup.LayoutParams.MatchParent,
@@ -53,11 +49,17 @@ public PageSearchField(Context context, SearchBehavior behavior)
5349

5450
// Listen for transition events (show/hide)
5551
m_searchView.AddTransitionListener(this);
56-
57-
m_container.AddView(m_searchView);
5852
}
5953

60-
public AView View => m_container!;
54+
/// <summary>
55+
/// The pill-shaped SearchBar to be placed at the bottom of the page.
56+
/// </summary>
57+
public AView SearchBarView => m_searchBar!;
58+
59+
/// <summary>
60+
/// The full-screen SearchView to be attached to the root decor view.
61+
/// </summary>
62+
public AView SearchViewView => m_searchView!;
6163

6264
public void Focus()
6365
{
@@ -107,9 +109,15 @@ public void Cleanup()
107109
m_searchView.RemoveTransitionListener(this);
108110
}
109111

110-
m_container?.RemoveAllViews();
112+
// Remove SearchView from its parent (root decor view)
113+
if (m_searchView?.Parent is ViewGroup searchViewParent)
114+
searchViewParent.RemoveView(m_searchView);
115+
116+
// Remove SearchBar from its parent
117+
if (m_searchBar?.Parent is ViewGroup searchBarParent)
118+
searchBarParent.RemoveView(m_searchBar);
119+
111120
m_searchBar = null;
112121
m_searchView = null;
113-
m_container = null;
114122
}
115123
}

src/library/DIPS.Mobile.UI/Components/Pages/Search/Android/SearchBehavior.cs

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
using Android.Views;
22
using Android.Widget;
3-
using Microsoft.Maui.Platform;
43

54
namespace DIPS.Mobile.UI.Components.Pages.Search;
65

@@ -20,7 +19,7 @@ partial void SetupNativeSearch(ContentPage page)
2019

2120
m_searchField = new PageSearchField(context, this);
2221

23-
// Wrap the page's native view: insert a LinearLayout with SearchField at top, page content below
22+
// Wrap the page's native view: insert a LinearLayout with page content at top, SearchBar at bottom
2423
if (platformView.Parent is ViewGroup parent)
2524
{
2625
var index = parent.IndexOfChild(platformView);
@@ -36,11 +35,22 @@ partial void SetupNativeSearch(ContentPage page)
3635
ViewGroup.LayoutParams.MatchParent)
3736
};
3837

39-
m_wrapperLayout.AddView(m_searchField.View);
38+
// Page content fills remaining space (weight=1)
4039
m_wrapperLayout.AddView(platformView, new LinearLayout.LayoutParams(
4140
ViewGroup.LayoutParams.MatchParent, 0, 1f));
4241

42+
// SearchBar pill at the bottom
43+
m_wrapperLayout.AddView(m_searchField.SearchBarView);
44+
4345
parent.AddView(m_wrapperLayout, index);
46+
47+
// Add SearchView to the root decor view so it can overlay the entire page (full-screen search mode)
48+
if (context is Android.App.Activity activity)
49+
{
50+
var decorView = activity.Window?.DecorView as ViewGroup;
51+
var contentRoot = decorView?.FindViewById<FrameLayout>(Android.Resource.Id.Content);
52+
contentRoot?.AddView(m_searchField.SearchViewView);
53+
}
4454
}
4555

4656
FocusSearchAction = () => m_searchField?.Focus();

0 commit comments

Comments
 (0)