-
Notifications
You must be signed in to change notification settings - Fork 200
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
♻️ Connecting Compose ProfileCardScreen as an iOS app screen #825
♻️ Connecting Compose ProfileCardScreen as an iOS app screen #825
Conversation
… it in the Shared file.
…o convert it to UIImage has been added. This method has to be integrated later, since the exact same file exists in other modules.
Detekt check failed. Please run |
package io.github.droidkaigi.confsched.profilecard | ||
|
||
import androidx.compose.ui.graphics.ImageBitmap | ||
import kotlinx.cinterop.ExperimentalForeignApi | ||
import kotlinx.cinterop.refTo | ||
import platform.CoreGraphics.CGBitmapContextCreate | ||
import platform.CoreGraphics.CGBitmapContextCreateImage | ||
import platform.CoreGraphics.CGColorSpaceCreateWithName | ||
import platform.CoreGraphics.CGImageAlphaInfo | ||
import platform.CoreGraphics.kCGBitmapByteOrder32Little | ||
import platform.CoreGraphics.kCGColorSpaceSRGB | ||
import platform.UIKit.UIImage | ||
|
||
// TODO Integrate with app-ios-shared methods. | ||
@OptIn(ExperimentalForeignApi::class) | ||
internal fun ImageBitmap.toUiImage(): UIImage { | ||
val buffer = IntArray(width * height) | ||
readPixels(buffer) | ||
|
||
// https://github.com/takahirom/roborazzi/blob/main/roborazzi-compose-ios/src/iosMain/kotlin/io/github/takahirom/roborazzi/RoborazziIos.kt#L88C51-L88C68 | ||
val colorSpace = CGColorSpaceCreateWithName(kCGColorSpaceSRGB) | ||
val bitmapInfo = CGImageAlphaInfo.kCGImageAlphaPremultipliedFirst.value or kCGBitmapByteOrder32Little | ||
val context = CGBitmapContextCreate( | ||
data = buffer.refTo(0), | ||
width = width.toULong(), | ||
height = height.toULong(), | ||
bitsPerComponent = 8u, | ||
bytesPerRow = (4 * width).toULong(), | ||
space = colorSpace, | ||
bitmapInfo = bitmapInfo, | ||
) | ||
|
||
val cgImage = CGBitmapContextCreateImage(context) | ||
return cgImage?.let { UIImage.imageWithCGImage(it) } ?: UIImage() | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The exact same implementation is available in another module.
However, I was not sure where to put this process, so I copied it and put it as is.
Which module should I put it in? 🤔
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How about putting this to core/ui?👀
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We can have another pull request for this👀
KmpProfileCardComposeViewControllerWrapper { text, image in | ||
// TODO Implement a sharing function. | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The goal is to have the Compose editing screen appear when the profile card icon in the bottom navigation bar is tapped in the iOS app.
Since the goal of this task is the above, the share function is not part of this PR.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good to me!
Issue
Overview (Required)
Movie (Optional)
before.mov