svenjacobs / reveal

Reveal effect (coach mark) for Compose Multiplatform targeting Android, iOS, Desktop and Web
MIT License
409 stars 7 forks source link

Stuck after changing UIMode light/dark #127

Closed myounis97 closed 3 months ago

myounis97 commented 4 months ago

Describe the bug After switching from/to light/dark mode the overlay view becomes not clickable and the content under the overlay becomes clickable

To Reproduce Steps to reproduce the behavior:

  1. Make sure the overlay is presented
  2. Switch the UIMode from the notifications drawer
  3. Click on the overlay
  4. See error

Expected behavior The overlay should intercept click events not the content behind it

Smartphone (please complete the following information):

Additional Context This line becomes null after configuration change val rev by rememberUpdatedState(currentRevealable.value)

So the launched effect only takes the alpha as key and it would not update the clickModifier

val clickModifier = when {
            revealState.isVisible && rev != null -> Modifier.pointerInput(Unit) {
                detectTapGestures(
                    onPress = { offset ->
                        rev?.key?.let(
                            if (rev?.area?.contains(offset) == true) {
                                rev?.onClick ?: onRevealableClick
                            } else {
                                onOverlayClick
                            },
                        )
                    },
                )
            }

            else -> Modifier
        }

        LaunchedEffect(animatedOverlayAlpha) {
            @Suppress("ktlint:standard:wrapping")
            revealCanvasState.overlayContent = when {
                animatedOverlayAlpha > 0.0f -> ({
                    overlayEffect.Overlay(
                        revealState = revealState,
                        currentRevealable = currentRevealable,
                        previousRevealable = previousRevealable,
                        modifier = clickModifier
                            .semantics { testTag = "overlay" }
                            .fillMaxSize()
                            .alpha(animatedOverlayAlpha),
                        content = overlayContent,
                    )
                })

                else -> null
            }
        }
svenjacobs commented 4 months ago

Hello @myounis97, thanks for the bug report. I can confirm this behavior. I will have a look into it 👀

svenjacobs commented 3 months ago

This has been fixed in #130.

You're right that rev briefly becomes null. That is if a configuration change like dark mode is not explicitly handled by an application, the Activity will be restarted. Then RevealState is restored, since it is saveable, and rev points to the revealable item again.

However for some reason clickModifier wasn't properly updated and was still the empty Modifier from the else branch. By removing rev != null from the condition the modifier is properly updated.

The fix will be available in version 3.0.7.

svenjacobs commented 3 months ago

@myounis97 By the way, what a funny coincidence that your library has a similar name 😁

myounis97 commented 3 months ago

This has been fixed in #130.

You're right that rev briefly becomes null. That is if a configuration change like dark mode is not explicitly handled by an application, the Activity will be restarted. Then RevealState is restored, since it is saveable, and rev points to the revealable item again.

However for some reason clickModifier wasn't properly updated and was still the empty Modifier from the else branch. By removing rev != null from the condition the modifier is properly updated.

The fix will be available in version 3.0.7.

Thanks for your efforts 🚀