Skip to content

Commit

Permalink
Add ShellSearchView (#121)
Browse files Browse the repository at this point in the history
* Add ShellSearchView

* Fix the layout issue in ShellSearchResultList

* Enable nullable

* Fix maximum height of ShellSearchResultList
  • Loading branch information
shyunMin authored and rookiejava committed Jan 19, 2022
1 parent a4f8e11 commit 467cda8
Show file tree
Hide file tree
Showing 4 changed files with 546 additions and 3 deletions.
52 changes: 49 additions & 3 deletions src/Controls/src/Core/Platform/Tizen/Shell/ShellNavBar.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,10 @@ public class ShellNavBar : EBox, IFlyoutBehaviorObserver, IDisposable
TImage _menuIcon = null;
TButton _menuButton = null;
TLabel _title = null;
ShellSearchView _searchView = null;
EvasObject _nativeTitleView = null;

SearchHandler _searchHandler = null;
View _titleView = null;
Page _page = null;

Expand Down Expand Up @@ -102,6 +105,20 @@ public FlyoutBehavior FlyoutBehavior
}
}

public SearchHandler SearchHandler
{
get
{
return _searchHandler;
}
set
{
_searchHandler = value;
UpdateSearchHandler(_searchHandler);
UpdateChildren();
}
}

public View TitleView
{
get
Expand Down Expand Up @@ -177,7 +194,7 @@ public void SetPage(Page page)
{
_page = page;
Title = page.Title;
//SearchHandler = Shell.GetSearchHandler(page);
SearchHandler = Shell.GetSearchHandler(page);
TitleView = Shell.GetTitleView(page);
UpdateMenuIcon();
}
Expand Down Expand Up @@ -284,17 +301,42 @@ void UpdateTitleView(View titleView)
}
}

void UpdateSearchHandler(SearchHandler handler)
{
if (_searchView != null)
{
UnPack(_searchView.NativeView);
_searchView.Dispose();
_searchView = null;
}

if (handler != null)
{
_searchView = new ShellSearchView(handler, MauiContext);
_searchView.NativeView.Show();
PackEnd(_searchView.NativeView);
}
}

void UpdateChildren()
{
if (_titleView != null)
if (_searchHandler != null)
{
_searchView.NativeView.Show();
_title?.Hide();
_nativeTitleView?.Hide();
}
else if (_titleView != null)
{
_nativeTitleView.Show();
_title?.Hide();
_searchView?.NativeView?.Hide();
}
else
{
_title.Show();
_nativeTitleView?.Hide();
_searchView?.NativeView?.Hide();
}
}

Expand Down Expand Up @@ -324,7 +366,11 @@ void OnLayout()
contentBound.Width -= (menuBound.Width + menuMargin + titleHMargin * 2);
contentBound.Height -= titleVMargin * 2;

if (_titleView != null)
if (_searchView != null)
{
_searchView.NativeView.Geometry = contentBound;
}
else if (_titleView != null)
{
_nativeTitleView.Geometry = contentBound;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
using System;
using System.Collections.Generic;
using ElmSharp;
using Tizen.UIExtensions.ElmSharp;
using EColor = ElmSharp.Color;

namespace Microsoft.Maui.Controls.Platform
{
public class ShellSearchResultList : GenList
{
GenItemClass _defaultClass = null;
IReadOnlyList<object> _itemsSource;

public ShellSearchResultList(IMauiContext context) : base(context?.Context?.BaseLayout)
{
MauiContext = context;

SetAlignment(-1, -1);
SetWeight(1, 1);
AllowFocus(true);

Homogeneous = true;
SelectionMode = GenItemSelectionMode.Always;
BackgroundColor = EColor.White;

_defaultClass = new GenItemClass(ThemeConstants.GenItemClass.Styles.Full)
{
GetContentHandler = GetContent,
};
}

public int Height { get; private set; }

public IReadOnlyList<object> ItemsSource
{
get => _itemsSource;
set
{
Clear();
Height = 0;

_itemsSource = value;
foreach (var item in _itemsSource)
{
Append(item);
}
}
}

protected IMauiContext MauiContext { get; private set; }

protected EvasObject NativeParent
{
get => MauiContext?.Context?.BaseLayout;
}

public void UpdateLayout()
{
if (FirstItem != null && Height == 0)
{
var view = FirstItem.Data as View;
var native = view.ToNative(MauiContext);
var measured = view.Measure(DPExtensions.ConvertToScaledDP(Geometry.Width), double.PositiveInfinity);
Height = DPExtensions.ConvertToScaledPixel(measured.Request.Height);
}

var bound = Geometry;
bound.Height = Math.Min(Height * _itemsSource.Count, bound.Width);
Geometry = bound;

UpdateRealizedItems();
}

public DataTemplate ItemTemplate { get; set; }

EvasObject GetContent(object data, string part)
{
var view = data as View;
var native = view.ToNative(MauiContext);

if (Height == 0)
{
var measured = view.Measure(DPExtensions.ConvertToScaledDP(Geometry.Width), double.PositiveInfinity);
Height = DPExtensions.ConvertToScaledPixel(measured.Request.Height);
}

native.MinimumHeight = Height;
return native;
}

void Append(object data)
{
var view = ItemTemplate.CreateContent() as View;
view.Parent = Shell.Current;
view.BindingContext = data;
Append(_defaultClass, view);
}
}
}
Loading

0 comments on commit 467cda8

Please sign in to comment.