10
10
11
11
'use strict' ;
12
12
13
+ import type { TextStyleProp , ViewStyleProp } from '../StyleSheet/StyleSheet' ;
14
+ import type { InspectedElementFrame } from './Inspector' ;
15
+
16
+ import React from 'react' ;
17
+
13
18
const View = require ( '../Components/View/View' ) ;
14
19
const StyleSheet = require ( '../StyleSheet/StyleSheet' ) ;
15
20
const Text = require ( '../Text/Text' ) ;
16
21
const resolveBoxStyle = require ( './resolveBoxStyle' ) ;
17
- const React = require ( 'react' ) ;
18
22
19
23
const blank = {
20
24
top : 0 ,
@@ -23,51 +27,65 @@ const blank = {
23
27
bottom : 0 ,
24
28
} ;
25
29
26
- class BoxInspector extends React . Component < $FlowFixMeProps > {
27
- render ( ) : React . Node {
28
- const frame = this . props . frame ;
29
- const style = this . props . style ;
30
- const margin = ( style && resolveBoxStyle ( 'margin' , style ) ) || blank ;
31
- const padding = ( style && resolveBoxStyle ( 'padding' , style ) ) || blank ;
32
- return (
33
- < BoxContainer title = "margin" titleStyle = { styles . marginLabel } box = { margin } >
34
- < BoxContainer title = "padding" box = { padding } >
35
- < View >
36
- < Text style = { styles . innerText } >
37
- ({ ( frame . left || 0 ) . toFixed ( 1 ) } , { ( frame . top || 0 ) . toFixed ( 1 ) } )
38
- </ Text >
39
- < Text style = { styles . innerText } >
40
- { ( frame . width || 0 ) . toFixed ( 1 ) } ×{ ' ' }
41
- { ( frame . height || 0 ) . toFixed ( 1 ) }
42
- </ Text >
43
- </ View >
44
- </ BoxContainer >
45
- </ BoxContainer >
46
- ) ;
47
- }
48
- }
30
+ type BoxInspectorProps = $ReadOnly < {
31
+ style : ViewStyleProp ,
32
+ frame : ?InspectedElementFrame ,
33
+ } > ;
34
+
35
+ function BoxInspector ( { style, frame} : BoxInspectorProps ) : React . Node {
36
+ const margin = ( style && resolveBoxStyle ( 'margin' , style ) ) || blank ;
37
+ const padding = ( style && resolveBoxStyle ( 'padding' , style ) ) || blank ;
49
38
50
- class BoxContainer extends React . Component < $FlowFixMeProps > {
51
- render ( ) : React . Node {
52
- const box = this . props . box ;
53
- return (
54
- < View style = { styles . box } >
55
- < View style = { styles . row } >
56
- { }
57
- < Text style = { [ this . props . titleStyle , styles . label ] } >
58
- { this . props . title }
39
+ return (
40
+ < BoxContainer title = "margin" titleStyle = { styles . marginLabel } box = { margin } >
41
+ < BoxContainer title = "padding" box = { padding } >
42
+ < View >
43
+ < Text style = { styles . innerText } >
44
+ ({ ( frame ?. left || 0 ) . toFixed ( 1 ) } , { ( frame ?. top || 0 ) . toFixed ( 1 ) } )
45
+ </ Text >
46
+ < Text style = { styles . innerText } >
47
+ { ( frame ?. width || 0 ) . toFixed ( 1 ) } ×{ ' ' }
48
+ { ( frame ?. height || 0 ) . toFixed ( 1 ) }
59
49
</ Text >
60
- < Text style = { styles . boxText } > { box . top } </ Text >
61
- </ View >
62
- < View style = { styles . row } >
63
- < Text style = { styles . boxText } > { box . left } </ Text >
64
- { this . props . children }
65
- < Text style = { styles . boxText } > { box . right } </ Text >
66
50
</ View >
67
- < Text style = { styles . boxText } > { box . bottom } </ Text >
51
+ </ BoxContainer >
52
+ </ BoxContainer >
53
+ ) ;
54
+ }
55
+
56
+ type BoxContainerProps = $ReadOnly < {
57
+ title : string ,
58
+ titleStyle ?: TextStyleProp ,
59
+ box : $ReadOnly < {
60
+ top : number ,
61
+ left : number ,
62
+ right : number ,
63
+ bottom : number ,
64
+ } > ,
65
+ children : React . Node ,
66
+ } > ;
67
+
68
+ function BoxContainer ( {
69
+ title,
70
+ titleStyle,
71
+ box,
72
+ children,
73
+ } : BoxContainerProps ) : React . Node {
74
+ return (
75
+ < View style = { styles . box } >
76
+ < View style = { styles . row } >
77
+ { }
78
+ < Text style = { [ titleStyle , styles . label ] } > { title } </ Text >
79
+ < Text style = { styles . boxText } > { box . top } </ Text >
80
+ </ View >
81
+ < View style = { styles . row } >
82
+ < Text style = { styles . boxText } > { box . left } </ Text >
83
+ { children }
84
+ < Text style = { styles . boxText } > { box . right } </ Text >
68
85
</ View >
69
- ) ;
70
- }
86
+ < Text style = { styles . boxText } > { box . bottom } </ Text >
87
+ </ View >
88
+ ) ;
71
89
}
72
90
73
91
const styles = StyleSheet . create ( {
0 commit comments