Skip to content

Commit 5077d0b

Browse files
committed
tab press
1 parent 8cbce95 commit 5077d0b

File tree

4 files changed

+32
-13
lines changed

4 files changed

+32
-13
lines changed

App.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ const middlewareConfig = {
4848
}
4949
}
5050

51-
const store = createStore(reducers, applyMiddleware(axiosMiddleware(client, middlewareConfig), logger))
51+
export const store = createStore(reducers, applyMiddleware(axiosMiddleware(client, middlewareConfig), logger))
5252

5353
console.disableYellowBox = true
5454

src/pages/Launch/index.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ class Launch extends Component {
2121
title='跳过'
2222
buttonStyle={styles.launchButton}
2323
onPress={() => {
24-
this.props.switch()
24+
this.props.switchStack()
2525
}}
2626
/>
2727
</ImageBackground>
@@ -32,5 +32,5 @@ class Launch extends Component {
3232

3333

3434
export default connect(undefined, {
35-
switch: changeStack
35+
switchStack: changeStack
3636
})(Launch)

src/pages/Profile/index.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,13 +14,13 @@ class Profile extends Component {
1414
<DLButton
1515
buttonStyle={styles.logoutButton}
1616
title='Log out'
17-
onPress={() => this.props.switch()}
17+
onPress={() => this.props.switchStack()}
1818
/>
1919
</View>
2020
)
2121
}
2222
}
2323

2424
export default connect(undefined, {
25-
switch: changeStack
25+
switchStack: changeStack
2626
})(Profile)

src/routes/index.js

Lines changed: 27 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@ import LaunchPage from '../pages/Launch'
1515
import BadgeItem from '../components/BadgeTabbarItem'
1616

1717
import styles from '../styles'
18+
import { store } from '../../App'
19+
import { changeStack } from '../store/actions/login'
1820

1921
function _renderTabbarIcon(icon) {
2022
return <Image source={icon} style={styles.tabBarIcon} />
@@ -82,12 +84,29 @@ const TabBarStack = () => (
8284
tabBarIcon: ({ focused }) => tabarIcons[route.name].render(focused),
8385
})}
8486
>
85-
<Tab.Screen name="Home" component={HomeStack} options={({ route }) => ({
86-
tabBarLabel: '首页',
87-
tabBarVisible: route.state && route.state.index === 0
88-
})} />
89-
<Tab.Screen name="Message" component={MessageStack} options={{ tabBarLabel: '信息' }} />
90-
<Tab.Screen name="Profile" component={ProfilePage} options={{ tabBarLabel: '我的' }} />
87+
<Tab.Screen name="Home"
88+
component={HomeStack}
89+
options={({ route }) => ({
90+
tabBarLabel: '首页',
91+
tabBarVisible: route.state && route.state.index === 0
92+
})}
93+
/>
94+
<Tab.Screen
95+
name="Message"
96+
component={MessageStack}
97+
options={{ tabBarLabel: '信息' }}
98+
/>
99+
<Tab.Screen
100+
name="Profile"
101+
component={ProfilePage}
102+
options={{ tabBarLabel: '我的' }}
103+
listeners={{
104+
tabPress: e => {
105+
store.dispatch(changeStack())
106+
e.preventDefault()
107+
}
108+
}}
109+
/>
91110
</Tab.Navigator>
92111
)
93112

@@ -105,10 +124,10 @@ const AppStack = ({ isLaunching }) => (
105124
</Stack.Navigator>
106125
)
107126

108-
const SwitchStack = ({ isLaunching }) => {
127+
const SwitchStack = ({ isLaunching, switchStack }) => {
109128
return (
110129
<NavigationContainer>
111-
<AppStack isLaunching={isLaunching} />
130+
<AppStack isLaunching={isLaunching} switchStack={switchStack} />
112131
</NavigationContainer>
113132
)
114133
}

0 commit comments

Comments
 (0)