-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
90 lines (84 loc) · 1.77 KB
/
index.js
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
import {
StyleSheet,
Dimensions,
Platform,
StatusBar,
} from 'react-native';
var {height, width} = Dimensions.get('window');
if (Platform.OS === 'android') {
height = height - StatusBar.currentHeight;
}
const styles = {
container: {
flex: 1,
},
fullWidth: {
width: width,
},
fullHeight: {
height: height,
},
fullScreen: {
width: width,
height: height,
},
alignCenter: {
justifyContent: 'center',
alignItems: 'center',
},
alignStartCenter: {
justifyContent: 'flex-start',
alignItems: 'center',
},
alignEndCenter: {
justifyContent: 'flex-end',
alignItems: 'center',
},
alignCenterStart: {
justifyContent: 'center',
alignItems: 'flex-start',
},
alignCenterEnd: {
justifyContent: 'center',
alignItems: 'flex-end',
},
alignStartStart: {
justifyContent: 'flex-start',
alignItems: 'flex-start',
},
row: {
flexDirection: 'row',
},
column: {
flexDirection: 'column',
},
absoluteBottom: {
position: 'absolute',
bottom: 0,
},
absoluteTop: {
position: 'absolute',
top: 0,
},
line: {
alignSelf: 'stretch',
},
};
class StyleUtils {
constructor() {
this.setStyle = this.setStyle.bind(this);
this._styles = {...styles};
Object.keys(styles).forEach((k) => {
this.setStyle(k, styles[k]);
});
}
_styles: {}
setStyle(name, style) {
if (typeof style !== "object") throw new Error("Style must be an object");
if (Object.keys(style).length <= 0) throw new Error("Style must have at least one key");
this._styles = {...this._styles, [name]: style};
this.styles = StyleSheet.create(this._styles);
Object.defineProperty(this, name, { get: () => this.styles[name], configurable: true });
}
}
export default StyleUtils;