NavigatorIOS
is a wrapper around
UINavigationController
,
enabling you to implement a navigation stack. It works exactly the same as it
would on a native app using UINavigationController
, providing the same
animations and behavior from UIKIt.
As the name implies, it is only available on iOS. Take a look at
Navigator
for a similar solution for your
cross-platform needs, or check out
react-native-navigation, a
component that aims to provide native navigation on both iOS and Android.
To set up the navigator, provide the initialRoute
prop with a route
object. A route object is used to describe each scene that your app
navigates to. initialRoute
represents the first route in your navigator.
In this code, the navigator renders the component specified in initialRoute,
which in this case is MyScene
. This component will receive a route
prop
and a navigator
prop representing the navigator. The navigator's navigation
bar will render the title for the current scene, "My Initial Scene".
You can optionally pass in a passProps
property to your initialRoute
.
NavigatorIOS
passes this in as props to the rendered component:
You can then access the props passed in via {this.props.myProp}
.
To trigger navigation functionality such as pushing or popping a view, you
have access to a navigator
object. The object is passed in as a prop to any
component that is rendered by NavigatorIOS
. You can then call the
relevant methods to perform the navigation action you need:
You can also trigger navigator functionality from the NavigatorIOS
component:
The code above adds a _handleNavigationRequest
private method that is
invoked from the NavigatorIOS
component when the right navigation bar item
is pressed. To get access to the navigator functionality, a reference to it
is saved in the ref
prop and later referenced to push a new scene into the
navigation stack.
Props passed to NavigatorIOS
will set the default configuration
for the navigation bar. Props passed as properties to a route object will set
the configuration for that route's navigation bar, overriding any props
passed to the NavigatorIOS
component.
In the example above the navigation bar color is changed when the new route is pushed.
The default background color of the navigation bar.
NavigatorIOS uses route
objects to identify child views, their props,
and navigation bar configuration. Navigation operations such as push
operations expect routes to look like this the initialRoute
.
Boolean value that indicates whether the interactive pop gesture is enabled. This is useful for enabling/disabling the back swipe navigation gesture.
If this prop is not provided, the default behavior is for the back swipe
gesture to be enabled when the navigation bar is shown and disabled when
the navigation bar is hidden. Once you've provided the
interactivePopGestureEnabled
prop, you can never restore the default
behavior.
The default wrapper style for components in the navigator.
A common use case is to set the backgroundColor
for every scene.
Boolean value that indicates whether the navigation bar is hidden by default.
Boolean value that indicates whether to hide the 1px hairline shadow by default.
The default color used for the buttons in the navigation bar.
The default text color of the navigation bar title.
Boolean value that indicates whether the navigation bar is translucent by default
Navigate forward to a new route.
Name and Type | Description |
---|---|
route object | The new route to navigate to. |
Go back N scenes at once. When N=1, behavior matches pop()
.
Name and Type | Description |
---|---|
n number | The number of scenes to pop. |
Pop back to the previous scene.
Replace a route in the navigation stack.
Name and Type | Description |
---|---|
route object | The new route that will replace the specified one. |
index number | The route into the stack that should be replaced. If it is negative, it counts from the back of the stack. |
Replace the route for the current scene and immediately load the view for the new route.
Name and Type | Description |
---|---|
route object | The new route to navigate to. |
Replace the route/view for the previous scene.
Name and Type | Description |
---|---|
route object | The new route to will replace the previous scene. |
Go back to the topmost item in the navigation stack.
Go back to the item for a particular route object.
Name and Type | Description |
---|---|
route object | The new route to navigate to. |
Replaces the previous route/view and transitions back to it.
Name and Type | Description |
---|---|
route object | The new route that replaces the previous scene. |
Replaces the top item and pop to it.
Name and Type | Description |
---|---|
route object | The new route that will replace the topmost item. |
You can edit the content above on GitHub and send us a pull request!
Examples # | Edit on GitHub |