Skip to content

Instantly share code, notes, and snippets.

@micimize
Created August 26, 2018 02:38
Show Gist options
  • Save micimize/f095ca606880da626cd562ce7c5c7a3a to your computer and use it in GitHub Desktop.
Save micimize/f095ca606880da626cd562ce7c5c7a3a to your computer and use it in GitHub Desktop.
monkey patch for react-native inspector problems
/**
* Copyright (c) 2015-present, Facebook, Inc.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*
* @providesModule resolveBoxStyle
* @flow
*/
'use strict';
/**
* Resolve a style property into it's component parts, e.g.
*
* resolveProperties('margin', {margin: 5, marginBottom: 10})
* ->
* {top: 5, left: 5, right: 5, bottom: 10}
*
* If none are set, returns false.
*/
function resolveBoxStyle(prefix: string, style: Object): ?Object {
var res = {};
var subs = ['top', 'left', 'bottom', 'right'];
var set = false;
subs.forEach(sub => {
res[sub] = safe(style[prefix] || 0);
});
if (style[prefix]) {
set = true;
}
if (style[prefix + 'Vertical']) {
res.top = res.bottom = safe(style[prefix + 'Vertical']);
set = true;
}
if (style[prefix + 'Horizontal']) {
res.left = res.right = safe(style[prefix + 'Horizontal']);
set = true;
}
subs.forEach(sub => {
var val = safe(style[prefix + capFirst(sub)]);
if (val) {
res[sub] = val;
set = true;
}
});
if (!set) {
return;
}
return res;
}
function capFirst(text) {
return text[0].toUpperCase() + text.slice(1);
}
function safe(num){
return typeof num === 'number' ? num : 0
}
module.exports = resolveBoxStyle;
@micimize
Copy link
Author

replace node_modules/react-native/Libraries/Inspector/resolveBoxStyle.js with this and you should be able to inspect elements (you won't see padding or margin for % or auto elements)

The only change is the safe function

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment