Last active
October 9, 2022 13:49
-
-
Save Syex/977413f43d15646583dd743f50852a1e to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
data class Event(val username: String) | |
class UserViewModel : ViewModel() { | |
val events = MutableSharedFlow<Event> | |
} | |
class UserFragment : Fragment() { | |
private val viewModel by viewModels<UserViewModel>() | |
private lateinit var binding: UserBinding | |
override fun onViewCreated(view: View, savedInstanceState: Bundle?) { | |
super.onViewCreated(view, savedInstanceState) | |
viewModel.events | |
.onEach { | |
// we access Android views in our Fragment directly | |
binding.usernameView.text = it.username | |
} | |
.launchIn(viewLifecycleOwner.lifecycle.coroutineScope) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment