Open michalgwo opened 2 weeks ago
I see. Res
is compose-specific, so would add a dependency, that's a no-no.
But you can just use the regular constructor of the FeatureDictionary.
Adding a function like
fun createFeatureDictionary(
featuresAccess: ResourceAccessAdapter,
brandFeaturesAccess: ResourceAccessAdapter?,
) = FeatureDictionary(
featureCollection = IDLocalizedFeatureCollection(featuresAccess),
brandFeatureCollection = brandFeaturesAccess?.let { IDBrandPresetsFeatureCollection(it) }
)
Then, you just need to implement a ResourceAccessAdapter
that uses the functions from KMP Compose Resources to access the resources.
It took way too long to find this out, but you can use
val buffer = Buffer()
UnsafeBufferOperations.moveToTail(buffer, byteArray)
to wrap a ByteArray
into a Buffer
(without copying it). A Buffer
implements Source
.
Maybe one day KMP Compose Resources will also directly offer a function like Res.readSource
.
Is there a method like Res.exists
at all, though?
Is there a method like
Res.exists
at all, though?
Not exactly, but it can be checked with Res.getUri()
which returns MissingResourceException
when the file doesn't exist.
Currently, there are 2 options to initialize the dictionary, either by providing
FileSystem
orAssetManager
, but onlyFileSystem
is available in the common source set of the Kotlin Multiplatform project. In case when we keep our presets data in compose resources, they are not available fromFileSystem
, they are bundled into apk, thus right now it's not possible to get them with osmfeatures library in the common source set.To get a raw file from compose resources we can use
Res.readBytes("files/presets/preset.json")
(reference).To solve this issue, I propose to make
FeatureDictionary.create()
accept aRes
object as a parameter and read presets from compose resources byRes.readBytes()