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

♻️ Connecting Compose ProfileCardScreen as an iOS app screen #825

Conversation

Corvus400
Copy link
Contributor

@Corvus400 Corvus400 commented Aug 27, 2024

Issue

Overview (Required)

  • The parts of the UI that were implemented in SwiftUI have been changed to show the UI created in Jetpack Compose.
  • Sharing functionality should be outside the scope of this task, so we have not implemented it.

Movie (Optional)

Before After
before.mov

@Corvus400 Corvus400 changed the title Feature/change native implement to compose multiplatform ♻️ Connecting Compose ProfileCardScreen as an iOS app screen Aug 27, 2024
Copy link

Detekt check failed. Please run ./gradlew detekt --auto-correct to fix the issues.

@github-actions github-actions bot temporarily deployed to deploygate-distribution August 27, 2024 05:27 Inactive
Comment on lines +1 to +35
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()
}
Copy link
Contributor Author

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? 🤔

Copy link
Member

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?👀

Copy link
Member

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👀

@github-actions github-actions bot temporarily deployed to deploygate-distribution August 27, 2024 05:31 Inactive
Comment on lines +192 to +194
KmpProfileCardComposeViewControllerWrapper { text, image in
// TODO Implement a sharing function.
}
Copy link
Contributor Author

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.

@Corvus400 Corvus400 marked this pull request as ready for review August 27, 2024 05:46
Copy link
Member

@takahirom takahirom left a 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!

@takahirom takahirom merged commit 5cafbc7 into DroidKaigi:main Aug 27, 2024
13 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Connecting Compose ProfileCardScreen as an iOS app screen
2 participants