forked from EthanLipnik/OpenSesame
-
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.
Fixed bugs, improved searching, and added a new sheet
- Loading branch information
1 parent
9044d5d
commit 0f2f652
Showing
20 changed files
with
295 additions
and
117 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
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
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
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
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
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
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
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
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
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,88 @@ | ||
// | ||
// BottomSheet.swift | ||
// OpenSesame | ||
// | ||
// Created by Ethan Lipnik on 9/18/21. | ||
// | ||
|
||
import SwiftUI | ||
import ScreenCorners | ||
|
||
struct BottomSheet<ContentView: View>: ViewModifier { | ||
@Binding var isPresented: Bool | ||
let isInteractiveDismissEnabled: Bool | ||
let contentView: ContentView | ||
|
||
init(isPresented: Binding<Bool>, isInteractiveDismissEnabled: Bool, @ViewBuilder content: @escaping () -> ContentView) { | ||
self._isPresented = isPresented | ||
self.isInteractiveDismissEnabled = isInteractiveDismissEnabled | ||
self.contentView = content() | ||
} | ||
|
||
@State private var offset: CGSize = .zero | ||
|
||
func body(content: Content) -> some View { | ||
let cornerRadius = UIScreen.main.displayCornerRadius | ||
|
||
return content | ||
.overlay( | ||
isPresented ? | ||
VStack { | ||
RoundedRectangle(cornerRadius: 4) | ||
.fill(Color.secondary.opacity(0.5)) | ||
.frame(width: 40, height: 8) | ||
contentView | ||
} | ||
.padding() | ||
.background(RoundedRectangle(cornerRadius: cornerRadius == 0 ? 10 : cornerRadius, style: .continuous) | ||
.fill(Color("Tertiary")) | ||
.shadow(radius: 30, y: 10)) | ||
.frame(maxWidth: 600, minHeight: 300) | ||
.padding() | ||
.offset(offset) | ||
.animation(.spring(), value: offset) | ||
.gesture(DragGesture() | ||
.onChanged({ value in | ||
let height: CGFloat = { | ||
if offset.height > 0 { | ||
return value.translation.height | ||
} else { | ||
return value.translation.height / 10 | ||
} | ||
}() | ||
|
||
offset = CGSize(width: value.translation.width / 10, height: height) | ||
}) | ||
.onEnded({ value in | ||
if value.translation.height > 100 && isInteractiveDismissEnabled { | ||
withAnimation(.default) { | ||
isPresented = false | ||
} | ||
} | ||
|
||
offset = .zero | ||
})) | ||
.transition(.move(edge: .bottom)) | ||
: nil, | ||
alignment: .bottom) | ||
.animation(.spring(), value: isPresented) | ||
} | ||
} | ||
|
||
extension View { | ||
func bottomSheet<ContentView: View>(isPresented: Binding<Bool>, isInteractiveDismissEnabled: Bool = true, @ViewBuilder content: @escaping () -> ContentView) -> some View { | ||
self.modifier(BottomSheet(isPresented: isPresented, isInteractiveDismissEnabled: isInteractiveDismissEnabled, content: content)) | ||
} | ||
} | ||
|
||
struct BottomSheet_Previews: PreviewProvider { | ||
static var previews: some View { | ||
Rectangle() | ||
.bottomSheet(isPresented: .constant(true)) { | ||
VStack { | ||
Text("Hey") | ||
} | ||
} | ||
} | ||
} | ||
|
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
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
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
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
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
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
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
Oops, something went wrong.