Skip to content

Commit f832c45

Browse files
coadofacebook-github-bot
authored andcommittedJan 13, 2025·
Replace $FlowFixMe in BoxInspector and refactor (#48601)
Summary: Pull Request resolved: #48601 Changelog: [General][Changed] - Improved types in BoxInspector and refactored a code Reviewed By: NickGerleman Differential Revision: D68017470 fbshipit-source-id: f55b958aeee44babb41cea996f944cbc551a7a7b
1 parent 49e5c58 commit f832c45

File tree

2 files changed

+65
-46
lines changed

2 files changed

+65
-46
lines changed
 

‎packages/react-native/Libraries/Inspector/BoxInspector.js

+60-42
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,15 @@
1010

1111
'use strict';
1212

13+
import type {TextStyleProp, ViewStyleProp} from '../StyleSheet/StyleSheet';
14+
import type {InspectedElementFrame} from './Inspector';
15+
16+
import React from 'react';
17+
1318
const View = require('../Components/View/View');
1419
const StyleSheet = require('../StyleSheet/StyleSheet');
1520
const Text = require('../Text/Text');
1621
const resolveBoxStyle = require('./resolveBoxStyle');
17-
const React = require('react');
1822

1923
const blank = {
2024
top: 0,
@@ -23,51 +27,65 @@ const blank = {
2327
bottom: 0,
2428
};
2529

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)} &times;{' '}
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;
4938

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)} &times;{' '}
48+
{(frame?.height || 0).toFixed(1)}
5949
</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>
6650
</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>
6885
</View>
69-
);
70-
}
86+
<Text style={styles.boxText}>{box.bottom}</Text>
87+
</View>
88+
);
7189
}
7290

7391
const styles = StyleSheet.create({

‎packages/react-native/Libraries/__tests__/__snapshots__/public-api-test.js.snap

+5-4
Original file line numberDiff line numberDiff line change
@@ -5167,10 +5167,11 @@ declare module.exports: BorderBox;
51675167
`;
51685168

51695169
exports[`public API should not change unintentionally Libraries/Inspector/BoxInspector.js 1`] = `
5170-
"declare const React: $FlowFixMe;
5171-
declare class BoxInspector extends React.Component<$FlowFixMeProps> {
5172-
render(): React.Node;
5173-
}
5170+
"type BoxInspectorProps = $ReadOnly<{
5171+
style: ViewStyleProp,
5172+
frame: ?InspectedElementFrame,
5173+
}>;
5174+
declare function BoxInspector(BoxInspectorProps): React.Node;
51745175
declare module.exports: BoxInspector;
51755176
"
51765177
`;

0 commit comments

Comments
 (0)
Please sign in to comment.