Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Replace $FlowFixMeProps in StyleInspector and refactor #48608

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
66 changes: 36 additions & 30 deletions packages/react-native/Libraries/Inspector/StyleInspector.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,42 +10,48 @@

'use strict';

import type {ViewStyleProp} from '../StyleSheet/StyleSheet';
import type {____FlattenStyleProp_Internal} from '../StyleSheet/StyleSheetTypes';

import React from 'react';

const View = require('../Components/View/View');
const StyleSheet = require('../StyleSheet/StyleSheet');
const Text = require('../Text/Text');
const React = require('react');

class StyleInspector extends React.Component<$FlowFixMeProps> {
render(): React.Node {
if (!this.props.style) {
return <Text style={styles.noStyle}>No style</Text>;
}
const names = Object.keys(this.props.style);
return (
<View style={styles.container}>
<View>
{names.map(name => (
<Text key={name} style={styles.attr}>
{name}:
</Text>
))}
</View>
type Props = $ReadOnly<{
style?: ?____FlattenStyleProp_Internal<ViewStyleProp>,
}>;

<View>
{names.map(name => {
const value = this.props.style[name];
return (
<Text key={name} style={styles.value}>
{typeof value !== 'string' && typeof value !== 'number'
? JSON.stringify(value)
: value}
</Text>
);
})}
</View>
</View>
);
function StyleInspector({style}: Props): React.Node {
if (!style) {
return <Text style={styles.noStyle}>No style</Text>;
}
const names = Object.keys(style);
return (
<View style={styles.container}>
<View>
{names.map(name => (
<Text key={name} style={styles.attr}>
{name}:
</Text>
))}
</View>

<View>
{names.map(name => {
const value = style?.[name];
return (
<Text key={name} style={styles.value}>
{typeof value !== 'string' && typeof value !== 'number'
? JSON.stringify(value)
: value}
</Text>
);
})}
</View>
</View>
);
}

const styles = StyleSheet.create({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5324,10 +5324,10 @@ declare export default function ReactDevToolsOverlay(Props): React.Node;
`;

exports[`public API should not change unintentionally Libraries/Inspector/StyleInspector.js 1`] = `
"declare const React: $FlowFixMe;
declare class StyleInspector extends React.Component<$FlowFixMeProps> {
render(): React.Node;
}
"type Props = $ReadOnly<{
style?: ?____FlattenStyleProp_Internal<ViewStyleProp>,
}>;
declare function StyleInspector(Props): React.Node;
declare module.exports: StyleInspector;
"
`;
Expand Down
Loading