Skip to content

Commit 49e5c58

Browse files
coadofacebook-github-bot
authored andcommittedJan 13, 2025·
Replace $FlowFixMeProps in StyleInspector and refactor (#48608)
Summary: Pull Request resolved: #48608 Changelog: [General][Changed] - Improved types in StyleInspector and refactored a code Reviewed By: fabriziocucci Differential Revision: D68018846 fbshipit-source-id: ce737ec28a54c5d80d98f79380327b049c3e394b
1 parent 2959d49 commit 49e5c58

File tree

2 files changed

+40
-34
lines changed

2 files changed

+40
-34
lines changed
 

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

+36-30
Original file line numberDiff line numberDiff line change
@@ -10,42 +10,48 @@
1010

1111
'use strict';
1212

13+
import type {ViewStyleProp} from '../StyleSheet/StyleSheet';
14+
import type {____FlattenStyleProp_Internal} from '../StyleSheet/StyleSheetTypes';
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');
16-
const React = require('react');
1721

18-
class StyleInspector extends React.Component<$FlowFixMeProps> {
19-
render(): React.Node {
20-
if (!this.props.style) {
21-
return <Text style={styles.noStyle}>No style</Text>;
22-
}
23-
const names = Object.keys(this.props.style);
24-
return (
25-
<View style={styles.container}>
26-
<View>
27-
{names.map(name => (
28-
<Text key={name} style={styles.attr}>
29-
{name}:
30-
</Text>
31-
))}
32-
</View>
22+
type Props = $ReadOnly<{
23+
style?: ?____FlattenStyleProp_Internal<ViewStyleProp>,
24+
}>;
3325

34-
<View>
35-
{names.map(name => {
36-
const value = this.props.style[name];
37-
return (
38-
<Text key={name} style={styles.value}>
39-
{typeof value !== 'string' && typeof value !== 'number'
40-
? JSON.stringify(value)
41-
: value}
42-
</Text>
43-
);
44-
})}
45-
</View>
46-
</View>
47-
);
26+
function StyleInspector({style}: Props): React.Node {
27+
if (!style) {
28+
return <Text style={styles.noStyle}>No style</Text>;
4829
}
30+
const names = Object.keys(style);
31+
return (
32+
<View style={styles.container}>
33+
<View>
34+
{names.map(name => (
35+
<Text key={name} style={styles.attr}>
36+
{name}:
37+
</Text>
38+
))}
39+
</View>
40+
41+
<View>
42+
{names.map(name => {
43+
const value = style?.[name];
44+
return (
45+
<Text key={name} style={styles.value}>
46+
{typeof value !== 'string' && typeof value !== 'number'
47+
? JSON.stringify(value)
48+
: value}
49+
</Text>
50+
);
51+
})}
52+
</View>
53+
</View>
54+
);
4955
}
5056

5157
const styles = StyleSheet.create({

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

+4-4
Original file line numberDiff line numberDiff line change
@@ -5333,10 +5333,10 @@ declare export default function ReactDevToolsOverlay(Props): React.Node;
53335333
`;
53345334

53355335
exports[`public API should not change unintentionally Libraries/Inspector/StyleInspector.js 1`] = `
5336-
"declare const React: $FlowFixMe;
5337-
declare class StyleInspector extends React.Component<$FlowFixMeProps> {
5338-
render(): React.Node;
5339-
}
5336+
"type Props = $ReadOnly<{
5337+
style?: ?____FlattenStyleProp_Internal<ViewStyleProp>,
5338+
}>;
5339+
declare function StyleInspector(Props): React.Node;
53405340
declare module.exports: StyleInspector;
53415341
"
53425342
`;

0 commit comments

Comments
 (0)