-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathNavigatorTest08.tsx
140 lines (123 loc) · 3.28 KB
/
NavigatorTest08.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
import * as React from 'react';
import { StyleSheet, FlatList, ListRenderItem } from 'react-native';
import { RouteViewPortal, RouteContentProps, NavigatorView, RouteViewEvents, NavRoutesConfigMap } from 'react-native-ios-navigator';
import { EventListItem } from './EventListItem';
import { RouteA } from './RouteA';
import { RouteB } from './RouteB';
import type { EventData, RecordEvent, RouteProps } from './SharedTypes';
export const RouteKeys = {
RouteA: 'RouteA',
RouteB: 'RouteB',
};
const ROUTES: NavRoutesConfigMap = {
[RouteKeys.RouteA]: {
routeOptionsDefault: {
largeTitleDisplayMode: 'never',
},
renderRoute: () => (
<RouteA/>
),
},
[RouteKeys.RouteB]: {
routeOptionsDefault: {
largeTitleDisplayMode: 'never',
},
renderRoute: () => (
<RouteB/>
),
},
};
type NavigatorTest08State = {
events: Array<EventData>;
};
export class NavigatorTest08 extends React.Component<RouteContentProps, NavigatorTest08State> {
constructor(props: RouteContentProps){
super(props);
this.state = {
events: [],
};
};
recordEvent: RecordEvent = (event) => {
this.setState((prevState) => ({
events: [event, ...prevState.events],
}));
};
_handleKeyExtractor = (item: EventData) => {
return `${item.timestamp}`;
};
_renderEventListItem: ListRenderItem<EventData> = ({item, index}) => {
const { events } = this.state;
const eventCount = events.length;
return(
<EventListItem
index={(eventCount - 1) - index}
eventListItem={item}
/>
);
};
render(){
const sharedRouteProps: RouteProps = {
recordEvent: this.recordEvent,
};
return(
<React.Fragment>
<RouteViewPortal
routeOptions={{
navBarButtonRightItemsConfig: [{
type: 'TEXT',
title: 'Clear'
}]
}}
/>
<RouteViewEvents
onPressNavBarRightItem={() => {
this.setState({
events: [],
});
}}
/>
<FlatList
style={styles.list}
contentContainerStyle={styles.listContentContainer}
data={this.state.events}
keyExtractor={this._handleKeyExtractor}
renderItem={this._renderEventListItem}
/>
<NavigatorView
style={styles.bottomNavigator}
sharedRouteProps={sharedRouteProps}
routes={ROUTES}
initialRoutes={[{routeKey: 'RouteA'}]}
onNavRouteWillShow={({nativeEvent}) => {
this.recordEvent({
eventType: 'onNavRouteWillShow',
routeKey: nativeEvent.routeKey,
routeIndex: nativeEvent.routeIndex,
timestamp: Date.now(),
});
}}
onNavRouteDidShow={({nativeEvent}) => {
this.recordEvent({
eventType: 'onNavRouteDidShow',
routeKey: nativeEvent.routeKey,
routeIndex: nativeEvent.routeIndex,
timestamp: Date.now(),
});
}}
/>
</React.Fragment>
);
};
};
const styles = StyleSheet.create({
list: {
flex: 1,
},
listContentContainer: {
paddingVertical: 10,
paddingHorizontal: 10,
},
bottomNavigator: {
flex: 1,
},
});