From ca52894b695312e91c2d2bb4e0356b37ae067589 Mon Sep 17 00:00:00 2001 From: doomsower Date: Thu, 4 Aug 2016 13:53:48 +0300 Subject: [PATCH 1/6] pop actions can pass props to previous screen --- src/Reducer.js | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/src/Reducer.js b/src/Reducer.js index 867360b75..8ba1ab304 100644 --- a/src/Reducer.js +++ b/src/Reducer.js @@ -46,6 +46,11 @@ function resetHistoryStack(child) { ); } +function refreshTopChild(children, refresh){ + const topChild = children[children.length - 1]; + return [...children.slice(0, -1), {...topChild, ...refresh}]; +} + function inject(state, action, props, scenes) { const condition = ActionMap[action.type] === ActionConst.REFRESH ? state.key === props.key || state.sceneKey === action.key : state.sceneKey === props.parent; @@ -75,7 +80,7 @@ function inject(state, action, props, scenes) { return { ...state, index: targetIndex, - children: state.children.slice(0, (targetIndex + 1)), + children: refreshTopChild(state.children.slice(0, (targetIndex + 1)), action.refresh), }; } @@ -104,7 +109,7 @@ function inject(state, action, props, scenes) { ...state, index: state.index - popNum, from: state.children[state.children.length - popNum], - children: state.children.slice(0, -1 * popNum), + children: refreshTopChild(state.children.slice(0, -1 * popNum), action.refresh), }; } case ActionConst.REFRESH: @@ -126,7 +131,7 @@ function inject(state, action, props, scenes) { ...state, index: ind, from: state.children[state.index], - children: state.children.slice(0, ind + 1), + children: refreshTopChild(tate.children.slice(0, ind + 1), action.refresh), }; } return { From 312d983ab4e05c38522b32de274457ec74d56213 Mon Sep 17 00:00:00 2001 From: doomsower Date: Thu, 4 Aug 2016 13:57:18 +0300 Subject: [PATCH 2/6] fix typo --- src/Reducer.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Reducer.js b/src/Reducer.js index 8ba1ab304..c9f0b7888 100644 --- a/src/Reducer.js +++ b/src/Reducer.js @@ -131,7 +131,7 @@ function inject(state, action, props, scenes) { ...state, index: ind, from: state.children[state.index], - children: refreshTopChild(tate.children.slice(0, ind + 1), action.refresh), + children: refreshTopChild(state.children.slice(0, ind + 1), action.refresh), }; } return { From d679b76a21c3e531ff33b8eba880bad219c996f4 Mon Sep 17 00:00:00 2001 From: doomsower Date: Thu, 4 Aug 2016 16:13:27 +0300 Subject: [PATCH 3/6] fix eslint warnings --- src/Reducer.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Reducer.js b/src/Reducer.js index c9f0b7888..b6e33266c 100644 --- a/src/Reducer.js +++ b/src/Reducer.js @@ -46,9 +46,9 @@ function resetHistoryStack(child) { ); } -function refreshTopChild(children, refresh){ +function refreshTopChild(children, refresh) { const topChild = children[children.length - 1]; - return [...children.slice(0, -1), {...topChild, ...refresh}]; + return [...children.slice(0, -1), { ...topChild, ...refresh }]; } function inject(state, action, props, scenes) { From 29765fd6176611cc00c8686bca4fa293d1821458 Mon Sep 17 00:00:00 2001 From: doomsower Date: Mon, 8 Aug 2016 11:51:44 +0300 Subject: [PATCH 4/6] Document pop with refresh in readme --- README.md | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 5f948f8b2..41fbb4d54 100644 --- a/README.md +++ b/README.md @@ -108,7 +108,9 @@ import {Actions} from 'react-native-router-flux' And then: * `Actions.ACTION_NAME(PARAMS)` will call the appropriate action and params will be passed to the scene. -* `Actions.pop()` will pop the current screen. It can also take a param `{popNum: [number]}` that allows to pop multiple screens at once. +* `Actions.pop()` will pop the current screen. It accepts following optional params: + * `{popNum: [number]}` allows to pop multiple screens at once + * `{refresh: {...propsToSetOnPreviousScene}}` allows to refresh the props of the scene that it pops back to * `Actions.refresh(PARAMS)` will update the properties of the current screen. ## Production Apps using react-native-router-flux From ad2d032c91fe5e8c5e2b7939cdd051a08d2eb311 Mon Sep 17 00:00:00 2001 From: doomsower Date: Mon, 8 Aug 2016 11:57:52 +0300 Subject: [PATCH 5/6] Do refreshTopChild if no refresh param is provided --- src/Reducer.js | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/src/Reducer.js b/src/Reducer.js index b6e33266c..c0dda3994 100644 --- a/src/Reducer.js +++ b/src/Reducer.js @@ -47,8 +47,13 @@ function resetHistoryStack(child) { } function refreshTopChild(children, refresh) { - const topChild = children[children.length - 1]; - return [...children.slice(0, -1), { ...topChild, ...refresh }]; + if (refresh) { + const topChild = children[children.length - 1]; + return [...children.slice(0, -1), { ...topChild, ...refresh }]; + } + else { + return children; + } } function inject(state, action, props, scenes) { From 672ec3603de98f5cda91128285f26d23771aa011 Mon Sep 17 00:00:00 2001 From: doomsower Date: Mon, 8 Aug 2016 12:02:45 +0300 Subject: [PATCH 6/6] Fix eslint warns --- src/Reducer.js | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/src/Reducer.js b/src/Reducer.js index c0dda3994..cadba2e59 100644 --- a/src/Reducer.js +++ b/src/Reducer.js @@ -51,9 +51,7 @@ function refreshTopChild(children, refresh) { const topChild = children[children.length - 1]; return [...children.slice(0, -1), { ...topChild, ...refresh }]; } - else { - return children; - } + return children; } function inject(state, action, props, scenes) {