splits/Splits/ModalView.swift

123 lines
3 KiB
Swift

//
// ModalView.swift
// Splits
//
// Created by Isaac Greene on 4/3/22.
//
import SwiftUI
import RichTextView
struct ModalView: View {
@State var mathSheet = false
@State var problemSheet = false
var body: some View {
VStack {
Text("Help")
.font(.largeTitle)
.bold()
.padding(.top, 40)
Text("Due to limitations in our system, you can only use kilometers and miles at this time. \nSmaller units like meters and feet are not supported. \nYou can, however, use decimals, such as .2km or .8mi.\n\nWe apologize for any inconvenience. In the future, we hope to make our app easier to use.")
.padding()
Button("See our math", action: {
self.mathSheet.toggle()
})
.padding(30)
.sheet(isPresented: self.$mathSheet, content: {
algorithmView()
})
Button("Known issues", action: {
self.problemSheet.toggle()
})
.padding(30)
.padding(.top, -30)
.sheet(isPresented: self.$problemSheet, content: {
problemView()
})
}
}
}
struct algorithmView: View {
var body: some View {
Text("The Algorithm")
.font(.largeTitle)
.bold()
VStack(alignment: .leading, spacing: 0) {
Text("Calculating pace is fairly straightforward, and does not change with increased complexity. The standard formula is simply this:\n")
mathView()
.frame(maxHeight: 300)
Text("\nWhere:\n")
HStack {
Text("\"t\"")
.font(.custom("Charter", size: 18))
Text("is total time")
}
HStack{
Text("\"d\"")
.font(.custom("Charter", size: 18))
Text("is distance")
}
HStack {
Text("\"p\"")
.font(.custom("Charter", size: 18))
Text("is the resulting pace")
}
}
.padding()
}
}
struct mathView: View {
@State var mathString:String = "[math] \\frac{t}{d} &= p [/math]"
var body: some View {
mathLaTeX_inator(mathString: $mathString)
.padding(30)
}
}
struct mathLaTeX_inator: UIViewRepresentable {
@Environment(\.colorScheme) var colorScheme
@Binding var mathString:String
func makeUIView(context: Context) -> RichTextView {
let richTextView = RichTextView(
input: mathString,
latexParser: LatexParser(),
font: UIFont.systemFont(ofSize: UIFont.systemFontSize),
textColor: (colorScheme == .dark ? UIColor.white : UIColor.black),
frame: CGRect.zero,
completion: nil
)
return richTextView
}
func updateUIView(_ uiView: RichTextView, context: Context) {
uiView.update(
input: mathString,
latexParser: LatexParser(),
font: UIFont.systemFont(ofSize: UIFont.systemFontSize),
textColor: (colorScheme == .dark ? UIColor.white : UIColor.black),
completion: nil
)
}
}
struct problemView: View {
var body: some View {
VStack {
Text("Known issues")
.font(.largeTitle)
.bold()
.padding(.top, 40)
Text("\n\u{2022} You can not dismiss the keyboard\n\t\u{2022} This hides the tab bar at the bottom\n\u{2022} Visually displayed seconds and total time are incorrect\n\t\u{2022} This DOES NOT affect pace. That is still correct.")
}
}
}