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

[WIP] feat: added v1 for kmm. needs cleanup #164

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

anuragdalia
Copy link

Summary

Checklist

  • Build and linting is passing.
  • [ x ] This change is not breaking existing flow of a system.
  • I have written test case for this change.
  • This change is tested from all aspects.
  • [ x ] Implemented any new third-party library (Which not existed before this change).

@anuragdalia anuragdalia changed the title WIP: feat: added v1 for kmm. needs cleanup [WIP] feat: added v1 for kmm. needs cleanup Apr 25, 2024
@anuragdalia anuragdalia marked this pull request as draft April 25, 2024 13:35
@anuragdalia
Copy link
Author

@PatilShreyas what do you suggest?

@PatilShreyas
Copy link
Owner

@anuragdalia that's nice! Let me review the changes and will get back.

Meanwhile, I assume you might have utilized the latest API from compose: https://developer.android.com/develop/ui/compose/graphics/draw/modifiers#composable-to-bitmap

@anuragdalia
Copy link
Author

Sure.

The new api is only available in 1.7.0-alpha.
Plus havent read enough on this to say if it's available on kmm or only android.
I took inspiration from #142

@PatilShreyas
Copy link
Owner

The new api is only available in 1.7.0-alpha. Plus havent read enough on this to say if it's available on kmm or only android. I took inspiration from #142

AFAIK, that new API is Multi-platform compatible. That's why looks more promising and reliable too. Will check it and will get back to you

@PatilShreyas
Copy link
Owner

@anuragdalia have you tested this implementation with any example on iOS simulator?

val width = this.size.width
val height = this.size.height

onDrawWithContent {
Copy link
Owner

Choose a reason for hiding this comment

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

I would strongly recommend to use this API which is KMP-compatible and comes from androix.compose package which will be reliable: https://developer.android.com/develop/ui/compose/graphics/draw/modifiers#composable-to-bitmap

Copy link
Author

Choose a reason for hiding this comment

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

I tried this. It says cmp but shows up in android only at the moment. Maybe some temporary doc/release bug.

  • it's in alpha. So we could move to it when it's stable
    What do say?

Copy link
Owner

Choose a reason for hiding this comment

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

Okay, works 👍🏻

canvas.drawPicture(this)
bitmap.setImmutable()
return bitmap
}
Copy link
Owner

Choose a reason for hiding this comment

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

Also, instead of creating duplicate Capturable implementation across multiple platforms, can't we just create a platform-specific implementation for CacheDrawModifierNode and internal implementation like Bitmap transformation, etc?

Copy link
Author

Choose a reason for hiding this comment

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

I was leaving room for more stronger changes that might come. But I think we can simplify it for now if you think that'd be better.
I'm pro the current setup so we don't have to do alot of expect/actuals

Copy link
Author

Choose a reason for hiding this comment

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

Given this is the core code.

Copy link
Owner

Choose a reason for hiding this comment

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

Anyway when 1.7.0 is gonna release, we'll have to cleanup this again. But currently this has lot of duplicate code and I only want a code here which has platform level differences.

Copy link
Owner

Choose a reason for hiding this comment

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

It would be nice if we keep all common things in commonMain and only modifier implementation in the platform specific source.

Copy link
Owner

Choose a reason for hiding this comment

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

Can you please make a change with this?

@@ -79,7 +59,7 @@ class CaptureController {
* @param config Bitmap config of the desired bitmap. Defaults to [Bitmap.Config.ARGB_8888]
*/
@ExperimentalComposeApi
fun captureAsync(config: Bitmap.Config = Bitmap.Config.ARGB_8888): Deferred<ImageBitmap> {
fun captureAsync(config: ColorType = ColorType.ARGB_4444): Deferred<ImageBitmap> {
Copy link
Owner

Choose a reason for hiding this comment

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

This will be a API breaking change but I think we can't get a rid of it 🤔, thoughts?

Copy link
Author

Choose a reason for hiding this comment

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

No we can't.
Or maybe We can have a custom class with that same name. And typealias in android. I think it won't break for old lib users then I guess. Need to dig

Copy link
Owner

Choose a reason for hiding this comment

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

Okay, we'll plan backward compatibility for this, no worries

@anuragdalia
Copy link
Author

Hey yes! I did test it on an ios device. Infact I'm using it in an app.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants