Skip to content

Instantly share code, notes, and snippets.

@Aldikitta
Created August 14, 2023 07:42
Show Gist options
  • Save Aldikitta/8596c47a1ebdc8176ffda494a2a6be7e to your computer and use it in GitHub Desktop.
Save Aldikitta/8596c47a1ebdc8176ffda494a2a6be7e to your computer and use it in GitHub Desktop.
PagingCompose
// this is for no filter, just basic paging
val maritalStatusVal: StateFlow<CreateScreenUiState> = flow {
val maritalStatusData = kmbMasterDataUseCase.getMaritalStatus(
body = KmbMasterDataRequestModel.KmbMasterDataRequest()
).cachedIn(viewModelScope)
emit(CreateScreenUiState(maritalStatus = maritalStatusData))
}.stateIn(
viewModelScope,
SharingStarted.WhileSubscribed(5_000),
CreateScreenUiState.default
)
CreateScreen() {
val uistate by createScreenViewModel.maritalStatusVal.collectAsState()
content(uistate = uistate)
}
content(
uistate: UiState
) {
val uistate = uistate.data.collectAsLazyPagingItems()
lazycolun{
items(uistate)
}
}
// pagiing with function
private val _maritalStatus = MutableStateFlow(CreateScreenUiState.default)
val maritalStatus: StateFlow<CreateScreenUiState> = _maritalStatus
fun maritalStatusFun() {
viewModelScope.launch {
Log.d("MYTAG", "maritalStatusFun: executed")
val maritalStatusData = kmbMasterDataUseCase.getMaritalStatus(
body = KmbMasterDataRequestModel.KmbMasterDataRequest()
).cachedIn(viewModelScope)
_maritalStatus.value = CreateScreenUiState(maritalStatus = maritalStatusData)
}
}
createscreen() {
val uistate2 by createScreenViewModel.maritalStatus.collectAsState()
LaunchedEffect(key1 = Unit) {
createScreenViewModel.maritalStatusFun()
}
content(uistate = uistate)
}
content(
uistate: UiState
) {
val uistate = uistate.data.collectAsLazyPagingItems()
lazycolun{
items(uistate)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment