Skip to content

Commit

Permalink
Added option for running the animation manually.
Browse files Browse the repository at this point in the history
  • Loading branch information
mikoskinen committed Sep 10, 2020
1 parent d0fe4ec commit f724c18
Show file tree
Hide file tree
Showing 5 changed files with 52 additions and 8 deletions.
3 changes: 2 additions & 1 deletion global.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
{
"sdk": {
"version": "3.1.100"
"version": "3.1.101",
"rollForward": "latestFeature"
}
}
27 changes: 27 additions & 0 deletions samples/BlazorAnimate.Sample/Pages/Manual.razor
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
@page "/manual"

<h1>Manual example</h1>

<p>
This sample shows how animation can be executed by clicking a button by setting the IsManual of the Animate component to true and then running the animation using Run-method.
</p>

<div class="mt-3"></div>

<button class="btn btn-primary" @onclick="RunAnimation">Animate</button>

<div class="mt-3"></div>

<Animate Animation="Animations.ZoomIn" Duration="TimeSpan.FromSeconds(0.5)" @ref="myAnim" IsManual="true">
<Counter></Counter>
</Animate>

@code {

private Animate myAnim;

private void RunAnimation()
{
myAnim.Run();
}
}
8 changes: 7 additions & 1 deletion samples/BlazorAnimate.Sample/Shared/NavMenu.razor
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,11 @@
<span class="oi oi-home" aria-hidden="true"></span> Home
</NavLink>
</li>
<li class="nav-item px-3">
<NavLink class="nav-link" href="Manual" Match="NavLinkMatch.All">
<span class="oi oi-account-login" aria-hidden="true"></span> Manual
</NavLink>
</li>
<li class="nav-item px-3">
<NavLink class="nav-link" href="anchoring">
<span class="oi oi-plus" aria-hidden="true"></span> Anchor
Expand All @@ -34,4 +39,5 @@
{
collapseNavMenu = !collapseNavMenu;
}
}

}
18 changes: 14 additions & 4 deletions src/BlazorAnimate/Animate.razor
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
@using System.Globalization
@using Microsoft.Extensions.Options

<div @attributes="@InputAttributes" data-aos="@_animationName" data-aos-delay="@_delay" data-aos-duration="@_duration" data-aos-easing="@_easingName"
data-aos-mirror="@_mirror" data-aos-once="@_once" data-aos-offset="@Offset" data-aos-anchor="@Anchor" data-aos-anchor-placement="@AnchorPlacement">
@ChildContent
</div>
@if (_manuallyExecuted || IsManual == false)
{
<div @attributes="@InputAttributes" data-aos="@_animationName" data-aos-delay="@_delay" data-aos-duration="@_duration" data-aos-easing="@_easingName"
data-aos-mirror="@_mirror" data-aos-once="@_once" data-aos-offset="@Offset" data-aos-anchor="@Anchor" data-aos-anchor-placement="@AnchorPlacement">
@ChildContent
</div>
}

@code
{
Expand All @@ -14,6 +17,7 @@
private string _delay = "";
private string _mirror;
private string _once;
private bool _manuallyExecuted = false;

[Parameter] public RenderFragment ChildContent { get; set; }
[Parameter] public IAnimation Animation { get; set; }
Expand All @@ -29,12 +33,18 @@
[Parameter] public string AnchorPlacement { get; set; }
[Parameter] public string OptionsName { get; set; } = Microsoft.Extensions.Options.Options.DefaultName;
[Parameter] public AnimateOptions Options { get; set; }
[Parameter] public bool IsManual { get; set; }

[Parameter(CaptureUnmatchedValues = true)]
public Dictionary<string, object> InputAttributes { get; set; }

[Inject] private IOptionsSnapshot<AnimateOptions> _optionsAccessor { get; set; }

public void Run()
{
_manuallyExecuted = true;
}

protected override void OnParametersSet()
{
SetDefaults();
Expand Down
4 changes: 2 additions & 2 deletions src/BlazorAnimate/BlazorAnimate.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,14 @@
<Description>Easily Animate Blazor Components using Blazor Animate. Powered by AOS.</Description>
<PackageDescription>Easily Animate Blazor Components using Blazor Animate. Powered by AOS.</PackageDescription>
<PackageProjectUrl>https://github.com/mikoskinen/Blazor.Animate</PackageProjectUrl>
<Copyright2019 Mikael Koskinen</Copyright>
<Copyright2020 Mikael Koskinen</Copyright>
<PackageId>BlazorAnimate</PackageId>
<Product>BlazorAnimate</Product>
<PackageLicenseExpression>MIT</PackageLicenseExpression>
<RepositoryUrl>https://github.com/mikoskinen/Blazor.Animate</RepositoryUrl>
<PackageTags>blazor;animation;animate</PackageTags>
<Title>Blazor Animate</Title>
<MinVerMinimumMajorMinor>2.0</MinVerMinimumMajorMinor>
<MinVerMinimumMajorMinor>3.0</MinVerMinimumMajorMinor>
</PropertyGroup>

<ItemGroup>
Expand Down

0 comments on commit f724c18

Please sign in to comment.