7
7
import android .net .Uri ;
8
8
import android .view .View ;
9
9
10
+ import androidx .annotation .UiThread ;
11
+
10
12
import com .facebook .react .bridge .Arguments ;
11
13
import com .facebook .react .bridge .Callback ;
12
14
import com .facebook .react .bridge .Promise ;
17
19
import com .facebook .react .bridge .WritableMap ;
18
20
import com .facebook .react .bridge .WritableNativeArray ;
19
21
import com .facebook .react .bridge .WritableNativeMap ;
20
- import com .facebook .react .uimanager .NativeViewHierarchyManager ;
21
- import com .facebook .react .uimanager .UIBlock ;
22
22
import com .facebook .react .uimanager .UIManagerModule ;
23
23
import com .instabug .library .Feature ;
24
24
import com .instabug .library .Instabug ;
@@ -899,24 +899,32 @@ public void networkLog(String jsonObject) throws JSONException {
899
899
networkLog .insert ();
900
900
}
901
901
902
+ @ UiThread
903
+ @ Nullable
904
+ private View resolveReactView (final int reactTag ) {
905
+ final ReactApplicationContext reactContext = getReactApplicationContext ();
906
+ final UIManagerModule uiManagerModule = reactContext .getNativeModule (UIManagerModule .class );
907
+
908
+ if (uiManagerModule == null ) {
909
+ return null ;
910
+ }
911
+
912
+ return uiManagerModule .resolveView (reactTag );
913
+ }
914
+
902
915
903
916
@ ReactMethod
904
917
public void addPrivateView (final int reactTag ) {
905
918
MainThreadHandler .runOnMainThread (new Runnable () {
906
919
@ Override
907
920
public void run () {
908
- UIManagerModule uiManagerModule = getReactApplicationContext ().getNativeModule (UIManagerModule .class );
909
- uiManagerModule .prependUIBlock (new UIBlock () {
910
- @ Override
911
- public void execute (NativeViewHierarchyManager nativeViewHierarchyManager ) {
912
- try {
913
- final View view = nativeViewHierarchyManager .resolveView (reactTag );
914
- Instabug .addPrivateViews (view );
915
- } catch (Exception e ) {
916
- e .printStackTrace ();
917
- }
918
- }
919
- });
921
+ try {
922
+ final View view = resolveReactView (reactTag );
923
+
924
+ Instabug .addPrivateViews (view );
925
+ } catch (Exception e ) {
926
+ e .printStackTrace ();
927
+ }
920
928
}
921
929
});
922
930
}
@@ -926,18 +934,13 @@ public void removePrivateView(final int reactTag) {
926
934
MainThreadHandler .runOnMainThread (new Runnable () {
927
935
@ Override
928
936
public void run () {
929
- UIManagerModule uiManagerModule = getReactApplicationContext ().getNativeModule (UIManagerModule .class );
930
- uiManagerModule .prependUIBlock (new UIBlock () {
931
- @ Override
932
- public void execute (NativeViewHierarchyManager nativeViewHierarchyManager ) {
933
- try {
934
- final View view = nativeViewHierarchyManager .resolveView (reactTag );
935
- Instabug .removePrivateViews (view );
936
- } catch (Exception e ) {
937
- e .printStackTrace ();
938
- }
939
- }
940
- });
937
+ try {
938
+ final View view = resolveReactView (reactTag );
939
+
940
+ Instabug .removePrivateViews (view );
941
+ } catch (Exception e ) {
942
+ e .printStackTrace ();
943
+ }
941
944
}
942
945
});
943
946
}
0 commit comments