/**
 * 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.
 */

package com.facebook.react.uimanager;

import javax.annotation.Nullable;

import android.view.View;
import android.view.ViewGroup;

import com.facebook.react.bridge.UiThreadUtil;

import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;

public class ViewHierarchyDumper {

  public static @Nullable JSONObject toJSON(@Nullable View view) {
    UiThreadUtil.assertOnUiThread();
    if (view == null) {
      return null;
    }
    JSONObject result = new JSONObject();
    try {
      result.put("class", view.getClass().getSimpleName());
      Object tag = view.getTag();
      if (tag != null && tag instanceof String) {
        result.put("id", tag);
      }
      if (view instanceof ViewGroup) {
        ViewGroup viewGroup = (ViewGroup) view;
        if (viewGroup.getChildCount() > 0) {
          JSONArray children = new JSONArray();
          for (int i = 0; i < viewGroup.getChildCount(); i++) {
            children.put(i, toJSON(viewGroup.getChildAt(i)));
          }
          result.put("children", children);
        }
      }
    } catch (JSONException ex) {
      return null;
    }
    return result;
  }
}

@@ -346,43 +346,8 @@
 r;%0A%0A
-import javax.annotation.Nullable;%0A%0A
 impo
@@ -587,26 +587,16 @@
  static 
-@Nullable 
 JSONObje
@@ -609,18 +609,8 @@
 SON(
-@Nullable 
 View
@@ -615,16 +615,37 @@
 ew view)
+ throws JSONException
  %7B%0A    U
@@ -680,56 +680,8 @@
 ();%0A
-    if (view == null) %7B%0A      return null;%0A    %7D
 %0A   
@@ -723,20 +723,8 @@
 ();%0A
-    try %7B%0A  
     
@@ -735,21 +735,17 @@
 lt.put(%22
-class
+n
 %22, view.
@@ -762,14 +762,8 @@
 .get
-Simple
 Name
@@ -765,24 +765,74 @@
 tName());%0A  
+  result.put(%22i%22, System.identityHashCode(view));%0A
     Object t
@@ -847,26 +847,24 @@
 w.getTag();%0A
-  
     if (tag 
@@ -901,26 +901,24 @@
 ng) %7B%0A      
-  
 result.put(%22
@@ -917,18 +917,17 @@
 lt.put(%22
-id
+t
 %22, tag);
@@ -927,30 +927,27 @@
 , tag);%0A    
-  %7D%0A  
+%7D%0A%0A
     if (view
@@ -967,26 +967,24 @@
 iewGroup) %7B%0A
-  
       ViewGr
@@ -1023,18 +1023,16 @@
 ;%0A      
-  
 if (view
@@ -1056,26 +1056,24 @@
 nt() %3E 0) %7B%0A
-  
         JSON
@@ -1114,18 +1114,16 @@
         
-  
 for (int
@@ -1164,26 +1164,24 @@
 t(); i++) %7B%0A
-  
           ch
@@ -1232,30 +1232,26 @@
 ));%0A        
-  %7D%0A  
+%7D%0A
         resu
@@ -1259,23 +1259,16 @@
 t.put(%22c
-hildren
 %22, child
@@ -1283,77 +1283,16 @@
     
-  
 %7D%0A    
- 
- 
 %7D%0A
-    %7D catch (JSONException ex) %7B%0A      return null;%0A    %7D
 %0A   

Add custom error reporter in Groups