Created
November 22, 2018 21:13
-
-
Save georgelima/c1215d5d7e0d86abdedf9cf87c843fe1 to your computer and use it in GitHub Desktop.
side-menu-reducer
This file contains hidden or 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
reducer: (action, state) => | |
switch (action) { | |
| Open => | |
ReasonReact.UpdateWithSideEffects( | |
{...state, isVisible: true}, | |
( | |
self => { | |
Animated.Value.setValue( | |
self.state.animation, | |
self.state.direction == Right ? menuWidth : -. menuWidth, | |
); | |
Animated.start( | |
Animated.spring( | |
~value=self.state.animation, | |
~toValue=`raw(0.), | |
~friction=10., | |
~tension=35., | |
(), | |
), | |
(), | |
); | |
} | |
), | |
) | |
| Close => | |
ReasonReact.SideEffects( | |
( | |
self => { | |
Animated.Value.setValue(self.state.animation, 0.); | |
Animated.start( | |
Animated.spring( | |
~value=self.state.animation, | |
~toValue= | |
`raw( | |
/** add with 45pt to ensure that the menu will disappear completely */ | |
self.state.direction | |
== Right ? | |
menuWidth +. 45. : -. (menuWidth +. 45.), | |
), | |
~friction=10., | |
~tension=50., | |
(), | |
), | |
~callback=_evt => self.send(Set(false)), | |
(), | |
); | |
(); | |
} | |
), | |
) | |
| ChangeVisibility(isVisible) => | |
ReasonReact.SideEffects((self => self.send(isVisible ? Open : Close))) | |
| Set(isVisible) => ReasonReact.Update({...state, isVisible}) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment