Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Question] How to properly integrate with #999

Closed
tallnato opened this issue Jun 27, 2024 · 1 comment · Fixed by #1000
Closed

[Question] How to properly integrate with #999

tallnato opened this issue Jun 27, 2024 · 1 comment · Fixed by #1000

Comments

@tallnato
Copy link

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
Copy link
Owner

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. 🤔

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants