From 46f3285a3f240f9325a548e677a1927402d76bd7 Mon Sep 17 00:00:00 2001 From: TranLuongTuanAnh Date: Mon, 28 Jan 2019 01:57:04 -0800 Subject: [PATCH] Fix issue #21065 getInspectorDataForViewTag is not a function (#21237) Summary: Fix renderer.getInspectorDataForViewTag is not a function when try Toggle Inspector Fixes #21065 Release Notes: -------------- [BUGFIX] [MINOR] [/react-native/Libraries/Inspector/Inspector.js] Pull Request resolved: https://github.com/facebook/react-native/pull/21237 Differential Revision: D13838339 Pulled By: cpojer fbshipit-source-id: 363a4beba211e7868395578c7941cbda119bc753 --- Libraries/Inspector/Inspector.js | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/Libraries/Inspector/Inspector.js b/Libraries/Inspector/Inspector.js index 89cf1af9df877e..7e85c4d099eba1 100644 --- a/Libraries/Inspector/Inspector.js +++ b/Libraries/Inspector/Inspector.js @@ -47,14 +47,20 @@ function findRenderers(): $ReadOnlyArray { function getInspectorDataForViewTag(touchedViewTag: number) { for (let i = 0; i < renderers.length; i++) { const renderer = renderers[i]; - const inspectorData = renderer.getInspectorDataForViewTag(touchedViewTag); - if (inspectorData.hierarchy.length > 0) { - return inspectorData; + if ( + Object.prototype.hasOwnProperty.call( + renderer, + 'getInspectorDataForViewTag', + ) + ) { + const inspectorData = renderer.getInspectorDataForViewTag(touchedViewTag); + if (inspectorData.hierarchy.length > 0) { + return inspectorData; + } } } throw new Error('Expected to find at least one React renderer.'); } - class Inspector extends React.Component< { inspectedViewTag: ?number,