-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
UI state changes on iOS not applied when called from Kotlin Flow Collect methods. #3766
Comments
May you provide a reproducible example? It's a bit hard to make it from the code snippet you provided |
I reproduced it in the template https://github.com/cryptrr/compose-multiplatform-ios-flow-uistate-bug It works perfectly on android but fails in iOS Screen.Recording.2023-10-05.at.12.56.07.AM.movScreen.Recording.2023-10-05.at.12.58.34.AM.mov |
What if you place the ViewModel as a key in the LaunchEffect? |
I just tried putting viewModel as the key. Unfortunately, that doesn't seem to be the problem either. |
Weird thing is, I am actually receiving the Event in the collector. It's only the |
Seems related to the coroutine scope, seems that it needs to be executed from the scope returned by |
I tried that some time ago. That ain't the problem either.
|
Humm I see🤔. Internal BottomSheet implementation stuff then 🤷🏻. |
This same problem also happens where I show internal App Notifications. The app notifications are received on the event flow collector from the viewModel. But the the notification is not shown on ios. So I'm not sure this is a problem with BottomSheet implementation. |
Idk. This seems it could be some weird UI Thread issue. |
This is reproduced on 1.4.3 . @pjBooms @eymar @igordmn @dima-avdeev-jb @SebastianAigner This is a serious problem for all event driven apps. Is there any workaround that we can use until this is fixed? |
This doesn't seem to do anything with the shared flow. The bottom sheet doesn't show when asked from a
|
Weird. Seems the BottomSheet is broken on Flows altogether. Have you tried opening similar UI elements like SnackbarHost? For me that's not working either. |
Doesn't seem to be related to flows, but a problem with |
Not working with |
So turns out there's a problem which causes an extra recomposition of |
Great, that fixes it. It's just that now I need to pass in all the 15 bottomsheetstates as key to the LaunchedEffect 😩 . Thank you @m-sasha , close the issue if you may. Edit: Just one BottomSheetState key is necessary in this case. |
Oh great to know. In general |
Only if the lambda is using state that can change. The most common use of |
Correct, that is a good point. |
Describe the bug
UI state changes on iOS not reflecting when called from Kotlin Flow Collect methods.
I am collecting events from flows to show ModalBottomSheetLayout. When I call the
ModalBottomSheetState.show()
from a normal code(non flow code), it will work. When called from a flow collector, it will not update the UI or show the Bottomsheet. In fact the bottomsheet actually gets updated in the background underneath the screen.I unsuccessfully tried wrapping it in
withContext(Dispatchers.Main){}
It really seems like there is a threading problem somewhere.
It works perfectly on Android.
Affected platforms
Select one of the platforms below:
Versions
To Reproduce
Steps and/or the code snippet to reproduce the behavior:
Create a
MutableSharedFlow
in a global ViewModel and try changing UI state from its collect or collectLatest method inside a composable.Expected behavior
The bottomSheet state should change and the sheet should be shown.
The text was updated successfully, but these errors were encountered: