diff --git a/Libraries/Inspector/ElementBox.js b/Libraries/Inspector/ElementBox.js index d360485bcbe5f5..36327fb31ab57b 100644 --- a/Libraries/Inspector/ElementBox.js +++ b/Libraries/Inspector/ElementBox.js @@ -14,6 +14,7 @@ const BorderBox = require('BorderBox'); const React = require('React'); const StyleSheet = require('StyleSheet'); const View = require('View'); +const Dimensions = require('Dimensions'); const flattenStyle = require('flattenStyle'); const resolveBoxStyle = require('resolveBoxStyle'); @@ -21,8 +22,8 @@ const resolveBoxStyle = require('resolveBoxStyle'); class ElementBox extends React.Component<$FlowFixMeProps> { render() { const style = flattenStyle(this.props.style) || {}; - const margin = resolveBoxStyle('margin', style); - const padding = resolveBoxStyle('padding', style); + let margin = resolveBoxStyle('margin', style); + let padding = resolveBoxStyle('padding', style); const frameStyle = {...this.props.frame}; const contentStyle = { @@ -31,6 +32,8 @@ class ElementBox extends React.Component<$FlowFixMeProps> { }; if (margin != null) { + margin = resolveRelativeSizes(margin); + frameStyle.top -= margin.top; frameStyle.left -= margin.left; frameStyle.height += margin.top + margin.bottom; @@ -51,6 +54,8 @@ class ElementBox extends React.Component<$FlowFixMeProps> { } if (padding != null) { + padding = resolveRelativeSizes(padding); + contentStyle.width -= padding.left + padding.right; contentStyle.height -= padding.top + padding.bottom; } @@ -82,4 +87,51 @@ const styles = StyleSheet.create({ }, }); +type Style = { + top: number, + right: number, + bottom: number, + left: number, +}; + +/** + * Resolves relative sizes (percentages and auto) in a style object. + * + * @param style the style to resolve + * @return a modified copy + */ +function resolveRelativeSizes(style: $ReadOnly