-
Notifications
You must be signed in to change notification settings - Fork 50
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Paywalls: Support Google fonts and font families with multiple fonts (#…
…1338) ### Description Followup to #1328 This PR adds support for Google fonts when launching the paywall as an activity and modifies the API to better support both these and bundled fonts and font families with multiple fonts.
- Loading branch information
Showing
14 changed files
with
195 additions
and
18 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
9 changes: 5 additions & 4 deletions
9
.../src/main/kotlin/com/revenuecat/purchases/ui/revenuecatui/activity/PaywallActivityArgs.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,17 +1,18 @@ | ||
package com.revenuecat.purchases.ui.revenuecatui.activity | ||
|
||
import android.os.Parcelable | ||
import com.revenuecat.purchases.ui.revenuecatui.fonts.FontResourceProvider | ||
import com.revenuecat.purchases.ui.revenuecatui.fonts.ParcelizableFontProvider | ||
import com.revenuecat.purchases.ui.revenuecatui.fonts.PaywallFontFamily | ||
import com.revenuecat.purchases.ui.revenuecatui.fonts.TypographyType | ||
import kotlinx.parcelize.Parcelize | ||
|
||
@Parcelize | ||
internal data class PaywallActivityArgs( | ||
val offeringId: String? = null, | ||
val fonts: Map<TypographyType, Int?>? = null, | ||
val fonts: Map<TypographyType, PaywallFontFamily?>? = null, | ||
) : Parcelable { | ||
constructor(offeringId: String? = null, fontProvider: FontResourceProvider?) : this( | ||
constructor(offeringId: String? = null, fontProvider: ParcelizableFontProvider?) : this( | ||
offeringId, | ||
fontProvider?.let { TypographyType.values().associateBy({ it }, { fontProvider.getFontResourceId(it) }) }, | ||
fontProvider?.let { TypographyType.values().associateBy({ it }, { fontProvider.getFont(it) }) }, | ||
) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
11 changes: 11 additions & 0 deletions
11
...atui/src/main/kotlin/com/revenuecat/purchases/ui/revenuecatui/fonts/CustomFontProvider.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
package com.revenuecat.purchases.ui.revenuecatui.fonts | ||
|
||
import androidx.compose.ui.text.font.FontFamily | ||
|
||
/** | ||
* Class that allows to provide a font family for all text styles. | ||
* @param fontFamily the [FontFamily] to be used for all text styles. | ||
*/ | ||
class CustomFontProvider(private val fontFamily: FontFamily) : FontProvider { | ||
override fun getFont(type: TypographyType) = fontFamily | ||
} |
11 changes: 11 additions & 0 deletions
11
...n/kotlin/com/revenuecat/purchases/ui/revenuecatui/fonts/CustomParcelizableFontProvider.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
package com.revenuecat.purchases.ui.revenuecatui.fonts | ||
|
||
/** | ||
* Class that allows to provide a font family for all text styles. | ||
* @param fontFamily the [PaywallFontFamily] to be used for all text styles. | ||
*/ | ||
class CustomParcelizableFontProvider( | ||
private val fontFamily: PaywallFontFamily, | ||
) : ParcelizableFontProvider { | ||
override fun getFont(type: TypographyType) = fontFamily | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
13 changes: 13 additions & 0 deletions
13
...catui/src/main/kotlin/com/revenuecat/purchases/ui/revenuecatui/fonts/FontStyleParceler.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
package com.revenuecat.purchases.ui.revenuecatui.fonts | ||
|
||
import android.os.Parcel | ||
import androidx.compose.ui.text.font.FontStyle | ||
import kotlinx.parcelize.Parceler | ||
|
||
internal object FontStyleParceler : Parceler<FontStyle> { | ||
override fun create(parcel: Parcel) = FontStyle(parcel.readInt()) | ||
|
||
override fun FontStyle.write(parcel: Parcel, flags: Int) { | ||
parcel.writeInt(value) | ||
} | ||
} |
13 changes: 13 additions & 0 deletions
13
...atui/src/main/kotlin/com/revenuecat/purchases/ui/revenuecatui/fonts/FontWeightParceler.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
package com.revenuecat.purchases.ui.revenuecatui.fonts | ||
|
||
import android.os.Parcel | ||
import androidx.compose.ui.text.font.FontWeight | ||
import kotlinx.parcelize.Parceler | ||
|
||
internal object FontWeightParceler : Parceler<FontWeight> { | ||
override fun create(parcel: Parcel) = FontWeight(parcel.readInt()) | ||
|
||
override fun FontWeight.write(parcel: Parcel, flags: Int) { | ||
parcel.writeInt(weight) | ||
} | ||
} |
28 changes: 28 additions & 0 deletions
28
...atui/src/main/kotlin/com/revenuecat/purchases/ui/revenuecatui/fonts/GoogleFontProvider.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
package com.revenuecat.purchases.ui.revenuecatui.fonts | ||
|
||
import android.os.Parcelable | ||
import androidx.annotation.ArrayRes | ||
import androidx.compose.ui.text.googlefonts.GoogleFont | ||
import kotlinx.parcelize.Parcelize | ||
|
||
/** | ||
* Represents a Google font provider. | ||
*/ | ||
@Parcelize | ||
data class GoogleFontProvider( | ||
/** | ||
* The resource ID of the font provider's certificate(s). | ||
*/ | ||
@ArrayRes val certificates: Int, | ||
val providerAuthority: String = "com.google.android.gms.fonts", | ||
val providerPackage: String = "com.google.android.gms", | ||
) : Parcelable { | ||
|
||
fun toGoogleProvider(): GoogleFont.Provider { | ||
return GoogleFont.Provider( | ||
providerAuthority, | ||
providerPackage, | ||
certificates, | ||
) | ||
} | ||
} |
11 changes: 5 additions & 6 deletions
11
...evenuecatui/fonts/FontResourceProvider.kt → ...uecatui/fonts/ParcelizableFontProvider.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,20 +1,19 @@ | ||
package com.revenuecat.purchases.ui.revenuecatui.fonts | ||
|
||
import androidx.annotation.FontRes | ||
import com.revenuecat.purchases.ui.revenuecatui.activity.PaywallActivityLauncher | ||
|
||
/** | ||
* Implement this interface to provide custom fonts to the [PaywallActivityLauncher]. | ||
* If you don't, the default material3 theme fonts will be used. | ||
* If you only want to use a single [PaywallFontFamily] for all text styles use [CustomParcelizableFontProvider]. | ||
* Use [FontProvider] instead if you are using Compose with [PaywallView] or [PaywallDialog]. | ||
*/ | ||
interface FontResourceProvider { | ||
interface ParcelizableFontProvider { | ||
/** | ||
* Returns the font resource id to be used for the given [TypographyType]. If null is returned, | ||
* Returns the [PaywallFontFamily] to be used for the given [TypographyType]. If null is returned, | ||
* the default font will be used. | ||
* @param type the [TypographyType] for which the font is being requested. | ||
* @return the font resource id to be used for the given [TypographyType]. | ||
* @return the [PaywallFontFamily] to be used for the given [TypographyType]. | ||
*/ | ||
@FontRes | ||
fun getFontResourceId(type: TypographyType): Int? | ||
fun getFont(type: TypographyType): PaywallFontFamily? | ||
} |
57 changes: 57 additions & 0 deletions
57
...evenuecatui/src/main/kotlin/com/revenuecat/purchases/ui/revenuecatui/fonts/PaywallFont.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
package com.revenuecat.purchases.ui.revenuecatui.fonts | ||
|
||
import android.os.Parcelable | ||
import androidx.annotation.FontRes | ||
import androidx.compose.ui.text.font.FontStyle | ||
import androidx.compose.ui.text.font.FontWeight | ||
import kotlinx.parcelize.Parcelize | ||
import kotlinx.parcelize.TypeParceler | ||
|
||
/** | ||
* Represents a font. You can create either a [GoogleFont] or a [ResourceFont]. | ||
*/ | ||
sealed class PaywallFont : Parcelable { | ||
/** | ||
* Represents a downloadable Google Font. | ||
*/ | ||
@Parcelize | ||
data class GoogleFont( | ||
/** | ||
* Name of the Google font you want to use. | ||
*/ | ||
val fontName: String, | ||
/** | ||
* Provider of the Google font. | ||
*/ | ||
val fontProvider: GoogleFontProvider, | ||
/** | ||
* The weight of the font. The system uses this to match a font to a font request. | ||
*/ | ||
@TypeParceler<FontWeight, FontWeightParceler>() | ||
val fontWeight: FontWeight = FontWeight.Normal, | ||
/** | ||
* The style of the font, normal or italic. The system uses this to match a font to a font request. | ||
*/ | ||
@TypeParceler<FontStyle, FontStyleParceler>() | ||
val fontStyle: FontStyle = FontStyle.Normal, | ||
) : PaywallFont() | ||
|
||
@Parcelize | ||
data class ResourceFont( | ||
/** | ||
* The resource ID of the font file in font resources. | ||
*/ | ||
@FontRes | ||
val resourceId: Int, | ||
/** | ||
* The weight of the font. The system uses this to match a font to a font request. | ||
*/ | ||
@TypeParceler<FontWeight, FontWeightParceler>() | ||
val fontWeight: FontWeight = FontWeight.Normal, | ||
/** | ||
* The style of the font, normal or italic. The system uses this to match a font to a font request. | ||
*/ | ||
@TypeParceler<FontStyle, FontStyleParceler>() | ||
val fontStyle: FontStyle = FontStyle.Normal, | ||
) : PaywallFont() | ||
} |
10 changes: 10 additions & 0 deletions
10
...catui/src/main/kotlin/com/revenuecat/purchases/ui/revenuecatui/fonts/PaywallFontFamily.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
package com.revenuecat.purchases.ui.revenuecatui.fonts | ||
|
||
import android.os.Parcelable | ||
import kotlinx.parcelize.Parcelize | ||
|
||
/** | ||
* Represents a font family. You can add one ore more [PaywallFont] with different weights and font styles. | ||
*/ | ||
@Parcelize | ||
data class PaywallFontFamily(val fonts: List<PaywallFont>) : Parcelable |