Initial commit

This commit is contained in:
oscarz
2024-08-12 10:49:20 +08:00
parent 3002510aaf
commit 00fd0adf89
331 changed files with 53210 additions and 130 deletions

View File

@ -6,13 +6,174 @@
//
import SwiftUI
import ToastUI
struct GrammarCheckView: View {
fileprivate struct BuyProView: View {
var onTryForFree: () -> Void
var body: some View {
Text(/*@START_MENU_TOKEN@*/"Hello, World!"/*@END_MENU_TOKEN@*/)
HStack {
VStack(alignment: .leading, spacing: 10) {
Text("Update to Pro")
.font(.headline)
Text("Remove Character limits and ads. Use Grammar Check with higher quality.")
.font(.subheadline)
}
Spacer()
Button("Try for free") {
//
// VIP
onTryForFree()
}
.padding(.vertical, 6) // 2/3
.padding(.horizontal, 20)
.background(Color.green)
.foregroundColor(.white)
.cornerRadius(5)
.font(.headline) //
.alignmentGuide(.bottom) { d in d[.bottom] } // VStack
}
.padding()
.background(Color.white)
.cornerRadius(5)
.padding(5)
}
}
#Preview {
GrammarCheckView()
enum ActiveSheet {
case camera, share
}
extension ActiveSheet: Identifiable {
var id: Self { self }
}
struct GrammarCheckView: View {
@EnvironmentObject var globalEnv: GlobalEnvironment //
//
@State private var textInput: String
@State private var inputResult : String
@State private var progressValue: Float = 0
@State private var showKeyboard: Bool = false
@State private var showBuyProView: Bool = true
@State private var showResult : Bool = false
@State var results : [GrammarRes]
@State private var showVIPPaymentView: Bool = false // VIP
//
@State private var isLoading = false //
@State private var showingToast = false // toast
@State private var toastText = ""
@State private var activeSheet: ActiveSheet?
@State private var isTextEditorFocused: Bool = false // InputView
// 使
init() {
let demoGrammarData = GrammarData.demoInstance()
self.textInput = demoGrammarData.inputText
self.inputResult = demoGrammarData.correctText
self.results = demoGrammarData.results
}
var body: some View {
NavigationView {
ZStack {
Color.pink.opacity(0.2).edgesIgnoringSafeArea(.all) //
VStack {
if showResult {
ResultView(textContent: $textInput, results: $results, showResult: $showResult, showKeyboard: $showKeyboard)
} else {
InputView(textInput: $textInput, progressValue: $progressValue, showKeyboard: $showKeyboard, showBuyProView: $showBuyProView, showResult: $showResult, results: $results, isLoading: $isLoading, showingToast: $showingToast, toastText: $toastText)
// .environment(\.isTextEditorFocused, $isTextEditorFocused) // InputView
}
if showBuyProView {
BuyProView(onTryForFree: {
showVIPPaymentView = true // VIP
})
//BuyProView()
}
}
.fullScreenCover(isPresented: $showVIPPaymentView) {
VIPPaymentView() // VIP
}
.navigationBarTitleDisplayMode(.inline)
.toolbar {
ToolbarItem(placement: .principal) {
HStack {
Text("Grammar & Spell Checker")
.font(.headline) //
if globalEnv.isVip {
Image("vipimg") // 使
.resizable() // 使
.scaledToFit() //
.frame(width: 24, height: 24) //
.foregroundColor(.yellow)
.font(.subheadline) //
.offset(y: -1) //
}
}
}
}
.foregroundColor(.black)
.navigationBarItems(leading: Button(action: {
//
self.activeSheet = .camera
}) {
Image(systemName: "camera")
}, trailing: Button(action: {
//
self.activeSheet = .share
}) {
Image(systemName: "square.and.arrow.up")
})
.sheet(item: $activeSheet, onDismiss: {
// sheet
}) { item in
switch item {
case .camera:
CameraView(textInput: $textInput)
case .share:
ShareSheet(itemsToShare: [textInput])
}
}
.toast(isPresented: $showingToast, dismissAfter: globalEnvironment.toastPresentMsNormal) {
HStack {
Image(systemName: "exclamationmark.bubble")
.foregroundColor(.yellow)
Text(toastText)
.foregroundColor(.black)
}
.padding()
.background(Color.white)
.cornerRadius(8)
.shadow(radius: 10)
}
//
if isLoading {
LoadingView()
}
}
}
}
}
// MARK:
struct GrammarCheckView_Previews: PreviewProvider {
static var previews: some View {
GrammarCheckView()
.environmentObject(IAPManager()) // IAPManager
.environmentObject(globalEnvironment) // IAPManager
}
}