77import android .net .Uri ;
88import android .view .View ;
99
10+ import androidx .annotation .UiThread ;
11+
1012import com .facebook .react .bridge .Arguments ;
1113import com .facebook .react .bridge .Callback ;
1214import com .facebook .react .bridge .Promise ;
1719import com .facebook .react .bridge .WritableMap ;
1820import com .facebook .react .bridge .WritableNativeArray ;
1921import com .facebook .react .bridge .WritableNativeMap ;
20- import com .facebook .react .uimanager .NativeViewHierarchyManager ;
21- import com .facebook .react .uimanager .UIBlock ;
2222import com .facebook .react .uimanager .UIManagerModule ;
2323import com .instabug .library .Feature ;
2424import com .instabug .library .Instabug ;
@@ -899,24 +899,32 @@ public void networkLog(String jsonObject) throws JSONException {
899899 networkLog .insert ();
900900 }
901901
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+
902915
903916 @ ReactMethod
904917 public void addPrivateView (final int reactTag ) {
905918 MainThreadHandler .runOnMainThread (new Runnable () {
906919 @ Override
907920 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+ }
920928 }
921929 });
922930 }
@@ -926,18 +934,13 @@ public void removePrivateView(final int reactTag) {
926934 MainThreadHandler .runOnMainThread (new Runnable () {
927935 @ Override
928936 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+ }
941944 }
942945 });
943946 }
0 commit comments