Skip to content

Instantly share code, notes, and snippets.

@donabrams
Last active April 10, 2017 17:35
Show Gist options
  • Save donabrams/556ebd7bd96dc494214ecd416e60836e to your computer and use it in GitHub Desktop.
Save donabrams/556ebd7bd96dc494214ecd416e60836e to your computer and use it in GitHub Desktop.
navigator deep dive

What's navigator'?

navigator' :: forall r eff. Prop (NavigatorProps r eff) -> r -> SceneRenderer r -> ReactElement
navigator' p initialRoute renderScene = navigatorU $ unsafeApplyProps {initialRoute, renderScene} p

Wrapper around https://facebook.github.io/react-native/docs/navigator.html and the unsafe constructor navigatorU.

What's r?

newtype Navigator r = Navigator (forall props state. ReactThis props state)

r is a combination of props and state type under a "this" context.

What's NavigatorProps?

type NavigatorProps r eff = {
    ref :: RefType (Navigator r)
  , configureScene :: SceneConfigurer r
  , initialRoute :: r
  , initialRouteStack :: Array r
  , navigationBar :: ReactElement
  , navigator :: ReactElement
  , onDidFocus :: UnitEventHandler eff
  , onWillFocus :: UnitEventHandler eff
  , renderScene :: SceneRenderer r
  , sceneStyle :: Styles
  , style :: Styles
}

NavigatorProps is a spec describing initial state, styles, transitions, and events liking "scenes"

Also, Prop is just a helper to make using record syntax easier:

type Prop a = a -> a

What's a SceneRenderer?

newtype SceneRenderer r = SceneRenderer (Fn2 r (Navigator r) ReactElement)

Takes this, applies it to a navigator and gets a ReactElement

So in the end, what is navigator'?

Given a route -> spec, some initial props, and a way to render scenes, give me an Element.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment