1
0
Fork 0
mirror of https://github.com/correl/elm-mdl.git synced 2025-04-07 17:00:06 -09:00

Fixed isAnimating logic, closing .

This commit is contained in:
Søren Debois 2016-04-20 15:36:34 +02:00
parent b7a11ecda1
commit 459620d85e
3 changed files with 28 additions and 18 deletions

View file

@ -66,7 +66,7 @@ layoutModel : Layout.Model
layoutModel = layoutModel =
{ defaultLayoutModel { defaultLayoutModel
| state = Layout.initState (List.length tabs) | state = Layout.initState (List.length tabs)
, mode = Layout.Waterfall True , mode = Layout.Waterfall False
, fixedHeader = False , fixedHeader = False
} }

View file

@ -93,6 +93,11 @@ lift get set fwd update action model =
(set model submodel', Effects.map fwd e) (set model submodel', Effects.map fwd e)
fx : a -> Effects a
fx =
Task.succeed >> Effects.task
delay : Time -> a -> Effects a delay : Time -> a -> Effects a
delay t x = delay t x =
Task.sleep t Task.sleep t

View file

@ -53,8 +53,6 @@ import Html.Events exposing (onClick, on)
import Effects exposing (Effects) import Effects exposing (Effects)
import Window import Window
import Json.Decode as Json
import Material.Helpers exposing (..) import Material.Helpers exposing (..)
import Material.Ripple as Ripple import Material.Ripple as Ripple
import Material.Icon as Icon import Material.Icon as Icon
@ -95,7 +93,7 @@ setupSignals f =
, scrollMailbox.signal , scrollMailbox.signal
|> Signal.map ((<) 0.0) |> Signal.map ((<) 0.0)
|> Signal.dropRepeats |> Signal.dropRepeats
|> Signal.map (ScrollContents >> f) |> Signal.map (TransitionHeader >> f)
] ]
@ -191,10 +189,10 @@ type Action
-- Private -- Private
| SmallScreen Bool -- True means small screen | SmallScreen Bool -- True means small screen
| ScrollTab Float | ScrollTab Float
| ScrollContents Bool -- True means strictly positive scrollTop | TransitionHeader Bool -- True means "transition to isCompact"
| Ripple Int Ripple.Action
| Click
| TransitionEnd | TransitionEnd
-- Subcomponents
| Ripple Int Ripple.Action
{-| Component update. {-| Component update.
@ -233,16 +231,21 @@ update action model =
(model, Effects.none) -- TODO (model, Effects.none) -- TODO
ScrollContents isScrolled -> TransitionHeader toCompact ->
let let
headerVisible = state.isSmallScreen || model.fixedHeader headerVisible = (not state.isSmallScreen) || model.fixedHeader
state' = state' =
{ state { state
| isCompact = isScrolled | isCompact = toCompact
, isAnimating = headerVisible , isAnimating = headerVisible
} }
in in
( { model | state = S state' }, Effects.none ) if not state.isAnimating then
( { model | state = S state' }
, delay 200 TransitionEnd -- See comment on transitionend in view.
)
else
(model, Effects.none)
TransitionEnd -> TransitionEnd ->
@ -250,11 +253,6 @@ update action model =
, Effects.none , Effects.none
) )
Click ->
( { model | state = S { state | isAnimating = True, isCompact = False } }
, Effects.none
)
-- AUXILIARY VIEWS -- AUXILIARY VIEWS
@ -380,6 +378,7 @@ tabsView addr model tabs =
headerView : Addr -> Model -> (Maybe Html, List Html, Maybe Html) -> Html headerView : Addr -> Model -> (Maybe Html, List Html, Maybe Html) -> Html
headerView addr model (drawerButton, rows, tabs) = headerView addr model (drawerButton, rows, tabs) =
let let
_ = Debug.log "foo" model.state
mode = mode =
case model.mode of case model.mode of
Standard -> "" Standard -> ""
@ -402,8 +401,14 @@ headerView addr model (drawerButton, rows, tabs) =
] ]
|> List.append ( |> List.append (
if isWaterfall model.mode then if isWaterfall model.mode then
[ onClick addr Click [
, on "transitionend" Json.value (\_ -> Signal.message addr TransitionEnd) -- onClick addr Click
--, on "transitionend" Json.value (\_ -> Signal.message addr TransitionEnd)
{- There is no "ontransitionend" property; you'd have to add a listener,
which Elm won't let us. We manually fire a delayed tick instead.
See also: https://github.com/evancz/virtual-dom/issues/30
-}
onClick addr (TransitionHeader False)
] ]
else else
[] []