Brian G
11/04/2021, 10:37 AMexternal interface BwipJs {}
external fun <Module : Any> import(path: String): Promise<Module>
@Composable
fun Barcode() {
val bwip = remember { mutableStateOf<BwipJs?>(null) }
LaunchedEffect(Unit) {
bwip.value = import<BwipJs>("bwip-js").await() // ClassCastException
}
}
Outside of Compose, in plain Kotlin/JS, the import works fine, and I'm successfully calling functions (rendering barcodes) using the BwipJs handle, e.g.
val canvas = document.createElement("canvas") as HTMLCanvasElement
import<BwipJs>("bwip-js").then { bwipjs ->
bwipjs.toCanvas(canvas)
}
Brian G
11/04/2021, 11:29 AMAkif Abasov [JB]
11/05/2021, 7:50 AMBrian G
11/05/2021, 10:22 AMAkif Abasov [JB]
11/05/2021, 6:53 PMPromise
, you can easily write your own version of await()
using `then`/`catch` methods of Promise
and coroutines API which will work corretcly.Akif Abasov [JB]
11/05/2021, 6:56 PMBrian G
11/07/2021, 11:01 AM