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

feat: [CustomerCenter] Introduce CustomerCenterNavigationLink #4664

Merged
merged 7 commits into from
Jan 15, 2025
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
//
// CustomerCenterNavigationLink.swift
// RevenueCat
//
// Created by Facundo Menzella on 14/1/25.
//

import RevenueCat
import SwiftUI

/// A view that provides a navigation link to `CustomerCenterView` with a customizable label.
///
/// This is the **preferred way** to integrate `CustomerCenterView` into your `NavigationStack`,
/// ensuring proper navigation behavior by setting `isEmbededInNavigation` to `true`.
///
///
/// Example:
/// ```swift
/// CustomerCenterNavigationLink {
/// HStack {
/// Image(systemName: "person.circle")
/// Text("Customer Center")
/// }
/// }
///
/// CustomerCenterNavigationLink(Text("Customer Center"))
/// ```
@available(iOS 15.0, *)
@available(macOS, unavailable)
@available(tvOS, unavailable)
@available(watchOS, unavailable)
public struct CustomerCenterNavigationLink<Label: View>: View {

@ViewBuilder let label: () -> Label

/// Initializes the navigation link with a label view provided by a closure.
///
/// Use this initializer when the label requires dynamic content or complex logic.
///
/// Example:
/// ```swift
/// CustomerCenterNavigationLink {
/// HStack {
/// Image(systemName: "person.circle")
/// Text("Customer Center")
/// }
/// }
/// ```
///
/// - Parameter label: A closure that returns the view to display as the navigation link’s label.
public init(label: @escaping () -> Label) {
facumenzella marked this conversation as resolved.
Show resolved Hide resolved
facumenzella marked this conversation as resolved.
Show resolved Hide resolved
self.label = label
}

/// The content and behavior of the navigation link.
public var body: some View {
NavigationLink {
CustomerCenterView(isEmbeddedInNavigationStack: true)
} label: {
label()
}
}
}