mirror of
https://github.com/status-im/react-native.git
synced 2025-01-09 17:15:54 +00:00
3683beb88a
Reviewed By: kentaromiura Differential Revision: D4026114 fbshipit-source-id: 67808af91454d95941fea01eef58a4d9086f46e1
43 lines
1.1 KiB
JavaScript
43 lines
1.1 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) {
|
|
return ReactNativeComponentTree.getInstanceFromNode(nativeTag);
|
|
}
|
|
|
|
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};
|