Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

🔧 This addresses the case where the image of the ProfileCard used for sharing on SNS etc. is corrupted in some cases. #928

Merged
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 @@ -5,6 +5,7 @@ import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.size
import androidx.compose.foundation.shape.RoundedCornerShape
import androidx.compose.runtime.Composable
import androidx.compose.runtime.CompositionLocalProvider
import androidx.compose.runtime.LaunchedEffect
import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableStateOf
Expand All @@ -18,6 +19,8 @@ import androidx.compose.ui.graphics.graphicsLayer
import androidx.compose.ui.graphics.layer.GraphicsLayer
import androidx.compose.ui.graphics.layer.drawLayer
import androidx.compose.ui.graphics.rememberGraphicsLayer
import androidx.compose.ui.platform.LocalDensity
import androidx.compose.ui.unit.Density
import androidx.compose.ui.unit.dp
import co.touchlab.kermit.Logger
import coil3.compose.AsyncImagePainter
Expand Down Expand Up @@ -58,19 +61,26 @@ internal fun BackgroundCapturableCardBack(
}
},
) {
FlipCardBack(
uiState,
qrCodeImagePainter,
modifier = Modifier
.size(width = 300.dp, height = 380.dp)
.border(
3.dp,
Color.Black,
RoundedCornerShape(8.dp),
)
.graphicsLayer {
rotationY = 180f
},
)
CompositionLocalProvider(
LocalDensity provides Density(
density = 1f,
fontScale = 1f,
),
) {
Comment on lines +64 to +69
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If fontScale is not set to a fixed value, the text will either overflow or become smaller if the device settings are changed.
So, I used the CompositionLocalProvider to fix the density and font scale of the composable for taking photos so that the display would not break.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have never thought of this before. This is super smart 👀

FlipCardBack(
uiState,
qrCodeImagePainter,
modifier = Modifier
.size(width = 300.dp, height = 380.dp)
.border(
3.dp,
Color.Black,
RoundedCornerShape(8.dp),
)
.graphicsLayer {
rotationY = 180f
},
)
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.size
import androidx.compose.foundation.shape.RoundedCornerShape
import androidx.compose.runtime.Composable
import androidx.compose.runtime.CompositionLocalProvider
import androidx.compose.runtime.LaunchedEffect
import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableStateOf
Expand All @@ -16,6 +17,8 @@ import androidx.compose.ui.graphics.Color
import androidx.compose.ui.graphics.ImageBitmap
import androidx.compose.ui.graphics.layer.drawLayer
import androidx.compose.ui.graphics.rememberGraphicsLayer
import androidx.compose.ui.platform.LocalDensity
import androidx.compose.ui.unit.Density
import androidx.compose.ui.unit.dp
import co.touchlab.kermit.Logger
import coil3.compose.AsyncImagePainter
Expand Down Expand Up @@ -56,16 +59,23 @@ internal fun BackgroundCapturableCardFront(
}
},
) {
FlipCardFront(
uiState,
profileImagePainter,
modifier = Modifier
.size(width = 300.dp, height = 380.dp)
.border(
3.dp,
Color.Black,
RoundedCornerShape(8.dp),
),
)
CompositionLocalProvider(
LocalDensity provides Density(
density = 1f,
fontScale = 1f,
),
) {
FlipCardFront(
uiState,
profileImagePainter,
modifier = Modifier
.size(width = 300.dp, height = 380.dp)
.border(
3.dp,
Color.Black,
RoundedCornerShape(8.dp),
),
)
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ import androidx.compose.ui.graphics.layer.GraphicsLayer
import androidx.compose.ui.graphics.layer.drawLayer
import androidx.compose.ui.platform.LocalDensity
import androidx.compose.ui.unit.IntSize
import androidx.compose.ui.unit.dp
import coil3.compose.AsyncImagePainter
import com.preat.peekaboo.image.picker.toImageBitmap
import io.github.droidkaigi.confsched.designsystem.theme.KaigiTheme
Expand Down Expand Up @@ -96,6 +95,7 @@ private fun ShareableCardContent(
val offsetYBackPx = 76f
val offsetXFrontPx = -136f
val offsetYFrontPx = -61f
val verticalPaddingPx = 30f

val density = LocalDensity.current

Expand All @@ -108,7 +108,7 @@ private fun ShareableCardContent(
)
.background(LocalProfileCardTheme.current.primaryColor),
) {
Box(modifier = Modifier.padding(vertical = 30.dp)) {
Box(modifier = Modifier.padding(vertical = with(density) { verticalPaddingPx.toDp() })) {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This part has been forgotten to be modified, and is one of the causes of the display corruption when in landscape mode.

backImage?.let {
Image(
bitmap = it,
Expand Down
Loading