Skip to content

Commit

Permalink
Merge pull request #20 from ZeroGachis/task/customisable-article-card…
Browse files Browse the repository at this point in the history
…-list-v2

Adapt ArticleCardList To Condensed Card option
  • Loading branch information
pewho authored Nov 12, 2020
2 parents b53c87f + 32b86d0 commit 6c7daec
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,16 @@
x:DataType="viewModels:SectionSheetSampleViewModel">
<ContentPage.Content>
<ScrollView>
<layouts:SectionSheet>
<cardLists:ArticleCardList ArticlesList="{Binding Articles}" />
</layouts:SectionSheet>
<StackLayout>
<layouts:SectionSheet>
<Label Text="Normal Size" />
<cardLists:ArticleCardList ArticlesList="{Binding Articles}" />
</layouts:SectionSheet>
<layouts:SectionSheet>
<Label Text="Condensed Size" />
<cardLists:ArticleCardList ArticlesList="{Binding Articles}" IsCondensed="True" />
</layouts:SectionSheet>
</StackLayout>
</ScrollView>
</ContentPage.Content>
</ContentPage>
4 changes: 3 additions & 1 deletion Smartway.UiComponent/CardLists/ArticleCardList.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@
xmlns:cards="clr-namespace:Smartway.UiComponent.Cards;assembly=Smartway.UiComponent"
xmlns:separators="clr-namespace:Smartway.UiComponent.Separators;assembly=Smartway.UiComponent"
x:Class="Smartway.UiComponent.CardLists.ArticleCardList"
x:Name="List">
x:Name="List"
>
<ContentView.Content>
<StackLayout Orientation="Vertical" x:Name="ArticleListElement" BindableLayout.ItemsSource="{Binding Source={x:Reference List}, Path=ArticlesList}">
<BindableLayout.ItemTemplate>
Expand All @@ -20,6 +21,7 @@
NavigationCommand="{Binding NavigationCommand}"
NavigationParameter="{Binding NavigationParameter}"
OnShortageSince="{Binding OnShortageSince}"
IsCondensed="{Binding Source={x:Reference List}, Path=IsCondensed}"
/>
</StackLayout>
</DataTemplate>
Expand Down
8 changes: 7 additions & 1 deletion Smartway.UiComponent/CardLists/ArticleCardList.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ namespace Smartway.UiComponent.CardLists
public partial class ArticleCardList
{
public static readonly BindableProperty ArticlesListProperty = BindableProperty.Create(nameof(ArticlesList), typeof(ObservableCollection<object>), typeof(ArticleCardList));
public static readonly BindableProperty IsCondensedProperty = BindableProperty.Create(nameof(IsCondensed), typeof(bool), typeof(ArticleCardList), false);

public ObservableCollection<object> ArticlesList
{
Expand All @@ -23,9 +24,14 @@ public ArticleCardList()
ArticleListElement.PropertyChanged += ArticleListChanged;
}

public bool IsCondensed
{
get => (bool) GetValue(IsCondensedProperty);
set => SetValue(IsCondensedProperty, value);
}

private void ArticleListChanged(object sender, PropertyChangedEventArgs e)
{
OnPropertyChanged(nameof(ArticlesList));
var element = ArticleListElement.Children.Cast<StackLayout>().FirstOrDefault(_ => _.IsVisible);
if (element != null)
{
Expand Down

0 comments on commit 6c7daec

Please sign in to comment.