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

Include Web Support For Compose Module #422

Closed
wakaztahir opened this issue Feb 24, 2023 · 2 comments · Fixed by #430 or #438
Closed

Include Web Support For Compose Module #422

wakaztahir opened this issue Feb 24, 2023 · 2 comments · Fixed by #430 or #438

Comments

@wakaztahir
Copy link
Contributor

wakaztahir commented Feb 24, 2023

here's a sample that I use , that works on my web app here https://qawaz.github.io/sketchable-web , this will only load the file once , more requests will return with empty strings until the resource has loaded

private var loader: JsStringProvider? by mutableStateOf(null)
private var isLoading = false

private val WebExceptionHandler: (Throwable) -> Unit = {
    it.printStackTrace()
}

@Composable
actual fun stringResource(res: StringResource): String {
    return if (loader == null && !isLoading) {
        isLoading = true
        LaunchedEffect(null) {
            try {
                loader = res.loader.getOrLoad()
            } catch (e: Throwable) {
                WebExceptionHandler(e)
            }
            isLoading = false
        }
        ""
    } else {
        return loader?.let { load ->
            try {
                res.localized(load, null)
            } catch (e: Throwable) {
                WebExceptionHandler(e)
                null
            }
        } ?: "fail"
    }
}

@Composable
actual fun loadAsText(asset: AssetResource): String {
    return produceState("") {
        value = asset.getText()
    }.value
}
@wakaztahir
Copy link
Contributor Author

wakaztahir commented Feb 24, 2023

loadAsText is similar for other modules i.e jvmMain and androidMain , so I think it should be added there as well

I could create a pull request but this project configuration is bloated , resources file with a path to mpp-library's resources , it doesn't work on windows , kotlin version 1.6.10 causes error on windows with Projects must be configuring , plus compose-jb version is outdated , Kotlin version should be 1.8.0 and compose version should be 1.3.0
I fixed all this and then it started downloading a 180 mb's file of adoptopenjdk and that point I just gave up , My internet connection is slow you see...

@Alex009 Alex009 linked a pull request Mar 3, 2023 that will close this issue
Alex009 added a commit that referenced this issue Mar 10, 2023
Alex009 added a commit that referenced this issue Mar 10, 2023
@Alex009 Alex009 linked a pull request Mar 10, 2023 that will close this issue
Alex009 added a commit that referenced this issue Mar 10, 2023
@Alex009
Copy link
Member

Alex009 commented Mar 10, 2023

will be released in 0.21.0

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