imp: toast view

This commit is contained in:
Ryan Zhao 2023-08-28 11:24:26 +10:00
parent 0045100200
commit 353abe7089
8 changed files with 71 additions and 13 deletions

View File

@ -166,6 +166,7 @@
7BDCFC0B2421EB7600641C39 /* Localizable.strings in Resources */ = {isa = PBXBuildFile; fileRef = B6F509951AA53F760068F56A /* Localizable.strings */; };
7BDE2A982A8B122900AE4393 /* LandingView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7BDE2A972A8B122900AE4393 /* LandingView.swift */; };
7BDE2A9A2A8C59CF00AE4393 /* AttributedText.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7BDE2A992A8C59CF00AE4393 /* AttributedText.swift */; };
7BF570D32A9C1F9300DB013E /* Toast.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7BF570D22A9C1F9300DB013E /* Toast.swift */; };
7BF8D1FB2A70AF57005F1D6E /* SwiftUI+Theme.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7BF8D1FA2A70AF57005F1D6E /* SwiftUI+Theme.swift */; };
7BFA8AE32831D0D4001876F3 /* ContextMenuVC+EmojiReactsView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7BFA8AE22831D0D4001876F3 /* ContextMenuVC+EmojiReactsView.swift */; };
7BFD1A8A2745C4F000FB91B9 /* Permissions.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7BFD1A892745C4F000FB91B9 /* Permissions.swift */; };
@ -1289,6 +1290,7 @@
7BDE2A972A8B122900AE4393 /* LandingView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = LandingView.swift; sourceTree = "<group>"; };
7BDE2A992A8C59CF00AE4393 /* AttributedText.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AttributedText.swift; sourceTree = "<group>"; };
7BE2701D2A64C11500CEB71A /* SessionCarouselView+SwiftUI.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "SessionCarouselView+SwiftUI.swift"; sourceTree = "<group>"; };
7BF570D22A9C1F9300DB013E /* Toast.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Toast.swift; sourceTree = "<group>"; };
7BF8D1FA2A70AF57005F1D6E /* SwiftUI+Theme.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "SwiftUI+Theme.swift"; sourceTree = "<group>"; };
7BFA8AE22831D0D4001876F3 /* ContextMenuVC+EmojiReactsView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "ContextMenuVC+EmojiReactsView.swift"; sourceTree = "<group>"; };
7BFD1A892745C4F000FB91B9 /* Permissions.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Permissions.swift; sourceTree = "<group>"; };
@ -2962,6 +2964,7 @@
FD0B77AF29B69A65009169BA /* TopBannerController.swift */,
7BDE2A992A8C59CF00AE4393 /* AttributedText.swift */,
7B87EF432A8DA720002A0E8F /* SessionTextField.swift */,
7BF570D22A9C1F9300DB013E /* Toast.swift */,
);
path = Components;
sourceTree = "<group>";
@ -5514,6 +5517,7 @@
C331FFB92558FA8D00070591 /* UIView+Constraints.swift in Sources */,
7BDE2A9A2A8C59CF00AE4393 /* AttributedText.swift in Sources */,
7B87EF442A8DA720002A0E8F /* SessionTextField.swift in Sources */,
7BF570D32A9C1F9300DB013E /* Toast.swift in Sources */,
FD0B77B029B69A65009169BA /* TopBannerController.swift in Sources */,
FD37E9F628A5F106003AE748 /* Configuration.swift in Sources */,
7BF8D1FB2A70AF57005F1D6E /* SwiftUI+Theme.swift in Sources */,

View File

@ -12,7 +12,7 @@ struct LoadAccountView: View {
@State var tabIndex = 0
@State private var recoveryPassword: String = ""
@State private var hexEncodedSeed: String = ""
@State private var errorString: String? = nil
@State private var errorString: String? = "Test Error"
var body: some View {
ZStack(alignment: .topLeading) {
@ -273,18 +273,9 @@ struct ScanQRCodeView: View {
maxHeight: .infinity
)
if error?.isEmpty == false {
VStack {
Spacer()
Text(error!)
.font(.system(size: Values.verySmallFontSize))
.foregroundColor(themeColor: .textPrimary)
.multilineTextAlignment(.center)
.frame(
width: 320,
height: 44
)
if let error: String = error, !error.isEmpty {
withAnimation(.easeIn(duration: 0.5)) {
Toast(error)
}
}
} else {

View File

@ -0,0 +1,54 @@
// Copyright © 2023 Rangeproof Pty Ltd. All rights reserved.
import SwiftUI
public struct Toast: View {
@State var dismiss: Bool = false
let message: String
static let width: CGFloat = 320
static let height: CGFloat = 44
public init(_ message: String) {
self.message = message
}
public var body: some View {
VStack {
Spacer()
if !dismiss {
ZStack {
Capsule()
.foregroundColor(themeColor: .toast_background)
Text(message)
.font(.system(size: Values.verySmallFontSize))
.foregroundColor(themeColor: .textPrimary)
.multilineTextAlignment(.center)
.frame(maxWidth: .infinity)
.padding(.horizontal, Values.mediumSpacing)
}
.frame(
width: Self.width,
height: Self.height
)
.padding(.bottom, Values.smallSpacing)
}
}
.onAppear {
Timer.scheduledTimerOnMainThread(withTimeInterval: 5) { _ in
withAnimation(.easeOut(duration: 0.5)) {
dismiss.toggle()
}
}
}
}
}
struct Toast_Previews: PreviewProvider {
static var previews: some View {
Toast("This QR code does not contain a Recovery Password.")
}
}

View File

@ -83,6 +83,7 @@ internal enum Theme_ClassicDark: ThemeColors {
.alert_text: .classicDark6,
.alert_background: .classicDark1,
.alert_buttonBackground: .classicDark1,
.toast_background: .classicDark2,
// ConversationButton
.conversationButton_background: .classicDark1,
@ -203,6 +204,7 @@ internal enum Theme_ClassicDark: ThemeColors {
.alert_text: .classicDark6,
.alert_background: .classicDark1,
.alert_buttonBackground: .classicDark1,
.toast_background: .classicDark2,
// ConversationButton
.conversationButton_background: .classicDark1,

View File

@ -83,6 +83,7 @@ internal enum Theme_ClassicLight: ThemeColors {
.alert_text: .classicLight0,
.alert_background: .classicLight6,
.alert_buttonBackground: .classicLight6,
.toast_background: .classicLight4,
// ConversationButton
.conversationButton_background: .classicLight6,
@ -203,6 +204,7 @@ internal enum Theme_ClassicLight: ThemeColors {
.alert_text: .classicLight0,
.alert_background: .classicLight6,
.alert_buttonBackground: .classicLight6,
.toast_background: .classicLight4,
// ConversationButton
.conversationButton_background: .classicLight6,

View File

@ -83,6 +83,7 @@ internal enum Theme_OceanDark: ThemeColors {
.alert_text: .oceanDark7,
.alert_background: .oceanDark3,
.alert_buttonBackground: .oceanDark3,
.toast_background: .oceanDark4,
// ConversationButton
.conversationButton_background: .oceanDark3,
@ -203,6 +204,7 @@ internal enum Theme_OceanDark: ThemeColors {
.alert_text: .oceanDark7,
.alert_background: .oceanDark3,
.alert_buttonBackground: .oceanDark3,
.toast_background: .oceanDark4,
// ConversationButton
.conversationButton_background: .oceanDark3,

View File

@ -83,6 +83,7 @@ internal enum Theme_OceanLight: ThemeColors {
.alert_text: .oceanLight0,
.alert_background: .oceanLight7,
.alert_buttonBackground: .oceanLight7,
.toast_background: .oceanLight5,
// ConversationButton
.conversationButton_background: .oceanLight7,
@ -203,6 +204,7 @@ internal enum Theme_OceanLight: ThemeColors {
.alert_text: .oceanLight0,
.alert_background: .oceanLight7,
.alert_buttonBackground: .oceanLight7,
.toast_background: .oceanLight5,
// ConversationButton
.conversationButton_background: .oceanLight7,

View File

@ -195,6 +195,7 @@ public indirect enum ThemeValue: Hashable {
case alert_text
case alert_background
case alert_buttonBackground
case toast_background
// ConversationButton
case conversationButton_background