Skip to content

Instantly share code, notes, and snippets.

@raipankaj
Created April 18, 2022 05:17
Show Gist options
  • Select an option

  • Save raipankaj/bcdc3b4e37bed373a5fe6c7a47f80281 to your computer and use it in GitHub Desktop.

Select an option

Save raipankaj/bcdc3b4e37bed373a5fe6c7a47f80281 to your computer and use it in GitHub Desktop.
Download font support in Jetpack Compose
@OptIn(ExperimentalTextApi::class)
private fun getGoogleFontFamily(
name: String,
provider: GoogleFont.Provider = googleFontProvider,
weights: List<FontWeight>
): FontFamily {
return FontFamily(
weights.map {
Font(GoogleFont(name), provider, it)
}
)
}
@OptIn(ExperimentalTextApi::class)
private val googleFontProvider: GoogleFont.Provider by lazy {
GoogleFont.Provider(
providerAuthority = "com.google.android.gms.fonts",
providerPackage = "com.google.android.gms",
certificates = R.array.com_google_android_gms_fonts_certs
)
}
@OptIn(ExperimentalTextApi::class)
val AppFontTypography = Typography(
defaultFontFamily = getGoogleFontFamily(
name = "Poppins",
weights = listOf(
FontWeight.Normal,
FontWeight.Bold,
FontWeight.ExtraLight,
FontWeight.SemiBold
)
)
)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment