DamusPurpleWelcomeView.swift (5521B)
1 // 2 // DamusPurpleWelcomeView.swift 3 // damus 4 // 5 // Created by Daniel D’Aquino on 2023-12-04. 6 // 7 8 import Foundation 9 import SwiftUI 10 11 fileprivate extension Animation { 12 static func content() -> Animation { 13 Animation.easeInOut(duration: 1).delay(3) 14 } 15 } 16 17 struct DamusPurpleWelcomeView: View { 18 @Environment(\.dismiss) var dismiss 19 @State var start = false 20 var next_page: () -> Void 21 22 var body: some View { 23 VStack { 24 Image("damus-dark-logo") 25 .resizable() 26 .frame(width: 50, height: 50) 27 .clipShape(RoundedRectangle(cornerRadius: 10.0)) 28 .overlay( 29 RoundedRectangle(cornerRadius: 10) 30 .stroke(LinearGradient( 31 colors: [DamusColors.lighterPink.opacity(0.8), .white.opacity(0), DamusColors.deepPurple.opacity(0.6)], 32 startPoint: .topLeading, 33 endPoint: .bottomTrailing), lineWidth: 1) 34 ) 35 .shadow(radius: 5) 36 .padding(20) 37 .opacity(start ? 1.0 : 0.0) 38 .animation(.content(), value: start) 39 40 Text("Welcome to Purple", comment: "Greeting to subscription service") 41 .font(.largeTitle) 42 .fontWeight(.bold) 43 .foregroundStyle( 44 LinearGradient( 45 colors: [.black, .black, DamusColors.pink, DamusColors.lighterPink], 46 startPoint: start ? .init(x: -3, y: 4) : .bottomLeading, 47 endPoint: start ? .topTrailing : .init(x: 3, y: -4) 48 ) 49 ) 50 .opacity(start ? 1.0 : 0.0) 51 .animation(Animation.easeInOut(duration: 3).delay(0), value: start) 52 53 Image(systemName: "star.fill") 54 .resizable() 55 .frame(width: 96, height: 90) 56 .foregroundStyle( 57 LinearGradient( 58 colors: [.black, DamusColors.purple, .white, .white], 59 startPoint: start ? .init(x: -1, y: 1.5) : .bottomLeading, 60 endPoint: start ? .topTrailing : .init(x: 10, y: -11) 61 ) 62 ) 63 .animation(Animation.snappy(duration: 3).delay(1), value: start) 64 .shadow( 65 color: start ? DamusColors.lightBackgroundPink : DamusColors.purple.opacity(0.3), 66 radius: start ? 30 : 10 67 ) 68 .animation(Animation.snappy(duration: 3).delay(0), value: start) 69 .scaleEffect(x: start ? 1 : 3, y: start ? 1 : 3) 70 .opacity(start ? 1.0 : 0.0) 71 .animation(Animation.snappy(duration: 2).delay(0), value: start) 72 73 Text("Thank you very much for signing up for Damus\u{00A0}Purple. Your contribution helps us continue our fight for a more Open and Free\u{00A0}internet.\n\nYou will also get access to premium features, and a star badge on your profile.\n\nEnjoy!", comment: "Appreciation to user for purchasing subscription service") 74 .lineSpacing(5) 75 .multilineTextAlignment(.center) 76 .foregroundStyle(.white.opacity(0.8)) 77 .padding(.horizontal, 20) 78 .padding(.top, 50) 79 .padding(.bottom, 20) 80 .opacity(start ? 1.0 : 0.0) 81 .animation(.content(), value: start) 82 83 Button(action: { 84 self.next_page() 85 }, label: { 86 HStack { 87 Spacer() 88 Text("Continue", comment: "Prompt to user to continue") 89 Spacer() 90 } 91 }) 92 .padding(.horizontal, 30) 93 .buttonStyle(GradientButtonStyle()) 94 .opacity(start ? 1.0 : 0.0) 95 .animation(Animation.easeInOut(duration: 2).delay(3), value: start) 96 } 97 .background(content: { 98 ZStack { 99 Image("purple-blue-gradient-1") 100 .offset(CGSize(width: 300.0, height: -0.0)) 101 .opacity(start ? 1.0 : 0.2) 102 .background(.black) 103 Image("stars-bg") 104 .resizable(resizingMode: .stretch) 105 .frame(width: 500, height: 500) 106 .offset(x: -100, y: 50) 107 .scaleEffect(start ? 1 : 1.1) 108 .animation(Animation.easeOut(duration: 3).delay(0), value: start) 109 Image("purple-blue-gradient-1") 110 .offset(CGSize(width: 300.0, height: -0.0)) 111 .opacity(start ? 1.0 : 0.2) 112 113 } 114 }) 115 .onAppear(perform: { 116 // SwiftUI quirk #98332: If I try to trigger an immediate animation, the animation does not work when this view is placed under a TabView. 117 // Triggering the animation only after a slight delay makes it work. 118 DispatchQueue.main.asyncAfter(deadline: .now() + 0.5, execute: { 119 withAnimation(.easeOut(duration: 6), { 120 start = true 121 }) 122 }) 123 124 }) 125 .interactiveDismissDisabled() 126 } 127 } 128 129 struct DamusPurpleWelcomeView_Previews: PreviewProvider { 130 static var previews: some View { 131 DamusPurpleWelcomeView(next_page: {}) 132 } 133 }