Skip to content
This repository was archived by the owner on May 1, 2024. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 32 additions & 0 deletions samples/XCT.Sample/Pages/Animations/AnimationPage.xaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
<?xml version="1.0" encoding="UTF-8" ?>
<pages:BasePage xmlns="http://xamarin.com/schemas/2014/forms"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
xmlns:pages="clr-namespace:Xamarin.CommunityToolkit.Sample.Pages"
xmlns:vm="clr-namespace:Xamarin.CommunityToolkit.Sample.ViewModels.Animations"
x:Class="Xamarin.CommunityToolkit.Sample.Pages.Animations.AnimationPage"
x:DataType="{x:Null}">
<pages:BasePage.BindingContext>
<vm:AnimationViewModel />
</pages:BasePage.BindingContext>

<Grid RowDefinitions="*,*">
<Label Text="Select an animation below and then tap start."
HorizontalTextAlignment="Center"
x:Name="Lab"/>

<StackLayout Grid.Row="1">
<Picker ItemsSource="{Binding Animations}"
SelectedItem="{Binding SelectedAnimation}"
ItemDisplayBinding="{Binding Name}"/>

<Button Text="Start"
Command="{Binding StartAnimationCommand}"
CommandParameter="{x:Reference Name=Lab}"/>

<Button Text="Stop"
Command="{Binding StopAnimationCommand}"/>
</StackLayout>


</Grid>
</pages:BasePage>
10 changes: 10 additions & 0 deletions samples/XCT.Sample/Pages/Animations/AnimationPage.xaml.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
namespace Xamarin.CommunityToolkit.Sample.Pages.Animations
{
public partial class AnimationPage : BasePage
{
public AnimationPage()
{
InitializeComponent();
}
}
}
13 changes: 4 additions & 9 deletions samples/XCT.Sample/Pages/Behaviors/AnimationBehaviorPage.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,7 @@
Spacing="10">

<Label Text="This sample demonstrates how to use ViewTappedAnimationBehaviour applying it in different UI elements."
Padding="10,10,10,50"
BackgroundColor="Red">
<Label.GestureRecognizers>
<TapGestureRecognizer Tapped="TapGestureRecognizer_Tapped" />
</Label.GestureRecognizers>
</Label>
Padding="10,10,10,50"/>

<Button Text="Tada"
FontSize="40"
Expand All @@ -29,9 +24,9 @@
<Button.Behaviors>
<xct:AnimationBehavior EventName="Clicked">
<xct:AnimationBehavior.AnimationType>
<xct:TadaAnimationType Easing="{x:Static Easing.Linear}"
Duration="1000"
RotationAngle="100"/>
<xct:TadaAnimation Easing="{x:Static Easing.Linear}"
IsRepeated="True"
Duration="1000"/>
</xct:AnimationBehavior.AnimationType>
</xct:AnimationBehavior>
</Button.Behaviors>
Expand Down
15 changes: 1 addition & 14 deletions samples/XCT.Sample/Pages/Behaviors/AnimationBehaviorPage.xaml.cs
Original file line number Diff line number Diff line change
@@ -1,20 +1,7 @@
using Xamarin.CommunityToolkit.Animations;
using Xamarin.Forms;

namespace Xamarin.CommunityToolkit.Sample.Pages.Behaviors
namespace Xamarin.CommunityToolkit.Sample.Pages.Behaviors
{
public partial class AnimationBehaviorPage : BasePage
{
public AnimationBehaviorPage() => InitializeComponent();

private async void TapGestureRecognizer_Tapped(object sender, System.EventArgs e)
{
var label = (View)sender;

new TadaAnimation(
rotationAngle: 30,
length: 1000,
views: label).Commit();
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
using System;
using Xamarin.CommunityToolkit.Behaviors;
using Xamarin.Forms;

namespace Xamarin.CommunityToolkit.Sample.ViewModels.Animations
{
public class AnimationDetailViewModel : BaseViewModel
{
public string Name { get; }

public Func<View, Action<double, bool>, PreBuiltAnimationBase> CreateAnimation { get; }

public AnimationDetailViewModel(string name, Func<View, Action<double, bool>, PreBuiltAnimationBase> createAnimation)
{
Name = name;
CreateAnimation = createAnimation;
}
}
}
78 changes: 78 additions & 0 deletions samples/XCT.Sample/ViewModels/Animations/AnimationViewModel.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
using System.Collections.ObjectModel;
using System.Linq;
using System.Threading;
using System.Threading.Tasks;
using Xamarin.CommunityToolkit.Behaviors;
using Xamarin.CommunityToolkit.ObjectModel;
using Xamarin.Forms;

namespace Xamarin.CommunityToolkit.Sample.ViewModels.Animations
{
public class AnimationViewModel : BaseViewModel
{
PreBuiltAnimationBase? currentAnimation;
CancellationTokenSource? cancellationTokenSource;
AnimationDetailViewModel? selectedAnimation;

public ObservableCollection<AnimationDetailViewModel> Animations { get; }

public AnimationDetailViewModel? SelectedAnimation
{
get => selectedAnimation;
set => SetProperty(ref selectedAnimation, value);
}

public AsyncCommand<View> StartAnimationCommand { get; }

public Command StopAnimationCommand { get; }

public AnimationViewModel()
{
Animations = new ObservableCollection<AnimationDetailViewModel>
{
new AnimationDetailViewModel("Tada", (view, onFinished) => new TadaAnimation()),
new AnimationDetailViewModel("RubberBand", (view, onFinished) => new RubberBandAnimation())
};

SelectedAnimation = Animations.First();
StartAnimationCommand = new AsyncCommand<View>(v => OnStart(v), (view) => !(SelectedAnimation is null));
StopAnimationCommand = new Command(OnStop, () => cancellationTokenSource != null);
}

async Task OnStart(View? view)
{
if (view is null)
{
return;
}

if (cancellationTokenSource != null)
{
cancellationTokenSource.Cancel();
}

currentAnimation = SelectedAnimation!.CreateAnimation(view, (d, b) =>
{
StartAnimationCommand.ChangeCanExecute();
StopAnimationCommand.ChangeCanExecute();
});

cancellationTokenSource = new CancellationTokenSource();
StopAnimationCommand.ChangeCanExecute();

await currentAnimation.Animate(cancellationTokenSource.Token, view);

cancellationTokenSource = null;
StopAnimationCommand.ChangeCanExecute();
}

void OnStop()
{
if (cancellationTokenSource != null)
{
cancellationTokenSource.Cancel();
}
}
}
}

Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using System.Collections.Generic;
using Xamarin.CommunityToolkit.Sample.Models;
using Xamarin.CommunityToolkit.Sample.Pages.Animations;
using Xamarin.CommunityToolkit.Sample.Pages.Behaviors;
using Xamarin.CommunityToolkit.Sample.Pages.Converters;
using Xamarin.CommunityToolkit.Sample.Pages.Effects;
Expand All @@ -14,6 +15,9 @@ public class WelcomeViewModel : BaseGalleryViewModel
{
protected override IEnumerable<SectionModel> CreateItems() => new[]
{
new SectionModel(typeof(AnimationPage), "Animations", Color.FromHex("#41337A"),
"A set of pre-built animations to give your app a real edge."),

new SectionModel(typeof(BehaviorsGalleryPage), "Behaviors", Color.FromHex("#8E8CD8"),
"Behaviors lets you add functionality to user interface controls without having to subclass them. Behaviors are written in code and added to controls in XAML or code"),

Expand Down

This file was deleted.

This file was deleted.

Loading