Image tap auto-dismiss the view

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

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

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

Loading…
Cancel
Save