Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import androidx.activity.result.ActivityResultLauncher
import androidx.activity.result.contract.ActivityResultContracts.RequestMultiplePermissions
import androidx.activity.result.contract.ActivityResultContracts.RequestPermission
import androidx.activity.result.contract.ActivityResultContracts.StartActivityForResult
import androidx.fragment.app.DialogFragment
import androidx.lifecycle.Lifecycle.State.STARTED
import androidx.lifecycle.findViewTreeLifecycleOwner
import androidx.lifecycle.lifecycleScope
Expand Down Expand Up @@ -444,7 +445,8 @@ internal class HotwireWebFragmentDelegate(

private suspend fun screenshotView() {
hotwireView?.let {
screenshotHolder.captureScreenshot(it)
val window = (navDestination.fragment as? DialogFragment)?.dialog?.window
screenshotHolder.captureScreenshot(it, window)
screenshotHolder.showScreenshotIfAvailable(it)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import android.os.Handler
import android.os.Looper
import android.view.PixelCopy
import android.view.View
import android.view.Window
import dev.hotwire.navigation.logging.logError
import dev.hotwire.navigation.logging.logDebug
import dev.hotwire.navigation.views.HotwireView
Expand All @@ -35,16 +36,16 @@ internal class HotwireViewScreenshotHolder {
}
}

suspend fun captureScreenshot(hotwireView: HotwireView) {
bitmap = copyViewToBitmap(hotwireView)
suspend fun captureScreenshot(hotwireView: HotwireView, window: Window? = null) {
val screenshotWindow = window ?: hotwireView.getActivity()?.window
bitmap = copyViewToBitmap(hotwireView, screenshotWindow)
screenshotOrientation = hotwireView.currentOrientation()
screenshotZoomed = currentlyZoomed
}

private suspend fun copyViewToBitmap(hotwireView: HotwireView): Bitmap? {
private suspend fun copyViewToBitmap(hotwireView: HotwireView, window: Window?): Bitmap? {
return suspendCancellableCoroutine { continuation ->
val start = System.currentTimeMillis()
val window = hotwireView.getActivity()?.window

if (window == null || !hotwireView.isLaidOut || !hasEnoughMemoryForScreenshot() ||
hotwireView.width <= 0 || hotwireView.height <= 0
Expand Down Expand Up @@ -112,4 +113,4 @@ internal class HotwireViewScreenshotHolder {
}
return null
}
}
}
Loading