Skip to content

Commit

Permalink
PurchaseTesterSwiftUI: fixed iOS compilation
Browse files Browse the repository at this point in the history
Fixes from #2345.

The changes were made to make `macOS` work better, but they're only available in iOS 16+.
This brings back the previous `NavigationView` and `NavigationLink` APIs that are backwards compatible.
  • Loading branch information
NachoSoto committed Mar 24, 2023
1 parent 339e13d commit 604cff1
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 21 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -24,23 +24,21 @@ struct PurchaseTesterApp: App {
WindowGroup(id: Windows.default.rawValue) {
Group {
if let configuration {
NavigationSplitView {
ContentView(configuration: configuration)
.environmentObject(self.revenueCatCustomerData)
.toolbar {
ToolbarItem(placement: .principal) {
Button {
self.configuration = nil
} label: {
Text("Reconfigure")
}
}
}
} detail: {
DynamicCustomerView(customerInfo: self.$revenueCatCustomerData.customerInfo)
Group {
#if os(macOS)
NavigationSplitView {
self.content(configuration)
} detail: {
DynamicCustomerView(customerInfo: self.$revenueCatCustomerData.customerInfo)
}
.navigationSplitViewStyle(.balanced)
.navigationSplitViewColumnWidth(100)
#else
NavigationView {
self.content(configuration)
}
#endif
}
.navigationSplitViewStyle(.balanced)
.navigationSplitViewColumnWidth(100)
.task(id: self.configuration?.purchases) {
self.revenueCatCustomerData.customerInfo = nil

Expand Down Expand Up @@ -102,6 +100,20 @@ struct PurchaseTesterApp: App {
}
}

private func content(_ configuration: ConfiguredPurchases) -> some View {
ContentView(configuration: configuration)
.environmentObject(self.revenueCatCustomerData)
.toolbar {
ToolbarItem(placement: .principal) {
Button {
self.configuration = nil
} label: {
Text("Reconfigure")
}
}
}
}

private var isConfigured: Bool {
return self.configuration != nil
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,9 @@ struct HomeView: View {
#endif
}
}
#if os(macOS)
.padding()
#endif
.task {
await self.fetchData()
}
Expand Down Expand Up @@ -232,8 +234,10 @@ private struct CustomerInfoHeaderView: View {
HStack {
Spacer()

NavigationLink(value: self.revenueCatCustomerData.customerInfo) {
Text("View Info")
if let customerInfo = self.revenueCatCustomerData.customerInfo {
NavigationLink(destination: CustomerView(customerInfo: customerInfo)) {
Text("View Info")
}
}

Spacer()
Expand Down Expand Up @@ -280,9 +284,6 @@ private struct CustomerInfoHeaderView: View {

}.padding(.top, 20)
}
.navigationDestination(for: CustomerInfo.self) {
CustomerView(customerInfo: $0)
}
}

}
Expand Down

0 comments on commit 604cff1

Please sign in to comment.