From 3b39452d479c815a606317969436020970f1b29d Mon Sep 17 00:00:00 2001 From: Alex de Mulder Date: Fri, 1 Apr 2016 16:19:19 +0200 Subject: [PATCH] Added popToTop functionality --- src/Actions.js | 1 + src/Reducer.js | 8 +++++++- 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/src/Actions.js b/src/Actions.js index d5418c22f..cf661df47 100644 --- a/src/Actions.js +++ b/src/Actions.js @@ -13,6 +13,7 @@ export const PUSH_ACTION = "push"; export const REPLACE_ACTION = "replace"; export const POP_ACTION2 = "back"; export const POP_ACTION = "BackAction"; +export const POP_TO_TOP = 'popToTop'; export const REFRESH_ACTION = "refresh"; export const RESET_ACTION = "reset"; export const INIT_ACTION = "init"; diff --git a/src/Reducer.js b/src/Reducer.js index 4b96d0ca3..ac39649f2 100644 --- a/src/Reducer.js +++ b/src/Reducer.js @@ -7,7 +7,7 @@ * */ -import {PUSH_ACTION, POP_ACTION2, FOCUS_ACTION, JUMP_ACTION, INIT_ACTION, REPLACE_ACTION, RESET_ACTION, POP_ACTION, REFRESH_ACTION} from "./Actions"; +import {PUSH_ACTION, POP_ACTION2, POP_TO_TOP, FOCUS_ACTION, JUMP_ACTION, INIT_ACTION, REPLACE_ACTION, RESET_ACTION, POP_ACTION, REFRESH_ACTION} from "./Actions"; import assert from "assert"; import Immutable from "immutable"; import {getInitialState} from "./State"; @@ -48,6 +48,11 @@ function inject(state, action, props, scenes) { case POP_ACTION: assert(!state.tabs, "pop() operation cannot be run on tab bar (tabs=true)") return {...state, index:state.index-1, children:state.children.slice(0, -1) }; + case POP_TO_TOP: + assert(state.tabs, "Parent="+state.key+" is not tab bar, popToTop action is not valid"); + let child = state.children[state.index]; + let newChild = {...child, ...{children: [child.children[0]], index:0}}; + return {...state, ...{children:[...state.children.slice(0,state.index), newChild, ...state.children.slice(state.index+1)]}}; case REFRESH_ACTION: return {...state, ...props}; case PUSH_ACTION: @@ -152,6 +157,7 @@ function reducer({initialState, scenes}){ switch (action.type) { case POP_ACTION2: case POP_ACTION: + case POP_TO_TOP: case REFRESH_ACTION: case PUSH_ACTION: case JUMP_ACTION: