Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit f23c022

Browse files
committed
[ReactNative] Send debug component ownership info in createView
1 parent 1373dab commit f23c022

File tree

2 files changed

+56
-0
lines changed

2 files changed

+56
-0
lines changed
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
/**
2+
* Copyright (c) 2015-present, Facebook, Inc.
3+
* All rights reserved.
4+
*
5+
* This source code is licensed under the BSD-style license found in the
6+
* LICENSE file in the root directory of this source tree. An additional grant
7+
* of patent rights can be found in the PATENTS file in the same directory.
8+
*
9+
* Utility class to provide the component owner hierarchy to native code for
10+
* debugging purposes.
11+
*
12+
* @providesModule RCTDebugComponentOwnership
13+
* @flow
14+
*/
15+
16+
'use strict';
17+
18+
var DebugComponentOwnershipModule = require('NativeModules').DebugComponentOwnershipModule;
19+
var InspectorUtils = require('InspectorUtils');
20+
var ReactNativeTagHandles = require('ReactNativeTagHandles');
21+
22+
function componentToString(component) {
23+
return component.getName ? component.getName() : 'Unknown';
24+
}
25+
26+
function getRootTagForTag(tag: number): ?number {
27+
var rootNodeID = ReactNativeTagHandles.tagToRootNodeID[tag];
28+
if (!rootNodeID) {
29+
return null;
30+
}
31+
var rootID = ReactNativeTagHandles.getNativeTopRootIDFromNodeID(rootNodeID);
32+
if (!rootID) {
33+
return null;
34+
}
35+
return ReactNativeTagHandles.rootNodeIDToTag[rootID];
36+
}
37+
38+
module.exports = {
39+
40+
/**
41+
* Asynchronously returns the owner hierarchy as an array of strings. Request id is
42+
* passed along to the native module so that the native module can identify the
43+
* particular call instance.
44+
*
45+
* Example returned owner hierarchy: ['RootView', 'Dialog', 'TitleView', 'Text']
46+
*/
47+
getOwnerHierarchy: function(requestID: number, tag: number) {
48+
var rootTag = getRootTagForTag(tag);
49+
var instance = InspectorUtils.findInstanceByNativeTag(rootTag, tag);
50+
var ownerHierarchy = instance ?
51+
InspectorUtils.getOwnerHierarchy(instance).map(componentToString) :
52+
null;
53+
DebugComponentOwnershipModule.receiveOwnershipHierarchy(requestID, tag, ownerHierarchy);
54+
},
55+
};

Libraries/JavaScriptAppEngine/Initialization/InitializeJavaScriptAppEngine.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
/* globals GLOBAL: true, window: true */
2424

2525
// Just to make sure the JS gets packaged up.
26+
require('RCTDebugComponentOwnership');
2627
require('RCTDeviceEventEmitter');
2728
require('PerformanceLogger');
2829

0 commit comments

Comments
 (0)