forked from dotnet/maui
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Add ShellSearchView * Fix the layout issue in ShellSearchResultList * Enable nullable * Fix maximum height of ShellSearchResultList
- Loading branch information
1 parent
91cdfc7
commit edd5018
Showing
4 changed files
with
546 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
99 changes: 99 additions & 0 deletions
99
src/Controls/src/Core/Platform/Tizen/Shell/ShellSearchResultList.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
} | ||
} |
Oops, something went wrong.