Skip to content

Instantly share code, notes, and snippets.

@prafullakumar
Last active February 20, 2021 16:04
Show Gist options
  • Save prafullakumar/ff764535a8171e8ae805af2c67c86e7b to your computer and use it in GitHub Desktop.
Save prafullakumar/ff764535a8171e8ae805af2c67c86e7b to your computer and use it in GitHub Desktop.
import SwiftUI
struct Banner: View {
struct BannerDataModel {
var title:String
var detail:String
var type: BannerType
}
enum BannerType {
case info
case warning
case success
case error
var tintColor: Color {
switch self {
case .info:
return .blue
case .success:
return .green
case .warning:
return .yellow
case .error:
return .red
}
}
var sfSymbol: String {
switch self {
case .info:
return "info.circle"
case .success:
return "checkmark.seal"
case .warning:
return "exclamationmark.octagon"
case .error:
return "xmark.octagon"
}
}
}
let data: BannerDataModel
@Binding var show: Bool
var body: some View {
VStack {
HStack {
Image.init(systemName: data.type.sfSymbol)
VStack(alignment: .leading, spacing: 2) {
Text(data.title)
.bold()
Text(data.detail)
.font(Font.system(size: 15, weight: Font.Weight.light, design: Font.Design.default))
}
Spacer()
}
.foregroundColor(Color.white)
.padding(12)
.background(data.type.tintColor)
.cornerRadius(8)
Spacer()
}
.padding()
.animation(.easeInOut)
.transition(AnyTransition.move(edge: .top).combined(with: .opacity))
.onTapGesture {
withAnimation {
self.show = false
}
}.onAppear(perform: {
DispatchQueue.main.asyncAfter(deadline: .now() + 2) {
withAnimation {
self.show = false
}
}
})
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment