|
10 | 10 |
|
11 | 11 | 'use strict';
|
12 | 12 |
|
| 13 | +import type {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 flattenStyle = require('../StyleSheet/flattenStyle');
|
15 | 20 | const StyleSheet = require('../StyleSheet/StyleSheet');
|
16 | 21 | const Dimensions = require('../Utilities/Dimensions').default;
|
17 | 22 | const BorderBox = require('./BorderBox');
|
18 | 23 | const resolveBoxStyle = require('./resolveBoxStyle');
|
19 |
| -const React = require('react'); |
20 |
| - |
21 |
| -class ElementBox extends React.Component<$FlowFixMeProps> { |
22 |
| - render(): React.Node { |
23 |
| - const style = flattenStyle(this.props.style) || {}; |
24 |
| - let margin: ?$ReadOnly<Style> = resolveBoxStyle('margin', style); |
25 |
| - let padding: ?$ReadOnly<Style> = resolveBoxStyle('padding', style); |
26 |
| - |
27 |
| - const frameStyle = {...this.props.frame}; |
28 |
| - const contentStyle: {width: number, height: number} = { |
29 |
| - width: this.props.frame.width, |
30 |
| - height: this.props.frame.height, |
31 |
| - }; |
32 |
| - |
33 |
| - if (margin != null) { |
34 |
| - margin = resolveRelativeSizes(margin); |
35 |
| - |
36 |
| - frameStyle.top -= margin.top; |
37 |
| - frameStyle.left -= margin.left; |
38 |
| - frameStyle.height += margin.top + margin.bottom; |
39 |
| - frameStyle.width += margin.left + margin.right; |
40 |
| - |
41 |
| - if (margin.top < 0) { |
42 |
| - contentStyle.height += margin.top; |
43 |
| - } |
44 |
| - if (margin.bottom < 0) { |
45 |
| - contentStyle.height += margin.bottom; |
46 |
| - } |
47 |
| - if (margin.left < 0) { |
48 |
| - contentStyle.width += margin.left; |
49 |
| - } |
50 |
| - if (margin.right < 0) { |
51 |
| - contentStyle.width += margin.right; |
52 |
| - } |
53 |
| - } |
54 | 24 |
|
55 |
| - if (padding != null) { |
56 |
| - padding = resolveRelativeSizes(padding); |
| 25 | +type Props = $ReadOnly<{ |
| 26 | + frame: InspectedElementFrame, |
| 27 | + style?: ?ViewStyleProp, |
| 28 | +}>; |
| 29 | + |
| 30 | +function ElementBox({frame, style}: Props): React.Node { |
| 31 | + const flattenedStyle = flattenStyle(style) || {}; |
| 32 | + let margin: ?$ReadOnly<Style> = resolveBoxStyle('margin', flattenedStyle); |
| 33 | + let padding: ?$ReadOnly<Style> = resolveBoxStyle('padding', flattenedStyle); |
57 | 34 |
|
58 |
| - contentStyle.width -= padding.left + padding.right; |
59 |
| - contentStyle.height -= padding.top + padding.bottom; |
| 35 | + const frameStyle = {...frame}; |
| 36 | + const contentStyle: {width: number, height: number} = { |
| 37 | + width: frame.width, |
| 38 | + height: frame.height, |
| 39 | + }; |
| 40 | + |
| 41 | + if (margin != null) { |
| 42 | + margin = resolveRelativeSizes(margin); |
| 43 | + |
| 44 | + frameStyle.top -= margin.top; |
| 45 | + frameStyle.left -= margin.left; |
| 46 | + frameStyle.height += margin.top + margin.bottom; |
| 47 | + frameStyle.width += margin.left + margin.right; |
| 48 | + |
| 49 | + if (margin.top < 0) { |
| 50 | + contentStyle.height += margin.top; |
| 51 | + } |
| 52 | + if (margin.bottom < 0) { |
| 53 | + contentStyle.height += margin.bottom; |
60 | 54 | }
|
| 55 | + if (margin.left < 0) { |
| 56 | + contentStyle.width += margin.left; |
| 57 | + } |
| 58 | + if (margin.right < 0) { |
| 59 | + contentStyle.width += margin.right; |
| 60 | + } |
| 61 | + } |
61 | 62 |
|
62 |
| - return ( |
63 |
| - <View style={[styles.frame, frameStyle]} pointerEvents="none"> |
64 |
| - <BorderBox box={margin} style={styles.margin}> |
65 |
| - <BorderBox box={padding} style={styles.padding}> |
66 |
| - <View style={[styles.content, contentStyle]} /> |
67 |
| - </BorderBox> |
68 |
| - </BorderBox> |
69 |
| - </View> |
70 |
| - ); |
| 63 | + if (padding != null) { |
| 64 | + padding = resolveRelativeSizes(padding); |
| 65 | + |
| 66 | + contentStyle.width -= padding.left + padding.right; |
| 67 | + contentStyle.height -= padding.top + padding.bottom; |
71 | 68 | }
|
| 69 | + |
| 70 | + return ( |
| 71 | + <View style={[styles.frame, frameStyle]} pointerEvents="none"> |
| 72 | + <BorderBox box={margin} style={styles.margin}> |
| 73 | + <BorderBox box={padding} style={styles.padding}> |
| 74 | + <View style={[styles.content, contentStyle]} /> |
| 75 | + </BorderBox> |
| 76 | + </BorderBox> |
| 77 | + </View> |
| 78 | + ); |
72 | 79 | }
|
73 | 80 |
|
74 | 81 | const styles = StyleSheet.create({
|
|
0 commit comments