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

Going back from MessagesScreen sometimes doesn't work #5600

Open
knezevic-pando opened this issue Jan 29, 2025 · 0 comments
Open

Going back from MessagesScreen sometimes doesn't work #5600

knezevic-pando opened this issue Jan 29, 2025 · 0 comments
Labels
bug Something isn't working

Comments

@knezevic-pando
Copy link

Describe the bug
Going back from MessagesScreen sometimes doesn't work.
onBackPressed callback of the MessagesScreen composable is not invoked. This happens if you enter the screen while keyboard is opened or is closed at the time of navigating to MessagesScreen. Cannot go back even when you close the keyboard/send a message/reopen and close keyboard.
In MessagesScreen, there is a line to check if keyboard is opened:
val isImeVisible = WindowInsets.ime.getBottom(LocalDensity.current) > 0

However in the case above this value always seems to be true when using it in the back handler.
It seems it doesn't take this value into consideration so it seems like it uses the first value, and never updates.

val isImeVisible = WindowInsets.ime.getBottom(LocalDensity.current) > 0
val backAction: BackAction = remember(listViewModel, composerViewModel, attachmentsPickerViewModel) {
        {
            val isStartedForThread = listViewModel.isStartedForThread
            val isInThread = listViewModel.isInThread
            val isShowingOverlay = listViewModel.isShowingOverlay

            when {
                isImeVisible -> Unit
                attachmentsPickerViewModel.isShowingAttachments -> attachmentsPickerViewModel.changeAttachmentState(
                    false,
                )

                isShowingOverlay -> listViewModel.selectMessage(null)
                isStartedForThread -> onBackPressed()
                isInThread -> {
                    listViewModel.leaveThread()
                    composerViewModel.leaveThread()
                }

                else -> onBackPressed()
            }
        }
    }

If we add isImeVisible to remember's keys, then it seems to be working fine:

val isImeVisible = WindowInsets.ime.getBottom(LocalDensity.current) > 0
val backAction: BackAction = remember(listViewModel, composerViewModel, attachmentsPickerViewModel, isImeVisible) {
        {
        ....

SDK version

  • 6.9.0

To Reproduce
Steps to reproduce the behavior:

  1. Let's assume that you have some screen where you can search your channels
  2. Search for a channel(let the keyboard be open)
  3. Go to Messages screen for that channel
  4. Trigger system back press or toolbar back button
  5. Nothing happens

Expected behavior
User is able to do whatever their onBackPressed callback is supposed to do, e.g. navigate back.
However, onBackPressed callback is not invoked.

Device:

  • Vendor and model: Xiaomi Redmi Note 7 and Samsung Galaxy S24
  • Android version: 10 and 14

Screenshots
If applicable, add screenshots to help explain your problem.

@knezevic-pando knezevic-pando added the bug Something isn't working label Jan 29, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant