Skip to content

Commit

Permalink
fix: webview in stack (#607)
Browse files Browse the repository at this point in the history
Added check for if there is WebView on the screen we are transitioning to. If there is, we don't change the layer type in the stack navigator to avoid crash.
  • Loading branch information
WoLewicki authored Sep 29, 2020
1 parent c8312f5 commit 72c0209
Showing 1 changed file with 20 additions and 1 deletion.
21 changes: 20 additions & 1 deletion android/src/main/java/com/swmansion/rnscreens/Screen.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import android.view.ViewGroup;
import android.view.WindowManager;
import android.view.inputmethod.InputMethodManager;
import android.webkit.WebView;
import android.widget.TextView;

import androidx.annotation.Nullable;
Expand Down Expand Up @@ -151,7 +152,25 @@ public void setTransitioning(boolean transitioning) {
return;
}
mTransitioning = transitioning;
super.setLayerType(transitioning ? View.LAYER_TYPE_HARDWARE : View.LAYER_TYPE_NONE, null);
boolean isWebViewInScreen = hasWebView(this);
if (isWebViewInScreen && getLayerType() != View.LAYER_TYPE_HARDWARE) {
return;
}
super.setLayerType(transitioning && !isWebViewInScreen ? View.LAYER_TYPE_HARDWARE : View.LAYER_TYPE_NONE, null);
}

private boolean hasWebView(ViewGroup viewGroup) {
for(int i = 0; i < viewGroup.getChildCount(); i++) {
View child = viewGroup.getChildAt(i);
if (child instanceof WebView) {
return true;
} else if (child instanceof ViewGroup) {
if (hasWebView((ViewGroup) child)) {
return true;
}
}
}
return false;
}

public void setStackPresentation(StackPresentation stackPresentation) {
Expand Down

0 comments on commit 72c0209

Please sign in to comment.