Improve display of results
This commit is contained in:
@ -5,10 +5,14 @@ struct ListPopup: View {
|
||||
@Environment(\.dismiss)
|
||||
var dismiss
|
||||
|
||||
let title: LocalizedStringKey
|
||||
|
||||
let items: [String]
|
||||
|
||||
var body: some View {
|
||||
VStack {
|
||||
Text(title)
|
||||
.font(.title)
|
||||
List {
|
||||
ForEach(items, id: \.self) { page in
|
||||
Text(page)
|
||||
|
@ -5,12 +5,14 @@ struct TextWithPopup: View {
|
||||
|
||||
let symbol: SFSymbol
|
||||
|
||||
let title: LocalizedStringKey
|
||||
|
||||
let text: LocalizedStringKey
|
||||
|
||||
let items: [String]
|
||||
|
||||
@State
|
||||
private var isHovering = false
|
||||
private var showSheet = false
|
||||
|
||||
var body: some View {
|
||||
HStack {
|
||||
@ -23,14 +25,69 @@ struct TextWithPopup: View {
|
||||
.contentShape(Rectangle())
|
||||
.onTapGesture {
|
||||
if items.count > 0 {
|
||||
isHovering.toggle()
|
||||
showSheet.toggle()
|
||||
}
|
||||
}
|
||||
.sheet(isPresented: $isHovering) {
|
||||
ListPopup(items: items)
|
||||
.sheet(isPresented: $showSheet) {
|
||||
ListPopup(title: title, items: items)
|
||||
.onTapGesture {
|
||||
isHovering.toggle()
|
||||
showSheet.toggle()
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
struct PopupWithList<ListContent>: View where ListContent: View {
|
||||
|
||||
let symbol: SFSymbol
|
||||
|
||||
let text: LocalizedStringKey
|
||||
|
||||
let canShowPopup: Bool
|
||||
|
||||
let content: ListContent
|
||||
|
||||
init(symbol: SFSymbol, text: LocalizedStringKey, canShowPopup: Bool, @ViewBuilder content: () -> ListContent) {
|
||||
self.symbol = symbol
|
||||
self.text = text
|
||||
self.canShowPopup = canShowPopup
|
||||
self.content = content()
|
||||
}
|
||||
|
||||
@State
|
||||
private var showSheet = false
|
||||
|
||||
var body: some View {
|
||||
HStack {
|
||||
Image(systemSymbol: symbol)
|
||||
.resizable()
|
||||
.aspectRatio(contentMode: .fit)
|
||||
.frame(width: 16, height: 16)
|
||||
Text(text)
|
||||
}
|
||||
.contentShape(Rectangle())
|
||||
.onTapGesture {
|
||||
if canShowPopup {
|
||||
showSheet.toggle()
|
||||
}
|
||||
}
|
||||
.sheet(isPresented: $showSheet) {
|
||||
Popup(content: content)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private struct Popup<Content>: View where Content: View {
|
||||
|
||||
@Environment(\.dismiss)
|
||||
var dismiss
|
||||
|
||||
let content: Content
|
||||
|
||||
var body: some View {
|
||||
VStack {
|
||||
content
|
||||
Button("Dismiss") { dismiss() }
|
||||
}.padding()
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user