Mike Digman
04/24/2023, 7:31 PMDesktopXmlVectorParser
to web, making Android XML resources easy to access. Required only changing a few lines within the parser itself (to handle null cases).@Composable
private fun Resource.rememberXMLImageVector(): LoadState<ImageVector> {
val state: MutableState<LoadState<ImageVector>> = remember(this) { mutableStateOf(LoadState.Loading()) }
val density = LocalDensity.current
LaunchedEffect(this) {
state.value = try {
val xmlString = readBytes().decodeToString()
val xmlDom = DOMParser().parseFromString(xmlString, "application/xml")
val rootXmlElement = xmlDom.documentElement!!
val imageVector = rootXmlElement.parseVectorRoot(density)
LoadState.Success(imageVector)
} catch (e: Exception) {
LoadState.Error(e)
}
}
return state.value
}
Oleksandr Karpovich [JB]
04/25/2023, 9:17 AMparseXML
implementation missing
https://github.com/JetBrains/compose-multiplatform/blob/master/components/resource[…]rc/jsMain/kotlin/org/jetbrains/compose/resources/Resource.js.kt
I think these 3 lines would be useful for that method implementation:
val xmlString = readBytes().decodeToString()
val xmlDom = DOMParser().parseFromString(xmlString, "application/xml")
val rootXmlElement = xmlDom.documentElement!!
The caveat is that resources lib has its own interface for Node, Element, etc. But their implementations should be able to simply delegate to the corresponding js instances.
Your contribution is very much welcome 🙂Mike Digman
04/25/2023, 6:49 PMOleksandr Karpovich [JB]
04/26/2023, 2:11 PMMike Digman
04/26/2023, 6:05 PMOleksandr Karpovich [JB]
04/27/2023, 9:28 AMMike Digman
04/27/2023, 3:59 PM