1+ /***********************************************
2+ * MIT License
3+ *
4+ * Copyright (c) 2016 珠峰课堂,Ramroll
5+ * Permission is hereby granted, free of charge, to any person obtaining a copy
6+ * of this software and associated documentation files (the "Software"), to deal
7+ * in the Software without restriction, including without limitation the rights
8+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+ * copies of the Software, and to permit persons to whom the Software is
10+ * furnished to do so, subject to the following conditions:
11+ *
12+ * The above copyright notice and this permission notice shall be included in all
13+ * copies or substantial portions of the Software.
14+ *
15+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+ * SOFTWARE.
22+ *
23+ */
24+
25+ import React , { Component } from 'react'
26+
27+ import { View , Text } from 'react-native'
28+
29+ import { ZButton } from "domain/component"
30+ import { flexCenter } from "basic"
31+
32+
33+ export class Example3 extends Component {
34+
35+ _onPress ( ) {
36+ // POP 两次 --- 会连续跳两张页面
37+ // 体验很糟糕
38+ // this.props.navigator.pop()
39+ // this.props.navigator.pop()
40+
41+
42+ // 可以
43+ // 但是很难确定应该pop几张页面
44+ // 程序不好维护
45+ // this.props.navigator.popN(2)
46+
47+
48+ /** 方法1 **/
49+ // 拿到RouteStack
50+ // const routes = this.props.navigator.getCurrentRoutes()
51+ // Es6的语法, find方法传入一个prediction
52+ // const routeTo = routes.reverse().find(v => v.name === "Example1")
53+ // this.props.navigator.popToRoute(routeTo)
54+
55+
56+ /** 方法2 **/
57+ // const routes = this.props.navigator.getCurrentRoutes()
58+ // const routeTo = routes.find(v => v.name === "Example1")
59+ // this.props.navigator.resetTo(routeTo)
60+
61+
62+ /** 方法3 - 万不得以 **/
63+
64+ //[Example1, Example2, Example3] -> [Example1, Example3]
65+ //有性能问题
66+ this . props . navigator . immediatelyResetRouteStack ( [ { name : "Example1" } , { name : "Example3" } ] )
67+
68+ // 有时序问题
69+ // 此处在特定机型上可能触发bug,在10ms内 immediatelyResetRouteStack没有执行完成
70+ setTimeout ( ( ( ) => {
71+ // [Example1, Example2] -> [Example1]
72+ this . props . navigator . pop ( )
73+ } ) . bind ( this ) , 10 )
74+
75+ }
76+
77+
78+ render ( ) {
79+
80+
81+ return < View style = { { flex : 1 , ...flexCenter , backgroundColor : "yellow" } } >
82+ < Text > 页面Example3</ Text >
83+ < ZButton onPress = { this . _onPress . bind ( this ) } > 成功</ ZButton >
84+ </ View >
85+ }
86+ }
87+
88+ // 到了Example3 路由栈 [Example1, Example2, Example3]
89+ // 期望"成功"按钮返回Example1 ----> [Example1]
0 commit comments