-
Notifications
You must be signed in to change notification settings - Fork 6
/
BottomNavigationBar.tsx
131 lines (124 loc) · 3.73 KB
/
BottomNavigationBar.tsx
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
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
import React from 'react';
import { StyleSheet, ScrollView, View } from 'react-native';
import { Text, NumberInput, BottomNavigationBar, NavigationButton, Checkbox, getColor } from '@carbon/react-native';
import DashboardIcon from '@carbon/icons/es/dashboard/20';
import MapIcon from '@carbon/icons/es/map/20';
import ActivityIcon from '@carbon/icons/es/activity/20';
import CollaborateIcon from '@carbon/icons/es/collaborate/20';
import MedicationIcon from '@carbon/icons/es/medication/20';
import FavoriteIcon from '@carbon/icons/es/favorite--filled/20';
import AccessibilityIcon from '@carbon/icons/es/accessibility--alt/20';
import UserIcon from '@carbon/icons/es/user--avatar/20';
const styles = StyleSheet.create({
parentView: {
flex: 1,
},
view: {
padding: 16,
flex: 1,
},
container: {
flexGrow: 1,
paddingBottom: 64,
},
appBreaker: {
backgroundColor: getColor('tagBackgroundMagenta'),
height: 20,
},
baseSpacing: {
marginBottom: 16,
},
});
export default class TestBottomNavigationBar extends React.Component {
state = {
disabled: false,
total: '4',
currentPage: 1,
};
private get items(): NavigationButton[] {
const { currentPage, disabled } = this.state;
return [
{
text: 'Dashboard',
icon: DashboardIcon,
active: currentPage === 1,
onPress: () => {
this.setState({ currentPage: 1 });
},
},
{
text: 'Map',
icon: MapIcon,
disabled: disabled,
active: currentPage === 2,
onPress: () => {
this.setState({ currentPage: 2 });
},
},
{
text: 'Collaborate',
icon: CollaborateIcon,
active: currentPage === 3,
onPress: () => {
this.setState({ currentPage: 3 });
},
},
{
text: 'Current long name that has to be cut',
icon: ActivityIcon,
active: currentPage === 4,
onPress: () => {
this.setState({ currentPage: 4 });
},
},
{
text: 'Favorites',
icon: FavoriteIcon,
active: currentPage === 5,
onPress: () => {
this.setState({ currentPage: 5 });
},
},
{
text: 'Accessibility',
icon: AccessibilityIcon,
active: currentPage === 6,
onPress: () => {
this.setState({ currentPage: 6 });
},
},
{
text: 'Account',
icon: UserIcon,
active: currentPage === 7,
onPress: () => {
this.setState({ currentPage: 7 });
},
},
{
text: 'Medication',
icon: MedicationIcon,
active: currentPage === 8,
onPress: () => {
this.setState({ currentPage: 8 });
},
},
];
}
render(): React.ReactNode {
const { total, currentPage, disabled } = this.state;
const itemsToUse = this.items.slice(0, Number(total));
const currentItem = itemsToUse[currentPage - 1];
return (
<View style={styles.parentView}>
<ScrollView keyboardShouldPersistTaps="handled" contentInsetAdjustmentBehavior="automatic" contentContainerStyle={styles.container} style={styles.view}>
{!!currentItem && <Text style={styles.baseSpacing} type="heading-03" text={`Current page: ${currentItem?.text}`} />}
<NumberInput value={total} label="Number of items to load" onChangeText={(value) => this.setState({ total: value })} numberRules={{ max: 5, min: 2 }} />
<Checkbox checked={disabled} id="disabled" onPress={(value) => this.setState({ disabled: value })} label="Disable second item" />
</ScrollView>
<BottomNavigationBar items={itemsToUse} />
<View style={styles.appBreaker} />
</View>
);
}
}