123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255 |
- //
- // PurchaseView.swift
- // AIEmoji
- //
- // Created by 100Years on 2025/6/30.
- //
- import SwiftUI
- import SwiftUIX
- struct PurchaseView :View {
-
- @ObservedObject var viewModel: PurchaseViewModel
-
- var body: some View {
-
- let vipType = PurchaseManager.default.vipType
-
- VStack {
- Spacer()
-
- VStack(alignment: .leading, spacing: 12, content: {
- TSFeatureItemView(image: .purchaseIconPhoto, text: "Unlimited Photo Filters & Styles".localized)
- TSFeatureItemView(image: .purchaseIconUnlimited, text: "Unlimited AI Image Generation".localized)
- TSFeatureItemView(image: .purchaseIconVideo, text: String(format: "%d Video Effects & Video Generations".localized,viewModel.selectedType.creatVideoMaxNum))
- TSFeatureItemView(image: .purchaseIconAd, text: "No Ads or Watermarks".localized)
- }).multilineTextAlignment(.center).font(.font(size: 16,weight:.regular)).foregroundColor(.white)
-
- // VStack {
- // let text = vipType == .none ? "Get PRO Access".localized : "Super Offer for Yearly Pro".localized
- // Text(text)
- // .multilineTextAlignment(.center)
- // .font(.font(name: .PoppinsBoldItalic,size: 26))
- // .foregroundColor(UIColor.white.color)
- // .frame(width: k_ScreenWidth - 32, alignment: .center)
- //
- // if vipType == .none {
- // Spacer().frame(height: 12)
- // HStack {
- // Text("Unlimited")
- // .foregroundColor("#FECB34".uiColor.color)
- //
- // Text("Generation")
- // .foregroundColor(UIColor.white.color)
- //
- // }
- // .multilineTextAlignment(.center)
- // .font(.font(name: .PoppinsBoldItalic,size: 26))
- // .frame(height: 26*kDesignScale)
- // }
- // }
-
- Spacer().frame(height: 32)
-
- VStack(spacing: 12) {
-
- if vipType == .none {
- ZStack(alignment: .topTrailing) {
- // //增加月付费
- // PurchaseItemView(title: "One Month".localized, type: .month, selectedType: $viewModel.selectedType).onTapGesture {
- // viewModel.selectedType = .month
- PurchaseItemView(title: "One Year".localized, type: .year, selectedType: $viewModel.selectedType).onTapGesture {
- viewModel.selectedType = .year
- viewModel.buyPublisher.send(true)
- }
- TSVipRecView(save: vipType.saveString)
- .offset(x:-30,y:-14)
- }
-
- PurchaseItemView(title: "One Week".localized, type: .week(.week), selectedType: $viewModel.selectedType).onTapGesture {
- viewModel.selectedType = .week(.week)
- viewModel.buyPublisher.send(true)
- }
- }else{
- PurchaseItemTypeOneView(title: "One Year".localized, type: .year, selectedType: $viewModel.selectedType).onTapGesture {
- viewModel.selectedType = .year
- viewModel.buyPublisher.send(true)
- }
- }
-
- Spacer().frame(height: 4)
-
- Button {
- viewModel.buyPublisher.send(true)
- } label: {
- ZStack {
- UIColor.themeColor.color
- Text("Unlock All Features".localized)
- .font(.font(size: 16,weight: .medium))
- .foregroundColor(.hex("#111111"))
-
- }.frame(maxWidth: .infinity ,minHeight: 48.0,maxHeight: 48.0)
- .cornerRadius(24.0)
- }
-
- HStack {
- Text("Recurring billing, cancel anytime".localized)
- .foregroundColor(Color.hex("#FFBD59")) +
- Text(",Payment will be charged to your iTunes account at confirmation of purchase. Subscriptions automatically renew for the same applicable term and price, unless auto-renew is turned off at least 24 hours before the end of the current period.".localized)
- .foregroundColor(UIColor.lesserText.color)
- }
- .multilineTextAlignment(.center).font(.font(size: 8))
- .onTapGesture {
- viewModel.privacyPublisher.send(true)
- }
-
- Spacer().frame(height: 6.0)
-
- HStack(spacing: 8) {
- Text("Terms of Service".localized)
- .onTapGesture {
- viewModel.termPublisher.send(true)
- }
- Text("|")
- Text("Privacy Policy".localized)
- .onTapGesture {
- viewModel.privacyPublisher.send(true)
- }
- if vipType == .none {
- Text("|")
- Text("Restore".localized)
- .onTapGesture {
- viewModel.restorePublisher.send(true)
- }
- }
- }.font(.system(size: 12)).foregroundColor(.hex("#999999"))
- }.padding(.horizontal)
-
- Spacer().frame(height:9+k_Height_safeAreaInsetsBottom())
- }
- }
-
- // 定义一个返回 View 的方法
- func customText(text:String,fontName:FontName,color:Color) -> some View {
- let gorgeousColor = color //UIColor.themeColor.color
- return Text(text)
- .font(.font(name: fontName,size: 48))
-
- .gradientForeground(
- colors: [.hex("#FA794F"),.hex("#F8C32A"),.hex("#FEFBF4")],
- startPoint: UnitPoint.leading,
- endPoint: UnitPoint.trailing
- )
- .foregroundColor(gorgeousColor)
- .frame(height: 20)
- }
- }
- struct PurchaseItemView: View {
- var title: String
- var type: PremiumPeriod
- @Binding var selectedType: PremiumPeriod
- var body: some View {
- ZStack {
- Color.white.opacity(0.1)
- HStack {
- //左边加个
- VStack(alignment: .leading, spacing: 14) {
- Text(title).font(.font(size: 14)).foregroundColor(UIColor.white.color)
-
- HStack {
- Text(PurchaseManager.default.price(for: type) ?? "--").font(.font(size: 18,weight: .medium)).foregroundColor(UIColor.mainText.color)
- if type == .year { //.month {//增加月付费
- Text(" (≈\(PurchaseManager.default.averageWeekly(for:type) ?? "--")/\("Per week".localized))").font(.font(size: 12,weight: .medium)).foregroundColor(UIColor.mainText.withAlphaComponent(0.6).color)
- }
- }
- }
- Spacer()
- //
- // //右边每周的💰
- // VStack(alignment: .trailing, spacing: 2) {
- // Text("\(PurchaseManager.default.averageWeekly(for:type) ?? "--")")
- // Text("Per week".localized)
- //
- // }.font(.font(size: 16,weight: .regular)).foregroundColor(Color.white.opacity(0.6))
- }.padding(.horizontal)
- }
- .frame(height: 74) // 设置高度
- .cornerRadius(16.0) // 圆角
- .overlay(
- RoundedRectangle(cornerRadius: 16)
- .stroke(Color.hex("#FECB34"), lineWidth: type == selectedType ? 1 : 0) // 边框
- )
- }
- }
- struct PurchaseItemTypeOneView: View {
- var title: String
- var type: PremiumPeriod
- @Binding var selectedType: PremiumPeriod
- var body: some View {
- ZStack {
- Color.white.opacity(0.1)
- HStack {
- //左边加个
- VStack(alignment: .leading, spacing: 8) {
- Text(title).font(.font(size: 14,weight: .medium)).foregroundColor(UIColor.white.color)
- Text(String(format:"Only %@ per day".localized,"\(PurchaseManager.default.averageDay(for:type) ?? "--")"))
- .font(.font(size: 12,weight: .medium))
- . foregroundColor(UIColor.white.color).opacity(0.7)
- }
- Spacer()
-
- Text(PurchaseManager.default.price(for: type) ?? "--").font(.font(size: 18,weight: .medium)).foregroundColor(UIColor.mainText.color)
- }.padding(.horizontal)
- }
- .frame(height: 74) // 设置高度
- .cornerRadius(16.0) // 圆角
- .overlay(
- RoundedRectangle(cornerRadius: 16)
- .stroke(Color.hex("#FECB34"), lineWidth: type == selectedType ? 1 : 0) // 边框
- )
- }
- }
- //推荐选择view
- struct TSVipRecView: View {
- var save:String //年 80%,月 30%
- var body: some View {
-
- HStack(spacing: 4) {
- Image("upvote_black").resizable().frame(width: 16, height: 16)
- Text("Save-Vip".localized + " " + save).font(.font(size: 12,weight: .medium)).foregroundColor(.hex("#111111"))
- }
- .padding(EdgeInsets(top: 6, leading: 6, bottom: 6, trailing: 6))
- .background(Color.hex("#FECB34"))
- .frame(height: 28) // 设置高度
- .cornerRadius([.topLeading, .topTrailing, .bottomLeading, .bottomTrailing], 16.0)
- }
- }
- //推荐选择view
- struct TSFeatureItemView: View {
- var image:ImageResource
- var text:String
- var body: some View {
- let backgroundColor = Color.clear
- ZStack {
- HStack(alignment: .center, spacing: 12) {
- Image(image).resizable().frame(width: 24, height: 24)
- Text(text)
- }
- }
- }
- }
|