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
|
import React from 'react';
import {
ScrollView,
View,
StyleSheet,
} from 'react-native';
import {
RkText,
RkButton,
RkStyleSheet,
} from 'react-native-ui-kitten';
import { MainRoutes } from '../../config/navigation/routes';
import NavigationType from '../../config/navigation/propTypes';
export class GridV2 extends React.Component {
static propTypes = {
navigation: NavigationType.isRequired,
};
static navigationOptions = {
title: 'Grid Menu'.toUpperCase(),
};
state = {
dimensions: undefined,
};
onContainerLayout = (event) => {
if (this.state.height) {
return;
}
const dimensions = event.nativeEvent.layout;
this.setState({ dimensions });
};
renderItems = () => MainRoutes.map(this.renderItem);
renderItem = (item) => (
<RkButton
rkType='tile'
style={{ height: this.state.dimensions.width / 3, width: this.state.dimensions.width / 3 }}
key={item.id}
onPress={() => this.onItemPressed(item)}>
<RkText style={styles.icon} rkType='primary moon xxlarge'>
{item.icon}
</RkText>
<RkText rkType='small'>{item.title}</RkText>
</RkButton>
);
onItemPressed = (item) => {
this.props.navigation.navigate(item.id);
};
render() {
const items = this.state.dimensions === undefined ? <View /> : this.renderItems();
return (
<ScrollView
style={styles.root}
onLayout={this.onContainerLayout}
contentContainerStyle={styles.rootContainer}>
{items}
</ScrollView>
);
}
}
const styles = RkStyleSheet.create(theme => ({
root: {
backgroundColor: theme.colors.screen.base,
},
rootContainer: {
flexDirection: 'row',
flexWrap: 'wrap',
},
empty: {
borderWidth: StyleSheet.hairlineWidth,
borderColor: theme.colors.border.base,
},
icon: {
marginBottom: 16,
},
}));
|