Hello there, I am experimenting with the new comp...
# compose
l
Hello there, I am experimenting with the new compose multiplatform 1.5.1 and trying to do custom fonts in somehow common way. I see that there is a new experimental resource() function which gives a ByteArray for any given resource. My question is, how can I load it into a proper Font on Android? On iOS there seem to be a function for that but it is not resolving for Android for some reason. And afaik, loading Font directly from ByteArray is not possible, one would need to write it into a file and I’d need context for that. Am I missing something?
h
https://proandroiddev.com/custom-font-magic-in-compose-multiplatform-unlock-your-creativity-dcd0c9fa7756 this article gives a good example of how custom typography can be setup in a multiplatform setting. The main APIs that are going to be helpful to you are
FontListFontFamily
and
Font
. If you can define each
Font
as a common expect/actual value, then you can create your own common FontFamily using
FontListFontFamily
.
l
Yes I’ve read that article and was actually going for that originally, but was wondering if that is actually necessary given the new API
h
sorry I misinterpreted your question. Yes, unfortunately there is no way in Android to create a Typeface/Font from ByteArray. You'll need to write it to a file then re-read.
l
Well the question is, can I write it to a file without Context on Android? Do you know about such possibility?