Skip to content

Commit

Permalink
adds empty animation (#26)
Browse files Browse the repository at this point in the history
  • Loading branch information
andrewMacmurray authored Nov 29, 2021
1 parent ac6ab5f commit f1d2049
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 4 deletions.
16 changes: 14 additions & 2 deletions src/Internal/Animation.elm
Original file line number Diff line number Diff line change
Expand Up @@ -174,8 +174,15 @@ renderIteration i =


name_ : Animation -> String
name_ (Animation d options frames) =
"anim-" ++ String.fromInt d ++ optionNames options ++ framesNames frames
name_ anim =
if isEmpty anim then
"anim-empty"

else
"anim-"
++ String.fromInt (duration_ anim)
++ optionNames (rawOptions_ anim)
++ framesNames (frames_ anim)


optionNames : List Option -> String
Expand Down Expand Up @@ -231,6 +238,11 @@ iterationName i =
-- Helpers


isEmpty : Animation -> Bool
isEmpty anim =
duration_ anim == 0


options_ : Animation -> Options
options_ =
rawOptions_
Expand Down
27 changes: 25 additions & 2 deletions src/Simple/Animation.elm
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
module Simple.Animation exposing
( Animation, Millis, fromTo, steps
( Animation, Millis, fromTo, steps, empty
, Step, step, set, wait, waitTillComplete
, Option, loop, count, delay, reverse, yoyo
, linear, easeIn, easeOut, easeInOut, cubic
Expand All @@ -12,7 +12,7 @@ module Simple.Animation exposing
# Create an Animation
@docs Animation, Millis, fromTo, steps
@docs Animation, Millis, fromTo, steps, empty
# Steps
Expand Down Expand Up @@ -152,6 +152,29 @@ steps { options, startAt } steps_ =
)


{-| Create an Empty Animation - Useful when you want to conditionally animate something
fadeIf : Bool -> Animation
fadeIf shouldFade =
if shouldFade then
Animation.fromTo
{ duration = 1000
, options = []
}
[ P.opacity 0 ]
[ P.opacity 1 ]
else
Animation.empty
`Animation.empty` is equivalent to an animation with `0` duration
-}
empty : Animation
empty =
fromTo { duration = 0, options = [] } [] []



-- Step

Expand Down
10 changes: 10 additions & 0 deletions tests/FromToTest.elm
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
module FromToTest exposing (suite)

import Expect
import Internal.Animation as Animation
import Simple.Animation as Animation exposing (Animation)
import Simple.Animation.Property as P
import Test exposing (..)
Expand Down Expand Up @@ -47,4 +49,12 @@ suite =
, "animation-duration: 1000ms"
, "animation-timing-function: linear"
]
, test "Empty Animations have formatted name" <|
\_ ->
[ Animation.empty
, Animation.fromTo { duration = 0, options = [] } [] []
, Animation.steps { startAt = [], options = [] } []
]
|> List.map Animation.name_
|> Expect.equal (List.repeat 3 "anim-empty")
]

0 comments on commit f1d2049

Please sign in to comment.