Skip to content

Commit

Permalink
Merged website
Browse files Browse the repository at this point in the history
  • Loading branch information
daved01 committed Jul 23, 2021
2 parents 4fa8491 + 267897b commit d4af90e
Show file tree
Hide file tree
Showing 9 changed files with 169 additions and 13 deletions.
8 changes: 8 additions & 0 deletions DriverAssistant.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
objects = {

/* Begin PBXBuildFile section */
6301F9A626A039600001E40E /* WebViewContainer.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6301F9A526A039600001E40E /* WebViewContainer.swift */; };
6301F9A826A039F90001E40E /* WebView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6301F9A726A039F90001E40E /* WebView.swift */; };
63683F5C269F133B00ACFD2B /* NavigationView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 63683F5B269F133B00ACFD2B /* NavigationView.swift */; };
636F5F3726AAC89A00BDF3D6 /* yolov5s.mlmodel in Sources */ = {isa = PBXBuildFile; fileRef = 636F5F3626AAC89A00BDF3D6 /* yolov5s.mlmodel */; };
63832B7D269A246C00590A9F /* DisplayView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 63832B7C269A246C00590A9F /* DisplayView.swift */; };
Expand All @@ -23,6 +25,8 @@
/* End PBXBuildFile section */

/* Begin PBXFileReference section */
6301F9A526A039600001E40E /* WebViewContainer.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = WebViewContainer.swift; sourceTree = "<group>"; };
6301F9A726A039F90001E40E /* WebView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = WebView.swift; sourceTree = "<group>"; };
63683F5B269F133B00ACFD2B /* NavigationView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NavigationView.swift; sourceTree = "<group>"; };
636F5F3626AAC89A00BDF3D6 /* yolov5s.mlmodel */ = {isa = PBXFileReference; lastKnownFileType = file.mlmodel; path = yolov5s.mlmodel; sourceTree = "<group>"; };
63832B7C269A246C00590A9F /* DisplayView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DisplayView.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -59,6 +63,8 @@
63683F5B269F133B00ACFD2B /* NavigationView.swift */,
63832B80269A24BF00590A9F /* LibraryView.swift */,
63832B7E269A249000590A9F /* SettingsView.swift */,
6301F9A726A039F90001E40E /* WebView.swift */,
6301F9A526A039600001E40E /* WebViewContainer.swift */,
);
path = Views;
sourceTree = "<group>";
Expand Down Expand Up @@ -180,6 +186,7 @@
buildActionMask = 2147483647;
files = (
63832B7F269A249000590A9F /* SettingsView.swift in Sources */,
6301F9A626A039600001E40E /* WebViewContainer.swift in Sources */,
FAB417F62099308400494E9C /* VisionObjectRecognitionViewController.swift in Sources */,
FAD500A11ED668B60074D713 /* ViewController.swift in Sources */,
63832B81269A24BF00590A9F /* LibraryView.swift in Sources */,
Expand All @@ -189,6 +196,7 @@
63683F5C269F133B00ACFD2B /* NavigationView.swift in Sources */,
FAD5009F1ED668B60074D713 /* AppDelegate.swift in Sources */,
FA68723920AA028000D82F25 /* ObjectDetector.mlmodel in Sources */,
6301F9A826A039F90001E40E /* WebView.swift in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
Expand Down
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"
}
}
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
6 changes: 3 additions & 3 deletions DriverAssistant/Views/NavigationView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,11 @@ struct NavigationView: View {
Spacer()
HStack {
Spacer()
NavigationLink(destination: LibraryView()) {
NavigationLink(destination: WebView()) {
VStack {
Image("sharp_video_library_black_24pt")
Image("baseline_lightbulb_black_24pt")
.foregroundColor(elementColour)
Text("Library")
Text("How detection works")
.font(.caption)
.foregroundColor(elementColour)
}
Expand Down
14 changes: 4 additions & 10 deletions DriverAssistant/Views/SettingsView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -23,25 +23,19 @@ struct Settings: View {
HStack(alignment: .center) {
Toggle(isOn: $showSpeed) {
Text("Show speed")
.font(.body)
}
}
HStack(alignment: .center) {
Toggle(isOn: $shareData) {
Text("Share data")
.font(.body)
}
}
HStack(alignment: .center) {

Toggle(isOn: $metricUnits) {
Text("Use metric units")

.font(.body)
}

}

}
.navigationBarTitle("Settings")
}
}
}

struct Settings_Previews: PreviewProvider {
Expand Down
49 changes: 49 additions & 0 deletions DriverAssistant/Views/WebView.swift
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()
}
}

79 changes: 79 additions & 0 deletions DriverAssistant/Views/WebViewContainer.swift
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
}
}
}

0 comments on commit d4af90e

Please sign in to comment.