-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMainScreen.js
165 lines (155 loc) · 4.87 KB
/
MainScreen.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
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
164
165
import React, { Component } from 'react';
import { Dimensions } from 'react-native';
import styled from 'styled-components/native';
/**
* Swap back and forth between NamesList and NamesListFunc
* to compare difference between behavior when there's a function
* component vs class component.
*/
import NamesList from './NamesList';
import NamesListFunc from './NamesListFunc';
import FooterComponent from './FooterComponent';
import TextWrapper from './TextWrapper';
const windowWidth = Dimensions.get('window').width;
const windowHeight = Dimensions.get('window').height;
const SMALL_OFFSET = windowHeight * 0.013;
const NAV_OFFSET = 0;
const OFFSET = 0;
const MAX = 40;
const ContentView = styled.View`
height: ${(props) =>
windowHeight -
(props && props.size === 'small'
? SMALL_OFFSET
: props.size === 'large'
? OFFSET
: props.size === 'nav'
? NAV_OFFSET
: 0)}px;
border-top-left-radius: ${0};
border-top-right-radius: ${0};
top: ${(props) =>
props && props.size === 'small'
? SMALL_OFFSET + 'px'
: props.size === 'large'
? OFFSET + 'px'
: props.size === 'nav'
? NAV_OFFSET + 'px'
: 'auto'};
position: relative;
padding-bottom: ${(props) =>
props.size === 'small'
? SMALL_OFFSET
: props.size === 'large'
? OFFSET
: props.size === 'nav'
? NAV_OFFSET
: 0}px;
overflow: hidden;
flex: 1;
`;
const MainScreenWrapper = styled.View`
flex: 1;
backgroundcolor: transparent;
`;
class MainScreen extends Component {
/** Lifecycle methods */
constructor(props) {
super(props);
// props is expected to have data set in it.
this.state = {
names: {},
progress: false,
page: 0,
};
this.showProgressBar = this.showProgressBar.bind(this);
this.hideProgressBar = this.hideProgressBar.bind(this);
this.onLayout = this.onLayout.bind(this);
this.onScrollHandler = this.onScrollHandler.bind(this);
console.log(
'MainScreen constructor has props.data.length: ' + props.data?.length
);
}
/**
* Note: You cannot trust that componentDidMount will get called when
* screen is dismissed; react-navigation does not do that.
*/
componentDidMount() {
this.hideProgressBar('MainScreen componentDidMount');
}
/** End Lifecycle methods */
showProgressBar(msg) {
//return <ProgressBar progress={0.3} indeterminate={true} width={null} />;
console.log('MainScreen showProgressBar ' + msg);
this.setState({ progress: true });
}
hideProgressBar(msg) {
//return <ProgressBar progress={0.3} indeterminate={true} width={null} />;
console.log('MainScreen hideProgressBar ' + msg);
this.setState({ progress: false });
}
onLayout() {
this.hideProgressBar('MainScreen onLayout');
}
onScrollHandler() {
const newPage = this.state.page + 1;
this.setState({ page: newPage });
console.log('MainScreen onScrollHandler page is ' + newPage);
}
render() {
if (!this.props?.route?.params?.names) {
return null;
}
let data = this.props.route.params.names;
console.log('MainScreen.render');
let showAlpha = this.props.route.params.showAlpha;
let headerData = {
A: [{ id: 11, name: 'Aaliyah', description: 'Aaliyah' }],
};
let progressBar = null;
if (this.state.progress) {
progressBar = <TextWrapper>Laying out views</TextWrapper>;
} else {
progressBar = <TextWrapper>Finished laying out views</TextWrapper>;
}
console.log('MainScreen rendering. page is ' + this.state.page);
return (
<MainScreenWrapper onLayout={this.onLayout}>
{/**
<NavigationEvents
onDidFocus={() => {} } // noop
onWillFocus={() => { this.showProgressBar('willFocus'); } }
onWillBlur={() => { this.hideProgressBar('willBlur'); } }
onDidBlur={() => { this.hideProgressBar('didBlur'); } }
/> */}
{progressBar}
<ContentView
size='small'
tabs={true}
isPadding={true}
onLayout={(event) => {
this.height = event.nativeEvent.layout.height;
}}>
<NamesListFunc
key='namesList'
/*ref={ref => (this.contactList = ref)}*/
data={data}
showAlpha={Boolean(showAlpha)}
inverted={Boolean(this.props.route.params.inverted)}
flatList={Boolean(this.props.route.params.flatList)}
loader={Boolean(this.props.route.params.loader)}
headerData={headerData}
insetPadding={true}
page={this.state.page}
onScrollHandler={
this.props.route.params.loader ? this.onScrollHandler : () => {}
}
onSwipeablePress={this._handleSwipeableButton}
containerHeight={this.height || windowHeight}></NamesListFunc>
</ContentView>
<FooterComponent />
</MainScreenWrapper>
);
}
}
export default MainScreen;