@@ -2,55 +2,38 @@ import React, { Component } from 'react';
2
2
import {
3
3
View ,
4
4
Platform ,
5
- I18nManager
5
+ I18nManager ,
6
+ Dimensions
6
7
} from 'react-native' ;
7
8
import Modalbox from 'react-native-modalbox' ;
8
9
import RootSiblings from 'react-native-root-siblings' ;
9
- import Dimensions from 'Dimensions ' ;
10
+ import PropTypes from 'prop-types ' ;
10
11
11
- var ResponsiveAppModal = React . createClass ( {
12
- propTypes : {
13
- ...Modalbox . propTypes ,
14
- screenHeight : React . PropTypes . number ,
15
- screenWidth : React . PropTypes . number ,
16
- verticalMargin : React . PropTypes . number ,
17
- horizontalMargin : React . PropTypes . number ,
18
- sizeMatching : React . PropTypes . oneOf ( [ 'content' , 'screen' ] ) . isRequired
19
- } ,
20
- getInitialState : function ( ) {
12
+ export default class ResponsiveAppModal extends Component < { } > {
13
+ constructor ( props ) {
14
+ super ( props ) ;
21
15
const { width, height } = Dimensions . get ( 'window' ) ;
22
- return {
16
+ this . state = {
23
17
width : width ,
24
18
height : height ,
25
19
} ;
26
- } ,
27
- getDefaultProps ( ) {
28
- return {
29
- swipeToClose : false ,
30
- backButtonClose : true ,
31
- isOpen : false ,
32
- style : {
33
- height : null ,
34
- width : null
35
- }
36
- } ;
37
- } ,
20
+ }
38
21
componentWillMount ( ) {
39
22
this . modal = new RootSiblings ( this . renderModal ( this . props , this . state ) ) ;
40
23
if ( typeof Dimensions . addEventListener === 'function' )
41
24
Dimensions . addEventListener ( 'change' , this . _dimensionsChanged ) ;
42
- } ,
25
+ }
43
26
componentWillUpdate ( nextProps , nextState ) {
44
27
this . modal . update ( this . renderModal ( nextProps , nextState ) ) ;
45
- } ,
28
+ }
46
29
componentWillUnmount ( ) {
47
30
this . modal . destroy ( ) ;
48
31
this . modal = null ;
49
32
50
33
if ( typeof Dimensions . addEventListener === 'function' )
51
34
Dimensions . removeEventListener ( 'change' , this . _dimensionsChanged ) ;
52
- } ,
53
- _dimensionsChanged ( Dimensions ) {
35
+ }
36
+ _dimensionsChanged = ( Dimensions ) => {
54
37
const { width, height } = Dimensions . window ;
55
38
56
39
let newDimensions = {
@@ -60,8 +43,8 @@ var ResponsiveAppModal = React.createClass({
60
43
if ( newDimensions . width != this . state . width || newDimensions . height != this . state . height ) {
61
44
this . setState ( newDimensions ) ;
62
45
}
63
- } ,
64
- _renderAndroid ( props , state ) {
46
+ }
47
+ _renderAndroid = ( props , state ) = > {
65
48
let { screenHeight, screenWidth, verticalMargin, horizontalMargin, sizeMatching, style } = this . props ;
66
49
if ( ! screenHeight >= 0 || ! screenHeight >= 0 ) {
67
50
let { width, height } = state ;
@@ -85,8 +68,8 @@ var ResponsiveAppModal = React.createClass({
85
68
</ View >
86
69
</ Modalbox >
87
70
) ;
88
- } ,
89
- _renderIOS ( props , state ) {
71
+ }
72
+ _renderIOS = ( props , state ) => {
90
73
let { screenHeight, screenWidth, verticalMargin, horizontalMargin, sizeMatching, style } = props ;
91
74
if ( ! screenHeight >= 0 || ! screenHeight >= 0 ) {
92
75
let { width, height } = state ;
@@ -107,17 +90,33 @@ var ResponsiveAppModal = React.createClass({
107
90
{ props . children }
108
91
</ Modalbox >
109
92
) ;
110
- } ,
111
- renderModal ( props , state ) {
93
+ }
94
+ renderModal = ( props , state ) = > {
112
95
return Platform . select ( {
113
96
ios : this . _renderIOS ( props , state ) ,
114
97
android : this . _renderAndroid ( props , state ) ,
115
98
} )
116
- } ,
99
+ }
117
100
render ( ) {
118
101
//the render function is not used, instead
119
102
return ( < View > </View > ) ;
120
103
}
121
- } ) ;
104
+ }
122
105
123
- module . exports = ResponsiveAppModal ;
106
+ ResponsiveAppModal . propTypes = {
107
+ ...Modalbox . propTypes ,
108
+ screenHeight : PropTypes . number ,
109
+ screenWidth : PropTypes . number ,
110
+ verticalMargin : PropTypes . number ,
111
+ horizontalMargin : PropTypes . number ,
112
+ sizeMatching : PropTypes . oneOf ( [ 'content' , 'screen' ] ) . isRequired
113
+ }
114
+ ResponsiveAppModal . defaultProps = {
115
+ swipeToClose : false ,
116
+ backButtonClose : true ,
117
+ isOpen : false ,
118
+ style : {
119
+ height : null ,
120
+ width : null
121
+ }
122
+ }
0 commit comments