Skip to content

Commit 8ff4d23

Browse files
author
qinhui
committed
Fix the low-version compilation error problem
1 parent 1d1cdb6 commit 8ff4d23

1 file changed

Lines changed: 28 additions & 21 deletions

File tree

iOS/APIExample-SwiftUI/APIExample-SwiftUI/ContentView.swift

Lines changed: 28 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -101,27 +101,7 @@ struct ContentView: View {
101101
ForEach(menus) { section in
102102
Section(header: Text(section.name)) {
103103
ForEach(section.rows) { item in
104-
if item.name == "Picture In Picture".localized {
105-
if #available(iOS 15.0, *) {
106-
NavigationLink(destination: {
107-
item.view.navigationTitle(item.name)
108-
}) {
109-
Text(item.name)
110-
}
111-
} else {
112-
Button(action: {
113-
showAlert()
114-
}) {
115-
Text(item.name)
116-
}
117-
}
118-
} else {
119-
NavigationLink(destination: {
120-
item.view.navigationTitle(item.name)
121-
}) {
122-
Text(item.name)
123-
}
124-
}
104+
MenuItemView(item: item)
125105
}
126106
}
127107
}
@@ -131,6 +111,33 @@ struct ContentView: View {
131111
.navigationBarTitleDisplayMode(.inline)
132112
}
133113
}
114+
}
115+
116+
struct MenuItemView: View {
117+
var item: MenuItem
118+
var body: some View {
119+
if item.name == "Picture In Picture".localized {
120+
if #available(iOS 15.0, *) {
121+
NavigationLink(destination: {
122+
item.view.navigationTitle(item.name)
123+
}) {
124+
Text(item.name)
125+
}
126+
} else {
127+
Button(action: {
128+
showAlert()
129+
}) {
130+
Text(item.name)
131+
}
132+
}
133+
} else {
134+
NavigationLink(destination: {
135+
item.view.navigationTitle(item.name)
136+
}) {
137+
Text(item.name)
138+
}
139+
}
140+
}
134141

135142
func showAlert() {
136143
let alert = UIAlertController(title: "Unsupported", message: "Picture in Picture is not supported on this version of iOS.", preferredStyle: .alert)

0 commit comments

Comments
 (0)