react-native-purchases-ui 8.11.1 → 8.11.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/android/build.gradle +1 -1
- package/android/src/main/java/com/revenuecat/purchases/react/ui/PaywallFooterViewManager.kt +28 -28
- package/android/src/main/java/com/revenuecat/purchases/react/ui/PaywallViewManager.kt +7 -7
- package/android/src/main/java/com/revenuecat/purchases/react/ui/views/ComposeViewWrapper.kt +65 -0
- package/android/src/main/java/com/revenuecat/purchases/react/ui/views/WrappedPaywallComposeView.kt +34 -0
- package/android/src/main/java/com/revenuecat/purchases/react/ui/views/WrappedPaywallFooterComposeView.kt +31 -0
- package/package.json +2 -2
package/android/build.gradle
CHANGED
@@ -3,19 +3,17 @@ package com.revenuecat.purchases.react.ui
|
|
3
3
|
import androidx.core.view.children
|
4
4
|
import com.facebook.react.uimanager.ThemedReactContext
|
5
5
|
import com.revenuecat.purchases.react.ui.events.OnMeasureEvent
|
6
|
-
import com.revenuecat.purchases.ui.
|
6
|
+
import com.revenuecat.purchases.react.ui.views.WrappedPaywallFooterComposeView
|
7
7
|
import com.revenuecat.purchases.ui.revenuecatui.fonts.CustomFontProvider
|
8
|
-
import com.revenuecat.purchases.ui.revenuecatui.views.PaywallFooterView
|
9
8
|
|
10
|
-
|
11
|
-
internal class PaywallFooterViewManager : BasePaywallViewManager<PaywallFooterView>() {
|
9
|
+
internal class PaywallFooterViewManager : BasePaywallViewManager<WrappedPaywallFooterComposeView>() {
|
12
10
|
|
13
11
|
override fun getName(): String {
|
14
12
|
return "RCPaywallFooterView"
|
15
13
|
}
|
16
14
|
|
17
|
-
override fun createViewInstance(themedReactContext: ThemedReactContext):
|
18
|
-
return object :
|
15
|
+
override fun createViewInstance(themedReactContext: ThemedReactContext): WrappedPaywallFooterComposeView {
|
16
|
+
return object : WrappedPaywallFooterComposeView(themedReactContext) {
|
19
17
|
|
20
18
|
// This is required so the change from Loading to Loaded resizes the view
|
21
19
|
// https://github.com/facebook/react-native/issues/17968#issuecomment-1672111483
|
@@ -43,27 +41,29 @@ internal class PaywallFooterViewManager : BasePaywallViewManager<PaywallFooterVi
|
|
43
41
|
// https://medium.com/traveloka-engineering/react-native-at-traveloka-native-ui-components-c6b66f789f35
|
44
42
|
public override fun onMeasure(widthMeasureSpec: Int, heightMeasureSpec: Int) {
|
45
43
|
super.onMeasure(widthMeasureSpec, heightMeasureSpec)
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
44
|
+
if (isAttached) {
|
45
|
+
var maxWidth = 0
|
46
|
+
var maxHeight = 0
|
47
|
+
children.forEach {
|
48
|
+
it.measure(widthMeasureSpec, MeasureSpec.UNSPECIFIED)
|
49
|
+
maxWidth = maxWidth.coerceAtLeast(it.measuredWidth)
|
50
|
+
maxHeight = maxHeight.coerceAtLeast(it.measuredHeight)
|
51
|
+
}
|
52
|
+
val finalWidth = maxWidth.coerceAtLeast(suggestedMinimumWidth)
|
53
|
+
val finalHeight = maxHeight.coerceAtLeast(suggestedMinimumHeight)
|
54
|
+
setMeasuredDimension(finalWidth, finalHeight)
|
56
55
|
|
57
|
-
|
58
|
-
|
56
|
+
val density = context.resources.displayMetrics.density
|
57
|
+
val finalHeightInDp = finalHeight / density
|
59
58
|
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
59
|
+
val onMeasureEvent = OnMeasureEvent(
|
60
|
+
this.surfaceId,
|
61
|
+
this.id,
|
62
|
+
finalHeightInDp.toInt()
|
63
|
+
)
|
64
|
+
(context as? ThemedReactContext)?.reactApplicationContext?.let { reactApplicationContext ->
|
65
|
+
emitEvent(reactApplicationContext, this.id, onMeasureEvent)
|
66
|
+
}
|
67
67
|
}
|
68
68
|
}
|
69
69
|
}.also { view ->
|
@@ -72,15 +72,15 @@ internal class PaywallFooterViewManager : BasePaywallViewManager<PaywallFooterVi
|
|
72
72
|
}
|
73
73
|
}
|
74
74
|
|
75
|
-
override fun setOfferingId(view:
|
75
|
+
override fun setOfferingId(view: WrappedPaywallFooterComposeView, identifier: String) {
|
76
76
|
view.setOfferingId(identifier)
|
77
77
|
}
|
78
78
|
|
79
|
-
override fun setFontFamily(view:
|
79
|
+
override fun setFontFamily(view: WrappedPaywallFooterComposeView, customFontProvider: CustomFontProvider) {
|
80
80
|
view.setFontProvider(customFontProvider)
|
81
81
|
}
|
82
82
|
|
83
|
-
override fun setDisplayDismissButton(view:
|
83
|
+
override fun setDisplayDismissButton(view: WrappedPaywallFooterComposeView, display: Boolean) {
|
84
84
|
// No-op since PaywallFooterView doesn't have a dismiss button
|
85
85
|
}
|
86
86
|
|
@@ -1,11 +1,11 @@
|
|
1
1
|
package com.revenuecat.purchases.react.ui
|
2
2
|
|
3
3
|
import com.facebook.react.uimanager.ThemedReactContext
|
4
|
+
import com.revenuecat.purchases.react.ui.views.WrappedPaywallComposeView
|
4
5
|
import com.revenuecat.purchases.ui.revenuecatui.fonts.CustomFontProvider
|
5
|
-
import com.revenuecat.purchases.ui.revenuecatui.views.PaywallView
|
6
6
|
|
7
7
|
|
8
|
-
internal class PaywallViewManager : BasePaywallViewManager<
|
8
|
+
internal class PaywallViewManager : BasePaywallViewManager<WrappedPaywallComposeView>() {
|
9
9
|
|
10
10
|
companion object {
|
11
11
|
const val REACT_CLASS = "Paywall"
|
@@ -15,8 +15,8 @@ internal class PaywallViewManager : BasePaywallViewManager<PaywallView>() {
|
|
15
15
|
return REACT_CLASS
|
16
16
|
}
|
17
17
|
|
18
|
-
override fun createViewInstance(themedReactContext: ThemedReactContext):
|
19
|
-
return
|
18
|
+
override fun createViewInstance(themedReactContext: ThemedReactContext): WrappedPaywallComposeView {
|
19
|
+
return WrappedPaywallComposeView(themedReactContext).also { view ->
|
20
20
|
view.setPaywallListener(createPaywallListenerWrapper(themedReactContext, view))
|
21
21
|
view.setDismissHandler(getDismissHandler(themedReactContext, view))
|
22
22
|
}
|
@@ -26,15 +26,15 @@ internal class PaywallViewManager : BasePaywallViewManager<PaywallView>() {
|
|
26
26
|
return PaywallViewShadowNode()
|
27
27
|
}
|
28
28
|
|
29
|
-
override fun setOfferingId(view:
|
29
|
+
override fun setOfferingId(view: WrappedPaywallComposeView, identifier: String) {
|
30
30
|
view.setOfferingId(identifier)
|
31
31
|
}
|
32
32
|
|
33
|
-
override fun setFontFamily(view:
|
33
|
+
override fun setFontFamily(view: WrappedPaywallComposeView, customFontProvider: CustomFontProvider) {
|
34
34
|
view.setFontProvider(customFontProvider)
|
35
35
|
}
|
36
36
|
|
37
|
-
override fun setDisplayDismissButton(view:
|
37
|
+
override fun setDisplayDismissButton(view: WrappedPaywallComposeView, display: Boolean) {
|
38
38
|
view.setDisplayDismissButton(display)
|
39
39
|
}
|
40
40
|
|
@@ -0,0 +1,65 @@
|
|
1
|
+
package com.revenuecat.purchases.react.ui.views
|
2
|
+
|
3
|
+
import android.content.Context
|
4
|
+
import android.util.AttributeSet
|
5
|
+
import android.view.View
|
6
|
+
import android.view.ViewGroup
|
7
|
+
import android.widget.FrameLayout
|
8
|
+
|
9
|
+
abstract class ComposeViewWrapper<T : View> : FrameLayout {
|
10
|
+
protected var wrappedView: T? = null
|
11
|
+
protected var isAttached = false
|
12
|
+
|
13
|
+
constructor(context: Context, attrs: AttributeSet?) : super(context, attrs) {
|
14
|
+
init(context, attrs)
|
15
|
+
}
|
16
|
+
|
17
|
+
constructor(context: Context, attrs: AttributeSet?, defStyleAttr: Int) : super(context, attrs, defStyleAttr) {
|
18
|
+
init(context, attrs)
|
19
|
+
}
|
20
|
+
|
21
|
+
constructor(context: Context) : super(context) {
|
22
|
+
init(context, null)
|
23
|
+
}
|
24
|
+
|
25
|
+
protected abstract fun createWrappedView(context: Context, attrs: AttributeSet?): T
|
26
|
+
|
27
|
+
private fun init(context: Context, attrs: AttributeSet?) {
|
28
|
+
wrappedView = createWrappedView(context, attrs).apply {
|
29
|
+
layoutParams = LayoutParams(
|
30
|
+
ViewGroup.LayoutParams.MATCH_PARENT,
|
31
|
+
ViewGroup.LayoutParams.MATCH_PARENT
|
32
|
+
)
|
33
|
+
}
|
34
|
+
addView(wrappedView)
|
35
|
+
}
|
36
|
+
|
37
|
+
override fun onAttachedToWindow() {
|
38
|
+
super.onAttachedToWindow()
|
39
|
+
isAttached = true
|
40
|
+
requestLayout()
|
41
|
+
}
|
42
|
+
|
43
|
+
override fun onDetachedFromWindow() {
|
44
|
+
super.onDetachedFromWindow()
|
45
|
+
isAttached = false
|
46
|
+
}
|
47
|
+
|
48
|
+
override fun onMeasure(widthMeasureSpec: Int, heightMeasureSpec: Int) {
|
49
|
+
if (isAttached) {
|
50
|
+
super.onMeasure(widthMeasureSpec, heightMeasureSpec)
|
51
|
+
} else {
|
52
|
+
setMeasuredDimension(
|
53
|
+
MeasureSpec.getSize(widthMeasureSpec),
|
54
|
+
MeasureSpec.getSize(heightMeasureSpec)
|
55
|
+
)
|
56
|
+
}
|
57
|
+
}
|
58
|
+
|
59
|
+
override fun onLayout(changed: Boolean, left: Int, top: Int, right: Int, bottom: Int) {
|
60
|
+
super.onLayout(changed, left, top, right, bottom)
|
61
|
+
if (isAttached) {
|
62
|
+
wrappedView?.requestLayout()
|
63
|
+
}
|
64
|
+
}
|
65
|
+
}
|
package/android/src/main/java/com/revenuecat/purchases/react/ui/views/WrappedPaywallComposeView.kt
ADDED
@@ -0,0 +1,34 @@
|
|
1
|
+
package com.revenuecat.purchases.react.ui.views
|
2
|
+
|
3
|
+
import android.content.Context
|
4
|
+
import android.util.AttributeSet
|
5
|
+
import com.revenuecat.purchases.ui.revenuecatui.PaywallListener
|
6
|
+
import com.revenuecat.purchases.ui.revenuecatui.fonts.FontProvider
|
7
|
+
import com.revenuecat.purchases.ui.revenuecatui.views.PaywallView
|
8
|
+
|
9
|
+
class WrappedPaywallComposeView(context: Context) : ComposeViewWrapper<PaywallView>(context) {
|
10
|
+
|
11
|
+
override fun createWrappedView(context: Context, attrs: AttributeSet?): PaywallView {
|
12
|
+
return PaywallView(context, attrs)
|
13
|
+
}
|
14
|
+
|
15
|
+
fun setPaywallListener(listener: PaywallListener?) {
|
16
|
+
wrappedView?.setPaywallListener(listener)
|
17
|
+
}
|
18
|
+
|
19
|
+
fun setDismissHandler(dismissHandler: (() -> Unit)?) {
|
20
|
+
wrappedView?.setDismissHandler(dismissHandler)
|
21
|
+
}
|
22
|
+
|
23
|
+
fun setOfferingId(offeringId: String?) {
|
24
|
+
wrappedView?.setOfferingId(offeringId)
|
25
|
+
}
|
26
|
+
|
27
|
+
fun setFontProvider(fontProvider: FontProvider?) {
|
28
|
+
wrappedView?.setFontProvider(fontProvider)
|
29
|
+
}
|
30
|
+
|
31
|
+
fun setDisplayDismissButton(shouldDisplayDismissButton: Boolean) {
|
32
|
+
wrappedView?.setDisplayDismissButton(shouldDisplayDismissButton)
|
33
|
+
}
|
34
|
+
}
|
@@ -0,0 +1,31 @@
|
|
1
|
+
package com.revenuecat.purchases.react.ui.views
|
2
|
+
|
3
|
+
import android.content.Context
|
4
|
+
import android.util.AttributeSet
|
5
|
+
import com.revenuecat.purchases.ui.revenuecatui.PaywallListener
|
6
|
+
import com.revenuecat.purchases.ui.revenuecatui.fonts.CustomFontProvider
|
7
|
+
import com.revenuecat.purchases.ui.revenuecatui.views.OriginalTemplatePaywallFooterView
|
8
|
+
|
9
|
+
open class WrappedPaywallFooterComposeView(context: Context) : ComposeViewWrapper<OriginalTemplatePaywallFooterView>(context) {
|
10
|
+
|
11
|
+
override fun createWrappedView(context: Context, attrs: AttributeSet?): OriginalTemplatePaywallFooterView {
|
12
|
+
return OriginalTemplatePaywallFooterView(context, attrs)
|
13
|
+
}
|
14
|
+
|
15
|
+
fun setOfferingId(identifier: String) {
|
16
|
+
wrappedView?.setOfferingId(identifier)
|
17
|
+
}
|
18
|
+
|
19
|
+
fun setFontProvider(customFontProvider: CustomFontProvider) {
|
20
|
+
wrappedView?.setFontProvider(customFontProvider)
|
21
|
+
}
|
22
|
+
|
23
|
+
fun setPaywallListener(listener: PaywallListener) {
|
24
|
+
wrappedView?.setPaywallListener(listener)
|
25
|
+
}
|
26
|
+
|
27
|
+
fun setDismissHandler(handler: (() -> Unit)) {
|
28
|
+
wrappedView?.setDismissHandler(handler)
|
29
|
+
}
|
30
|
+
|
31
|
+
}
|
package/package.json
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
{
|
2
2
|
"name": "react-native-purchases-ui",
|
3
3
|
"title": "React Native Purchases UI",
|
4
|
-
"version": "8.11.
|
4
|
+
"version": "8.11.2",
|
5
5
|
"description": "React Native in-app purchases and subscriptions made easy. Supports iOS and Android.",
|
6
6
|
"main": "lib/commonjs/index",
|
7
7
|
"module": "lib/module/index",
|
@@ -115,6 +115,6 @@
|
|
115
115
|
},
|
116
116
|
"dependencies": {
|
117
117
|
"@revenuecat/purchases-typescript-internal": "13.33.0",
|
118
|
-
"react-native-purchases": "8.11.
|
118
|
+
"react-native-purchases": "8.11.2"
|
119
119
|
}
|
120
120
|
}
|