Skip to content

Commit

Permalink
Formatting & renaming
Browse files Browse the repository at this point in the history
  • Loading branch information
mbarta committed Jan 9, 2025
1 parent c6c3527 commit 4c7bd0f
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 21 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,8 @@ internal class HotwireWebFragmentDelegate(
private val screenshotHolder = HotwireViewScreenshotHolder()
private val navigator get() = navDestination.navigator
private val session get() = navigator.session
private val turboView get() = callback.hotwireView
private val viewTreeLifecycleOwner get() = turboView?.findViewTreeLifecycleOwner()
private val hotwireView get() = callback.hotwireView
private val viewTreeLifecycleOwner get() = hotwireView?.findViewTreeLifecycleOwner()

/**
* Get the session's WebView instance
Expand Down Expand Up @@ -137,7 +137,7 @@ internal class HotwireWebFragmentDelegate(
fun refresh(displayProgress: Boolean) {
if (webView.url == null) return

turboView?.webViewRefresh?.apply {
hotwireView?.webViewRefresh?.apply {
if (displayProgress && !isRefreshing) {
isRefreshing = true
}
Expand All @@ -151,7 +151,7 @@ internal class HotwireWebFragmentDelegate(
* Displays the error view that's implemented via [HotwireWebFragmentCallback.createErrorView].
*/
fun showErrorView(error: VisitError) {
turboView?.addErrorView(callback.createErrorView(error))
hotwireView?.addErrorView(callback.createErrorView(error))
}

// -----------------------------------------------------------------------
Expand Down Expand Up @@ -275,7 +275,7 @@ internal class HotwireWebFragmentDelegate(

private fun initView() {
screenshotHolder.currentlyZoomed = false
turboView?.let {
hotwireView?.let {
initializePullToRefresh(it)
initializeErrorPullToRefresh(it)

Expand All @@ -289,7 +289,7 @@ internal class HotwireWebFragmentDelegate(
}

private fun attachWebView(onReady: (Boolean) -> Unit = {}) {
val view = turboView
val view = hotwireView

if (view == null) {
onReady(false)
Expand All @@ -316,7 +316,7 @@ internal class HotwireWebFragmentDelegate(
val webView = webView
screenshotView()

turboView?.detachWebView(webView) {
hotwireView?.detachWebView(webView) {
callback.onWebViewDetached(webView)
onReady()
}
Expand Down Expand Up @@ -345,7 +345,7 @@ internal class HotwireWebFragmentDelegate(

private fun webViewIsAttached(): Boolean {
val webView = webView
return turboView?.webViewIsAttached(webView) ?: false
return hotwireView?.webViewIsAttached(webView) ?: false
}

private fun title(): String {
Expand Down Expand Up @@ -406,14 +406,14 @@ internal class HotwireWebFragmentDelegate(
}

private suspend fun screenshotView() {
turboView?.let {
hotwireView?.let {
screenshotHolder.captureScreenshot(it)
screenshotHolder.showScreenshotIfAvailable(it)
}
}

private fun showProgressView(location: String) {
turboView?.addProgressView(callback.createProgressView(location))
hotwireView?.addProgressView(callback.createProgressView(location))
}

private fun initializePullToRefresh(hotwireView: HotwireView) {
Expand All @@ -434,15 +434,15 @@ internal class HotwireWebFragmentDelegate(
}

private fun pullToRefreshEnabled(enabled: Boolean) {
turboView?.webViewRefresh?.isEnabled = enabled
hotwireView?.webViewRefresh?.isEnabled = enabled
}

private fun removeTransitionalViews() {
turboView?.webViewRefresh?.isRefreshing = false
turboView?.errorRefresh?.isRefreshing = false
turboView?.removeProgressView()
turboView?.removeScreenshot()
turboView?.removeErrorView()
hotwireView?.webViewRefresh?.isRefreshing = false
hotwireView?.errorRefresh?.isRefreshing = false
hotwireView?.removeProgressView()
hotwireView?.removeScreenshot()
hotwireView?.removeErrorView()
}

private fun generateIdentifier(): Int {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ import dev.hotwire.navigation.logging.logEvent
import dev.hotwire.navigation.views.HotwireView
import kotlinx.coroutines.ExperimentalCoroutinesApi
import kotlinx.coroutines.suspendCancellableCoroutine
import java.security.AccessController.getContext

internal class HotwireViewScreenshotHolder {
private var bitmap: Bitmap? = null
Expand Down Expand Up @@ -47,7 +46,9 @@ internal class HotwireViewScreenshotHolder {
val start = System.currentTimeMillis()
val window = hotwireView.getActivity()?.window

if (window == null || !hotwireView.isLaidOut || !hasEnoughMemoryForScreenshot() || (hotwireView.width <= 0 || hotwireView.height <= 0)) {
if (window == null || !hotwireView.isLaidOut || !hasEnoughMemoryForScreenshot() ||
hotwireView.width <= 0 || hotwireView.height <= 0
) {
if (continuation.isActive) {
continuation.resume(null, null)
}
Expand All @@ -61,9 +62,7 @@ internal class HotwireViewScreenshotHolder {

try {
PixelCopy.request(
window,
rect,
bitmap,
window, rect, bitmap,
{ result ->
if (result == PixelCopy.SUCCESS) {
logEvent(
Expand Down

0 comments on commit 4c7bd0f

Please sign in to comment.