-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #5 from oridotaoyebode/master
Added example of how to use ShimmerLayout in a ListView
- Loading branch information
Showing
7 changed files
with
536 additions
and
203 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
53 changes: 53 additions & 0 deletions
53
...le/XFShimmerLayoutSample/XFShimmerLayoutSample/ViewModels/ShimmerListViewPageViewModel.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,53 @@ | ||
using System.Collections.ObjectModel; | ||
using System.Threading.Tasks; | ||
using Xamarin.Forms; | ||
using XFShimmerLayoutSample.Models; | ||
|
||
namespace XFShimmerLayoutSample.ViewModels | ||
{ | ||
public class ShimmerListViewPageViewModel: NotifyingObject | ||
{ | ||
private bool _isBusy; | ||
public bool IsBusy | ||
{ | ||
get => _isBusy; | ||
set => Set(ref _isBusy, value); | ||
} | ||
|
||
private ObservableCollection<string> _things; | ||
public ObservableCollection<string> Things | ||
{ | ||
get => _things; | ||
set => Set(ref _things, value); | ||
} | ||
|
||
private Command _startAnimationCommand; | ||
public Command StartAnimationCommand | ||
{ | ||
get => _startAnimationCommand; | ||
set => Set(ref _startAnimationCommand, value); | ||
} | ||
|
||
public ShimmerListViewPageViewModel() | ||
{ | ||
StartAnimationCommand = new Command(async () => | ||
{ | ||
Things = new ObservableCollection<string> | ||
{ | ||
"jjj", | ||
"jjj", | ||
"jjj", | ||
"jjj", | ||
"jjj" | ||
}; | ||
IsBusy = true; | ||
|
||
await Task.Delay(5000); | ||
|
||
|
||
//Load real data here. | ||
IsBusy = false; | ||
}); | ||
} | ||
} | ||
} |
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
234 changes: 234 additions & 0 deletions
234
src/Sample/XFShimmerLayoutSample/XFShimmerLayoutSample/Views/ShimmerListViewPage.xaml
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,234 @@ | ||
<?xml version="1.0" encoding="utf-8" ?> | ||
<ContentPage | ||
x:Class="XFShimmerLayoutSample.Views.ShimmerListViewPage" | ||
xmlns="http://xamarin.com/schemas/2014/forms" | ||
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml" | ||
xmlns:controls="clr-namespace:XFShimmerLayout.Controls;assembly=XFShimmerLayout" | ||
xmlns:viewModels="clr-namespace:XFShimmerLayoutSample.ViewModels;assembly=XFShimmerLayoutSample"> | ||
|
||
<ContentPage.BindingContext> | ||
<!-- For Test Reasons binding context is set through this way. Better use a DI Container --> | ||
<viewModels:ShimmerListViewPageViewModel /> | ||
</ContentPage.BindingContext> | ||
<Grid x:Name="myGrid"> | ||
<Grid.RowDefinitions> | ||
<RowDefinition Height="*" /> | ||
<RowDefinition Height="50" /> | ||
</Grid.RowDefinitions> | ||
|
||
<ListView HasUnevenRows="True" ItemsSource="{Binding Things}"> | ||
<ListView.ItemTemplate> | ||
<DataTemplate> | ||
<ViewCell> | ||
<controls:ShimmerLayout Angle="-45" GradientSize=".2" IsLoading="{Binding BindingContext.IsBusy, Source={x:Reference myGrid}}"> | ||
<StackLayout Padding="24" Spacing="16"> | ||
<Grid ColumnSpacing="8" RowSpacing="4"> | ||
<Grid.RowDefinitions> | ||
<RowDefinition Height="Auto" /> | ||
<RowDefinition Height="Auto" /> | ||
</Grid.RowDefinitions> | ||
<Grid.ColumnDefinitions> | ||
<ColumnDefinition Width="Auto" /> | ||
<ColumnDefinition Width="*" /> | ||
<ColumnDefinition Width="Auto" /> | ||
</Grid.ColumnDefinitions> | ||
|
||
<BoxView | ||
Grid.Row="0" | ||
Grid.RowSpan="2" | ||
Grid.Column="0" | ||
BackgroundColor="Brown" | ||
CornerRadius="20" | ||
HeightRequest="40" | ||
VerticalOptions="Center" | ||
WidthRequest="40" /> | ||
|
||
<BoxView | ||
Grid.Row="0" | ||
Grid.Column="1" | ||
BackgroundColor="Brown" | ||
HeightRequest="20" | ||
HorizontalOptions="Start" | ||
WidthRequest="150" /> | ||
|
||
<BoxView | ||
Grid.Row="1" | ||
Grid.Column="1" | ||
BackgroundColor="Brown" | ||
HeightRequest="14" | ||
HorizontalOptions="Start" | ||
VerticalOptions="Center" | ||
WidthRequest="50" /> | ||
|
||
<BoxView | ||
Grid.Row="1" | ||
Grid.Column="2" | ||
BackgroundColor="Brown" | ||
HeightRequest="18" | ||
HorizontalOptions="End" | ||
VerticalOptions="Center" | ||
WidthRequest="100" /> | ||
</Grid> | ||
|
||
<Grid ColumnSpacing="8" RowSpacing="4"> | ||
<Grid.RowDefinitions> | ||
<RowDefinition Height="Auto" /> | ||
<RowDefinition Height="Auto" /> | ||
</Grid.RowDefinitions> | ||
<Grid.ColumnDefinitions> | ||
<ColumnDefinition Width="Auto" /> | ||
<ColumnDefinition Width="*" /> | ||
<ColumnDefinition Width="Auto" /> | ||
</Grid.ColumnDefinitions> | ||
|
||
<BoxView | ||
Grid.Row="0" | ||
Grid.RowSpan="2" | ||
Grid.Column="0" | ||
BackgroundColor="Brown" | ||
CornerRadius="20" | ||
HeightRequest="40" | ||
VerticalOptions="Center" | ||
WidthRequest="40" /> | ||
|
||
<BoxView | ||
Grid.Row="0" | ||
Grid.Column="1" | ||
BackgroundColor="Brown" | ||
HeightRequest="20" | ||
HorizontalOptions="Start" | ||
WidthRequest="150" /> | ||
|
||
<BoxView | ||
Grid.Row="1" | ||
Grid.Column="1" | ||
BackgroundColor="Brown" | ||
HeightRequest="14" | ||
HorizontalOptions="Start" | ||
VerticalOptions="Center" | ||
WidthRequest="50" /> | ||
|
||
<BoxView | ||
Grid.Row="1" | ||
Grid.Column="2" | ||
BackgroundColor="Brown" | ||
HeightRequest="18" | ||
HorizontalOptions="End" | ||
VerticalOptions="Center" | ||
WidthRequest="100" /> | ||
</Grid> | ||
|
||
<Grid ColumnSpacing="8" RowSpacing="4"> | ||
<Grid.RowDefinitions> | ||
<RowDefinition Height="Auto" /> | ||
<RowDefinition Height="Auto" /> | ||
</Grid.RowDefinitions> | ||
<Grid.ColumnDefinitions> | ||
<ColumnDefinition Width="Auto" /> | ||
<ColumnDefinition Width="*" /> | ||
<ColumnDefinition Width="Auto" /> | ||
</Grid.ColumnDefinitions> | ||
|
||
<BoxView | ||
Grid.Row="0" | ||
Grid.RowSpan="2" | ||
Grid.Column="0" | ||
BackgroundColor="Brown" | ||
CornerRadius="20" | ||
HeightRequest="40" | ||
VerticalOptions="Center" | ||
WidthRequest="40" /> | ||
|
||
<BoxView | ||
Grid.Row="0" | ||
Grid.Column="1" | ||
BackgroundColor="Brown" | ||
HeightRequest="20" | ||
HorizontalOptions="Start" | ||
WidthRequest="150" /> | ||
|
||
<BoxView | ||
Grid.Row="1" | ||
Grid.Column="1" | ||
BackgroundColor="Brown" | ||
HeightRequest="14" | ||
HorizontalOptions="Start" | ||
VerticalOptions="Center" | ||
WidthRequest="50" /> | ||
|
||
<BoxView | ||
Grid.Row="1" | ||
Grid.Column="2" | ||
BackgroundColor="Brown" | ||
HeightRequest="18" | ||
HorizontalOptions="End" | ||
VerticalOptions="Center" | ||
WidthRequest="100" /> | ||
</Grid> | ||
|
||
<Grid ColumnSpacing="8" RowSpacing="4"> | ||
<Grid.RowDefinitions> | ||
<RowDefinition Height="Auto" /> | ||
<RowDefinition Height="Auto" /> | ||
</Grid.RowDefinitions> | ||
<Grid.ColumnDefinitions> | ||
<ColumnDefinition Width="Auto" /> | ||
<ColumnDefinition Width="*" /> | ||
<ColumnDefinition Width="Auto" /> | ||
</Grid.ColumnDefinitions> | ||
|
||
<BoxView | ||
Grid.Row="0" | ||
Grid.RowSpan="2" | ||
Grid.Column="0" | ||
BackgroundColor="Brown" | ||
CornerRadius="20" | ||
HeightRequest="40" | ||
VerticalOptions="Center" | ||
WidthRequest="40" /> | ||
|
||
<BoxView | ||
Grid.Row="0" | ||
Grid.Column="1" | ||
BackgroundColor="Brown" | ||
HeightRequest="20" | ||
HorizontalOptions="Start" | ||
WidthRequest="150" /> | ||
|
||
<BoxView | ||
Grid.Row="1" | ||
Grid.Column="1" | ||
BackgroundColor="Brown" | ||
HeightRequest="14" | ||
HorizontalOptions="Start" | ||
VerticalOptions="Center" | ||
WidthRequest="50" /> | ||
|
||
<BoxView | ||
Grid.Row="1" | ||
Grid.Column="2" | ||
BackgroundColor="Brown" | ||
HeightRequest="18" | ||
HorizontalOptions="End" | ||
VerticalOptions="Center" | ||
WidthRequest="100" /> | ||
</Grid> | ||
</StackLayout> | ||
</controls:ShimmerLayout> | ||
|
||
</ViewCell> | ||
</DataTemplate> | ||
</ListView.ItemTemplate> | ||
</ListView> | ||
|
||
<Button | ||
Grid.Row="1" | ||
Padding="8" | ||
BackgroundColor="DarkCyan" | ||
Command="{Binding StartAnimationCommand}" | ||
CornerRadius="10" | ||
HorizontalOptions="FillAndExpand" | ||
Text="Start Animation" | ||
TextColor="White" /> | ||
</Grid> | ||
</ContentPage> |
13 changes: 13 additions & 0 deletions
13
src/Sample/XFShimmerLayoutSample/XFShimmerLayoutSample/Views/ShimmerListViewPage.xaml.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,13 @@ | ||
using Xamarin.Forms.Xaml; | ||
|
||
namespace XFShimmerLayoutSample.Views | ||
{ | ||
[XamlCompilation(XamlCompilationOptions.Compile)] | ||
public partial class ShimmerListViewPage | ||
{ | ||
public ShimmerListViewPage () | ||
{ | ||
InitializeComponent (); | ||
} | ||
} | ||
} |
Oops, something went wrong.