Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[EXTERNAL] Exposing fontprovider setter in PaywallView and PaywallFooterView by @Jjastiny #1589

Merged
merged 13 commits into from
Feb 1, 2024

Conversation

tonidero
Copy link
Contributor

@tonidero tonidero commented Feb 1, 2024

External contribution from #1588

Checklist

  • If applicable, create follow-up issues for purchases-ios and hybrids

Motivation

  • It's not possible for us to change the font family in react-native-purchase.
  • My hope was to expose this font provider methods for the RN Bridge so that we can at least set custom font family.

Description

  • Exposing fontProviders for PaywallFooterView and PaywallView.
  • theme composition local provider should update this autmoatically.

Need to add something like this on the React Native side.
If user did link the font via

<font-family xmlns:app="http://schemas.android.com/apk/res/android">
        <font app:fontStyle="normal" android:fontWeight="200" android:font="@font/montserrat" />
</font-family>
    ReactFontManager.getInstance().addCustomFont(this, "Montserrat", R.font.montserrat);

We could just bring the font family

    @ReactProp(name= "fontFamily")
    fun setFontFamily(view: PaywallFooterView, fontFamily: String?){
        val typeface = ReactFontManager.getInstance()
            .getTypeface(fontFamily /** Montserrat in this case. **/, ReactFontManager.TypefaceStyle.NORMAL, assets)
        
        view.setFontProvider(CustomFontProvider(FontFamily(typeface)))
    }
Screenshot 2024-01-26 at 10 04 03 PM

Jjastiny and others added 10 commits January 26, 2024 11:39
…to exposing-fontprovider

# Conflicts:
#	ui/revenuecatui/src/main/kotlin/com/revenuecat/purchases/ui/revenuecatui/views/PaywallFooterView.kt
…ew(context))

expose the font provider. set a private getter and setter to reduce some boilerplate
### Checklist
- [ ] If applicable, create follow-up issues for `purchases-ios` and
hybrids

### Motivation
- It's not possible for us to change the font family in
react-native-purchase.
- My hope was to expose this font provider methods for the RN Bridge so
that we can at least set custom font family.

### Description
- Exposing fontProviders for PaywallFooterView and PaywallView.
- theme composition local provider should update this autmoatically.

Need to add something like this on the React Native side.
If user did link the font via
```xml
<font-family xmlns:app="http://schemas.android.com/apk/res/android">
        <font app:fontStyle="normal" android:fontWeight="200" android:font="@font/montserrat" />
</font-family>
```

```kotlin
    ReactFontManager.getInstance().addCustomFont(this, "Montserrat", R.font.montserrat);
```

We could just bring the font family 
```kotlin
    @ReactProp(name= "fontFamily")
    fun setFontFamily(view: PaywallFooterView, fontFamily: String?){
        val typeface = ReactFontManager.getInstance()
            .getTypeface(fontFamily /** Montserrat in this case. **/, ReactFontManager.TypefaceStyle.NORMAL, assets)
        
        view.setFontProvider(CustomFontProvider(FontFamily(typeface)))
    }
```

<img width="350" alt="Screenshot 2024-01-26 at 10 04 03 PM"
src="https://github.com/RevenueCat/purchases-android/assets/6516487/e8e41b0d-c1fd-4446-8d5b-11cb9de200e5">
@tonidero tonidero added the feat A new feature label Feb 1, 2024
@@ -14,7 +15,7 @@ import com.revenuecat.purchases.ui.revenuecatui.views.PaywallFooterView
private class PaywallFooterViewAPI {

fun checkType(context: Context) {
val paywallFooterView: FrameLayout = PaywallFooterView(context)
val paywallFooterView: AbstractComposeView = PaywallFooterView(context)
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a breaking change... But feels that it should be ok... Any thoughts?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If it works I think we should go for it, it will simplify the views

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Paywalls is still experimental so :)

@tonidero tonidero marked this pull request as ready for review February 1, 2024 08:26
@tonidero tonidero requested a review from a team February 1, 2024 08:26
@tonidero tonidero changed the title [EXTERNAL] Exposing fontprovider in PaywallView and PaywallFooterView by @Jjastiny [EXTERNAL] Exposing fontprovider setter in PaywallView and PaywallFooterView by @Jjastiny Feb 1, 2024
@tonidero tonidero force-pushed the external/Jjastiny/exposing-fontprovider branch from 2cb4572 to 4cf3a8e Compare February 1, 2024 08:38
Copy link

codecov bot commented Feb 1, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Comparison is base (fce561f) 83.71% compared to head (4cf3a8e) 83.71%.
Report is 1 commits behind head on main.

❗ Current head 4cf3a8e differs from pull request most recent head 123f64e. Consider uploading reports for the commit 123f64e to get more accurate results

Additional details and impacted files
@@           Coverage Diff           @@
##             main    #1589   +/-   ##
=======================================
  Coverage   83.71%   83.71%           
=======================================
  Files         218      218           
  Lines        7260     7260           
  Branches     1011     1011           
=======================================
  Hits         6078     6078           
  Misses        788      788           
  Partials      394      394           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@@ -113,16 +126,6 @@ class PaywallView : FrameLayout {
.setOfferingId(initialOfferingId)
.setShouldDisplayDismissButton(shouldDisplayDismissButton ?: false)
.build()
addView(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we change line 123 to be paywallOptions = PaywallOptions.Builder?

@tonidero tonidero enabled auto-merge (squash) February 1, 2024 15:42
@@ -133,4 +136,12 @@ class PaywallView : FrameLayout {
this.initialFontProvider = fontProvider
this.shouldDisplayDismissButton = shouldDisplayDismissButton
}

@Composable
override fun Content() {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is much nicer

@tonidero tonidero merged commit 8704c8f into main Feb 1, 2024
7 checks passed
@tonidero tonidero deleted the external/Jjastiny/exposing-fontprovider branch February 1, 2024 16:00
NachoSoto added a commit to RevenueCat/purchases-ios that referenced this pull request Feb 2, 2024
…3626)

This is the iOS counterpart to
RevenueCat/purchases-android#1589
This exposes the `fontName` as a parameter and sets `CustomFontProvider`. 

### Description
- Created `updateFontWithFontName` for `PaywallViewController`
- Created init function for `offerIdentifier` and `fontName`

<img width="450" alt="301765252-95f61abb-10a1-4903-a2ef-12572ae3eaff"
src="https://github.com/RevenueCat/purchases-ios/assets/6516487/56061916-0391-447a-ae74-57f2dddcf7a7">

---------

Co-authored-by: NachoSoto <NachoSoto@users.noreply.github.com>
NachoSoto added a commit to RevenueCat/purchases-ios that referenced this pull request Feb 2, 2024
@Jjastiny) (#3628)

Original PR: #3626.

This is the iOS counterpart to
RevenueCat/purchases-android#1589
This exposes the `fontName` as a parameter and sets
`CustomFontProvider`.

### Changes:
- Created `updateFontWithFontName` for `PaywallViewController`
- Created init function for `offerIdentifier` and `fontName`

<img width="450" alt="301765252-95f61abb-10a1-4903-a2ef-12572ae3eaff"
src="https://github.com/RevenueCat/purchases-ios/assets/6516487/56061916-0391-447a-ae74-57f2dddcf7a7">

---------

Co-authored-by: Justin Yang <jjastiny@gmail.com>
vegaro added a commit that referenced this pull request Feb 6, 2024
#1589 made
`PaywallFooterView` an `AbstractComposeView`, which broke React Native's
implementation because we override `onMeasure` which is final in
`AbstractComposeView`
vegaro pushed a commit that referenced this pull request Feb 6, 2024
**This is an automatic release.**

### New Features
* [EXTERNAL] Exposing fontprovider setter in `PaywallView` and
`PaywallFooterView` by @Jjastiny (#1589) via Toni Rico (@tonidero)
### RevenueCatUI
* `Paywalls`:  add 4 new variables (#1599) via NachoSoto (@NachoSoto)
### Bugfixes
* Catch Exception instead of only IllegalArgumentException when decoding
paywallData (#1601) via Cesar de la Vega (@vegaro)
* Revert making PaywallFooterView an AbstractComposeView (#1598) via
Cesar de la Vega (@vegaro)
* Add missing forwarding to `PaywallListener.onPurchaseCancelled`
(#1590) via Cesar de la Vega (@vegaro)
### Dependency Updates
* Bump danger from 9.4.2 to 9.4.3 (#1597) via dependabot[bot]
(@dependabot[bot])
### Other Changes
* Update CHANGELOG with 6.9.6 release notes (#1596) via Toni Rico
(@tonidero)

Co-authored-by: revenuecat-ops <ops@revenuecat.com>
tonidero added a commit to RevenueCat/react-native-purchases that referenced this pull request Feb 23, 2024
…View (contributed by @Jjastiny) (#916)

Thank you for contributing to react-native-purchases. Before pressing
the "Create Pull Request" button, please provide the following:

- [x] A description about what and why you are contributing, even if
it's trivial.

- [x] The issue number(s) or PR number(s) in the description if you are
contributing in response to those.

  - [ ] If applicable, unit tests.

This PR adds a fontFamily string in PaywallOptions Prop, which enables
the developers to change the font for the paywall to their custom font.
```typescript
export interface PaywallViewOptions {
  offering?: PurchasesOffering | null;
  fontFamily?: String | null; // New
}
```

This is the RN native module update for following PR's
RevenueCat/purchases-ios#3628 AND
RevenueCat/purchases-android#1589

---------

Co-authored-by: Jjastiny <jjastiny@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feat A new feature
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants