-
-
Notifications
You must be signed in to change notification settings - Fork 27
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add ability to set a custom popup bar view
- Loading branch information
Showing
12 changed files
with
321 additions
and
36 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,103 @@ | ||
// | ||
// MapView.swift | ||
// LNPopupUIExample | ||
// | ||
// Created by Leo Natan (Wix) on 9/3/20. | ||
// | ||
|
||
import SwiftUI | ||
import MapKit | ||
|
||
struct EnlargingButton: View { | ||
let label: String | ||
let action: (Bool) -> Void | ||
@State var pressed: Bool = false | ||
|
||
init(label: String, perform action: @escaping (Bool) -> Void) { | ||
self.label = label | ||
self.action = action | ||
} | ||
|
||
var body: some View { | ||
return Text(label) | ||
.font(.title) | ||
.foregroundColor(.white) | ||
.padding(10) | ||
.background(RoundedRectangle(cornerRadius: 10).foregroundColor(.blue)) | ||
.scaleEffect(self.pressed ? 1.2 : 1.0) | ||
.onLongPressGesture(minimumDuration: .infinity, maximumDistance: .infinity, pressing: { pressing in | ||
withAnimation(.easeInOut) { | ||
self.pressed = pressing | ||
self.action(pressing) | ||
} | ||
}, perform: { }) | ||
} | ||
} | ||
|
||
struct CustomBarMapView: View { | ||
static private let center = CLLocationCoordinate2D(latitude: 40.6892, longitude: -74.0445) | ||
static private let defaultRegion = MKCoordinateRegion(center: CustomBarMapView.center, span: MKCoordinateSpan(latitudeDelta: 0.5, longitudeDelta: 0.5)) | ||
|
||
static private let zoomedRegion = MKCoordinateRegion(center: CustomBarMapView.center, span: MKCoordinateSpan(latitudeDelta: 0.01, longitudeDelta: 0.01)) | ||
|
||
@State private var region = CustomBarMapView.defaultRegion | ||
|
||
private let onDismiss: () -> Void | ||
|
||
init(onDismiss: @escaping () -> Void) { | ||
self.onDismiss = onDismiss | ||
} | ||
|
||
@State var input: String = "" | ||
@State var isPopupOpen: Bool = false | ||
|
||
var body: some View { | ||
ZStack(alignment: Alignment(horizontal: .leading, vertical: .top)) { | ||
Map(coordinateRegion: $region) | ||
.ignoresSafeArea() | ||
.animation(.easeInOut) | ||
Button(action: { | ||
onDismiss() | ||
}, label: { | ||
Image(systemName: "chevron.left.circle.fill") | ||
.resizable() | ||
.renderingMode(.template) | ||
.frame(width: 30, height: 30, alignment: .center) | ||
}) | ||
.background(Color(.systemBackground).cornerRadius(15)) | ||
.padding(10) | ||
} | ||
.popup(isBarPresented: Binding.constant(true), isPopupOpen: $isPopupOpen) { | ||
Color.red | ||
.ignoresSafeArea() | ||
} | ||
.popupBarCustomView(wantsDefaultTapGesture: false, wantsDefaultPanGesture: false, wantsDefaultHighlightGesture: false) { | ||
ZStack(alignment: .trailing) { | ||
HStack { | ||
Spacer() | ||
EnlargingButton(label: "Zoom") { pressing in | ||
self.region = pressing ? CustomBarMapView.zoomedRegion : CustomBarMapView.defaultRegion | ||
}.padding() | ||
Spacer() | ||
|
||
} | ||
Button(action: { | ||
isPopupOpen.toggle() | ||
}, label: { | ||
Image(systemName: "chevron.up.square.fill") | ||
.resizable() | ||
.renderingMode(.template) | ||
.frame(width: 30, height: 30, alignment: .center) | ||
}) | ||
.background(Color(.systemBackground).cornerRadius(15)) | ||
.padding(10) | ||
} | ||
} | ||
} | ||
} | ||
|
||
struct MapView_Previews: PreviewProvider { | ||
static var previews: some View { | ||
CustomBarMapView(onDismiss: {}) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
// | ||
// SceneSelection.swift | ||
// LNPopupUIExample | ||
// | ||
// Created by Leo Natan (Wix) on 9/2/20. | ||
// | ||
|
||
import SwiftUI | ||
|
||
struct SceneSelection: View { | ||
@State var musicSheetPresented: Bool = false | ||
@State var mapSheetPresented: Bool = false | ||
|
||
var body: some View { | ||
NavigationView { | ||
List { | ||
Section(header: Text("Demo App").frame(height: 48, alignment: .bottom)) { | ||
Button("Apple Music") { | ||
musicSheetPresented.toggle() | ||
} | ||
.foregroundColor(Color(.label)) | ||
.fullScreenCover(isPresented: $musicSheetPresented, content: { | ||
MusicView { | ||
musicSheetPresented.toggle() | ||
} | ||
}) | ||
} | ||
Section(header: Text("Custom Popup Bar")) { | ||
Button("Custom Popup Bar with SwiftUI") { | ||
mapSheetPresented.toggle() | ||
} | ||
.foregroundColor(Color(.label)) | ||
.fullScreenCover(isPresented: $mapSheetPresented, content: { | ||
CustomBarMapView { | ||
mapSheetPresented.toggle() | ||
} | ||
}) | ||
} | ||
} | ||
.listStyle(GroupedListStyle()) | ||
.navigationBarTitle("LNPopupUI") | ||
.navigationBarTitleDisplayMode(.inline) | ||
} | ||
.navigationViewStyle(StackNavigationViewStyle()) | ||
.ignoresSafeArea() | ||
} | ||
} | ||
|
||
struct SceneSelection_Previews: PreviewProvider { | ||
static var previews: some View { | ||
SceneSelection() | ||
|
||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.