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

Mismatch in catches of comparables #13

Closed
jeluchu opened this issue Jan 25, 2022 · 11 comments · Fixed by #24 or #25
Closed

Mismatch in catches of comparables #13

jeluchu opened this issue Jan 25, 2022 · 11 comments · Fixed by #24 or #25
Labels
bug Something isn't working enhancement New feature or request
Milestone

Comments

@jeluchu
Copy link

jeluchu commented Jan 25, 2022

Hello again!

I've been doing some tests, and I've seen a couple of things that I don't know if this is really the case or if they are errors. I'll tell you about them so that you can clarify them for me.

First case: Composable capture in LazyColumn

I have a LazyColumn that has several items both above and below Capturable. I have in one of them a button with which I perform the controller.capture() action and at that moment I generate the bitmap to share/save it. The problem is that it does not really capture the composable that you have indicated, it obtains the size of the real composable, but if you have made scroll and that composable is between the TopAppBar for example the generated image is not really the one previously indicated.

Capture of the image generated after the scroll has taken place
Capture generated when the compostable is fully displayed on the screen


LazyColumn {

 { ... }

            item {
                Capturable(
                    controller = controller,
                    onCaptured = { bitmap, _ ->
                        if (bitmap != null)
                            with(context) {
                                saveBitmap(bitmap.asAndroidBitmap())?.let { bitmapUri ->
                                    share(
                                        message = "",
                                        uri = bitmapUri
                                    )
                                }
                            }
                    }
                ) {
                    LetterImage(
                        addressee = addressee.value.text,
                        message = message.value.text,
                        sender = sender.value.text,
                        textColor = textColor.value,
                        bgColor = bgColor.value,
                        letterImage = letterImage
                    )
                }
            }

  { ... }

}

Second case: Background colour of the capture

Even if no background colour has been specified in the composable to be captured, the background colour that is inside the view is obtained, i.e. there is no option to capture the composable with a transparent background if I want it to capture it. As you can see in the images above, the background colour I have on the screen is red, but when I capture the image of the card, it adds a red background colour even though I want it to be transparent.

Thank you in advance! And thank you for your work! 😄

@jeluchu
Copy link
Author

jeluchu commented Jan 25, 2022

I include a small video that I have made from the app so you can see how the Capturable area looks like, the Capturable area would be the following: Capture generated when the compostable is fully displayed on the screen

Video of the process inside LazyColumn and Capturable

@jeluchu
Copy link
Author

jeluchu commented Mar 6, 2022

Any news or solutions to this problem @PatilShreyas? 🤔

@PatilShreyas
Copy link
Owner

Thanks for the image and videos @jeluchu. Will look into it

PatilShreyas added a commit that referenced this issue Mar 17, 2022
@PatilShreyas PatilShreyas added bug Something isn't working enhancement New feature or request labels Mar 20, 2022
@PatilShreyas PatilShreyas added this to the v1.0.3 milestone Mar 20, 2022
@PatilShreyas PatilShreyas linked a pull request Mar 20, 2022 that will close this issue
5 tasks
PatilShreyas added a commit that referenced this issue Mar 20, 2022
@PatilShreyas PatilShreyas linked a pull request Mar 20, 2022 that will close this issue
@PatilShreyas
Copy link
Owner

This issue has been fixed and released in v1.0.3. Thanks!

@jeluchu
Copy link
Author

jeluchu commented Mar 20, 2022

@PatilShreyas I have updated the library to version 1.0.3, but the error that I indicated in this incident still occurs, as soon as the content is no longer in view the generated image is not correct or expected, here you can see the test I have done https://ibb.co/svtkDJ9, it is hiding because there is a Toolbar above, as below is the button that calls the function to generate the biome, if not down in the view is complete: https://ibb.co/WcTKXD1 but to generate the bitmap is cut as you indicated in the first picture

@PatilShreyas
Copy link
Owner

Are you also including toolbar inside Capturable composable's content?

@jeluchu
Copy link
Author

jeluchu commented Mar 21, 2022

@PatilShreyas No, in principle this is inside a Scaffold, which then inside has a LazyColumn and inside is the Capturale

    Scaffold(
        topBar = {
            SimpleToolbar(
                backgroundColor = bgLetters,
                leftIcon = R.drawable.ic_arrow_left,
                style = TypographyNook.h3,
                navigateAction = navigate.goBack
            )
        },
        backgroundColor = bgLetters
    ) {

        LazyColumn(
            Modifier
                .fillMaxSize()
        ) {

            item {
                Capturable(
                    controller = controller,
                    onCaptured = { bitmap, _ ->
                        if (bitmap != null)
                            with(context) {
                                saveBitmap(bitmap.asAndroidBitmap())?.let { bitmapUri ->
                                    share(
                                        message = "",
                                        uri = bitmapUri
                                    )
                                }
                            }
                    }
                ) {
                    LetterImage(
                        addressee = addressee.value.text,
                        message = message.value.text,
                        sender = sender.value.text,
                        textColor = textColor.value,
                        bgColor = bgColor.value,
                        letterImage = letterImage
                    )
                }
            }

         ... // More items in the LazyColumn

      }

        GeneralButton(
              modifier = Modifier
                        .fillMaxWidth()
                        .padding(horizontal = 16.dp),
              bgColor = Color.White.copy(.4f),
              contentColor = bgFabSearchHHP
        ) { controller.capture() }  // And this is the button at the bottom of the view that performs the capture function

}

@PatilShreyas
Copy link
Owner

If this LetterImage is a network image then disable hardware bitmap in builder configuration.

@jeluchu
Copy link
Author

jeluchu commented Mar 21, 2022

LetterImage is a Box() that contains a network image and 3 Text(), I'm looking at the documentation of the builder but I don't know where I have to indicate/disable what you tell me, since I understand that it will be in the Capturable builder configuration, right?

@PatilShreyas
Copy link
Owner

No, whatever network image you're using, every network image builder has an option for that. For e.g. coil also has it. Just say allowHardware(false) in builder.

@jeluchu
Copy link
Author

jeluchu commented Mar 22, 2022

Yes, I use Coil, I have just tried what you have indicated and it seems to be working correctly, thank you very much @PatilShreyas!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working enhancement New feature or request
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants