On iPad, NavigationView needs to use .columns style to properly show split view (sidebar + detail pane). On iPhone, .stack style works correctly. Previously, iPad was not using the columns style, causing the detail view (MeterDetailView for offline meters) to appear instead of the correct MeterView (with Home, Live, Chart tabs) for connected meters. This ensures: - iPhone: Stack navigation (one view at a time) - iPad: Split view (sidebar + content side by side)
@@ -11,10 +11,35 @@ |
||
| 11 | 11 |
import SwiftUI |
| 12 | 12 |
|
| 13 | 13 |
struct ContentView: View {
|
| 14 |
+ #if os(iOS) |
|
| 15 |
+ private static let isPhone: Bool = UIDevice.current.userInterfaceIdiom == .phone |
|
| 16 |
+ #else |
|
| 17 |
+ private static let isPhone: Bool = false |
|
| 18 |
+ #endif |
|
| 19 |
+ |
|
| 14 | 20 |
var body: some View {
|
| 21 |
+ if Self.isPhone {
|
|
| 22 |
+ navigationViewPhone |
|
| 23 |
+ } else {
|
|
| 24 |
+ navigationViewPad |
|
| 25 |
+ } |
|
| 26 |
+ } |
|
| 27 |
+ |
|
| 28 |
+ @ViewBuilder |
|
| 29 |
+ private var navigationViewPhone: some View {
|
|
| 30 |
+ NavigationView {
|
|
| 31 |
+ SidebarView() |
|
| 32 |
+ .navigationBarTitle(Text("USB Meters"), displayMode: .inline)
|
|
| 33 |
+ } |
|
| 34 |
+ .navigationViewStyle(.stack) |
|
| 35 |
+ } |
|
| 36 |
+ |
|
| 37 |
+ @ViewBuilder |
|
| 38 |
+ private var navigationViewPad: some View {
|
|
| 15 | 39 |
NavigationView {
|
| 16 | 40 |
SidebarView() |
| 17 | 41 |
.navigationBarTitle(Text("USB Meters"), displayMode: .inline)
|
| 18 | 42 |
} |
| 43 |
+ .navigationViewStyle(.columns) |
|
| 19 | 44 |
} |
| 20 | 45 |
} |