hierarchyChangeEvents
Create a Flow of view group hierarchy change events on the ViewGroup instance where the value emitted is one of the 2 event types: HierarchyChangeEvent.ChildAdded, HierarchyChangeEvent.ChildRemoved
Note: Created flow keeps a strong reference to the ViewGroup instance until the coroutine that launched the flow collector is cancelled.
Example of usage:
viewGroup.hierarchyChangeEvents()
.onEach { event ->
when(event) {
is HierarchyChangeEvent.ChildAdded -> {
// handle child added event
}
is HierarchyChangeEvent.ChildRemoved -> {
// handle child removed event
}
}
}
.launchIn(uiScope)
Content copied to clipboard