Skip to content

Commit

Permalink
Merge pull request #1001 from mikepenz/develop
Browse files Browse the repository at this point in the history
dev -> main
  • Loading branch information
mikepenz authored Jun 29, 2024
2 parents d829008 + 803e72a commit bdb789c
Show file tree
Hide file tree
Showing 17 changed files with 281 additions and 92 deletions.
31 changes: 23 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@

## Latest releases 🛠

- Kotlin 2.x && Multiplatform && Compose && Plugin | [v11.2.1](https://github.com/mikepenz/AboutLibraries/tree/v11.2.1)
- Kotlin 2.x && Multiplatform && Compose && Plugin | [v11.2.2](https://github.com/mikepenz/AboutLibraries/tree/v11.2.2)

## Gradle Plugin

Expand Down Expand Up @@ -222,15 +222,22 @@ implementation "com.mikepenz:aboutlibraries-compose-m3:${latestAboutLibsRelease}
### Usage

```kotlin
// android
// android (when using the default resource location
LibrariesContainer(
Modifier.fillMaxSize()
)

// compose-desktop
LibrariesContainer(useResource("aboutlibraries.json") {
it.bufferedReader().readText()
}, Modifier.fillMaxSize())
// compose resource API
val libraries by rememberLibraries {
Res.readBytes("files/aboutlibraries.json").decodeToString()
}

// compose manually
val libraries by rememberLibraries {
useResource("aboutlibraries.json") { res -> res.bufferedReader().readText() }
}

LibrariesContainer(libraries, Modifier.fillMaxSize())
```

<details><summary><b>Compose-jb</b></summary>
Expand All @@ -242,13 +249,21 @@ Find a sample application as the `app-desktop` module. It showcases the usage to
### Generate Dependency Information

```bash
./gradlew app-desktop:exportLibraryDefinitions -PaboutLibraries.exportPath=src/main/resources/
./gradlew :app-desktop:exportLibraryDefinitions -PaboutLibraries.exportPath=src/main/resources/

# Filter exported definition by variant by passing `-PaboutLibraries.exportVariant==<VARIANT>`
./gradlew :app-wasm:exportLibraryDefinitions -PaboutLibraries.exportPath=src/main/resources/ -PaboutLibraries.exportVariant=wasmJs
./gradlew :app-wasm:exportLibraryDefinitions -PaboutLibraries.exportPath=src/main/resources/ -PaboutLibraries.exportVariant=jvm
```

### Run Desktop app
### Run Demo app(s)

```
# JVM Desktop app
./gradlew :app-desktop:run
# WASM Web app
./gradlew :app-wasm:run
```

### Screenshot
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,15 @@ import androidx.compose.foundation.lazy.LazyListState
import androidx.compose.foundation.lazy.rememberLazyListState
import androidx.compose.material.Text
import androidx.compose.runtime.Composable
import androidx.compose.runtime.State
import androidx.compose.runtime.produceState
import androidx.compose.ui.Modifier
import androidx.compose.ui.unit.Dp
import androidx.compose.ui.unit.dp
import com.mikepenz.aboutlibraries.Libs
import com.mikepenz.aboutlibraries.entity.Library
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.withContext

/**
* Displays all provided libraries in a simple list.
Expand All @@ -32,8 +36,7 @@ fun LibrariesContainer(
onLibraryClick: ((Library) -> Unit)? = null,
) {
val libs = Libs.Builder().withJson(aboutLibsJson).build()
LibrariesContainer(
libs,
LibrariesContainer(libs,
modifier = modifier,
lazyListState = lazyListState,
contentPadding = contentPadding,
Expand All @@ -48,8 +51,7 @@ fun LibrariesContainer(
onLibraryClick = onLibraryClick,
licenseDialogBody = { library ->
Text(library.licenses.firstOrNull()?.licenseContent ?: "")
}
)
})
}

/**
Expand All @@ -73,8 +75,7 @@ fun LibrariesContainer(
) {
val libs = librariesBlock()

LibrariesContainer(
libs,
LibrariesContainer(libs,
modifier,
lazyListState,
contentPadding,
Expand All @@ -89,7 +90,33 @@ fun LibrariesContainer(
onLibraryClick,
licenseDialogBody = { library ->
Text(library.licenses.firstOrNull()?.licenseContent ?: "")
}
)
})
}

}
/**
* Creates a State<Libs?> that holds the [Libs] as loaded by the [libraries].
*
* @see Libs
*/
@Composable
fun rememberLibraries(
libraries: ByteArray,
): State<Libs?> = rememberLibraries {
libraries.decodeToString()
}

/**
* Creates a State<Libs?> that holds the [Libs] as loaded by the [block].
*
* @see Libs
*/
@Composable
fun rememberLibraries(
block: suspend () -> String,
): State<Libs?> {
return produceState<Libs?>(initialValue = null) {
value = withContext(Dispatchers.Default) {
Libs.Builder().withJson(block()).build()
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -237,6 +237,7 @@ internal inline fun LazyListScope.libraryItems(
}
}

@OptIn(ExperimentalLayoutApi::class)
@Composable
internal fun Library(
library: Library,
Expand Down Expand Up @@ -290,7 +291,7 @@ internal fun Library(
)
}
if (showLicenseBadges && library.licenses.isNotEmpty()) {
Row {
FlowRow {
library.licenses.forEach {
Badge(
modifier = Modifier.padding(padding.badgePadding),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,15 @@ import androidx.compose.foundation.lazy.LazyListState
import androidx.compose.foundation.lazy.rememberLazyListState
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.runtime.State
import androidx.compose.runtime.produceState
import androidx.compose.ui.Modifier
import androidx.compose.ui.unit.Dp
import androidx.compose.ui.unit.dp
import com.mikepenz.aboutlibraries.Libs
import com.mikepenz.aboutlibraries.entity.Library
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.withContext

/**
* Displays all provided libraries in a simple list.
Expand Down Expand Up @@ -91,5 +95,34 @@ fun LibrariesContainer(
Text(library.licenses.firstOrNull()?.licenseContent ?: "")
}
)
}

/**
* Creates a State<Libs?> that holds the [Libs] as loaded by the [libraries].
*
* @see Libs
*/
@Composable
fun rememberLibraries(
libraries: ByteArray,
): State<Libs?> = rememberLibraries {
libraries.decodeToString()
}

}
/**
* Creates a State<Libs?> that holds the [Libs] as loaded by the [block].
*
* @see Libs
*/
@Composable
fun rememberLibraries(
block: suspend () -> String,
): State<Libs?> {
return produceState<Libs?>(initialValue = null) {
value = withContext(Dispatchers.Default) {
Libs.Builder()
.withJson(block())
.build()
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -238,7 +238,7 @@ internal inline fun LazyListScope.libraryItems(
}
}

@OptIn(ExperimentalMaterial3Api::class)
@OptIn(ExperimentalMaterial3Api::class, ExperimentalLayoutApi::class)
@Composable
internal fun Library(
library: Library,
Expand Down Expand Up @@ -292,7 +292,7 @@ internal fun Library(
)
}
if (showLicenseBadges && library.licenses.isNotEmpty()) {
Row {
FlowRow {
library.licenses.forEach {
Badge(
modifier = Modifier.padding(padding.badgePadding),
Expand Down
9 changes: 6 additions & 3 deletions app-desktop/src/main/kotlin/m3/main.kt
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,13 @@ import androidx.compose.material3.ExperimentalMaterial3Api
import androidx.compose.material3.Scaffold
import androidx.compose.material3.Text
import androidx.compose.material3.TopAppBar
import androidx.compose.runtime.getValue
import androidx.compose.ui.Modifier
import androidx.compose.ui.res.useResource
import androidx.compose.ui.window.Window
import androidx.compose.ui.window.application
import com.mikepenz.aboutlibraries.ui.compose.m3.LibrariesContainer
import com.mikepenz.aboutlibraries.ui.compose.m3.rememberLibraries

@OptIn(ExperimentalMaterial3Api::class)
fun main() = application {
Expand All @@ -19,9 +21,10 @@ fun main() = application {
Scaffold(
topBar = { TopAppBar(title = { Text("AboutLibraries Compose M3 Desktop Sample") }) }
) {
LibrariesContainer(useResource("aboutlibraries.json") {
it.bufferedReader().readText()
}, Modifier.fillMaxSize().padding(it))
val libraries by rememberLibraries {
useResource("aboutlibraries.json") { res -> res.bufferedReader().readText() }
}
LibrariesContainer(libraries, Modifier.fillMaxSize().padding(it))
}
}
}
Expand Down
9 changes: 6 additions & 3 deletions app-desktop/src/main/kotlin/main.kt
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,13 @@ import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.material.Scaffold
import androidx.compose.material.Text
import androidx.compose.material.TopAppBar
import androidx.compose.runtime.getValue
import androidx.compose.ui.Modifier
import androidx.compose.ui.res.useResource
import androidx.compose.ui.window.Window
import androidx.compose.ui.window.application
import com.mikepenz.aboutlibraries.ui.compose.LibrariesContainer
import com.mikepenz.aboutlibraries.ui.compose.rememberLibraries
import m2.SampleTheme

fun main() = application {
Expand All @@ -15,9 +17,10 @@ fun main() = application {
Scaffold(
topBar = { TopAppBar(title = { Text("AboutLibraries Compose Desktop Sample") }) }
) {
LibrariesContainer(useResource("aboutlibraries.json") {
it.bufferedReader().readText()
}, Modifier.fillMaxSize())
val libraries by rememberLibraries {
useResource("aboutlibraries.json") { res -> res.bufferedReader().readText() }
}
LibrariesContainer(libraries, Modifier.fillMaxSize())
}
}
}
Expand Down
Loading

0 comments on commit bdb789c

Please sign in to comment.