Image tap auto-dismiss the view

release
Laurent 3 years ago
parent 5305066e36
commit 5410f41f82
  1. 15
      LeCountdown/Views/CountdownFormView.swift
  2. 7
      LeCountdown/Views/ImageSelectionView.swift

@ -20,6 +20,8 @@ struct CountdownFormView : View {
var textFieldIsFocused: FocusState<Bool>.Binding
@State var imageSelectionSheetShown: Bool = false
var body: some View {
Form {
Section(header: Text("Duration")) {
@ -45,12 +47,12 @@ struct CountdownFormView : View {
Text("Sound")
}
Toggle("Sound repeats", isOn: repeatsBinding)
}
Section {
NavigationLink {
ImageSelectionView(imageBinding: imageBinding)
Section(header: Text("Background")) {
Button {
self.imageSelectionSheetShown = true
} label: {
Group {
if let image = self.imageBinding.wrappedValue {
@ -63,10 +65,13 @@ struct CountdownFormView : View {
.aspectRatio(1, contentMode: .fit)
.frame(width: 100.0, height: 100.0)
.cornerRadius(40.0)
}
}
}.sheet(isPresented: self.$imageSelectionSheetShown) {
ImageSelectionView(showBinding: self.$imageSelectionSheetShown, imageBinding: self.imageBinding)
}
}

@ -9,6 +9,8 @@ import SwiftUI
struct ImageSelectionView: View {
var showBinding: Binding<Bool>
var imageBinding: Binding<CoolPic>
private let columns: [GridItem] = [
@ -35,11 +37,10 @@ struct ImageSelectionView: View {
.frame(minWidth: 0, maxWidth: .infinity, minHeight: 0, maxHeight: .infinity)
.aspectRatio(1, contentMode: .fit)
.cornerRadius(40.0)
.roundedCorner(selected: self.imageBinding.wrappedValue == coolPic)
}
.onTapGesture {
self.imageBinding.wrappedValue = coolPic
self.showBinding.wrappedValue = false
print("coolPic = \(coolPic), image = \(String(describing: self.imageBinding.wrappedValue))")
}
@ -53,6 +54,6 @@ struct ImageSelectionView: View {
struct ImageSelectionView_Previews: PreviewProvider {
static var previews: some View {
ImageSelectionView(imageBinding: .constant(.pic3))
ImageSelectionView(showBinding: .constant(true), imageBinding: .constant(.pic3))
}
}

Loading…
Cancel
Save