-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[WEAV-50] Design System - Toast 구현 (#16)
* [WEAV-50] Toast, View Modifier, Extension 생성 * [WEAV-50] Toast Preview 생성
- Loading branch information
1 parent
d797f88
commit c984595
Showing
7 changed files
with
149 additions
and
0 deletions.
There are no files selected for viewing
23 changes: 23 additions & 0 deletions
23
...cts/DesignSystem/DesignCore/Resources/Images/Images.xcassets/alert.imageset/Contents.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
{ | ||
"images" : [ | ||
{ | ||
"filename" : "alert.png", | ||
"idiom" : "universal", | ||
"scale" : "1x" | ||
}, | ||
{ | ||
"filename" : "[email protected]", | ||
"idiom" : "universal", | ||
"scale" : "2x" | ||
}, | ||
{ | ||
"filename" : "[email protected]", | ||
"idiom" : "universal", | ||
"scale" : "3x" | ||
} | ||
], | ||
"info" : { | ||
"author" : "xcode", | ||
"version" : 1 | ||
} | ||
} |
Binary file added
BIN
+497 Bytes
...signSystem/DesignCore/Resources/Images/Images.xcassets/alert.imageset/alert.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+786 Bytes
...nSystem/DesignCore/Resources/Images/Images.xcassets/alert.imageset/[email protected]
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+1.09 KB
...nSystem/DesignCore/Resources/Images/Images.xcassets/alert.imageset/[email protected]
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
87 changes: 87 additions & 0 deletions
87
Projects/DesignSystem/DesignCore/Sources/Toast/ToastView.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,87 @@ | ||
// | ||
// ToastView.swift | ||
// ComponentsKit | ||
// | ||
// Created by 김지수 on 9/22/24. | ||
// Copyright © 2024 com.weave. All rights reserved. | ||
// | ||
|
||
import SwiftUI | ||
|
||
struct ToastViewModifier: ViewModifier { | ||
let message: String | ||
@Binding var isPresented: Bool | ||
let bottomPadding: CGFloat | ||
|
||
func body(content: Content) -> some View { | ||
content | ||
.overlay { | ||
ZStack { | ||
VStack { | ||
Spacer() | ||
Toast( | ||
message: message, | ||
isPresent: $isPresented | ||
) | ||
.offset(y: -(bottomPadding + Device.bottomInset)) | ||
} | ||
} | ||
} | ||
} | ||
} | ||
|
||
extension View { | ||
public func toast( | ||
message: String, | ||
isPresent: Binding<Bool>, | ||
bottomPadding: CGFloat = 0 | ||
) -> some View { | ||
modifier( | ||
ToastViewModifier( | ||
message: message, | ||
isPresented: isPresent, | ||
bottomPadding: bottomPadding | ||
) | ||
) | ||
} | ||
} | ||
|
||
struct Toast: View { | ||
let message: String | ||
@Binding var isPresent: Bool | ||
|
||
var body: some View { | ||
ZStack { | ||
RoundedRectangle(cornerRadius: 14) | ||
.inset(by: 1) | ||
.stroke( | ||
DesignCore.Colors.red300.opacity(0.5), | ||
lineWidth: 1 | ||
) | ||
.background(DesignCore.Colors.red300.opacity(0.08)) | ||
.clipShape(RoundedRectangle(cornerRadius: 14)) | ||
.shadow(.alert) | ||
|
||
HStack(spacing: 6) { | ||
DesignCore.Images.alert.image! | ||
.resizable() | ||
.frame(width: 20, height: 20) | ||
Text(message) | ||
.typography(.medium_16) | ||
.foregroundStyle(DesignCore.Colors.red300) | ||
} | ||
} | ||
.frame(height: 52) | ||
.padding(.horizontal, 28) | ||
.offset(y: isPresent ? 0 : 100) | ||
.opacity(isPresent ? 1 : 0) | ||
.animation(.bouncy(duration: 0.25), value: isPresent) | ||
.onChange(of: isPresent) { | ||
if isPresent { | ||
DispatchQueue.main.asyncAfter(deadline: .now() + 2) { | ||
isPresent = false | ||
} | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
35 changes: 35 additions & 0 deletions
35
Projects/Features/DesignPreview/Sources/DesignToastView.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
// | ||
// DesignToastView.swift | ||
// DesignPreview | ||
// | ||
// Created by 김지수 on 9/22/24. | ||
// Copyright © 2024 com.weave. All rights reserved. | ||
// | ||
|
||
import SwiftUI | ||
import DesignCore | ||
|
||
struct DesignToastView: View { | ||
@State var isPresent = false | ||
|
||
var body: some View { | ||
ZStack { | ||
DesignCore.Colors.background | ||
CTAButton(title: "Show Toast") { | ||
isPresent.toggle() | ||
} | ||
.padding(.horizontal, 36) | ||
} | ||
.toast( | ||
message: "나이를 입력해주세요", | ||
isPresent: $isPresent | ||
) | ||
.ignoresSafeArea() | ||
.navigationTitle("Toast") | ||
.navigationBarTitleDisplayMode(.inline) | ||
} | ||
} | ||
|
||
#Preview { | ||
DesignToastView() | ||
} |