mirror of
https://github.com/zhigang1992/react-native.git
synced 2026-03-26 07:04:05 +08:00
[ReactNative] refactor the inspector
Summary: The `InspectorOverlay` component was getting unwieldy, so I broke it into three components: - Inspector - InspectorOverlay - InspectorPanel and added @flow types. The inspector was also living under the `ReactIOS` directory, and I moved it up into the `Libraries` directory, as the inspector will soon be usable [on Android](https://phabricator.fb.com/D2138319). All features of the inspector should remain functional, with the addition of one feature: - you can toggle "touch to inspect" by tapping the "Inspect" button at the bottom of the inspection panel. When inspection is disabled, the panel remains, but you can interact with the app normally without touches being intercepted @public Test Plan: Open the inspector: - touch to inspect things, verify that margin, padding, size and position are reported correctly, and that the component hierarchy is navigable. - tap the "Inspect" button, and verify that you can interact with the app normally. {F22548949} [Video of toggling inspection](https://www.latest.facebook.com/pxlcld/mrs9)
This commit is contained in:
committed by
Spencer Ahrens
parent
ca33cbd4b9
commit
51e76fd166
59
Libraries/Inspector/resolveBoxStyle.js
Normal file
59
Libraries/Inspector/resolveBoxStyle.js
Normal file
@@ -0,0 +1,59 @@
|
||||
/**
|
||||
* Copyright (c) 2015-present, Facebook, Inc.
|
||||
* All rights reserved.
|
||||
*
|
||||
* This source code is licensed under the BSD-style license found in the
|
||||
* LICENSE file in the root directory of this source tree. An additional grant
|
||||
* of patent rights can be found in the PATENTS file in the same directory.
|
||||
*
|
||||
* @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] = style[prefix] || 0;
|
||||
});
|
||||
if (style[prefix]) {
|
||||
set = true;
|
||||
}
|
||||
if (style[prefix + 'Vertical']) {
|
||||
res.top = res.bottom = style[prefix + 'Vertical'];
|
||||
set = true;
|
||||
}
|
||||
if (style[prefix + 'Horizontal']) {
|
||||
res.left = res.right = style[prefix + 'Horizontal'];
|
||||
set = true;
|
||||
}
|
||||
subs.forEach(sub => {
|
||||
var val = 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);
|
||||
}
|
||||
|
||||
module.exports = resolveBoxStyle;
|
||||
|
||||
Reference in New Issue
Block a user