This repository has been archived by the owner on Feb 16, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathContentView.swift
54 lines (50 loc) · 1.78 KB
/
ContentView.swift
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
import SwiftUI
import Safer
let coordinator = Coordinator()
struct ContentView: View {
@State var progress = CGFloat(1)
@State var report = Report.new
@State private var text = ""
@State private var url = ""
@State private var searched = false
var body: some View {
NavigationView {
VStack {
HStack {
TextField(.init("URL"), text: $text, onCommit: commit)
.textContentType(.URL)
.keyboardType(.URL)
.autocapitalization(.none)
.disableAutocorrection(true)
.textFieldStyle(RoundedBorderTextFieldStyle())
Button(action: commit) {
Text(.init("Go"))
}
}.padding()
ProgressView(progress: progress)
.stroke(progress < 1 ? Color.accentColor : .clear,
style: .init(lineWidth: 4, lineCap: .round))
.frame(height: 4)
.cornerRadius(3)
.padding(.horizontal, 20)
if searched {
WebView(url: $url)
} else {
Text("Enter.url")
.foregroundColor(.secondary)
.multilineTextAlignment(.center)
.padding()
}
}.navigationBarTitle(.init("Safer"), displayMode: searched ? .inline : .large)
.navigationBarItems(trailing: BadgeView(report: $report))
}.onAppear {
coordinator.contentView = self
}
}
private func commit() {
withAnimation {
searched = true
}
url = text
}
}