createFontFamilyResolver
Deprecated This exists to bridge existing Font.ResourceLoader subclasses to be used as aFontFamily.ResourceLoader during upgrade.
fun createFontFamilyResolver(
fontResourceLoader: Font.ResourceLoader,
context: Context,
): FontFamily.Resolver
Bridge between subclasses of Font.ResourceLoader and the new FontFamily.Resolver API.
To use add as a CompositionLocal replacing the default FontFamily.Resolver:
LocalFontFamilyResolver provides createFontFamilyResolver(myFontResourceLoader, context)
This FontFamily.Resolver is capable of loading all fonts that the default FontFamily.Resolver is. In addition, it will delegate all resource fonts to the provided Font.ResourceLoader, preserving the behavior of Compose 1.0.
This method will be removed by Compose 2.0, and callers should migrate to using AndroidFont
to
implement the same behavior using font fallback chains.
A FontFamily.Resolver created this way will not share caches with other FontFamily.Resolvers.
fun createFontFamilyResolver(context: Context): FontFamily.Resolver
Create a new fontFamilyResolver for use outside of composition context
Example usages:
- Application.onCreate to preload fonts
- Creating Paragraph objects on background thread
Usages inside of Composition should use LocalFontFamilyResolver.current
All instances of FontFamily.Resolver created by createFontFamilyResolver
share the same
typeface caches.
fun createFontFamilyResolver(
context: Context,
coroutineContext: CoroutineContext,
): FontFamily.Resolver
Create a new fontFamilyResolver for use outside of composition context with a coroutine context.
Example usages:
- Application.onCreate to preload fonts
- Creating Paragraph objects on background thread
- Configuring LocalFontFamilyResolver with a different CoroutineScope
Usages inside of Composition should use LocalFontFamilyResolver.current
Any kotlinx.coroutines.CoroutineExceptionHandler
provided will be called with exceptions
related to fallback font loading. These exceptions are not fatal, and indicate that font fallback
continued to the next font load.
If no kotlinx.coroutines.CoroutineExceptionHandler
is provided, a default implementation will
be added that ignores all exceptions.
All instances of FontFamily.Resolver created by createFontFamilyResolver
share the same
typeface caches.
Parameters
context | Android context for resolving fonts |
coroutineContext | context to launch async requests in during resolution. |