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 6 commits 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

@anuragdalia anuragdalia Apr 28, 2024

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

@PatilShreyas PatilShreyas Apr 28, 2024

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.

@PatilShreyas
Copy link
Owner

@anuragdalia Any update on the changes which we discussed?

@minmax1993
Copy link

Thank you @PatilShreyas for the amazing library and for adding the kmm support @anuragdalia.
I know it's not officially released, but I've tested the branch and would like to give some feedback about iOS capturable.
@anuragdalia have you tested the capturable with iOS Webview? It's captured as a white bitmap image.

@PatilShreyas
Copy link
Owner

Thank you @PatilShreyas for the amazing library and for adding the kmm support @anuragdalia. I know it's not officially released, but I've tested the branch and would like to give some feedback about iOS capturable. @anuragdalia have you tested the capturable with iOS Webview? It's captured as a white bitmap image.

@minmax1993 Would be helpful if you share your feedback

@ssttkkl
Copy link

ssttkkl commented Aug 28, 2024

@anuragdalia Well I found the iOS implementation didn't use any iOS API so it can also runs on desktop and web. I added desktop and wasmJs target and created a PR: anuragdalia#1

@anuragdalia
Copy link
Author

Thank you @PatilShreyas for the amazing library and for adding the kmm support @anuragdalia. I know it's not officially released, but I've tested the branch and would like to give some feedback about iOS capturable. @anuragdalia have you tested the capturable with iOS Webview? It's captured as a white bitmap image.

Hi @minmax1993
no, i havent tested it specifically with ios webview. the ios webview is going to be a native component, so i am not sure if it will actually work. will give it a try next time i sit on this

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.

4 participants