mikepenz / AboutLibraries

AboutLibraries automatically collects all dependencies and licenses of any gradle project (Kotlin MultiPlatform), and provides easy to integrate UI components for Android and Compose-jb environments
http://mikepenz.github.io/AboutLibraries/
Apache License 2.0
3.68k stars 423 forks source link

[Question] How to properly integrate with #999

Closed tallnato closed 4 months ago

tallnato commented 4 months ago

Hi there,

I'm trying to add this library to a Kotlin Multiplatform project with Compose Multiplatform, targetting Android and iOS. I'm using also Multiplatform resources, where I store the aboutlibraries.json

I've started by running the gradle command to generate the aboutlibraries.json
./gradlew :shared:exportLibraryDefinitions -PaboutLibraries.exportPath=src/commonMain/composeResources/files

Then, on Compose side I did this, but looks very 'hacky'

@Composable
fun LibrariesLicensesScreen() {

  val coroutineScope = rememberCoroutineScope()
  var json by remember { mutableStateOf("") }

  coroutineScope.launch {
    json = Res.readBytes("files/aboutlibraries.json").decodeToString()
  }

  LibrariesContainer(
    aboutLibsJson = json,
    modifier = Modifier.fillMaxSize()
  )
}

Ignore the fact that the file is being read in the Composable, it was just for test porposes.

Is there a better way? Thank you so much

mikepenz commented 4 months ago

Good day.

So far we have intentionally chosen to offer a very flexible API allowing the integration to choose whichever architecture fits their project best.

Very similar to your approach the wasm example loads it for example this way:

                val libraries = produceState<Libs?>(null) {
                    value = withContext(Dispatchers.Default) {
                        Libs.Builder()
                            .withJson(Res.readBytes("files/aboutlibraries.json").decodeToString())
                            .build()
                    }
                }

Your approach is quite similar and also fine. The cleanest would certainly be to pull it out of the compose code, and only expose the state to compose world.

That said, I feel like there might be a good argument to build a new rememberLibraries API or similar to abstract this logic away. 🤔