Skip to content

Commit

Permalink
Merge pull request #50 from pklatka/@pklatka/progress-screen-android
Browse files Browse the repository at this point in the history
Fix native ActivityIndicator not being shown on Android
  • Loading branch information
pklatka authored Nov 17, 2023
2 parents e07f21a + 5e14420 commit 83594be
Showing 1 changed file with 18 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package com.reactnativeturbowebview

import android.content.Context
import android.graphics.Bitmap
import android.util.Log
import android.view.ViewGroup
import android.webkit.CookieManager
import android.widget.LinearLayout
Expand Down Expand Up @@ -180,7 +179,7 @@ class RNVisitableView(context: Context, sessionModule: RNVisitableViewModule) :
override fun detachWebView(onReady: () -> Unit) {
screenshotView()

(session.webView.parent as ViewGroup)?.endViewTransition(session.webView)
(session.webView.parent as ViewGroup?)?.endViewTransition(session.webView)

webViewContainer.post {
webViewContainer.removeAllViews()
Expand Down Expand Up @@ -209,15 +208,30 @@ class RNVisitableView(context: Context, sessionModule: RNVisitableViewModule) :
}
}

/*
* Fixes a bug in React Native, causing improper layout of the TurboView and its children.
* Refer to https://github.com/facebook/react-native/issues/17968 for the detailed issue discussion and context.
*/
override fun requestLayout() {
super.requestLayout()
post(measureAndLayout)
}

private val measureAndLayout = Runnable {
measure(
MeasureSpec.makeMeasureSpec(width, MeasureSpec.EXACTLY),
MeasureSpec.makeMeasureSpec(height, MeasureSpec.EXACTLY)
)
layout(left, top, right, bottom)
}

/**
* Fixes initial size of WebView
*/
override fun onLayout(changed: Boolean, left: Int, top: Int, right: Int, bottom: Int) {
super.onLayout(changed, left, top, right, bottom)
val width = right - left
val height = bottom - top
webView.layout(0, 0, width, height)
turboView.layout(0, 0, width, height)
screenshotView.layout(0, 0, width, height)
}

Expand Down

0 comments on commit 83594be

Please sign in to comment.