FontLoadingStrategy
value class FontLoadingStrategy private constructor(val value: Int)
Font loading strategy for a Font
in a FontListFontFamily
.
This controls how font loading resolves when displaying text in Compose.
For more information about font family resolution see FontFamily
.
Companion Object
Properties
val Blocking = FontLoadingStrategy(0)
Resolving this font will always block until the font loads.
This means that the first frame that uses this font will always display using the desired font, and text will never reflow.
This should typically be used for fonts that stored on-device. It is acceptable to block the first frame of an application to read a font from disk.
This should typically not be used for fonts that are fetched from a remote source such as
over http, as it will block all rendering until the font loads. Instead use Async
.
val OptionalLocal = FontLoadingStrategy(1)
Resolving this font is best-effort and will attempt to load from a local resource that MAY be available.
Resolving this font will always block until the font resolves, and text will never reflow.
An OptionalLocal
font describes a font that is installed locally, such as an optional
system installed font. Resolution of an OptionalLocal
font is expected to fail whenever
the resource is not available, which will fallback to the next font in the FontFamily
.
Typical usages involve following the OptionalLocal
font with the same font loaded from
a remote Async
source. It may also be followed by other OptionalLocal
fonts or
Blocking
fonts that have less specific styling to avoid async delay.
Apps should expect that OptionalLocal
fonts will fail to load on devices where the font
is not available.
*
This should typically not be used for fonts that are fetched from a remote source such as
over http, as it will block all rendering until the font loads. Instead use Async
.
val Async = FontLoadingStrategy(2)
Loading this font will never block, and will load on a background thread.
During loading, the app will not block but instead will find the next available font that
is immediately available (Blocking
or OptionalLocal
). When the font finishes loading,
text will reflow with the resolved typeface.
If no fallback fonts are available immediately, the platform default typeface will be used to draw text during loading.
If loading fails, the failure is stored permanently, and future uses of the font will always use the fallback.
This should typically not be used for fonts that are stored on-device and needed for the
first frame. Instead use Blocking
or OptionalLocal
.
This should always be used for fonts that are fetched from a remote source such as over http.