From f220bb6226ab7d0c5f14058121da1d2cb672e398 Mon Sep 17 00:00:00 2001 From: Mahdi Hosseinzadeh Date: Sat, 10 Feb 2024 12:17:52 +0330 Subject: [PATCH] Initial commit --- .../multiplatform/comshot/Comshot.android.kt | 13 ++++++++----- .../ir/mahozad/multiplatform/comshot/Comshot.kt | 2 ++ 2 files changed, 10 insertions(+), 5 deletions(-) diff --git a/library/src/androidMain/kotlin/ir/mahozad/multiplatform/comshot/Comshot.android.kt b/library/src/androidMain/kotlin/ir/mahozad/multiplatform/comshot/Comshot.android.kt index 87a9246..4828953 100644 --- a/library/src/androidMain/kotlin/ir/mahozad/multiplatform/comshot/Comshot.android.kt +++ b/library/src/androidMain/kotlin/ir/mahozad/multiplatform/comshot/Comshot.android.kt @@ -88,9 +88,13 @@ fun Activity.captureToImageeee(comcon: CompositionContext, content: @Composable composeView.createComposition() composeView.setContent(content) // composeView.setBackgroundColor(android.graphics.Color.BLUE) + + // Trigger rendering of the composable; only needed for ComposeView; not needed for other view types like TextView + // setContentView(composeView) + addContentView(composeView, ViewGroup.LayoutParams(10000, 10000)) composeView.measure( - View.MeasureSpec.makeMeasureSpec(500, View.MeasureSpec.EXACTLY), - View.MeasureSpec.makeMeasureSpec(500, View.MeasureSpec.EXACTLY), + View.MeasureSpec.makeMeasureSpec(10000, View.MeasureSpec.AT_MOST), + View.MeasureSpec.makeMeasureSpec(10000, View.MeasureSpec.AT_MOST), ) composeView.layout( 0, @@ -98,15 +102,14 @@ fun Activity.captureToImageeee(comcon: CompositionContext, content: @Composable composeView.measuredWidth, composeView.measuredHeight ) - // this.setContentView(composeView) - // this.addContentView(composeView, ViewGroup.LayoutParams(0, 0)) @OptIn(InternalComposeUiApi::class) composeView.showLayoutBounds = true println("width: ${composeView.measuredWidth} height: ${composeView.measuredHeight}") println("hasComposition: ${composeView.hasComposition}") val bitmap = Bitmap.createBitmap( - composeView.measuredWidth, composeView.measuredHeight, + composeView.measuredWidth, + composeView.measuredHeight, Bitmap.Config.ARGB_8888 ) val canvas = Canvas(bitmap) diff --git a/library/src/commonMain/kotlin/ir/mahozad/multiplatform/comshot/Comshot.kt b/library/src/commonMain/kotlin/ir/mahozad/multiplatform/comshot/Comshot.kt index 06dd9c1..f31744e 100644 --- a/library/src/commonMain/kotlin/ir/mahozad/multiplatform/comshot/Comshot.kt +++ b/library/src/commonMain/kotlin/ir/mahozad/multiplatform/comshot/Comshot.kt @@ -33,6 +33,8 @@ // https://stackoverflow.com/questions/1240967/draw-inflated-layout-xml-on-an-bitmap // https://stackoverflow.com/questions/9062015/create-bitmap-of-layout-that-is-off-screen // https://stackoverflow.com/questions/2661536/how-to-programmatically-take-a-screenshot-on-android +// https://stackoverflow.com/questions/29797590/android-webview-offscreen-rendering +// https://stackoverflow.com/questions/14631682/creating-and-using-a-fragments-view-whilst-not-visible-to-the-user /** * The compose-multiplatform-core/compose/ui/ui-test-junit4 depends on compose-multiplatform-core/compose/ui/ui-test