2015-05-26 18:16:25 +00:00
|
|
|
/**
|
|
|
|
* 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.
|
|
|
|
*
|
[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)
2015-06-11 20:50:48 +00:00
|
|
|
* @providesModule InspectorUtils
|
2015-05-26 18:16:25 +00:00
|
|
|
*/
|
|
|
|
'use strict';
|
|
|
|
|
2016-11-04 12:40:26 +00:00
|
|
|
var ReactNativeComponentTree = require('ReactNativeComponentTree');
|
2015-05-26 18:16:25 +00:00
|
|
|
|
|
|
|
function traverseOwnerTreeUp(hierarchy, instance) {
|
|
|
|
if (instance) {
|
|
|
|
hierarchy.unshift(instance);
|
|
|
|
traverseOwnerTreeUp(hierarchy, instance._currentElement._owner);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-06-08 21:30:48 +00:00
|
|
|
function findInstanceByNativeTag(nativeTag) {
|
2017-02-08 22:38:37 +00:00
|
|
|
var instance = ReactNativeComponentTree.getInstanceFromNode(nativeTag);
|
2017-02-21 23:37:10 +00:00
|
|
|
if (!instance || typeof instance.tag === 'number') {
|
2017-02-08 22:38:37 +00:00
|
|
|
// TODO(sema): We've disabled the inspector when using Fiber. Fix #15953531
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
return instance;
|
2015-05-26 18:16:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
function getOwnerHierarchy(instance) {
|
|
|
|
var hierarchy = [];
|
|
|
|
traverseOwnerTreeUp(hierarchy, instance);
|
|
|
|
return hierarchy;
|
|
|
|
}
|
|
|
|
|
2016-05-26 17:43:51 +00:00
|
|
|
function lastNotNativeInstance(hierarchy) {
|
|
|
|
for (let i = hierarchy.length - 1; i > 1; i--) {
|
|
|
|
const instance = hierarchy[i];
|
|
|
|
if (!instance.viewConfig) {
|
|
|
|
return instance;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return hierarchy[0];
|
|
|
|
}
|
|
|
|
|
|
|
|
module.exports = {findInstanceByNativeTag, getOwnerHierarchy, lastNotNativeInstance};
|