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

[Customer Center]: fix navigation when embedded in NavigationStack #4622

Merged
merged 6 commits into from
Jan 14, 2025
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 @@ -24,9 +24,18 @@ import SwiftUI
struct CompatibilityNavigationStack<Content: View>: View {

@ViewBuilder var content: Content
let isInNavigationStack: Bool

init(isInNavigationStack: Bool = false,
@ViewBuilder content: () -> Content) {
self.isInNavigationStack = isInNavigationStack
self.content = content()
}

var body: some View {
if #available(iOS 16.0, *) {
if isInNavigationStack {
content
} else if #available(iOS 16.0, *) {
facumenzella marked this conversation as resolved.
Show resolved Hide resolved
NavigationStack {
content
}
Expand Down
18 changes: 14 additions & 4 deletions RevenueCatUI/CustomerCenter/Views/CustomerCenterView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -42,30 +42,40 @@ public struct CustomerCenterView: View {
private var colorScheme

private let mode: CustomerCenterPresentationMode
private let isInNavigationStack: Bool

/// Create a view to handle common customer support tasks
/// - Parameters:
/// - customerCenterActionHandler: An optional `CustomerCenterActionHandler` to handle actions
/// from the Customer Center.
public init(customerCenterActionHandler: CustomerCenterActionHandler? = nil) {
self.init(customerCenterActionHandler: customerCenterActionHandler, mode: .default)
/// - isInNavigationStack: Whether this view is already inside a navigation stack
public init(customerCenterActionHandler: CustomerCenterActionHandler? = nil,
isInNavigationStack: Bool = false) {
facumenzella marked this conversation as resolved.
Show resolved Hide resolved
self.init(customerCenterActionHandler: customerCenterActionHandler,
mode: .default,
isInNavigationStack: isInNavigationStack)
}

/// Create a view to handle common customer support tasks
/// - Parameters:
/// - customerCenterActionHandler: An optional `CustomerCenterActionHandler` to handle actions
/// from the Customer Center.
/// - mode: The presentation mode for the Customer Center
/// - isInNavigationStack: Whether this view is already inside a navigation stack
init(customerCenterActionHandler: CustomerCenterActionHandler? = nil,
mode: CustomerCenterPresentationMode) {
mode: CustomerCenterPresentationMode,
isInNavigationStack: Bool = false) {
facumenzella marked this conversation as resolved.
Show resolved Hide resolved
self._viewModel = .init(wrappedValue:
CustomerCenterViewModel(customerCenterActionHandler: customerCenterActionHandler))
self.mode = mode
self.isInNavigationStack = isInNavigationStack
}

fileprivate init(viewModel: CustomerCenterViewModel,
mode: CustomerCenterPresentationMode = CustomerCenterPresentationMode.default) {
self._viewModel = .init(wrappedValue: viewModel)
self.mode = mode
self.isInNavigationStack = false
}

// swiftlint:disable:next missing_docs
Expand Down Expand Up @@ -157,7 +167,7 @@ private extension CustomerCenterView {
let accentColor = Color.from(colorInformation: configuration.appearance.accentColor,
for: self.colorScheme)

CompatibilityNavigationStack {
CompatibilityNavigationStack(isInNavigationStack: isInNavigationStack) {
destinationContent(configuration: configuration)
}
facumenzella marked this conversation as resolved.
Show resolved Hide resolved
.applyIf(accentColor != nil, apply: { $0.tint(accentColor) })
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,6 @@ struct RestorePurchasesAlert: ViewModifier {

@State
private var alertType: AlertType = .restorePurchases
@Environment(\.dismiss)
private var dismiss
@Environment(\.localization)
private var localization
@Environment(\.supportInformation)
Expand Down Expand Up @@ -164,7 +162,7 @@ struct RestorePurchasesAlert: ViewModifier {

private func dismissAlert() {
self.alertType = .restorePurchases
dismiss()
self.isPresented = false
facumenzella marked this conversation as resolved.
Show resolved Hide resolved
}
}

Expand Down