Skip to content

Commit 2fcd0c8

Browse files
committed
更新小圆点+1
1 parent bb65974 commit 2fcd0c8

File tree

5 files changed

+64
-19
lines changed

5 files changed

+64
-19
lines changed

Reducers/RootReducer.js

+7-7
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
import { combineReducers } from 'redux';
2-
import nav from './StackReducer';
3-
4-
//取决于这里你加入了多少 reducer
5-
export default RootReducer = combineReducers({
6-
nav
7-
});
1+
// import { combineReducers } from 'redux';
2+
// import nav from './StackReducer';
3+
//
4+
// //取决于这里你加入了多少 reducer
5+
// export default RootReducer = combineReducers({
6+
// nav
7+
// });

Reducers/StackReducer.js

+2
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44
// let nextState;
55
// switch (action.type) {
66
// default:
7+
// // console.log(state);
8+
// // console.log(action);
79
// nextState = MyApp.router.getStateForAction(action, state);
810
// break;
911
// }

Test/App.js

+39-7
Original file line numberDiff line numberDiff line change
@@ -8,33 +8,68 @@ import {
88
Text,
99
View,
1010
Image,
11-
Dimensions
11+
Dimensions,
12+
DeviceEventEmitter
1213
} from 'react-native';
1314

1415
const { width , height} = Dimensions.get('window');
1516

1617
import { addNavigationHelpers, NavigationActions } from "react-navigation";
1718
import {Provider}from 'react-redux';
1819

20+
// global.badgeNumber=11;
1921

2022
// import configureStore from '../Store/configureStore';
2123
// const store = configureStore();
2224

2325
import Routers from './Routers';
2426

2527
export default class App extends Component {
28+
state={
29+
badgeNumber:11
30+
}
31+
componentDidMount(){
32+
this.subscription = DeviceEventEmitter.addListener('badge',(number)=>{
33+
// alert(number)
34+
this.setState({
35+
badgeNumber:number
36+
})
37+
});
38+
};
2639

40+
componentWillUnmount(){
41+
this.subscription.remove();
42+
};
2743
render() {
2844
const { dispatch, nav } = this.props;
2945
// console.log(dispatch);
3046

47+
48+
3149
// const navigation = addNavigationHelpers({
3250
// dispatch,
3351
// state: nav
3452
// });
3553
// 如果集成了redux,screenProps这个属性就不能直接使用了。
3654
// 应该是要通过action里面处理,这里只提供思路不做完善了
37-
return (
55+
// return (
56+
// <Provider>
57+
// <View style={{flex:1}}>
58+
// <Routers screenProps={{themeColor:'yellow'}}/>
59+
// <View style={{position:'absolute',
60+
// width:width,height:20,bottom:29}}>
61+
// <View style={{height:20,width:20,borderRadius:10,
62+
// backgroundColor:'red',marginLeft:width/3-55}}>
63+
// <Text style={{backgroundColor:'transparent',
64+
// alignSelf:'center',justifyContent:'center'}}>
65+
// {this.state.badgeNumber}
66+
// </Text>
67+
// </View>
68+
// </View>
69+
// </View>
70+
// </Provider>
71+
// );
72+
return(
3873
<View style={{flex:1}}>
3974
<Routers screenProps={{themeColor:'yellow'}}/>
4075
<View style={{position:'absolute',
@@ -43,15 +78,12 @@ export default class App extends Component {
4378
backgroundColor:'red',marginLeft:width/3-55}}>
4479
<Text style={{backgroundColor:'transparent',
4580
alignSelf:'center',justifyContent:'center'}}>
46-
11
81+
{this.state.badgeNumber}
4782
</Text>
4883
</View>
4984
</View>
5085
</View>
51-
);
52-
// return(
53-
// <Routers screenProps={{themeColor:'yellow'}}/>
54-
// )
86+
)
5587
}
5688
}
5789
const styles = StyleSheet.create({

Test/Routers.js

+3-3
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,7 @@ const MyTab = TabNavigator({
132132

133133

134134
// 初始化StackNavigator
135-
export default MyApp = StackNavigator({
135+
export default MyApp = StackNavigator({
136136
// 将TabNavigator包裹在StackNavigator里面可以保证跳转页面的时候隐藏tabbar
137137
MyTab:{
138138
screen:MyTab,
@@ -172,9 +172,9 @@ const TabOptions = (tabBarTitle,normalImage,selectedImage,navTitle) => {
172172
// const AppWithNavigationState = ({ dispatch, nav }) => (
173173
// <MyApp navigation={addNavigationHelpers({ dispatch, state: nav })}/>
174174
// );
175-
175+
//
176176
// const mapStateToProps = state => ({
177177
// nav: state.nav,
178178
// });
179-
//
179+
180180
// export default connect(mapStateToProps)(AppWithNavigationState);

Test/Test2.js

+13-2
Original file line numberDiff line numberDiff line change
@@ -10,20 +10,27 @@ import {
1010
StyleSheet,
1111
Text,
1212
View,
13-
Image
13+
Image,
14+
DeviceEventEmitter
1415
} from 'react-native';
1516

1617
const GankIcon = require('../resources/Gank.png');
1718
const ShiTuIcon = require('../resources/ShiTu.png');
1819

20+
let badgeNumber = 11;
21+
1922
export default class Test2 extends Component {
2023

2124
static navigationOptions = ({navigation,screenProps}) => ({
2225
// 这里面的属性和App.js的navigationOptions是一样的。
2326
tabBarOnPress:(({ route, index },jumpToIndex)=>{
2427
// console.log(route);
2528
// alert(index);
26-
// alert(screenProps.themeColor)
29+
// console.log(this.props);
30+
// console.log(screenProps);
31+
// alert(badgeNumber);
32+
33+
// DeviceEventEmitter.emit('badge',badgeNumber++);
2734
jumpToIndex(index);
2835
}),
2936
// 下面就是文章中修改主题色的方法
@@ -48,6 +55,9 @@ export default class Test2 extends Component {
4855
),
4956
})
5057

58+
componentWillUnmount(){
59+
this.subscription.remove();
60+
};
5161
componentDidMount(){
5262
// 通过在componentDidMount里面设置setParams将title的值动态修改
5363
this.props.navigation.setParams({
@@ -62,6 +72,7 @@ export default class Test2 extends Component {
6272
}
6373

6474
render() {
75+
console.log(this.props);
6576
return (
6677
<View style={styles.container}>
6778
<Text style={styles.welcome}>

0 commit comments

Comments
 (0)