@@ -6,11 +6,15 @@ import androidx.compose.foundation.lazy.LazyListState
66import androidx.compose.foundation.lazy.rememberLazyListState
77import androidx.compose.material.Text
88import androidx.compose.runtime.Composable
9+ import androidx.compose.runtime.State
10+ import androidx.compose.runtime.produceState
911import androidx.compose.ui.Modifier
1012import androidx.compose.ui.unit.Dp
1113import androidx.compose.ui.unit.dp
1214import com.mikepenz.aboutlibraries.Libs
1315import com.mikepenz.aboutlibraries.entity.Library
16+ import kotlinx.coroutines.Dispatchers
17+ import kotlinx.coroutines.withContext
1418
1519/* *
1620 * Displays all provided libraries in a simple list.
@@ -32,8 +36,7 @@ fun LibrariesContainer(
3236 onLibraryClick : ((Library ) -> Unit )? = null,
3337) {
3438 val libs = Libs .Builder ().withJson(aboutLibsJson).build()
35- LibrariesContainer (
36- libs,
39+ LibrariesContainer (libs,
3740 modifier = modifier,
3841 lazyListState = lazyListState,
3942 contentPadding = contentPadding,
@@ -48,8 +51,7 @@ fun LibrariesContainer(
4851 onLibraryClick = onLibraryClick,
4952 licenseDialogBody = { library ->
5053 Text (library.licenses.firstOrNull()?.licenseContent ? : " " )
51- }
52- )
54+ })
5355}
5456
5557/* *
@@ -73,8 +75,7 @@ fun LibrariesContainer(
7375) {
7476 val libs = librariesBlock()
7577
76- LibrariesContainer (
77- libs,
78+ LibrariesContainer (libs,
7879 modifier,
7980 lazyListState,
8081 contentPadding,
@@ -89,7 +90,33 @@ fun LibrariesContainer(
8990 onLibraryClick,
9091 licenseDialogBody = { library ->
9192 Text (library.licenses.firstOrNull()?.licenseContent ? : " " )
92- }
93- )
93+ })
94+ }
9495
95- }
96+ /* *
97+ * Creates a State<Libs?> that holds the [Libs] as loaded by the [libraries].
98+ *
99+ * @see Libs
100+ */
101+ @Composable
102+ fun rememberLibraries (
103+ libraries : ByteArray ,
104+ ): State <Libs ?> = rememberLibraries {
105+ libraries.decodeToString()
106+ }
107+
108+ /* *
109+ * Creates a State<Libs?> that holds the [Libs] as loaded by the [block].
110+ *
111+ * @see Libs
112+ */
113+ @Composable
114+ fun rememberLibraries (
115+ block : suspend () -> String ,
116+ ): State <Libs ?> {
117+ return produceState<Libs ?>(initialValue = null ) {
118+ value = withContext(Dispatchers .Default ) {
119+ Libs .Builder ().withJson(block()).build()
120+ }
121+ }
122+ }
0 commit comments