A convenient library to show a shimmer effect while loading data. Easily convert your current view with a slick skeleton loading animation just by wrapping your view.
Using JitPack, you'll need to add to your repositories:
maven { url 'https://jitpack.io' }Then add the dependency:
implementation 'com.github.JustinGuedes:redactable-android:0.1.0'Firstly, ensure your data class has a way to return a placeholder version of the class, i.e. dummy data so the library can show a redacted version of the view:
data class Object(...) {
...
companion object {
val placeholder: Object
get() = Object(...) // Dummy data
}
...
}Secondly, create a loadable property which allows you to control the state of the loading view:
private var _loadable = MutableStateFlow<Loadable<Object>>(Object.placeholder)
val loadable = _loadable.asStateFlow()NOTE: The possible values for
loadableare:Loading(Object), Loaded(Object), error(Error).
Lastly, wrap your composable in a LoadableView:
val loadable = viewModel.loadable.collectAsState()
LoadableView(loadable.value) { data ->
// Use data
Text(text = "${data}",
modifier = Modifier.redactable()
)
}Redactable is released under the MIT license. See LICENSE for details.
