Skip to content

Commit

Permalink
Merge pull request elai950#6 from zunda-pixel/introduce-if-let
Browse files Browse the repository at this point in the history
add `if let` to safe unwrap
  • Loading branch information
Bersaelor committed Nov 24, 2023
2 parents 5ec169e + 246e2e5 commit 414603d
Showing 1 changed file with 12 additions and 12 deletions.
24 changes: 12 additions & 12 deletions Sources/AlertToast/AlertToast.swift
Original file line number Diff line number Diff line change
Expand Up @@ -264,8 +264,8 @@ public struct AlertToast: View{
.font(style?.titleFont ?? Font.headline.bold())
}

if subTitle != nil{
Text(LocalizedStringKey(subTitle!))
if let subTitle = subTitle {
Text(LocalizedStringKey(subTitle))
.font(style?.subTitleFont ?? Font.subheadline)
}
}
Expand Down Expand Up @@ -308,14 +308,14 @@ public struct AlertToast: View{

if title != nil || subTitle != nil{
VStack(alignment: type == .regular ? .center : .leading, spacing: 2){
if title != nil{
Text(LocalizedStringKey(title ?? ""))
if let title = title {
Text(LocalizedStringKey(title))
.font(style?.titleFont ?? Font.body.bold())
.multilineTextAlignment(.center)
.textColor(style?.titleColor ?? nil)
}
if subTitle != nil{
Text(LocalizedStringKey(subTitle ?? ""))
if let subTitle = subTitle {
Text(LocalizedStringKey(subTitle))
.font(style?.subTitleFont ?? Font.footnote)
.opacity(0.7)
.multilineTextAlignment(.center)
Expand Down Expand Up @@ -374,14 +374,14 @@ public struct AlertToast: View{
}

VStack(spacing: type == .regular ? 8 : 2){
if title != nil{
Text(LocalizedStringKey(title ?? ""))
if let title = title {
Text(LocalizedStringKey(title))
.font(style?.titleFont ?? Font.body.bold())
.multilineTextAlignment(.center)
.textColor(style?.titleColor ?? nil)
}
if subTitle != nil{
Text(LocalizedStringKey(subTitle ?? ""))
if let subTitle = subTitle {
Text(LocalizedStringKey(subTitle))
.font(style?.subTitleFont ?? Font.footnote)
.opacity(0.7)
.multilineTextAlignment(.center)
Expand Down Expand Up @@ -632,7 +632,7 @@ fileprivate struct BackgroundModifier: ViewModifier{

@ViewBuilder
func body(content: Content) -> some View {
if color != nil{
if let color = color {
content
.background(color)
}else{
Expand All @@ -650,7 +650,7 @@ fileprivate struct TextForegroundModifier: ViewModifier{

@ViewBuilder
func body(content: Content) -> some View {
if color != nil{
if let color = color {
content
.foregroundColor(color)
}else{
Expand Down

0 comments on commit 414603d

Please sign in to comment.