Skip to content

Commit

Permalink
fix: Only pass ViewBuilder in public init
Browse files Browse the repository at this point in the history
  • Loading branch information
PhilippeWeidmann committed Feb 11, 2025
1 parent 6c77914 commit 09ee64b
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 26 deletions.
14 changes: 4 additions & 10 deletions Sources/MyKSuite/Sources/Dashboard/HeaderView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,8 @@ import InfomaniakCoreSwiftUI
import SwiftUI

struct HeaderView<Content: View>: View {
private let myKSuite: MyKSuite
private let avatar: Content

init(myKSuite: MyKSuite, avatar: Content) {
self.myKSuite = myKSuite

self.avatar = avatar
}
let myKSuite: MyKSuite
let avatarView: () -> Content

var body: some View {
HStack {
Expand All @@ -37,7 +31,7 @@ struct HeaderView<Content: View>: View {
.iconSize(.medium)
.foregroundStyle(ColorHelper.secondary)

avatar
avatarView()
.frame(width: 24, height: 24)
}
.frame(width: 24, height: 24)
Expand All @@ -63,5 +57,5 @@ struct HeaderView<Content: View>: View {
}

#Preview {
HeaderView(myKSuite: PreviewHelper.sampleMyKSuite, avatar: EmptyView())
HeaderView(myKSuite: PreviewHelper.sampleMyKSuite) { EmptyView() }
}
Original file line number Diff line number Diff line change
Expand Up @@ -31,19 +31,19 @@ public struct MyKSuiteDashboardView<Content: View>: View {
@State private var myKSuite: MyKSuite?
private let apiFetcher: KSuiteApiFetchable
private let userId: Int
private let avatar: Content
private let avatarView: () -> Content

public init(apiFetcher: KSuiteApiFetchable, userId: Int, @ViewBuilder avatar: () -> Content) {
public init(apiFetcher: KSuiteApiFetchable, userId: Int, @ViewBuilder avatarView: @escaping () -> Content) {
self.apiFetcher = apiFetcher
self.userId = userId
self.avatar = avatar()
self.avatarView = avatarView
}

public var body: some View {
NavigationView {
if let myKSuite {
VStack(spacing: IKPadding.large) {
SubscriptionCardView(myKSuite: myKSuite, avatar: avatar)
SubscriptionCardView(myKSuite: myKSuite, avatarView: avatarView)

if !myKSuite.isFree {
SubscriptionBenefitsView()
Expand Down
26 changes: 14 additions & 12 deletions Sources/MyKSuite/Sources/Dashboard/SubscriptionCardView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,11 @@ import SwiftUI

struct SubscriptionCardView<Content: View>: View {
let myKSuite: MyKSuite
let avatar: Content
let avatarView: () -> Content

var body: some View {
VStack(spacing: IKPadding.large) {
HeaderView(myKSuite: myKSuite, avatar: avatar)
HeaderView(myKSuite: myKSuite, avatarView: avatarView)

Divider()
.overlay(ColorHelper.divider)
Expand All @@ -50,14 +50,16 @@ struct SubscriptionCardView<Content: View>: View {
}

#Preview {
SubscriptionCardView(myKSuite: PreviewHelper.sampleMyKSuite, avatar: EmptyView())
.padding()
.frame(maxHeight: .infinity, alignment: .top)
.background {
Resources.Assets.background.swiftUIImage
.resizable()
.scaledToFit()
.frame(maxHeight: .infinity, alignment: .top)
.ignoresSafeArea()
}
SubscriptionCardView(myKSuite: PreviewHelper.sampleMyKSuite) {
EmptyView()
}
.padding()
.frame(maxHeight: .infinity, alignment: .top)
.background {
Resources.Assets.background.swiftUIImage
.resizable()
.scaledToFit()
.frame(maxHeight: .infinity, alignment: .top)
.ignoresSafeArea()
}
}

0 comments on commit 09ee64b

Please sign in to comment.