Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added Navigation React Native Plugin #111

Merged
merged 202 commits into from
Jan 8, 2017
Merged

Conversation

grahammendick
Copy link
Owner

Native navigation is different to Web because going back must display the previous view exactly as it was. For example, in Netflix, going back after selecting a film must maintain the horizontal scroll positions of all category sections. The way to do this is to render, but hide, the stack of visited scenes and let React remember their State for you.

The Navigation router’s crumb trail is ideally suited for tracking the stack of visited scenes. So, created a SceneNavigator Component that renders a scene for each crumb in the trail together with the current scene. For performance, each crumb scene returns a cached React Element so that React ejects from the diffing routing at the earliest opportunity (it doesn’t even call render on the Element).

The SceneNavigator wraps React Motion around these scenes so they can be animated as the enter, leave or become a crumb. Created a spring that wraps React Motion’s spring so that the React Motion dependency isn’t exposed.

It's good practive to remove handler (might have nested
stateNavigators?)
No need for conditional state/data logic in style props (React Motion
handles not animating the initial state).
Hides react motion from user code. Import navigation's spring instead
Didn't make sense to have two props for this because it needs to leave
to the style it enters from. Copied the stripStyle function from react
motion internals (it's not exposed on public api)
Makes it clearer where the style is coming from
Changed div to View in SceneNavigator and created
NavigationReactNative.js as the public api
Hard-coded because it's the only non-typescript plugin
No point bring in babel and who different package process, when can
remove rest/spread and switch to typescript
Used the existing typescript rollup, build and package tasks even though
only need package. Had to target 'es6' because react-native.d.ts uses
Promise
Brought in navigation typings now for consistency with other plugins
Needs custom tab bar for icons
NavigationBackAndroid should return true if the navigation’s handled -
either by navigating prop returning false or canNavigateBack returning
true
Don’t need the onLayout listener in SceneNavigator. It seems to fire a
lot and causes unnecessary defenders.
Also means can reset the root background colour back to white because
the style takes on ios now
Otherwise, pressing back on android and then going back in will call
render without state
Now that truncateCrumbTrail is called before navigation, the navigation
data doesn’t include defaults (and might be null). Used rest/spread to
include defaults and ensure not null.
Can be that item passed as a string that will become number after the
link’s parsed. Not worried about that because data-first routing means
should pass consistent types (and already changed navigation react
active check to assume consistent types)
@grahammendick grahammendick merged commit 9768ead into master Jan 8, 2017
@grahammendick grahammendick deleted the navigationreactnative branch January 8, 2017 12:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant