Skip to content
Closed
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
102 changes: 60 additions & 42 deletions packages/react-native/Libraries/Inspector/BoxInspector.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,15 @@

'use strict';

import type {TextStyleProp, ViewStyleProp} from '../StyleSheet/StyleSheet';
import type {InspectedElementFrame} from './Inspector';

import React from 'react';

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

const blank = {
top: 0,
Expand All @@ -23,51 +27,65 @@ const blank = {
bottom: 0,
};

class BoxInspector extends React.Component<$FlowFixMeProps> {
render(): React.Node {
const frame = this.props.frame;
const style = this.props.style;
const margin = (style && resolveBoxStyle('margin', style)) || blank;
const padding = (style && resolveBoxStyle('padding', style)) || blank;
return (
<BoxContainer title="margin" titleStyle={styles.marginLabel} box={margin}>
<BoxContainer title="padding" box={padding}>
<View>
<Text style={styles.innerText}>
({(frame.left || 0).toFixed(1)}, {(frame.top || 0).toFixed(1)})
</Text>
<Text style={styles.innerText}>
{(frame.width || 0).toFixed(1)} &times;{' '}
{(frame.height || 0).toFixed(1)}
</Text>
</View>
</BoxContainer>
</BoxContainer>
);
}
}
type BoxInspectorProps = $ReadOnly<{
style: ViewStyleProp,
frame: ?InspectedElementFrame,
}>;

function BoxInspector({style, frame}: BoxInspectorProps): React.Node {
const margin = (style && resolveBoxStyle('margin', style)) || blank;
const padding = (style && resolveBoxStyle('padding', style)) || blank;

class BoxContainer extends React.Component<$FlowFixMeProps> {
render(): React.Node {
const box = this.props.box;
return (
<View style={styles.box}>
<View style={styles.row}>
{}
<Text style={[this.props.titleStyle, styles.label]}>
{this.props.title}
return (
<BoxContainer title="margin" titleStyle={styles.marginLabel} box={margin}>
<BoxContainer title="padding" box={padding}>
<View>
<Text style={styles.innerText}>
({(frame?.left || 0).toFixed(1)}, {(frame?.top || 0).toFixed(1)})
</Text>
<Text style={styles.innerText}>
{(frame?.width || 0).toFixed(1)} &times;{' '}
{(frame?.height || 0).toFixed(1)}
</Text>
<Text style={styles.boxText}>{box.top}</Text>
</View>
<View style={styles.row}>
<Text style={styles.boxText}>{box.left}</Text>
{this.props.children}
<Text style={styles.boxText}>{box.right}</Text>
</View>
<Text style={styles.boxText}>{box.bottom}</Text>
</BoxContainer>
</BoxContainer>
);
}

type BoxContainerProps = $ReadOnly<{
title: string,
titleStyle?: TextStyleProp,
box: $ReadOnly<{
top: number,
left: number,
right: number,
bottom: number,
}>,
children: React.Node,
}>;

function BoxContainer({
title,
titleStyle,
box,
children,
}: BoxContainerProps): React.Node {
return (
<View style={styles.box}>
<View style={styles.row}>
{}
<Text style={[titleStyle, styles.label]}>{title}</Text>
<Text style={styles.boxText}>{box.top}</Text>
</View>
<View style={styles.row}>
<Text style={styles.boxText}>{box.left}</Text>
{children}
<Text style={styles.boxText}>{box.right}</Text>
</View>
);
}
<Text style={styles.boxText}>{box.bottom}</Text>
</View>
);
}

const styles = StyleSheet.create({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5159,10 +5159,11 @@ declare module.exports: BorderBox;
`;

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