TabIcon.js
2.21 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
/**
* # Main.js
* This is the main app screen
*
*/
'use strict';
/*
* ## Imports
*
* Imports from redux
*/
import { bindActionCreators } from 'redux';
import { connect } from 'react-redux';
/**
* The actions we need
*/
import * as deviceActions from '../reducers/device/deviceActions';
/**
* Immutable
*/
import {Map} from 'immutable';
/**
* Router
*/
import {Actions} from 'react-native-router-flux';
/**
* The components needed from React
*/
import React,
{
Component,
StyleSheet,
View,
Image,
Text
}
from 'react-native';
/**
* Support for Hot reload
*
*/
const actions = [
deviceActions,
];
/**
* Instead of including all app states via ...state
* One could explicitly enumerate only those which Main.js will depend on.
*
*/
function mapStateToProps(state) {
return {
dot: state.device.dot
}
};
/*
* Bind all the functions from the ```actions``` and bind them with
* ```dispatch```
*/
function mapDispatchToProps(dispatch) {
const creators = Map()
.merge(...actions)
.filter(value => typeof value === 'function')
.toObject();
return {
actions: bindActionCreators(creators, dispatch),
dispatch
};
}
/**
* ## App class
*/
class TabIcon extends Component {
render() {
let color = this.props.selected ? '#444444' : '#B0B0B0';
let icon = this.props.selected ? this.props.iconName : this.props.iconName + '_normal' ;
let iconMarginTop = 10;
let dot = null;
if (this.props.hasDot) {
iconMarginTop = this.props.dot ? -1 : 10;
dot = this.props.dot ? <Image style={{width: 6, height: 6, marginTop: 5, marginLeft: 28}} source={{uri: 'red'}} resizeMode={'contain'} /> : null;
}
return (
<View style={{flex:1, flexDirection:'column', alignItems:'center', alignSelf:'center', height: 50}}>
{dot}
<Image style={{width: 20, height: 21, marginTop: iconMarginTop}} source={{uri: icon}} resizeMode={'contain'} />
<Text style={{color: color, marginTop: 5, fontSize: 10}}>{this.props.title}</Text>
</View>
);
}
};
/**
* Connect the properties
*/
export default connect(mapStateToProps, mapDispatchToProps)(TabIcon);