I'm trying to create a View for the bottom sheet. It will have some view with a button when we tap on the button a bottom sheet has to appear.
I can modify the bottom sheet's colour, height, corner radius, how much the background view has to blur.
struct BottomSheetView: View {
@Binding var showBottomSheet: Bool
@Binding var bgColor: Color
@Binding var cornerRadius: CGFloat
@Binding var bottomSheetRatio: CGFloat
@Binding var blurPoint: CGFloat
var body: some View {
GeometryReader { geometry in
ZStack {
VStack {
Button(action: {
self.showBottomSheet.toggle()
}){
Text("click here")
.padding()
}
Spacer()
}
.frame(minWidth: 0, maxWidth: .infinity, minHeight: 0, maxHeight: .infinity)
.blur(radius: self.showBottomSheet ? self.blurPoint : 0)
.onTapGesture {
if self.showBottomSheet {
self.showBottomSheet = false
}
}
Rectangle()
.fill(self.bgColor)
.cornerRadius(self.cornerRadius)
.offset(y: self.showBottomSheet ? geometry.size.height * self.bottomSheetRatio : geometry.size.height + 200)
.animation(.spring())
}
}
}
}
In the above code
VStack {
Button(action: {
self.showBottomSheet.toggle()
}){
Text("click here")
.padding()
}
Spacer()
}
This VStack should replace with some other View, from that View I want to pass the Binding values.
Is there a way to achieve that? Thanks in advance.
Button
? – Glenn PosadasBottomSheetView
in multiple views. I will create a separate View and integrate this bottom sheet in that view. – Azhagusundaram Tamil