Skip to content

Commit

Permalink
Merge pull request #5 from GlennBrann/glenn/testing-max-width
Browse files Browse the repository at this point in the history
Adding max width to default sheet
  • Loading branch information
GlennBrann authored Apr 26, 2023
2 parents 8a61f38 + fbcafa9 commit 99b94b9
Show file tree
Hide file tree
Showing 7 changed files with 36 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
// Created by Brannelly, Glenn on 10/5/21.
//

import Foundation
import SwiftUI

@available(iOS 15, *)
Expand Down
36 changes: 27 additions & 9 deletions Sources/ManySheets/DefaultBottomSheet/DefaultBottomSheet.swift
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
// Copyright © 2021 Glenn Brannelly. All rights reserved.
//

import Foundation
import SwiftUI

extension DefaultBottomSheet {
Expand Down Expand Up @@ -56,7 +57,9 @@ public struct DefaultBottomSheet<Content: View>: View {
let style: DefaultBottomSheetStyle

let options: [DefaultBottomSheet.Options]


let maxWidth: CGFloat?

let content: Content

@State var contentSize: CGSize = .zero
Expand All @@ -67,11 +70,13 @@ public struct DefaultBottomSheet<Content: View>: View {
isOpen: Binding<Bool>,
style: DefaultBottomSheetStyle = .defaultStyle(),
options: [DefaultBottomSheet.Options] = [],
maxWidth: CGFloat? = nil,
@ViewBuilder content: @escaping () -> Content
) {
self._isOpen = isOpen
self.style = style
self.options = options
self.maxWidth = maxWidth
self.content = content()
}

Expand All @@ -80,13 +85,19 @@ public struct DefaultBottomSheet<Content: View>: View {
GeometryReader { proxy in
if isOpen, (tapAwayToDismiss || blockContent) {
dimmingView
.frame(width: proxy.size.width, height: proxy.size.height)
.frame(
width: proxy.size.width,
height: proxy.size.height
)
.onTapGesture { if tapAwayToDismiss { isOpen = false } }
}
VStack(spacing: 0) {
if hasHandleBar {
dragBar
.frame(width: proxy.size.width, height: style.handleBarHeight)
.frame(
width: maxWidth != nil ? maxWidth! : proxy.size.width,
height: style.handleBarHeight
)
.background(style.backgroundColor)
.padding(.top, 4)
}
Expand All @@ -100,17 +111,24 @@ public struct DefaultBottomSheet<Content: View>: View {
.onPreferenceChange(SizePreferenceKey.self) {
self.contentSize = $0
}
.frame(width: proxy.size.width,
height: contentSize.height + proxy.safeAreaInsets.bottom,
alignment: .bottom)
.frame(
width: maxWidth != nil ? maxWidth! : proxy.size.width,
height: contentSize.height + proxy.safeAreaInsets.bottom,
alignment: .bottom
)
.background(style.backgroundColor)
.cornerRadius(style.cornerRadius, corners: [.topLeft, .topRight])
.frame(height: proxy.size.height, alignment: .bottom)
.animation(.interactiveSpring(), value: contentSize)
.animation(style.openAnimation, value: isOpen)
.offset(y: isOpen ? 0 : contentSize.height)
.shadow(color: hasShadow ? style.shadowColor : .clear,
radius: style.shadowRadius, x: style.shadowX, y: style.shadowY)
.offset(
x: maxWidth != nil ? proxy.size.width / 2 - maxWidth! / 2 : 0,
y: isOpen ? 0 : contentSize.height
)
.shadow(
color: hasShadow ? style.shadowColor : .clear,
radius: style.shadowRadius, x: style.shadowX, y: style.shadowY
)
.gesture(dragGesture())
}
.edgesIgnoringSafeArea(.vertical)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
// Copyright © 2021 Glenn Brannelly. All rights reserved.
//

import Foundation
import SwiftUI

public struct DefaultBottomSheetStyle {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
// Copyright © 2021 Glenn Brannelly. All rights reserved.
//

import Foundation
import SwiftUI

public struct ScaffoldBottomSheetPositions {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
// Copyright © 2021 Glenn Brannelly. All rights reserved.
//

import Foundation
import SwiftUI

public struct ScaffoldBottomSheetStyle {
Expand Down
4 changes: 4 additions & 0 deletions Sources/ManySheets/ViewExtension.swift
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
// Copyright © 2021 Glenn Brannelly. All rights reserved.
//

import Foundation
import SwiftUI

public extension View {
Expand All @@ -15,11 +16,13 @@ public extension View {
/// - isOpen: A binding used to display the bottom sheet.
/// - style: A property containing all bottom sheet styling
/// - options: An array that contains the bottom sheet options
/// - maxWidth: The max width of the bottom sheet
/// - content: A ViewBuilder used to set the content of the bottom sheet.
func defaultBottomSheet<Content: View>(
isOpen: Binding<Bool>,
style: DefaultBottomSheetStyle = .defaultStyle(),
options: [DefaultBottomSheet<Content>.Options] = [],
maxWidth: CGFloat? = nil,
@ViewBuilder content: @escaping () -> Content
) -> some View {
ZStack {
Expand All @@ -28,6 +31,7 @@ public extension View {
isOpen: isOpen,
style: style,
options: options,
maxWidth: maxWidth,
content: content
)
}
Expand Down
1 change: 1 addition & 0 deletions Sources/ManySheets/ViewHelpers.swift
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
// Copyright © 2021 Glenn Brannelly. All rights reserved.
//

import Foundation
import SwiftUI

// MARK: - RoundedCorners
Expand Down

0 comments on commit 99b94b9

Please sign in to comment.