Skip to content

Commit 8b0148d

Browse files
committed
feat: [SwiftUI Redux restroom finder] demo
1 parent 5b56824 commit 8b0148d

35 files changed

+1565
-5
lines changed

SwiftUI/SwiftUIRedux_MovieApp/Shared/HelloReduxApp.swift

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,12 @@ import SwiftUI
1010
@main
1111
struct HelloReduxApp: App {
1212
var body: some Scene {
13-
13+
1414
let store = Store(reducer: appReducer, state: AppState(),
1515
middlewares: [moviesMiddleware()])
1616

1717
WindowGroup {
18-
MovieDetailsView(movie:
19-
Movie(title: "Batman: The Killing Joke", imdbId: "tt4853102", poster: "https://m.media-amazon.com/images/M/MV5BMTdjZTliODYtNWExMi00NjQ1LWIzN2MtN2Q5NTg5NTk3NzliL2ltYWdlXkEyXkFqcGdeQXVyNTAyODkwOQ@@._V1_SX300.jpg")).environmentObject(store)
18+
ContentView().environmentObject(store)
2019
}
2120
}
2221
}

SwiftUI/SwiftUIRedux_MovieApp/Shared/Views/ContentView.swift

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,10 @@ struct ContentView: View {
3232
}).textFieldStyle(RoundedBorderTextFieldStyle()).padding()
3333

3434
List(props.movies, id: \.imdbId) { movie in
35-
MovieCell(movie: movie)
36-
}
35+
NavigationLink(destination: MovieDetailsView(movie: movie), label: {
36+
MovieCell(movie: movie)
37+
})
38+
}.listStyle(PlainListStyle())
3739
}
3840
.navigationTitle("Movies")
3941
.embedInNavigationView()

SwiftUI/SwiftUIRedux_RestRoomFinder/RestRoomFinder.xcodeproj/project.pbxproj

Lines changed: 767 additions & 0 deletions
Large diffs are not rendered by default.
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
{
2+
"colors" : [
3+
{
4+
"idiom" : "universal"
5+
}
6+
],
7+
"info" : {
8+
"author" : "xcode",
9+
"version" : 1
10+
}
11+
}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
{
2+
"images" : [
3+
{
4+
"idiom" : "universal",
5+
"platform" : "ios",
6+
"size" : "1024x1024"
7+
}
8+
],
9+
"info" : {
10+
"author" : "xcode",
11+
"version" : 1
12+
}
13+
}
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
{
2+
"info" : {
3+
"author" : "xcode",
4+
"version" : 1
5+
}
6+
}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
2+
3+
import Foundation
4+
5+
extension String {
6+
7+
func encodeURL() -> String? {
8+
return self.addingPercentEncoding(withAllowedCharacters: .urlHostAllowed)
9+
}
10+
11+
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
2+
3+
import Foundation
4+
import SwiftUI
5+
6+
extension View {
7+
func embedInNavigationView() -> some View {
8+
NavigationView { self }
9+
}
10+
}
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
3+
<plist version="1.0">
4+
<dict>
5+
<!-- 📍 Location -->
6+
<key>NSLocationUsageDescription</key>
7+
<string>$(PRODUCT_NAME) location use</string>
8+
9+
<!-- 📍 Location When In Use -->
10+
<key>NSLocationWhenInUseUsageDescription</key>
11+
<string>$(PRODUCT_NAME) location use</string>
12+
13+
<!-- 📍 Location Always -->
14+
<key>NSLocationAlwaysUsageDescription</key>
15+
<string>$(PRODUCT_NAME) always uses location </string>
16+
17+
<key>NSAppTransportSecurity</key>
18+
<dict>
19+
<key>NSAllowsArbitraryLoads</key>
20+
<true/>
21+
</dict>
22+
<key>UIViewControllerBasedStatusBarAppearance</key>
23+
<false/>
24+
</dict>
25+
</plist>
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
//
2+
// LocationManager.swift
3+
// RestRoomFinder
4+
//
5+
// Created by Yilong Chen on 09/06/2024.
6+
//
7+
8+
import Foundation
9+
import CoreLocation
10+
11+
class LocationManager: NSObject, ObservableObject {
12+
private let locationManager = CLLocationManager()
13+
@Published var location: CLLocation? = nil
14+
15+
override init() {
16+
super.init()
17+
18+
locationManager.delegate = self
19+
locationManager.desiredAccuracy = kCLLocationAccuracyBest
20+
locationManager.distanceFilter = kCLHeadingFilterNone
21+
locationManager.requestWhenInUseAuthorization()
22+
locationManager.startUpdatingLocation()
23+
}
24+
25+
func updateLocation() {
26+
locationManager.startUpdatingLocation()
27+
}
28+
}
29+
30+
extension LocationManager: CLLocationManagerDelegate {
31+
func locationManager(
32+
_ manager: CLLocationManager,
33+
didUpdateLocations locations: [CLLocation]
34+
) {
35+
guard let location = locations.last else {
36+
locationManager.stopUpdatingLocation()
37+
return
38+
}
39+
40+
DispatchQueue.main.async {
41+
self.location = location
42+
}
43+
44+
locationManager.stopUpdatingLocation()
45+
}
46+
}

0 commit comments

Comments
 (0)