Skip to content

Commit

Permalink
Padding content to avoid handle
Browse files Browse the repository at this point in the history
  • Loading branch information
nerdsupremacist committed Jul 22, 2020
1 parent 0d20940 commit bc379b6
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 10 deletions.
4 changes: 2 additions & 2 deletions Sources/Snap/SnapCalculator.swift
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ extension SnapPointCalculator {

let results = snaps.map { input -> SnapResult in
let offset = input.point.offset(deviceHeight: deviceHeight, safeAreaInsets: safeAreaInsets)
let contentHeight = deviceHeight - safeAreaInsets.top - safeAreaInsets.bottom - offset
let contentHeight = deviceHeight - safeAreaInsets.top - safeAreaInsets.bottom - handleThickness - 2 * handleVerticalPadding - offset
return SnapResult(state: input.state,
offset: offset + safeAreaInsets.bottom,
contentHeight: contentHeight)
Expand All @@ -95,7 +95,7 @@ extension SnapPoint {
case .fraction(let fraction):
return deviceHeight * (1 - fraction)
case .height(let height):
let totalHeight = height + safeAreaInsets.top + safeAreaInsets.bottom
let totalHeight = height + safeAreaInsets.top + safeAreaInsets.bottom + handleThickness + 2 * handleVerticalPadding
return deviceHeight - totalHeight
case .paddingToTop(let offset):
return offset
Expand Down
15 changes: 7 additions & 8 deletions Sources/Snap/SnapDrawer.swift
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@

import SwiftUI

let handleVerticalPadding: CGFloat = 16
let handleThickness: CGFloat = 5

public struct SnapDrawer<StateType: SnapState, Background : View, Content: View> : View {
private let calculator: SnapPointCalculator<StateType>

Expand Down Expand Up @@ -52,13 +55,10 @@ public struct SnapDrawer<StateType: SnapState, Background : View, Content: View>
return ZStack {
currentResult.state.visible.map { background($0).edgesIgnoringSafeArea(.all) }

VStack {
VStack(spacing: 0) {
currentResult.state.visible != nil ? Handle() : nil
currentResult.state.visible.map { content($0).frame(height: currentResult.contentHeight) }
Spacer()
}

VStack {
currentResult.state.visible != nil ? Handle().padding(.top, 16) : nil

Spacer()
}
}
Expand All @@ -76,12 +76,11 @@ public struct SnapDrawer<StateType: SnapState, Background : View, Content: View>
}

struct Handle : View {
private let handleThickness = CGFloat(5.0)
var body: some View {
RoundedRectangle(cornerRadius: handleThickness / 2.0)
.frame(width: 40, height: handleThickness)
.foregroundColor(Color.secondary)
.padding(5)
.padding(.vertical, handleVerticalPadding)
}
}

Expand Down

0 comments on commit bc379b6

Please sign in to comment.