@@ -14,38 +14,43 @@ import {
1414} from 'react-native-ui-lib' ; // eslint-disable-line
1515
1616export 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-
4017 constructor ( props ) {
4118 super ( props ) ;
4219
20+ this . content = { } ;
21+
4322 this . SCROLL_TYPE = {
4423 NONE : 'none' ,
4524 VERTICAL : 'vertical' ,
4625 HORIZONTAL : 'horizontal'
4726 } ;
4827
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+
4954 this . state = {
5055 panDirection : PanningProvider . Directions . DOWN ,
5156 position : 'bottom' ,
@@ -61,15 +66,21 @@ export default class DialogScreen extends Component {
6166 } ;
6267
6368 setPanDirection = panDirection => {
64- this . setState ( { panDirection} ) ;
69+ if ( panDirection !== this . state . panDirection ) {
70+ this . setState ( { panDirection} ) ;
71+ }
6572 } ;
6673
6774 setPosition = position => {
68- this . setState ( { position} ) ;
75+ if ( position !== this . state . position ) {
76+ this . setState ( { position} ) ;
77+ }
6978 } ;
7079
7180 setScroll = scroll => {
72- this . setState ( { scroll} ) ;
81+ if ( scroll !== this . state . scroll ) {
82+ this . setState ( { scroll} ) ;
83+ }
7384 } ;
7485
7586 toggleShowHeader = ( ) => {
@@ -92,11 +103,6 @@ export default class DialogScreen extends Component {
92103 this . setState ( { showDialog : false } ) ;
93104 } ;
94105
95- getTitle = ( ) => {
96- const { showHeader} = this . state ;
97- return showHeader ? 'This is a pannable header Dialog' : 'This is a Dialog' ;
98- } ;
99-
100106 getWarning = ( ) => {
101107 const { showHeader, scroll, panDirection} = this . state ;
102108 if ( ! showHeader && scroll !== this . SCROLL_TYPE . NONE ) {
@@ -151,7 +157,7 @@ Scroll: ${scroll}`;
151157 < FlatList
152158 showsVerticalScrollIndicator = { false }
153159 style = { styles . verticalScroll }
154- data = { DialogScreen . colors }
160+ data = { this . colors }
155161 renderItem = { this . renderVerticalItem }
156162 keyExtractor = { this . keyExtractor }
157163 />
@@ -168,7 +174,7 @@ Scroll: ${scroll}`;
168174 < FlatList
169175 horizontal
170176 showsHorizontalScrollIndicator = { false }
171- data = { DialogScreen . colors }
177+ data = { this . colors }
172178 renderItem = { this . renderHorizontalItem }
173179 keyExtractor = { this . keyExtractor }
174180 />
@@ -183,6 +189,10 @@ Scroll: ${scroll}`;
183189
184190 renderContent = ( ) => {
185191 const { scroll, showHeader} = this . state ;
192+ if ( this . content [ scroll + showHeader ] ) {
193+ return this . content [ scroll + showHeader ] ;
194+ }
195+
186196 let content ;
187197 switch ( scroll ) {
188198 case this . SCROLL_TYPE . VERTICAL :
@@ -197,16 +207,19 @@ Scroll: ${scroll}`;
197207 break ;
198208 }
199209
200- return (
210+ const data = (
201211 < View spread flex = { scroll !== this . SCROLL_TYPE . NONE } >
202212 < View marginT-20 marginH-20 >
203- { ! showHeader && < Text text50 > { this . getTitle ( ) } </ Text > }
213+ { ! showHeader && < Text text50 > { this . title } </ Text > }
204214 < Text marginT-20 = { ! showHeader } > { this . getMessage ( ) } </ Text >
205215 { this . getWarning ( ) }
206216 </ View >
207217 { content }
208218 </ View >
209219 ) ;
220+
221+ this . content [ scroll + showHeader ] = data ;
222+ return data ;
210223 } ;
211224
212225 getDialogKey = height => {
@@ -228,12 +241,12 @@ Scroll: ${scroll}`;
228241 bottom = { position === 'bottom' }
229242 height = { height }
230243 panDirection = { panDirection }
231- title = { this . getTitle ( ) }
232- style = { [ styles . dialog , isRounded && styles . roundedDialog ] }
244+ containerStyle = { isRounded ? styles . roundedDialog : styles . dialog }
233245 visible = { showDialog }
234246 onDismiss = { this . hideDialog }
235247 renderPannableHeader = { renderPannableHeader }
236- supportedOrientations = { [ 'portrait' , 'landscape' ] }
248+ pannableHeaderProps = { this . pannableTitle }
249+ supportedOrientations = { this . supportedOrientations }
237250 >
238251 { this . renderContent ( ) }
239252 </ Dialog >
@@ -303,6 +316,7 @@ const styles = StyleSheet.create({
303316 backgroundColor : Colors . white
304317 } ,
305318 roundedDialog : {
319+ backgroundColor : Colors . white ,
306320 marginBottom : Constants . isIphoneX ? 0 : 20 ,
307321 borderRadius : 12
308322 } ,
0 commit comments