@@ -14,38 +14,43 @@ import {
14
14
} from 'react-native-ui-lib' ; // eslint-disable-line
15
15
16
16
export default class DialogScreen extends Component {
17
- static colors = [
18
- { value : Colors . red10 , label : 'Red10' } ,
19
- { value : Colors . red30 , label : 'Red30' } ,
20
- { value : Colors . red50 , label : 'Red50' } ,
21
- { value : Colors . red70 , label : 'Red70' } ,
22
- { value : Colors . blue10 , label : 'Blue10' } ,
23
- { value : Colors . blue30 , label : 'Blue30' } ,
24
- { value : Colors . blue50 , label : 'Blue50' } ,
25
- { value : Colors . blue70 , label : 'Blue70' } ,
26
- { value : Colors . purple10 , label : 'Purple10' } ,
27
- { value : Colors . purple30 , label : 'Purple30' } ,
28
- { value : Colors . purple50 , label : 'Purple50' } ,
29
- { value : Colors . purple70 , label : 'Purple70' } ,
30
- { value : Colors . green10 , label : 'Green10' } ,
31
- { value : Colors . green30 , label : 'Green30' } ,
32
- { value : Colors . green50 , label : 'Green50' } ,
33
- { value : Colors . green70 , label : 'Green70' } ,
34
- { value : Colors . yellow10 , label : 'Yellow10' } ,
35
- { value : Colors . yellow30 , label : 'Yellow30' } ,
36
- { value : Colors . yellow50 , label : 'Yellow50' } ,
37
- { value : Colors . yellow70 , label : 'Yellow70' }
38
- ] ;
39
-
40
17
constructor ( props ) {
41
18
super ( props ) ;
42
19
20
+ this . content = { } ;
21
+
43
22
this . SCROLL_TYPE = {
44
23
NONE : 'none' ,
45
24
VERTICAL : 'vertical' ,
46
25
HORIZONTAL : 'horizontal'
47
26
} ;
48
27
28
+ this . pannableTitle = { title : 'This is a pannable header Dialog' } ;
29
+ this . title = 'This is a Dialog' ;
30
+ this . supportedOrientations = [ 'portrait' , 'landscape' ] ;
31
+ this . colors = [
32
+ { value : Colors . red10 , label : 'Red10' } ,
33
+ { value : Colors . red30 , label : 'Red30' } ,
34
+ { value : Colors . red50 , label : 'Red50' } ,
35
+ { value : Colors . red70 , label : 'Red70' } ,
36
+ { value : Colors . blue10 , label : 'Blue10' } ,
37
+ { value : Colors . blue30 , label : 'Blue30' } ,
38
+ { value : Colors . blue50 , label : 'Blue50' } ,
39
+ { value : Colors . blue70 , label : 'Blue70' } ,
40
+ { value : Colors . purple10 , label : 'Purple10' } ,
41
+ { value : Colors . purple30 , label : 'Purple30' } ,
42
+ { value : Colors . purple50 , label : 'Purple50' } ,
43
+ { value : Colors . purple70 , label : 'Purple70' } ,
44
+ { value : Colors . green10 , label : 'Green10' } ,
45
+ { value : Colors . green30 , label : 'Green30' } ,
46
+ { value : Colors . green50 , label : 'Green50' } ,
47
+ { value : Colors . green70 , label : 'Green70' } ,
48
+ { value : Colors . yellow10 , label : 'Yellow10' } ,
49
+ { value : Colors . yellow30 , label : 'Yellow30' } ,
50
+ { value : Colors . yellow50 , label : 'Yellow50' } ,
51
+ { value : Colors . yellow70 , label : 'Yellow70' }
52
+ ] ;
53
+
49
54
this . state = {
50
55
panDirection : PanningProvider . Directions . DOWN ,
51
56
position : 'bottom' ,
@@ -61,15 +66,21 @@ export default class DialogScreen extends Component {
61
66
} ;
62
67
63
68
setPanDirection = panDirection => {
64
- this . setState ( { panDirection} ) ;
69
+ if ( panDirection !== this . state . panDirection ) {
70
+ this . setState ( { panDirection} ) ;
71
+ }
65
72
} ;
66
73
67
74
setPosition = position => {
68
- this . setState ( { position} ) ;
75
+ if ( position !== this . state . position ) {
76
+ this . setState ( { position} ) ;
77
+ }
69
78
} ;
70
79
71
80
setScroll = scroll => {
72
- this . setState ( { scroll} ) ;
81
+ if ( scroll !== this . state . scroll ) {
82
+ this . setState ( { scroll} ) ;
83
+ }
73
84
} ;
74
85
75
86
toggleShowHeader = ( ) => {
@@ -92,11 +103,6 @@ export default class DialogScreen extends Component {
92
103
this . setState ( { showDialog : false } ) ;
93
104
} ;
94
105
95
- getTitle = ( ) => {
96
- const { showHeader} = this . state ;
97
- return showHeader ? 'This is a pannable header Dialog' : 'This is a Dialog' ;
98
- } ;
99
-
100
106
getWarning = ( ) => {
101
107
const { showHeader, scroll, panDirection} = this . state ;
102
108
if ( ! showHeader && scroll !== this . SCROLL_TYPE . NONE ) {
@@ -151,7 +157,7 @@ Scroll: ${scroll}`;
151
157
< FlatList
152
158
showsVerticalScrollIndicator = { false }
153
159
style = { styles . verticalScroll }
154
- data = { DialogScreen . colors }
160
+ data = { this . colors }
155
161
renderItem = { this . renderVerticalItem }
156
162
keyExtractor = { this . keyExtractor }
157
163
/>
@@ -168,7 +174,7 @@ Scroll: ${scroll}`;
168
174
< FlatList
169
175
horizontal
170
176
showsHorizontalScrollIndicator = { false }
171
- data = { DialogScreen . colors }
177
+ data = { this . colors }
172
178
renderItem = { this . renderHorizontalItem }
173
179
keyExtractor = { this . keyExtractor }
174
180
/>
@@ -183,6 +189,10 @@ Scroll: ${scroll}`;
183
189
184
190
renderContent = ( ) => {
185
191
const { scroll, showHeader} = this . state ;
192
+ if ( this . content [ scroll + showHeader ] ) {
193
+ return this . content [ scroll + showHeader ] ;
194
+ }
195
+
186
196
let content ;
187
197
switch ( scroll ) {
188
198
case this . SCROLL_TYPE . VERTICAL :
@@ -197,16 +207,19 @@ Scroll: ${scroll}`;
197
207
break ;
198
208
}
199
209
200
- return (
210
+ const data = (
201
211
< View spread flex = { scroll !== this . SCROLL_TYPE . NONE } >
202
212
< View marginT-20 marginH-20 >
203
- { ! showHeader && < Text text50 > { this . getTitle ( ) } </ Text > }
213
+ { ! showHeader && < Text text50 > { this . title } </ Text > }
204
214
< Text marginT-20 = { ! showHeader } > { this . getMessage ( ) } </ Text >
205
215
{ this . getWarning ( ) }
206
216
</ View >
207
217
{ content }
208
218
</ View >
209
219
) ;
220
+
221
+ this . content [ scroll + showHeader ] = data ;
222
+ return data ;
210
223
} ;
211
224
212
225
getDialogKey = height => {
@@ -228,12 +241,12 @@ Scroll: ${scroll}`;
228
241
bottom = { position === 'bottom' }
229
242
height = { height }
230
243
panDirection = { panDirection }
231
- containerStyle = { [ styles . dialog , isRounded && styles . roundedDialog ] }
244
+ containerStyle = { isRounded ? styles . roundedDialog : styles . dialog }
232
245
visible = { showDialog }
233
246
onDismiss = { this . hideDialog }
234
247
renderPannableHeader = { renderPannableHeader }
235
- pannableHeaderProps = { { title : this . getTitle ( ) } }
236
- supportedOrientations = { [ 'portrait' , 'landscape' ] }
248
+ pannableHeaderProps = { this . pannableTitle }
249
+ supportedOrientations = { this . supportedOrientations }
237
250
>
238
251
{ this . renderContent ( ) }
239
252
</ Dialog >
@@ -303,6 +316,7 @@ const styles = StyleSheet.create({
303
316
backgroundColor : Colors . white
304
317
} ,
305
318
roundedDialog : {
319
+ backgroundColor : Colors . white ,
306
320
marginBottom : Constants . isIphoneX ? 0 : 20 ,
307
321
borderRadius : 12
308
322
} ,
0 commit comments