Skip to content

Commit

Permalink
Address PR comments
Browse files Browse the repository at this point in the history
  • Loading branch information
tonidero committed Oct 11, 2023
1 parent a9ed2d3 commit 22992ca
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -42,21 +42,26 @@ internal class PaywallActivity : ComponentActivity(), PaywallViewListener {
}
}

override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
val args = getArgs()
val fontProvider = args?.mapFonts?.let { mapFonts ->
private fun getFontProvider(): FontProvider? {
return getArgs()?.fonts?.let { fonts ->
val fontsMap = fonts.mapValues { entry ->
entry.value?.let { fontRes ->
ResourcesCompat.getFont(this, fontRes)?.let { FontFamily(it) }
}
}
object : FontProvider {
override fun getFont(type: TypographyType): FontFamily? {
return mapFonts[type]?.let { fontRes ->
return ResourcesCompat.getFont(this@PaywallActivity, fontRes)?.let { FontFamily(it) }
}
return fontsMap[type]
}
}
}
}

override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
val paywallOptions = PaywallViewOptions.Builder()
.setOfferingId(getArgs()?.offeringId)
.setFontProvider(fontProvider)
.setFontProvider(getFontProvider())
.setListener(this)
.build()
setContent {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,17 @@
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.TypographyType
import kotlinx.parcelize.Parcelize

@Parcelize
internal data class PaywallActivityArgs(
val offeringId: String? = null,
val mapFonts: Map<TypographyType, Int?>? = null,
) : Parcelable
val fonts: Map<TypographyType, Int?>? = null,
) : Parcelable {
constructor(offeringId: String? = null, provider: FontResourceProvider?) : this(
offeringId,
provider?.let { TypographyType.values().associateBy({ it }, { provider.getFontResourceId(it) }) },
)
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import androidx.activity.result.ActivityResultLauncher
import androidx.fragment.app.Fragment
import com.revenuecat.purchases.Offering
import com.revenuecat.purchases.ui.revenuecatui.fonts.FontResourceProvider
import com.revenuecat.purchases.ui.revenuecatui.fonts.TypographyType

/**
* Implement this interface to receive the result of the paywall activity.
Expand Down Expand Up @@ -41,13 +40,10 @@ class PaywallActivityLauncher {
*/
@JvmOverloads
fun launch(offering: Offering? = null, fontResourceProvider: FontResourceProvider? = null) {
val fontMap = fontResourceProvider?.let { provider ->
TypographyType.values().associateBy({ it }, { provider.getFontResourceId(it) })
}
activityResultLauncher.launch(
PaywallActivityArgs(
offeringId = offering?.identifier,
mapFonts = fontMap,
provider = fontResourceProvider,
),
)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ import com.revenuecat.purchases.ui.revenuecatui.PaywallView
/**
* Implement this interface to provide custom fonts to the [PaywallView]. If you don't, the current material3 theme
* typography will be used.
* This can't be used when launching the paywall as an activity since the fonts are not parcelable/serializable.
* Use [FontResourceProvider] instead.
*/
interface FontProvider {
/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ 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.
* Use [FontProvider] instead if you are using Compose with [PaywallView] or [PaywallDialog].
*/
interface FontResourceProvider {
/**
Expand Down

0 comments on commit 22992ca

Please sign in to comment.