Coder Social home page Coder Social logo

Image blinks on opening about telephoto HOT 8 CLOSED

kmnaseef avatar kmnaseef commented on July 23, 2024
Image blinks on opening

from telephoto.

Comments (8)

kmnaseef avatar kmnaseef commented on July 23, 2024 1

Thank you very much @saket, that was the issue. Now everything work perfect

from telephoto.

saket avatar saket commented on July 23, 2024

Please add some more context in the form of a video or code to reproduce. It's hard to tell what's happening otherwise.

from telephoto.

AleksandarIlic avatar AleksandarIlic commented on July 23, 2024

It seems that .listener() is causing blinking. On my end it's blinking/flashing all the time.

val zoomSpec = ZoomSpec(maxZoomFactor = 4.0f)
val zoomableImageState = rememberZoomableImageState(rememberZoomableState(zoomSpec = zoomSpec))
ZoomableAsyncImage(
    modifier = modifier,
    state = zoomableImageState,
    model = ImageRequest.Builder(LocalContext.current)
        .data(imageUrl)
        .placeholderMemoryCacheKey(imageUrl)
        .crossfade(IMAGE_CROSSFADE_DURATION)
        .listener()
        .build(),
    contentDescription = null,
)

If I remove .listener() everything works fine.

Is there any other way to get notified when the image is loaded?

from telephoto.

saket avatar saket commented on July 23, 2024

From what I understand, this is happening because listener() is creating a new object on every recomposition, making telephoto think that the ImageRequest was changed. You'll need to remember your listener object (example).

I wonder how Coil is able to avoid this. Does AsyncImage not suffer from this problem?

from telephoto.

AleksandarIlic avatar AleksandarIlic commented on July 23, 2024

Thanks for the link.

I never had blinking problem with Coil. I'm using SubcomposeAsyncImage which also provides custom loading, error and success composable functions to render the states and it's really nice feature to have.

from telephoto.

saket avatar saket commented on July 23, 2024

Yep that's indeed nice to have. I want to explore if I can offer something similar in the future, but for now you're restricted to managing the loading & error states yourself.

from telephoto.

kmnaseef avatar kmnaseef commented on July 23, 2024

@saket , @AleksandarIlic thanks for the reply and sorry for late response.
I am using ZoomableAsyncImage inside a HorizontalPager. When I add/remove images from the 'imageUriList', Image blinks. But Coil doesn't have this issue

@OptIn(ExperimentalFoundationApi::class)
@Composable
fun ImageViewerScreen(
    imageUriList: List<Uri>
){
    val context = LocalContext.current
    val state = rememberPagerState(initialPage = 0, 0f) { imageUriList.size }

    HorizontalPager(
        key = { pos ->
            imageUriList[pos]
        },
        state = state,
        modifier = Modifier.fillMaxSize()

    ){ page ->

        ZoomableAsyncImage(
            modifier = Modifier.fillMaxSize(),
            model = imageUriList[page],
            contentDescription = "",
            imageLoader = ImageLoader.Builder(context)
                .components {
                    add(ImageDecoderDecoder.Factory())
                    add(SvgDecoder.Factory())
                }
                .build()
        )
    }
}

from telephoto.

saket avatar saket commented on July 23, 2024

I wonder if it's because you're creating a new ImageLoader for each image. Does hoisting and remembering your loader change anything?

val context = LocalContext.current
val state = rememberPagerState(initialPage = 0, 0f) { imageUriList.size }
val imageLoader = remember {
    ImageLoader.Builder(context)
        .components {
            add(ImageDecoderDecoder.Factory())
            add(SvgDecoder.Factory())
        }
        .build()
}
HorizontalPager(
    key = { pos ->
        imageUriList[pos]
    },
    state = state,
    modifier = Modifier.fillMaxSize()
) { page ->
    ZoomableAsyncImage(
        modifier = Modifier.fillMaxSize(),
        model = imageUriList[page],
        contentDescription = "",
        imageLoader = imageLoader,
    )
}

from telephoto.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.