Skip to content

Commit

Permalink
fix: issue on bridgeless when accessing ReactContext (preparing RN74) (
Browse files Browse the repository at this point in the history
  • Loading branch information
alanjhughes committed Mar 28, 2024
1 parent b989bd6 commit ab420a0
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 2 deletions.
Expand Up @@ -21,6 +21,7 @@
import com.facebook.react.bridge.CatalystInstance;
import com.facebook.react.bridge.JavaScriptModule;
import com.facebook.react.bridge.LifecycleEventListener;
import com.facebook.react.bridge.ReactApplicationContext;
import com.facebook.react.bridge.WritableMap;
import com.facebook.react.bridge.WritableNativeArray;
import com.facebook.react.bridge.WritableNativeMap;
Expand Down Expand Up @@ -391,6 +392,10 @@ public ThemedReactContext getThemedReactContext() {
return (ThemedReactContext) this.getContext();
}

public ReactApplicationContext getReactApplicationContext() {
return this.getThemedReactContext().getReactApplicationContext();
}

protected class RNCWebViewBridge {
private String TAG = "RNCWebViewBridge";
RNCWebView mWebView;
Expand Down
Expand Up @@ -87,7 +87,7 @@ public void onPageStarted(WebView webView, String url, Bitmap favicon) {
@Override
public boolean shouldOverrideUrlLoading(WebView view, String url) {
final RNCWebView rncWebView = (RNCWebView) view;
final boolean isJsDebugging = ((ReactContext) view.getContext()).getJavaScriptContextHolder().get() == 0;
final boolean isJsDebugging = rncWebView.getReactApplicationContext().getJavaScriptContextHolder().get() == 0;

if (!isJsDebugging && rncWebView.mMessagingJSModule != null) {
final Pair<Double, AtomicReference<RNCWebViewModuleImpl.ShouldOverrideUrlLoadingLock.ShouldOverrideCallbackState>> lock = RNCWebViewModuleImpl.shouldOverrideUrlLoadingLock.getNewLock();
Expand Down
Expand Up @@ -92,7 +92,7 @@ class RNCWebViewManagerImpl {
}
webView.setDownloadListener(DownloadListener { url, userAgent, contentDisposition, mimetype, contentLength ->
webView.setIgnoreErrFailedForThisURL(url)
val module = webView.themedReactContext.getNativeModule(RNCWebViewModule::class.java) ?: return@DownloadListener
val module = webView.reactApplicationContext.getNativeModule(RNCWebViewModule::class.java) ?: return@DownloadListener
val request: DownloadManager.Request = try {
DownloadManager.Request(Uri.parse(url))
} catch (e: IllegalArgumentException) {
Expand Down

0 comments on commit ab420a0

Please sign in to comment.