Skip to content

Instantly share code, notes, and snippets.

@georgelima
Created November 22, 2018 21:13
Show Gist options
  • Save georgelima/c1215d5d7e0d86abdedf9cf87c843fe1 to your computer and use it in GitHub Desktop.
Save georgelima/c1215d5d7e0d86abdedf9cf87c843fe1 to your computer and use it in GitHub Desktop.
side-menu-reducer
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