Currently I have a WebAppInterface that detects the events of the web, such WebAppInterface is called inside a @Composable WebView, inside the WebAppInterface I have a function that I have successfully checked that detects the events of the Web and also updates within the class the variable eventNumber
which is a StateFlow<Int>
, but from within the @Composoable when I try to react to the changes of the value from this variable nothing happens. Here my code:
class WebAppInterface {
private var _eventNumber: MutableStateFlow<Int> = MutableStateFlow(0)
val eventNumber: StateFlow<Int> = _eventNumber
@JavascriptInterface
fun createFirebaseEvent(name: String, params: String) {
val gson = Gson()
val mapType = object : TypeToken<Map<String, Any>>() {}.type
val paramMap: Map<String, Any> = gson.fromJson(params, mapType)
// firebaseTracker.trackEvent(name, paramMap)
CoroutineScope(Dispatchers.IO).launch {
_eventNumber.emit(_eventNumber.value + 1)
Log.i("TAGGED", "createFirebaseEvent: ${eventNumber.value}")
number = number +1
}
}
}
Here the Composable
@Composable
fun DisplayDialog() {
val numberEvent by webAppInterface.eventNumber.collectAsState()
//I have tried this way initially
LaunchedEffect(numberEvent) {
Log.i("TAGGED", "Dialog: $numberEvent")
}
LaunchedEffect(numberEvent) {
Log.i("TAGGED", "Dialog: $numberEvent")
}
}
3