https://kotlinlang.org logo
#compose
Title
# compose
j

Jan

10/06/2023, 8:00 AM
I do have a problem with compose-multiplatform and the newly added ExposedDropdownMenu. More in thread:
The ExposedDropDownMenu on Android does not display my initial selected element while on iOS its working, see picture (left android, right ios). Is that a known issue with compose-multiplatform 1.5.10-beta02
@Ivan Matkov maybe you know about it?
i

Ivan Matkov

10/06/2023, 8:32 AM
JetBrains doesn't change Android anyhow. In Compose Multiplatform projects our plugin includes original Google's artifact to your Android app. So, it's better to ping Google folks about Android-only issues
j

Jan

10/06/2023, 8:33 AM
ah, ok. thanks for bothering you
In my composable I do the follwing:
Copy code
val uiState: InventoryComponentViewModel.UiState by component.uiState.collectAsState()
    var selectedVenue by remember { mutableStateOf(uiState.selectedVenue) }
within uiState I have a property selectedVenue. If I debug my code its set in uiState but its not set in my selectedVenue variable. While evaluating these two expressions its says the following:
Image from iOS.jpg
p

Pablichjenkov

10/06/2023, 1:12 PM
What happens if you set uiState as the key for remember
j

Jan

10/06/2023, 1:17 PM
let me check
this works, but If I change the value afterwards and rotate the device the initial (first) value is displayed again
nice!
the issue regarding rotation was my fault
can you explain why its working?
and strange that its working on ios ...
p

Pablichjenkov

10/06/2023, 2:06 PM
It is due to
positional memoization
Leland Richardson has a good talk about that. Basically remember works by keeping the initial value from one composition to another composition. Without a key, remember uses its position in the slot table to determine if it was existing in the previous composition. And if it matches, it will pick the previous composition value, ignoring the value you pass in the composable function parameter.
So it is advisable to use keys with remember and LaunchEffect. In the case of iOS, if you follow the iOS issues, there is currently an open issue where iOS triggers more than one composition at startup. Perhaps that is updating something somewhere, making it work. I would have to see more in detail to see what is going on.