From 6b21007153365235418f3943a960a1f9546592e0 Mon Sep 17 00:00:00 2001 From: Tieda Wei Date: Sun, 13 Nov 2022 21:13:07 -0500 Subject: [PATCH] Add tapping on cancel button to dismiss bottom sheet in Example app --- iOS Example/Sources/ContentView.swift | 2 +- iOS Example/Sources/MapSettingView.swift | 9 +++++++-- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/iOS Example/Sources/ContentView.swift b/iOS Example/Sources/ContentView.swift index 3ea0554..ba8aa99 100644 --- a/iOS Example/Sources/ContentView.swift +++ b/iOS Example/Sources/ContentView.swift @@ -28,7 +28,7 @@ struct ContentView: View { topBarCornerRadius: 16, showTopIndicator: false ) { - MapSettingView() + MapSettingView{ self.showMapSetting = false } } .navigationBarTitle("Bottom Sheet") .navigationBarItems( diff --git a/iOS Example/Sources/MapSettingView.swift b/iOS Example/Sources/MapSettingView.swift index 4002116..ebd68e3 100644 --- a/iOS Example/Sources/MapSettingView.swift +++ b/iOS Example/Sources/MapSettingView.swift @@ -9,12 +9,17 @@ import SwiftUI struct MapSettingView: View { + let dismiss: () -> Void + var body: some View { VStack(alignment: .leading) { HStack { Text("Map Settings").font(.title).bold() Spacer() - Image(systemName: "xmark.circle.fill").foregroundColor(.gray).font(.system(size: 26)) + Image(systemName: "xmark.circle.fill") + .foregroundColor(.gray) + .font(.system(size: 26)) + .onTapGesture { dismiss() } }.padding(.horizontal) Picker(selection: .constant(0), label: Text("")) { Text("Map").tag(0) @@ -62,6 +67,6 @@ struct MapSettingView: View { struct MapSettingView_Previews: PreviewProvider { static var previews: some View { - MapSettingView() + MapSettingView(dismiss: {}) } }