-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
9 changed files
with
169 additions
and
13 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
26 changes: 26 additions & 0 deletions
26
DriverAssistant/Assets.xcassets/baseline_lightbulb_black_24pt.imageset/Contents.json
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,26 @@ | ||
{ | ||
"images" : [ | ||
{ | ||
"filename" : "baseline_lightbulb_black_24pt_1x.png", | ||
"idiom" : "universal", | ||
"scale" : "1x" | ||
}, | ||
{ | ||
"filename" : "baseline_lightbulb_black_24pt_2x.png", | ||
"idiom" : "universal", | ||
"scale" : "2x" | ||
}, | ||
{ | ||
"filename" : "baseline_lightbulb_black_24pt_3x.png", | ||
"idiom" : "universal", | ||
"scale" : "3x" | ||
} | ||
], | ||
"info" : { | ||
"author" : "xcode", | ||
"version" : 1 | ||
}, | ||
"properties" : { | ||
"template-rendering-intent" : "template" | ||
} | ||
} |
Binary file added
BIN
+201 Bytes
...ets/baseline_lightbulb_black_24pt.imageset/baseline_lightbulb_black_24pt_1x.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+341 Bytes
...ets/baseline_lightbulb_black_24pt.imageset/baseline_lightbulb_black_24pt_2x.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+486 Bytes
...ets/baseline_lightbulb_black_24pt.imageset/baseline_lightbulb_black_24pt_3x.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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,49 @@ | ||
// | ||
// WebView.swift | ||
// DriverAssistant | ||
// | ||
// Created by David Kirchhoff on 2021-07-15. | ||
// | ||
|
||
|
||
import SwiftUI | ||
|
||
struct WebView: View { | ||
@ObservedObject var webViewModel = WebViewModel(url: "https://www.neuralception.com/objectdetection") | ||
|
||
|
||
var body: some View { | ||
ZStack { | ||
WebViewContainer(webViewModel: webViewModel) | ||
if webViewModel.isLoading { | ||
//Spinner() | ||
// .frame(height: 30) | ||
Text("Loading...") | ||
} | ||
} | ||
.ignoresSafeArea() | ||
.navigationBarTitle(Text(webViewModel.title), displayMode: .inline) | ||
.navigationBarItems(leading: Button(action: { | ||
webViewModel.shouldGoBack.toggle() | ||
}, label: { | ||
if webViewModel.canGoBack { | ||
Image(systemName: "arrow.left") | ||
.frame(width: 44, height: 44, alignment: .center) | ||
.foregroundColor(.black) | ||
} else { | ||
EmptyView() | ||
.frame(width: 0, height: 0, alignment: .center) | ||
} | ||
}) | ||
) | ||
|
||
} | ||
|
||
} | ||
|
||
struct NavigationView_Previews: PreviewProvider { | ||
static var previews: some View { | ||
WebView() | ||
} | ||
} | ||
|
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,79 @@ | ||
// | ||
// WebViewContainer.swift | ||
// DriverAssistant | ||
// | ||
// Created by David Kirchhoff on 2021-07-15. | ||
// | ||
|
||
|
||
import Foundation | ||
import SwiftUI | ||
import WebKit | ||
|
||
struct WebViewContainer: UIViewRepresentable { | ||
@ObservedObject var webViewModel: WebViewModel | ||
|
||
func makeCoordinator() -> WebViewContainer.Coordinator { | ||
Coordinator(self, webViewModel) | ||
} | ||
|
||
func makeUIView(context: Context) -> WKWebView { | ||
guard let url = URL(string: self.webViewModel.url) else { | ||
return WKWebView() | ||
} | ||
|
||
let request = URLRequest(url: url) | ||
let webView = WKWebView() | ||
webView.navigationDelegate = context.coordinator | ||
webView.load(request) | ||
|
||
return webView | ||
} | ||
|
||
func updateUIView(_ uiView: WKWebView, context: Context) { | ||
if webViewModel.shouldGoBack { | ||
uiView.goBack() | ||
webViewModel.shouldGoBack = false | ||
} | ||
} | ||
} | ||
|
||
class WebViewModel: ObservableObject { | ||
@Published var isLoading: Bool = false | ||
@Published var canGoBack: Bool = false | ||
@Published var shouldGoBack: Bool = false | ||
@Published var title: String = "" | ||
|
||
var url: String | ||
|
||
init(url: String) { | ||
self.url = url | ||
} | ||
} | ||
|
||
extension WebViewContainer { | ||
class Coordinator: NSObject, WKNavigationDelegate { | ||
@ObservedObject private var webViewModel: WebViewModel | ||
private let parent: WebViewContainer | ||
|
||
init(_ parent: WebViewContainer, _ webViewModel: WebViewModel) { | ||
self.parent = parent | ||
self.webViewModel = webViewModel | ||
} | ||
|
||
func webView(_ webView: WKWebView, didStartProvisionalNavigation navigation: WKNavigation!) { | ||
webViewModel.isLoading = true | ||
} | ||
|
||
func webView(_ webView: WKWebView, didFinish navigation: WKNavigation!) { | ||
webViewModel.isLoading = false | ||
webViewModel.title = webView.title ?? "" | ||
webViewModel.canGoBack = webView.canGoBack | ||
} | ||
|
||
func webView(_ webView: WKWebView, didFail navigation: WKNavigation!, withError error: Error) { | ||
webViewModel.isLoading = false | ||
} | ||
} | ||
} | ||
|