-
Notifications
You must be signed in to change notification settings - Fork 1
/
NavigatorShowcase03.tsx
163 lines (135 loc) · 4.01 KB
/
NavigatorShowcase03.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
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
import * as React from 'react';
import { StyleSheet, View, Text, FlatList, ListRenderItem, TouchableOpacity } from 'react-native';
import { RouteContentProps, RouteViewPortal, RenderNavItem, NavBarAppearancePresets } from 'react-native-ios-navigator';
import { ListItemObject, LIST_ITEMS } from './Constants';
import { ListItem } from './ListItem';
import { RouteHeader } from './RouteHeader';
import * as Colors from '../../constants/Colors';
import type { onChangeSelectedItemTypeIndex } from './ItemTypesMenu';
type NavigatorShowcase03State = {
items: ListItemObject[],
isMenuExpanded: boolean;
selectedItemTypeIndex: number | null;
};
export class NavigatorShowcase03 extends React.Component<RouteContentProps, NavigatorShowcase03State> {
routeHeaderRef: RouteHeader;
constructor(props){
super(props);
this.state = {
items: LIST_ITEMS,
isMenuExpanded: false,
selectedItemTypeIndex: null
};
};
_handleOnChangeSelectedItemTypeIndex:
onChangeSelectedItemTypeIndex = (selectedItemType, index) => {
const state = this.state;
const didIndexChange = (state.selectedItemTypeIndex !== index);
this.setState(didIndexChange? {
selectedItemTypeIndex: index,
items: LIST_ITEMS.filter(item => (
item.itemType === selectedItemType
)),
}:{
selectedItemTypeIndex: null,
items: LIST_ITEMS
});
this.setState({
selectedItemTypeIndex: didIndexChange ? index : null,
});
};
_handleKeyExtractor = (item: ListItemObject) => {
return `id:${item.id}`;
};
_renderNavBarTitle: RenderNavItem = () => {
const { items } = this.state;
return (
<View style={styles.navBarTitleContainer}>
<Text style={styles.textNavBarTitle}>
{`Showing ${items.length} Items`}
</Text>
</View>
);
};
_renderNavBarRightItem: RenderNavItem = () => {
const state = this.state;
return (
<TouchableOpacity
onPress={() => {
const isExpanded = !state.isMenuExpanded;
this.routeHeaderRef.setMenuVisibility(isExpanded);
this.setState({
isMenuExpanded: isExpanded,
});
}}
>
<Text style={styles.navBarRightItemLabel}>
{state.isMenuExpanded? '⬆️' : '⬇️'}
</Text>
</TouchableOpacity>
);
};
_renderRouteHeader = () => {
const state = this.state;
return (
<RouteHeader
ref={r => { this.routeHeaderRef = r! }}
onChangeSelectedItemTypeIndex={this._handleOnChangeSelectedItemTypeIndex}
selectedItemTypeIndex={state.selectedItemTypeIndex}
isMenuExpanded={state.isMenuExpanded}
/>
);
};
_renderListItem: ListRenderItem<ListItemObject> = ({item}) => {
return (
<ListItem
item={item}
/>
);
};
render(){
return(
<React.Fragment>
<RouteViewPortal
renderRouteHeader={this._renderRouteHeader}
renderNavBarTitleItem={this._renderNavBarTitle}
renderNavBarRightItem={this._renderNavBarRightItem}
routeOptions={{
navBarAppearanceOverride: NavBarAppearancePresets.hidden,
applyBackButtonConfigToCurrentRoute: true,
backButtonDisplayMode: 'minimal',
navBarButtonBackItemConfig: {
type: 'IMAGE_EMPTY',
tintColor: Colors.PURPLE.A700,
},
}}
/>
<FlatList
style={styles.list}
contentContainerStyle={styles.listContentContainer}
data={this.state.items}
horizontal={false}
contentInsetAdjustmentBehavior={'always'}
keyExtractor={this._handleKeyExtractor}
renderItem={this._renderListItem}
/>
</React.Fragment>
);
};
};
const styles = StyleSheet.create({
list: {
},
listContentContainer: {
},
navBarTitleContainer: {
},
textNavBarTitle: {
color: Colors.PURPLE.A700,
fontSize: 14,
fontWeight: '600',
},
navBarRightItemLabel: {
fontSize: 17,
},
});