-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
118 additions
and
0 deletions.
There are no files selected for viewing
17 changes: 17 additions & 0 deletions
17
SemicolonDesign/Sources/BottomSheet/Preview/SDBottomSheetPreview.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,17 @@ | ||
import SwiftUI | ||
|
||
struct SDBottomSheetPreview: View { | ||
@State var isPresented: Bool = false | ||
var body: some View { | ||
Button { | ||
isPresented = true | ||
} label: { | ||
Text("Test BottomSheet") | ||
} | ||
.sdBottomSheet(isPresented: $isPresented, buttons: [ | ||
(text: "μμ νκΈ°", action: { print("!!!!!") }), | ||
(text: "μμ νκΈ°", action: { print("λ°κ°μμ") }) | ||
]) | ||
} | ||
} | ||
|
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,43 @@ | ||
import SwiftUI | ||
|
||
struct SDBottomSheet: View { | ||
@Binding var isPresented: Bool | ||
var buttons: [(text: String, action: () -> Void)] | ||
|
||
init( | ||
isPresented: Binding<Bool>, | ||
buttons: [(text: String, action: () -> Void)] | ||
) { | ||
self.buttons = buttons | ||
self._isPresented = isPresented | ||
} | ||
|
||
var body: some View { | ||
VStack(alignment: .leading, spacing: 0) { | ||
ForEach(buttons, id: \.text) { button in | ||
Button{ | ||
self.isPresented = false | ||
button.action() | ||
} label: { | ||
HStack { | ||
Text(button.text) | ||
Spacer() | ||
} | ||
} | ||
.padding(.bottom, 26) | ||
} | ||
} | ||
.foregroundColor(.black) | ||
.padding(.leading, 29) | ||
.padding(.top, 36) | ||
.padding(.bottom, 4) | ||
.background(Color.white) | ||
.cornerRadius(16, [.topLeft, .topRight]) | ||
} | ||
} | ||
|
||
struct SwiftUIView_Previews: PreviewProvider { | ||
static var previews: some View { | ||
SDBottomSheetPreview() | ||
} | ||
} |
28 changes: 28 additions & 0 deletions
28
SemicolonDesign/Sources/BottomSheet/SDBottomSheetModifier.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,28 @@ | ||
import SwiftUI | ||
|
||
struct SDBottomSheetModifier: ViewModifier { | ||
|
||
var isPresented: Binding<Bool> | ||
var buttons: [(text: String, action: () -> Void)] | ||
|
||
func body(content: Content) -> some View { | ||
ZStack { | ||
content | ||
if isPresented.wrappedValue { | ||
Color.black.opacity(0.4) | ||
.ignoresSafeArea() | ||
VStack { | ||
Spacer() | ||
Color.white | ||
.edgesIgnoringSafeArea(.bottom) | ||
.frame(height: CGFloat(40)) | ||
} | ||
VStack(spacing: 0) { | ||
Spacer() | ||
SDBottomSheet(isPresented: isPresented, buttons: buttons) | ||
} | ||
.animation(.easeOut, value: isPresented.wrappedValue) | ||
} | ||
} | ||
} | ||
} |
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,7 @@ | ||
import SwiftUI | ||
|
||
public extension View { | ||
func sdBottomSheet(isPresented: Binding<Bool>, buttons: [(text: String, action: () -> Void)]) -> some View { | ||
self.modifier(SDBottomSheetModifier(isPresented: isPresented, buttons: buttons)) | ||
} | ||
} |
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 @@ | ||
import SwiftUI | ||
|
||
extension View { | ||
func cornerRadius(_ radius: CGFloat, _ corners: UIRectCorner) -> some View { | ||
clipShape(RoundedCorner(radius: radius, corners: corners)) | ||
} | ||
} | ||
|
||
struct RoundedCorner: Shape { | ||
|
||
var radius: CGFloat = .infinity | ||
var corners: UIRectCorner = .allCorners | ||
|
||
func path(in rect: CGRect) -> Path { | ||
let path = UIBezierPath( | ||
roundedRect: rect, | ||
byRoundingCorners: corners, | ||
cornerRadii: CGSize(width: radius, height: radius) | ||
) | ||
return Path(path.cgPath) | ||
} | ||
|
||
} |