Initial commit
This commit is contained in:
@ -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
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user