mirror of
git://jb55.com/damus
synced 2024-09-30 00:40:45 +00:00
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:
parent
1a131cd179
commit
b3b6fdc29e
@ -438,6 +438,7 @@
|
||||
BAB68BED29543FA3007BA466 /* SelectWalletView.swift in Sources */ = {isa = PBXBuildFile; fileRef = BAB68BEC29543FA3007BA466 /* SelectWalletView.swift */; };
|
||||
D2277EEA2A089BD5006C3807 /* Router.swift in Sources */ = {isa = PBXBuildFile; fileRef = D2277EE92A089BD5006C3807 /* Router.swift */; };
|
||||
D70A3B172B02DCE5008BD568 /* NotificationFormatter.swift in Sources */ = {isa = PBXBuildFile; fileRef = D70A3B162B02DCE5008BD568 /* NotificationFormatter.swift */; };
|
||||
D7100C562B76F8E600C59298 /* PurpleViewPrimitives.swift in Sources */ = {isa = PBXBuildFile; fileRef = D7100C552B76F8E600C59298 /* PurpleViewPrimitives.swift */; };
|
||||
D71DC1EC2A9129C3006E207C /* PostViewTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = D71DC1EB2A9129C3006E207C /* PostViewTests.swift */; };
|
||||
D72341192B6864F200E1E135 /* DamusPurpleEnvironment.swift in Sources */ = {isa = PBXBuildFile; fileRef = D72341182B6864F200E1E135 /* DamusPurpleEnvironment.swift */; };
|
||||
D723411A2B6864F200E1E135 /* DamusPurpleEnvironment.swift in Sources */ = {isa = PBXBuildFile; fileRef = D72341182B6864F200E1E135 /* DamusPurpleEnvironment.swift */; };
|
||||
@ -1336,6 +1337,7 @@
|
||||
BAB68BEC29543FA3007BA466 /* SelectWalletView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SelectWalletView.swift; sourceTree = "<group>"; };
|
||||
D2277EE92A089BD5006C3807 /* Router.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Router.swift; sourceTree = "<group>"; };
|
||||
D70A3B162B02DCE5008BD568 /* NotificationFormatter.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NotificationFormatter.swift; sourceTree = "<group>"; };
|
||||
D7100C552B76F8E600C59298 /* PurpleViewPrimitives.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PurpleViewPrimitives.swift; sourceTree = "<group>"; };
|
||||
D71DC1EB2A9129C3006E207C /* PostViewTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PostViewTests.swift; sourceTree = "<group>"; };
|
||||
D72341182B6864F200E1E135 /* DamusPurpleEnvironment.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DamusPurpleEnvironment.swift; sourceTree = "<group>"; };
|
||||
D723C38D2AB8D83400065664 /* ContentFilters.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ContentFilters.swift; sourceTree = "<group>"; };
|
||||
@ -2581,6 +2583,7 @@
|
||||
4CFF8F5729C9FD07008DB934 /* Purple */ = {
|
||||
isa = PBXGroup;
|
||||
children = (
|
||||
D7100C542B76F8C200C59298 /* Detail */,
|
||||
4CFF8F5829C9FD1E008DB934 /* DamusPurpleView.swift */,
|
||||
D76556D52B1E6C08001B0CCC /* DamusPurpleWelcomeView.swift */,
|
||||
D7373BA52B688EA200F7783D /* DamusPurpleTranslationSetupView.swift */,
|
||||
@ -2634,6 +2637,14 @@
|
||||
path = Camera;
|
||||
sourceTree = "<group>";
|
||||
};
|
||||
D7100C542B76F8C200C59298 /* Detail */ = {
|
||||
isa = PBXGroup;
|
||||
children = (
|
||||
D7100C552B76F8E600C59298 /* PurpleViewPrimitives.swift */,
|
||||
);
|
||||
path = Detail;
|
||||
sourceTree = "<group>";
|
||||
};
|
||||
D72A2D032AD9C165002AFF62 /* Mocking */ = {
|
||||
isa = PBXGroup;
|
||||
children = (
|
||||
@ -3040,6 +3051,7 @@
|
||||
D74AAFCF2B155D8C006CF0F4 /* ZapDataModel.swift in Sources */,
|
||||
4C8D1A6F29F31E5000ACDF75 /* FriendsButton.swift in Sources */,
|
||||
3A5E47C52A4A6CF400C0D090 /* Trie.swift in Sources */,
|
||||
D7100C562B76F8E600C59298 /* PurpleViewPrimitives.swift in Sources */,
|
||||
B57B4C642B312BFA00A232C0 /* RelayAuthenticationDetail.swift in Sources */,
|
||||
D7EDED2E2B128E8A0018B19C /* CollectionExtension.swift in Sources */,
|
||||
D74AAFD62B155F0C006CF0F4 /* WalletConnect+.swift in Sources */,
|
||||
|
@ -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
|
||||
|
131
damus/Views/Purple/Detail/PurpleViewPrimitives.swift
Normal file
131
damus/Views/Purple/Detail/PurpleViewPrimitives.swift
Normal file
@ -0,0 +1,131 @@
|
||||
//
|
||||
// PurpleViewPrimitives.swift
|
||||
// damus
|
||||
//
|
||||
// Created by Daniel D’Aquino 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)
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user