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
103 changes: 55 additions & 48 deletions packages/react-native/Libraries/Inspector/ElementBox.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,65 +10,72 @@

'use strict';

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

import React from 'react';

const View = require('../Components/View/View');
const flattenStyle = require('../StyleSheet/flattenStyle');
const StyleSheet = require('../StyleSheet/StyleSheet');
const Dimensions = require('../Utilities/Dimensions').default;
const BorderBox = require('./BorderBox');
const resolveBoxStyle = require('./resolveBoxStyle');
const React = require('react');

class ElementBox extends React.Component<$FlowFixMeProps> {
render(): React.Node {
const style = flattenStyle(this.props.style) || {};
let margin: ?$ReadOnly<Style> = resolveBoxStyle('margin', style);
let padding: ?$ReadOnly<Style> = resolveBoxStyle('padding', style);

const frameStyle = {...this.props.frame};
const contentStyle: {width: number, height: number} = {
width: this.props.frame.width,
height: this.props.frame.height,
};

if (margin != null) {
margin = resolveRelativeSizes(margin);

frameStyle.top -= margin.top;
frameStyle.left -= margin.left;
frameStyle.height += margin.top + margin.bottom;
frameStyle.width += margin.left + margin.right;

if (margin.top < 0) {
contentStyle.height += margin.top;
}
if (margin.bottom < 0) {
contentStyle.height += margin.bottom;
}
if (margin.left < 0) {
contentStyle.width += margin.left;
}
if (margin.right < 0) {
contentStyle.width += margin.right;
}
}

if (padding != null) {
padding = resolveRelativeSizes(padding);
type Props = $ReadOnly<{
frame: InspectedElementFrame,
style?: ?ViewStyleProp,
}>;

function ElementBox({frame, style}: Props): React.Node {
const flattenedStyle = flattenStyle(style) || {};
let margin: ?$ReadOnly<Style> = resolveBoxStyle('margin', flattenedStyle);
let padding: ?$ReadOnly<Style> = resolveBoxStyle('padding', flattenedStyle);

contentStyle.width -= padding.left + padding.right;
contentStyle.height -= padding.top + padding.bottom;
const frameStyle = {...frame};
const contentStyle: {width: number, height: number} = {
width: frame.width,
height: frame.height,
};

if (margin != null) {
margin = resolveRelativeSizes(margin);

frameStyle.top -= margin.top;
frameStyle.left -= margin.left;
frameStyle.height += margin.top + margin.bottom;
frameStyle.width += margin.left + margin.right;

if (margin.top < 0) {
contentStyle.height += margin.top;
}
if (margin.bottom < 0) {
contentStyle.height += margin.bottom;
}
if (margin.left < 0) {
contentStyle.width += margin.left;
}
if (margin.right < 0) {
contentStyle.width += margin.right;
}
}

return (
<View style={[styles.frame, frameStyle]} pointerEvents="none">
<BorderBox box={margin} style={styles.margin}>
<BorderBox box={padding} style={styles.padding}>
<View style={[styles.content, contentStyle]} />
</BorderBox>
</BorderBox>
</View>
);
if (padding != null) {
padding = resolveRelativeSizes(padding);

contentStyle.width -= padding.left + padding.right;
contentStyle.height -= padding.top + padding.bottom;
}

return (
<View style={[styles.frame, frameStyle]} pointerEvents="none">
<BorderBox box={margin} style={styles.margin}>
<BorderBox box={padding} style={styles.padding}>
<View style={[styles.content, contentStyle]} />
</BorderBox>
</BorderBox>
</View>
);
}

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

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