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

Add shouldDisplayDismissButton #606

Merged
merged 8 commits into from
Dec 26, 2023
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import android.os.Bundle
import androidx.fragment.app.Fragment
import androidx.fragment.app.FragmentActivity
import androidx.lifecycle.ViewModelProvider
import com.revenuecat.purchases.Offering
import com.revenuecat.purchases.ui.revenuecatui.ExperimentalPreviewRevenueCatUIPurchasesAPI
import com.revenuecat.purchases.ui.revenuecatui.activity.PaywallActivityLauncher
import com.revenuecat.purchases.ui.revenuecatui.activity.PaywallResult
Expand All @@ -13,19 +14,22 @@ import com.revenuecat.purchases.ui.revenuecatui.activity.PaywallResultHandler
internal class PaywallFragment : Fragment(), PaywallResultHandler {
companion object {
private const val requiredEntitlementIdentifierKey = "requiredEntitlementIdentifier"
private const val shouldDisplayDismissButtonKey = "shouldDisplayDismissButton"
const val tag: String = "revenuecat-paywall-fragment"

@JvmStatic
fun newInstance(
activity: FragmentActivity,
requiredEntitlementIdentifier: String? = null,
paywallResultListener: PaywallResultListener? = null,
shouldDisplayDismissButton: Boolean? = null,
vegaro marked this conversation as resolved.
Show resolved Hide resolved
): PaywallFragment {
val paywallFragmentViewModel = ViewModelProvider(activity)[PaywallFragmentViewModel::class.java]
paywallFragmentViewModel.paywallResultListener = paywallResultListener
return PaywallFragment().apply {
arguments = Bundle().apply {
putString(requiredEntitlementIdentifierKey, requiredEntitlementIdentifier)
shouldDisplayDismissButton?.let { putBoolean(shouldDisplayDismissButtonKey, it) }
}
}
}
Expand All @@ -37,6 +41,9 @@ internal class PaywallFragment : Fragment(), PaywallResultHandler {
private val requiredEntitlementIdentifier: String?
get() = arguments?.getString(requiredEntitlementIdentifierKey)

private val shouldDisplayDismissButton: Boolean?
get() = arguments?.getBoolean(shouldDisplayDismissButtonKey)

override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)

Expand All @@ -46,8 +53,13 @@ internal class PaywallFragment : Fragment(), PaywallResultHandler {
)
viewModel = ViewModelProvider(requireActivity())[PaywallFragmentViewModel::class.java]

requiredEntitlementIdentifier?.let {
launcher.launchIfNeeded(requiredEntitlementIdentifier = it)
requiredEntitlementIdentifier?.let { requiredEntitlementIdentifier ->
shouldDisplayDismissButton?.let { shouldDisplayDismissButton ->
launcher.launchIfNeeded(
requiredEntitlementIdentifier = requiredEntitlementIdentifier,
shouldDisplayDismissButton = shouldDisplayDismissButton,
)
} ?: launcher.launchIfNeeded(requiredEntitlementIdentifier = requiredEntitlementIdentifier)
} ?: launcher.launch()
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,15 @@ import UIKit
}

@objc
public func presentPaywall() {
public func presentPaywall(
Copy link
Contributor

Choose a reason for hiding this comment

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

Should we add this to the api tests?

displayCloseButton: Bool = false
Copy link
Contributor

Choose a reason for hiding this comment

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

I wonder if we should make it nullable instead? So we can use the default defined in purchases-ios

Copy link
Contributor

Choose a reason for hiding this comment

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

Actually, not sure if that would work in objc, since nullable booleans didn't work well if I remember correctly

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I tried and I get

Method cannot be marked @objc because the type of the parameter cannot be represented in Objective-C

I can maybe do two functions?

Copy link
Contributor

Choose a reason for hiding this comment

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

That's an option yeah... Maybe that would be better to try to avoid having the default in multiple places, but I'm ok keeping it like this as well.

) {
guard let rootController = UIApplication.shared.keyWindow?.rootViewController else {
NSLog("Unable to find root UIViewController")
return
}

let controller = PaywallViewController(displayCloseButton: true)
let controller = PaywallViewController(displayCloseButton: displayCloseButton)
controller.delegate = self
controller.modalPresentationStyle = .pageSheet

Expand Down