refactor: move primitive views from DamusPurpleView into a separate file

This refactoring commit moves primitive, low complexity, helper views
from DamusPurpleView into a separate file, to reduce complexity on
DamusPurpleView.swift.

Although functions were changed into View structs, no logical changes
were made. (New version is functionally equivalent)

Signed-off-by: Daniel D’Aquino <daniel@daquino.me>
Reviewed-by: William Casarin <jb55@jb55.com>
Signed-off-by: William Casarin <jb55@jb55.com>
This commit is contained in:
Daniel D’Aquino
2024-02-14 21:31:43 +00:00
committed by William Casarin
parent 1a131cd179
commit b3b6fdc29e
3 changed files with 154 additions and 65 deletions

View File

@@ -149,24 +149,24 @@ struct DamusPurpleView: View {
var MarketingContent: some View {
VStack {
VStack(alignment: .leading, spacing: 30) {
Subtitle(NSLocalizedString("Help us stay independent in our mission for Freedom tech with our Purple subscription, and look cool doing it!", comment: "Damus purple subscription pitch"))
PurpleViewPrimitives.SubtitleView(text: NSLocalizedString("Help us stay independent in our mission for Freedom tech with our Purple subscription, and look cool doing it!", comment: "Damus purple subscription pitch"))
.multilineTextAlignment(.center)
HStack(spacing: 20) {
IconOnBox("heart.fill")
PurpleViewPrimitives.IconOnBoxView(name: "heart.fill")
VStack(alignment: .leading) {
Title(NSLocalizedString("Help Build The Future", comment: "Title for funding future damus development"))
PurpleViewPrimitives.TitleView(text: NSLocalizedString("Help Build The Future", comment: "Title for funding future damus development"))
Subtitle(NSLocalizedString("Support Damus development to help build the future of decentralized communication on the web.", comment: "Reason for supporting damus development"))
PurpleViewPrimitives.SubtitleView(text: NSLocalizedString("Support Damus development to help build the future of decentralized communication on the web.", comment: "Reason for supporting damus development"))
}
}
HStack(spacing: 20) {
IconOnBox("ai-3-stars.fill")
PurpleViewPrimitives.IconOnBoxView(name: "ai-3-stars.fill")
VStack(alignment: .leading) {
Title(NSLocalizedString("Exclusive features", comment: "Features only available on subscription service"))
PurpleViewPrimitives.TitleView(text: NSLocalizedString("Exclusive features", comment: "Features only available on subscription service"))
.padding(.bottom, -3)
HStack(spacing: 3) {
@@ -184,18 +184,18 @@ struct DamusPurpleView: View {
.background(DamusColors.lightBackgroundPink)
.cornerRadius(30.0)
Subtitle(NSLocalizedString("Be the first to access upcoming premium features: Automatic translations, longer note storage, and more", comment: "Description of new features to be expected"))
PurpleViewPrimitives.SubtitleView(text: NSLocalizedString("Be the first to access upcoming premium features: Automatic translations, longer note storage, and more", comment: "Description of new features to be expected"))
.padding(.top, 3)
}
}
HStack(spacing: 20) {
IconOnBox("badge")
PurpleViewPrimitives.IconOnBoxView(name: "badge")
VStack(alignment: .leading) {
Title(NSLocalizedString("Supporter Badge", comment: "Title for supporter badge"))
PurpleViewPrimitives.TitleView(text: NSLocalizedString("Supporter Badge", comment: "Title for supporter badge"))
Subtitle(NSLocalizedString("Get a special badge on your profile to show everyone your contribution to Freedom tech", comment: "Supporter badge description"))
PurpleViewPrimitives.SubtitleView(text: NSLocalizedString("Get a special badge on your profile to show everyone your contribution to Freedom tech", comment: "Supporter badge description"))
}
}
@@ -229,7 +229,7 @@ struct DamusPurpleView: View {
if damus_state.purple.enable_purple_iap_support {
switch self.products {
case .failed:
ProductLoadError
PurpleViewPrimitives.ProductLoadErrorView()
case .loaded(let products):
if let purchased {
PurchasedView(purchased)
@@ -406,60 +406,6 @@ struct DamusPurpleView: View {
prod in prod.id == selection.rawValue
}).first
}
// MARK: - Small helper views
func IconOnBox(_ name: String) -> some View {
ZStack {
RoundedRectangle(cornerRadius: 20.0)
.background(.ultraThinMaterial, in: RoundedRectangle(cornerRadius: 20.0))
.frame(width: 80, height: 80)
.overlay(
RoundedRectangle(cornerRadius: 20)
.stroke(LinearGradient(
colors: [DamusColors.pink, .white.opacity(0), .white.opacity(0.5), .white.opacity(0)],
startPoint: .topLeading,
endPoint: .bottomTrailing), lineWidth: 1)
)
Image(name)
.resizable()
.frame(width: 50, height: 50)
.foregroundColor(.white)
}
}
func Icon(_ name: String) -> some View {
Image(name)
.resizable()
.frame(width: 50, height: 50)
.foregroundColor(.white)
}
func Title(_ txt: String) -> some View {
Text(txt)
.font(.title3)
.bold()
.foregroundColor(.white)
.padding(.bottom, 3)
}
func Subtitle(_ txt: String) -> some View {
Text(txt)
.foregroundColor(.white.opacity(0.65))
}
var ProductLoadError: some View {
Text(NSLocalizedString("Subscription Error", comment: "Ah dang there was an error loading subscription information from the AppStore. Please try again later :("))
.foregroundColor(.white)
}
var SaveText: Text {
Text(NSLocalizedString("Save 14%", comment: "Percentage of purchase price the user will save"))
.font(.callout)
.italic()
.foregroundColor(DamusColors.green)
}
}
// MARK: - More helper views

View File

@@ -0,0 +1,131 @@
//
// PurpleViewPrimitives.swift
// damus
//
// Created by Daniel DAquino on 2024-02-09.
//
import Foundation
import SwiftUI
struct PurpleViewPrimitives {
struct IconOnBoxView: View {
var name: String
var body: some View {
ZStack {
RoundedRectangle(cornerRadius: 20.0)
.background(.ultraThinMaterial, in: RoundedRectangle(cornerRadius: 20.0))
.frame(width: 80, height: 80)
.overlay(
RoundedRectangle(cornerRadius: 20)
.stroke(LinearGradient(
colors: [DamusColors.pink, .white.opacity(0), .white.opacity(0.5), .white.opacity(0)],
startPoint: .topLeading,
endPoint: .bottomTrailing), lineWidth: 1)
)
Image(name)
.resizable()
.frame(width: 50, height: 50)
.foregroundColor(.white)
}
}
}
struct IconView: View {
var name: String
var body: some View {
Image(name)
.resizable()
.frame(width: 50, height: 50)
.foregroundColor(.white)
}
}
struct TitleView: View {
var text: String
var body: some View {
Text(text)
.font(.title3)
.bold()
.foregroundColor(.white)
.padding(.bottom, 3)
}
}
struct SubtitleView: View {
var text: String
var body: some View {
Text(text)
.foregroundColor(.white.opacity(0.65))
}
}
struct ProductLoadErrorView: View {
var body: some View {
Text(NSLocalizedString("Subscription Error", comment: "Ah dang there was an error loading subscription information from the AppStore. Please try again later :("))
.foregroundColor(.white)
}
}
struct SaveTextView: View {
var body: some View {
Text(NSLocalizedString("Save 14%", comment: "Percentage of purchase price the user will save"))
.font(.callout)
.italic()
.foregroundColor(DamusColors.green)
}
}
}
struct IconOnBoxView_Previews: PreviewProvider {
static var previews: some View {
PurpleViewPrimitives.IconOnBoxView(name: "badge")
.previewLayout(.sizeThatFits)
.background(Color.black)
}
}
struct IconView_Previews: PreviewProvider {
static var previews: some View {
PurpleViewPrimitives.IconView(name: "badge")
.previewLayout(.sizeThatFits)
.background(Color.black)
}
}
struct TitleView_Previews: PreviewProvider {
static var previews: some View {
PurpleViewPrimitives.TitleView(text: "Title Text")
.previewLayout(.sizeThatFits)
.background(Color.black)
}
}
struct SubtitleView_Previews: PreviewProvider {
static var previews: some View {
PurpleViewPrimitives.SubtitleView(text: "Subtitle Text")
.previewLayout(.sizeThatFits)
.background(Color.black)
}
}
struct ProductLoadErrorView_Previews: PreviewProvider {
static var previews: some View {
PurpleViewPrimitives.ProductLoadErrorView()
.previewLayout(.sizeThatFits)
.background(Color.black)
}
}
struct SaveTextView_Previews: PreviewProvider {
static var previews: some View {
PurpleViewPrimitives.SaveTextView()
.previewLayout(.sizeThatFits)
.background(Color.black)
}
}