Skip to content

Commit 7dfd543

Browse files
AsafBrieferyDevcharpeni
authored andcommitted
Added getCurrentRoutes functionality without the need of ref. (#157)
* Added getCurrentRoutes functionality without the need of ref. Helpful for popToRoute * fixed eslint errors
1 parent 08a8ded commit 7dfd543

File tree

2 files changed

+12
-1
lines changed

2 files changed

+12
-1
lines changed

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -181,6 +181,8 @@ that you're on with the new route that you pass it, and empties the navigation s
181181

182182
The **`this.props.popToRoute`** function takes in an object that can contain the same keys as `toRoute()`. The difference is that instead of adding a route to your stack, it pop all routes until the desired one.
183183

184+
The **`this.props.getCurrentRoutes()`** returns the current list of routes (same as [ReactNative Navigator getCurrentRoutes(0)]( https://facebook.github.io/react-native/docs/navigator.html#getcurrentroutes) ). This can be used as an argument for `popToRoute()`.
185+
184186
The functions **`this.props.setRightProps`**, **`this.props.setLeftProps`** and **`this.props.setTitleProps`** take in an object of props and sends that to your navbar's `RightComponent`, `LeftComponent` or `TitleComponent`, respectively.
185187
- This allows you to talk directly to your navbar, because previously you could only talk to it when navigating forward or backward.
186188

index.js

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -234,7 +234,9 @@ class Router extends React.Component {
234234
setTitleProps(props) {
235235
this.setState({ titleProps: props });
236236
}
237-
237+
getCurrentRoutes() {
238+
return this.refs.navigator.getCurrentRoutes();
239+
}
238240
customAction(opts) {
239241
this.props.customAction(opts);
240242
}
@@ -285,6 +287,11 @@ class Router extends React.Component {
285287
this.setState({ titleProps: props });
286288
};
287289

290+
const getCurrentRoutes = () => {
291+
const routes = this.refs.navigator.getCurrentRoutes();
292+
return routes;
293+
};
294+
288295
const customAction = (opts) => {
289296
this.props.customAction(opts);
290297
};
@@ -315,6 +322,7 @@ class Router extends React.Component {
315322
this.setRightProps = setRightProps;
316323
this.setLeftProps = setLeftProps;
317324
this.setTitleProps = setTitleProps;
325+
this.getCurrentRoutes = getCurrentRoutes;
318326
this.customAction = customAction;
319327

320328
return (
@@ -335,6 +343,7 @@ class Router extends React.Component {
335343
setRightProps={setRightProps}
336344
setLeftProps={setLeftProps}
337345
setTitleProps={setTitleProps}
346+
getCurrentRoutes={getCurrentRoutes}
338347
customAction={customAction}
339348
{...route.passProps}
340349
/>

0 commit comments

Comments
 (0)