Skip to content

Commit

Permalink
Merge pull request #10 from LucasJorgeHubert/feature/request-ride-view
Browse files Browse the repository at this point in the history
Feature - Request ride view
  • Loading branch information
LucasJorgeHubert authored May 23, 2023
2 parents 326779e + 977f200 commit 03d3c68
Show file tree
Hide file tree
Showing 23 changed files with 420 additions and 68 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@

*.xcuserstate
*.xcuserstate
16 changes: 16 additions & 0 deletions eUberUI.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@
/* Begin PBXBuildFile section */
C91BB1442A16BDC000C0B971 /* RideRequestView.swift in Sources */ = {isa = PBXBuildFile; fileRef = C91BB1432A16BDC000C0B971 /* RideRequestView.swift */; };
C97221BD2A169FD40014EABA /* MapViewState.swift in Sources */ = {isa = PBXBuildFile; fileRef = C97221BC2A169FD40014EABA /* MapViewState.swift */; };
C9AA5E762A1C113E00824737 /* RideType.swift in Sources */ = {isa = PBXBuildFile; fileRef = C9AA5E752A1C113E00824737 /* RideType.swift */; };
C9AA5E782A1CFA5600824737 /* Double.swift in Sources */ = {isa = PBXBuildFile; fileRef = C9AA5E772A1CFA5600824737 /* Double.swift */; };
C9AA5E7A2A1CFCD900824737 /* EUberLocation.swift in Sources */ = {isa = PBXBuildFile; fileRef = C9AA5E792A1CFCD900824737 /* EUberLocation.swift */; };
C9CFFE442A15179E00708A15 /* eUberUIApp.swift in Sources */ = {isa = PBXBuildFile; fileRef = C9CFFE432A15179E00708A15 /* eUberUIApp.swift */; };
C9CFFE482A1517A200708A15 /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = C9CFFE472A1517A200708A15 /* Assets.xcassets */; };
C9CFFE4B2A1517A200708A15 /* Preview Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = C9CFFE4A2A1517A200708A15 /* Preview Assets.xcassets */; };
Expand All @@ -24,6 +27,7 @@
C9CFFE8B2A15410900708A15 /* LocationSearchView.swift in Sources */ = {isa = PBXBuildFile; fileRef = C9CFFE8A2A15410900708A15 /* LocationSearchView.swift */; };
C9CFFE8D2A15447800708A15 /* LocationSearchResultCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = C9CFFE8C2A15447800708A15 /* LocationSearchResultCell.swift */; };
C9CFFE8F2A154F1900708A15 /* LocationSearchViewModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = C9CFFE8E2A154F1900708A15 /* LocationSearchViewModel.swift */; };
C9DD5C842A1D0B4500B357DB /* Color.swift in Sources */ = {isa = PBXBuildFile; fileRef = C9DD5C832A1D0B4500B357DB /* Color.swift */; };
/* End PBXBuildFile section */

/* Begin PBXContainerItemProxy section */
Expand All @@ -46,6 +50,9 @@
/* Begin PBXFileReference section */
C91BB1432A16BDC000C0B971 /* RideRequestView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = RideRequestView.swift; sourceTree = "<group>"; };
C97221BC2A169FD40014EABA /* MapViewState.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; name = MapViewState.swift; path = ../../../../../../../Users/lucashubert/Downloads/MapViewState.swift; sourceTree = "<group>"; };
C9AA5E752A1C113E00824737 /* RideType.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; name = RideType.swift; path = eUberUI/Core/Trips/View/RideType.swift; sourceTree = SOURCE_ROOT; };
C9AA5E772A1CFA5600824737 /* Double.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; name = Double.swift; path = eUberUI/Core/Trips/View/Double.swift; sourceTree = SOURCE_ROOT; };
C9AA5E792A1CFCD900824737 /* EUberLocation.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; name = EUberLocation.swift; path = eUberUI/Core/Trips/View/EUberLocation.swift; sourceTree = SOURCE_ROOT; };
C9CFFE402A15179E00708A15 /* eUberUI.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = eUberUI.app; sourceTree = BUILT_PRODUCTS_DIR; };
C9CFFE432A15179E00708A15 /* eUberUIApp.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = eUberUIApp.swift; sourceTree = "<group>"; };
C9CFFE472A1517A200708A15 /* Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Assets.xcassets; sourceTree = "<group>"; };
Expand All @@ -65,6 +72,7 @@
C9CFFE8A2A15410900708A15 /* LocationSearchView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = LocationSearchView.swift; sourceTree = "<group>"; };
C9CFFE8C2A15447800708A15 /* LocationSearchResultCell.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = LocationSearchResultCell.swift; sourceTree = "<group>"; };
C9CFFE8E2A154F1900708A15 /* LocationSearchViewModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = LocationSearchViewModel.swift; sourceTree = "<group>"; };
C9DD5C832A1D0B4500B357DB /* Color.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; name = Color.swift; path = eUberUI/Core/Trips/View/Color.swift; sourceTree = SOURCE_ROOT; };
/* End PBXFileReference section */

/* Begin PBXFrameworksBuildPhase section */
Expand Down Expand Up @@ -181,13 +189,17 @@
isa = PBXGroup;
children = (
C97221BC2A169FD40014EABA /* MapViewState.swift */,
C9AA5E752A1C113E00824737 /* RideType.swift */,
C9AA5E792A1CFCD900824737 /* EUberLocation.swift */,
);
path = Models;
sourceTree = "<group>";
};
C9CFFE772A151CB500708A15 /* Extensions */ = {
isa = PBXGroup;
children = (
C9AA5E772A1CFA5600824737 /* Double.swift */,
C9DD5C832A1D0B4500B357DB /* Color.swift */,
);
path = Extensions;
sourceTree = "<group>";
Expand Down Expand Up @@ -394,10 +406,14 @@
buildActionMask = 2147483647;
files = (
C9CFFE8B2A15410900708A15 /* LocationSearchView.swift in Sources */,
C9AA5E7A2A1CFCD900824737 /* EUberLocation.swift in Sources */,
C9AA5E762A1C113E00824737 /* RideType.swift in Sources */,
C9CFFE7D2A151D2400708A15 /* HomeView.swift in Sources */,
C9CFFE812A151F7400708A15 /* LocationManager.swift in Sources */,
C9DD5C842A1D0B4500B357DB /* Color.swift in Sources */,
C9CFFE502A1517A200708A15 /* eUberUI.xcdatamodeld in Sources */,
C9CFFE8F2A154F1900708A15 /* LocationSearchViewModel.swift in Sources */,
C9AA5E782A1CFA5600824737 /* Double.swift in Sources */,
C97221BD2A169FD40014EABA /* MapViewState.swift in Sources */,
C9CFFE8D2A15447800708A15 /* LocationSearchResultCell.swift in Sources */,
C9CFFE442A15179E00708A15 /* eUberUIApp.swift in Sources */,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
{
"colors" : [
{
"color" : {
"color-space" : "srgb",
"components" : {
"alpha" : "1.000",
"blue" : "1.000",
"green" : "1.000",
"red" : "1.000"
}
},
"idiom" : "universal"
},
{
"appearances" : [
{
"appearance" : "luminosity",
"value" : "dark"
}
],
"color" : {
"color-space" : "srgb",
"components" : {
"alpha" : "1.000",
"blue" : "0.130",
"green" : "0.130",
"red" : "0.130"
}
},
"idiom" : "universal"
}
],
"info" : {
"author" : "xcode",
"version" : 1
}
}
6 changes: 6 additions & 0 deletions eUberUI/Assets.xcassets/Colors/Contents.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"info" : {
"author" : "xcode",
"version" : 1
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
{
"colors" : [
{
"color" : {
"color-space" : "srgb",
"components" : {
"alpha" : "1.000",
"blue" : "0.130",
"green" : "0.130",
"red" : "0.130"
}
},
"idiom" : "universal"
},
{
"appearances" : [
{
"appearance" : "luminosity",
"value" : "dark"
}
],
"color" : {
"color-space" : "srgb",
"components" : {
"alpha" : "1.000",
"blue" : "1.000",
"green" : "1.000",
"red" : "1.000"
}
},
"idiom" : "universal"
}
],
"info" : {
"author" : "xcode",
"version" : 1
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
{
"colors" : [
{
"color" : {
"color-space" : "srgb",
"components" : {
"alpha" : "1.000",
"blue" : "0.921",
"green" : "0.921",
"red" : "0.921"
}
},
"idiom" : "universal"
},
{
"appearances" : [
{
"appearance" : "luminosity",
"value" : "dark"
}
],
"color" : {
"color-space" : "srgb",
"components" : {
"alpha" : "1.000",
"blue" : "0.261",
"green" : "0.261",
"red" : "0.261"
}
},
"idiom" : "universal"
}
],
"info" : {
"author" : "xcode",
"version" : 1
}
}
12 changes: 12 additions & 0 deletions eUberUI/Assets.xcassets/hatchback.imageset/Contents.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"images" : [
{
"filename" : "hatchback.png",
"idiom" : "universal"
}
],
"info" : {
"author" : "xcode",
"version" : 1
}
}
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
12 changes: 12 additions & 0 deletions eUberUI/Assets.xcassets/motorbike.imageset/Contents.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"images" : [
{
"filename" : "motorbike.png",
"idiom" : "universal"
}
],
"info" : {
"author" : "xcode",
"version" : 1
}
}
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
12 changes: 12 additions & 0 deletions eUberUI/Assets.xcassets/suv.imageset/Contents.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"images" : [
{
"filename" : "suv.png",
"idiom" : "universal"
}
],
"info" : {
"author" : "xcode",
"version" : 1
}
}
Binary file added eUberUI/Assets.xcassets/suv.imageset/suv.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
48 changes: 30 additions & 18 deletions eUberUI/Core/Home/View/HomeView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,28 +9,40 @@ import SwiftUI

struct HomeView: View {
@State private var mapState = MapViewState.noInput
@EnvironmentObject var locationViewModel: LocationSearchViewModel

var body: some View {
ZStack(alignment: .top) {
UberMapViewRepresentable(mapState: $mapState)
.ignoresSafeArea()

if mapState == .searchingForLocation {
LocationSearchView(mapState: $mapState)
} else if mapState == .noInput{
LocationSearchActivationView()
.padding(.vertical, 72)
.onTapGesture {
withAnimation(.spring()) {
mapState = .searchingForLocation
ZStack(alignment: .bottom) {
ZStack(alignment: .top) {
UberMapViewRepresentable(mapState: $mapState)
.ignoresSafeArea()

if mapState == .searchingForLocation {
LocationSearchView(mapState: $mapState)
} else if mapState == .noInput{
LocationSearchActivationView()
.padding(.vertical, 72)
.onTapGesture {
withAnimation(.spring()) {
mapState = .searchingForLocation
}
}
}
}

MapViewActionButton(mapState: $mapState)
.padding(.leading)
.padding(.top, 4)
}
if mapState == .locationSelected || mapState == .polylineAdded {
RideRequestView()
.transition(.move(edge: .bottom))
}
}.edgesIgnoringSafeArea(.bottom)
.onReceive(LocationManager.shared.$userLocation) { location in
if let location = location {
locationViewModel.userLocation = location
}
}

MapViewActionButton(mapState: $mapState)
.padding(.leading)
.padding(.top, 4)
}
}
}

Expand Down
6 changes: 4 additions & 2 deletions eUberUI/Core/Home/View/MapViewActionButton.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import SwiftUI

struct MapViewActionButton: View {
@Binding var mapState: MapViewState
@EnvironmentObject var viewModel: LocationSearchViewModel

var body: some View {
Button {
Expand All @@ -35,7 +36,8 @@ struct MapViewActionButton: View {
print("DEBUG: No input")
case .searchingForLocation:
mapState = .noInput
case .locationSelected:
case .locationSelected, .polylineAdded:
viewModel.selectedEUberLocation = nil
mapState = .noInput
}
}
Expand All @@ -44,7 +46,7 @@ struct MapViewActionButton: View {
switch state {
case .noInput:
return "line.3.horizontal"
case .searchingForLocation, .locationSelected:
case .searchingForLocation, .locationSelected, .polylineAdded:
return "arrow.left"
}
}
Expand Down
43 changes: 16 additions & 27 deletions eUberUI/Core/Home/View/UberMapViewRepresentable.swift
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import MapKit

struct UberMapViewRepresentable: UIViewRepresentable {
let mapView = MKMapView()
let locationManager = LocationManager()
let locationManager = LocationManager.shared
@Binding var mapState: MapViewState
@EnvironmentObject var locationViewModel: LocationSearchViewModel

Expand All @@ -30,13 +30,14 @@ struct UberMapViewRepresentable: UIViewRepresentable {
case .noInput:
context.coordinator.clearMapViewAndRecenterOnUserLocation()
break
case .searchingForLocation:
case .searchingForLocation, .polylineAdded:
break
case .locationSelected:
if let coordinate = locationViewModel.selectedLocationCoordinate {
if let coordinate = locationViewModel.selectedEUberLocation?.coordinate {
context.coordinator.addAndSelectAnnotation(withCoordinate: coordinate)
context.coordinator.configurePolyline(withDestinationCoordinate: coordinate)
}
break
}
}

Expand Down Expand Up @@ -92,36 +93,24 @@ extension UberMapViewRepresentable {
anno.coordinate = coordinate
self.parent.mapView.addAnnotation(anno)
self.parent.mapView.selectAnnotation(anno, animated: true)

parent.mapView.showAnnotations(parent.mapView.annotations, animated: true)
}

func configurePolyline(withDestinationCoordinate coordinate: CLLocationCoordinate2D) {
guard let userLocationCoordinate = self.userLocationCoordinate else { return }
getDestinationRoute(from: userLocationCoordinate, to: coordinate) { route in
self.parent.locationViewModel.getDestinationRoute(from: userLocationCoordinate, to: coordinate) { route in
self.parent.mapView.addOverlay(route.polyline)
}
}

func getDestinationRoute(
from userLocation: CLLocationCoordinate2D,
to destination: CLLocationCoordinate2D,
completion: @escaping(MKRoute) -> Void
) {
let userPlacemark = MKPlacemark(coordinate: userLocation)
let userDestination = MKPlacemark(coordinate: destination)
let request = MKDirections.Request()
request.source = MKMapItem(placemark: userPlacemark)
request.destination = MKMapItem(placemark: userDestination)
let direction = MKDirections(request: request)

direction.calculate { response, error in
if let error = error {
print("DEBUG: Failed to get direction with error \(error.localizedDescription)")
}
self.parent.mapState = .polylineAdded
let rect = self.parent.mapView.mapRectThatFits(
route.polyline.boundingMapRect,
edgePadding: .init(
top: 64,
left: 32,
bottom: 500,
right: 32
)
)
self.parent.mapView.setRegion(MKCoordinateRegion(rect), animated: true)

guard let route = response?.routes.first else { return }
completion(route)
}
}

Expand Down
Loading

0 comments on commit 03d3c68

Please sign in to comment.