react-native/Libraries/Inspector/InspectorUtils.js
Kevin Gozali fa34035def work around inspector redbox due to Fiber
Summary: This temporarily fixes redbox when using Inspector before Fiber is fully ready.

Reviewed By: sebmarkbage

Differential Revision: D4593324

fbshipit-source-id: 287df97f5ecf30c15890f7f7bca4646421bb41c8
2017-02-21 15:45:45 -08:00

48 lines
1.3 KiB
JavaScript

/**
* 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 InspectorUtils
*/
'use strict';
var ReactNativeComponentTree = require('ReactNativeComponentTree');
function traverseOwnerTreeUp(hierarchy, instance) {
if (instance) {
hierarchy.unshift(instance);
traverseOwnerTreeUp(hierarchy, instance._currentElement._owner);
}
}
function findInstanceByNativeTag(nativeTag) {
var instance = ReactNativeComponentTree.getInstanceFromNode(nativeTag);
if (!instance || typeof instance.tag === 'number') {
// TODO(sema): We've disabled the inspector when using Fiber. Fix #15953531
return null;
}
return instance;
}
function getOwnerHierarchy(instance) {
var hierarchy = [];
traverseOwnerTreeUp(hierarchy, instance);
return hierarchy;
}
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};