Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 35 additions & 0 deletions Docs/Reference.md
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,41 @@ Drawer(heights: [100, 340]) {
}.impact(.light)
```

### Dislodge

#### 👆 `dislodge(_: UIImpactFeedbackGenerator.FeedbackStyle) -> Drawer`

Sets the haptic impact of the drawer when dislodging from rest.

**Feedback Style**
Choose from the possible impact styles. [Apple Docs](https://developer.apple.com/documentation/uikit/uiimpactfeedbackgenerator/feedbackstyle)
```swift
public enum FeedbackStyle : Int {

/// A collision between small, light user interface elements.
case light = 0

/// A collision between moderately sized user interface elements.
case medium = 1

/// A collision between large, heavy user interface elements.
case heavy = 2

@available(iOS 13.0, *)
case soft = 3

@available(iOS 13.0, *)
case rigid = 4
}
```

**Usage**
```swift
Drawer(heights: [100, 340]) {
Color.blue
}.dislodge(.light)
```

### Spring

#### 🪀 `spring(_: CGFloat) -> Drawer`
Expand Down
6 changes: 6 additions & 0 deletions Sources/Drawer/Drawer+Drag.swift
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,12 @@ internal extension Drawer {
}

func dragChanged(_ value: DragGesture.Value) {
if dragging == false {
DispatchQueue.main.async {
self.dislodgeGenerator?.impactOccurred()
}
}

dragging = true

height = Drawer.dampen(
Expand Down
22 changes: 22 additions & 0 deletions Sources/Drawer/Drawer+Modifiers.swift
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ public extension Drawer {
didRest: didRest,
didLayoutForSizeClass: didLayoutForSizeClass,
impactGenerator: impactGenerator,
dislodgeGenerator: dislodgeGenerator,
content: content)
}

Expand All @@ -36,6 +37,7 @@ public extension Drawer {
didRest: didRest,
didLayoutForSizeClass: didLayoutForSizeClass,
impactGenerator: impactGenerator,
dislodgeGenerator: dislodgeGenerator,
content: content)
}

Expand All @@ -52,6 +54,24 @@ public extension Drawer {
didRest: didRest,
didLayoutForSizeClass: didLayoutForSizeClass,
impactGenerator: impactGenerator,
dislodgeGenerator: dislodgeGenerator,
content: content)
}

/// Sets the haptic feedback of dislodging the drawer
/// - Parameter dislodge: `FeedbackStyle` for dislodge level
/// - Returns: Drawer with specified dislodge level
func dislodge(_ dislodge: UIImpactFeedbackGenerator.FeedbackStyle) -> Drawer {
let dislodgeGenerator = UIImpactFeedbackGenerator(style: dislodge)
return Drawer(
heights: $heights,
height: height,
restingHeight: restingHeight,
springHeight: springHeight,
didRest: didRest,
didLayoutForSizeClass: didLayoutForSizeClass,
impactGenerator: impactGenerator,
dislodgeGenerator: dislodgeGenerator,
content: content)
}

Expand All @@ -67,6 +87,7 @@ public extension Drawer {
didRest: didRest,
didLayoutForSizeClass: didLayoutForSizeClass,
impactGenerator: impactGenerator,
dislodgeGenerator: dislodgeGenerator,
content: content)
}

Expand All @@ -83,6 +104,7 @@ public extension Drawer {
didRest: didRest,
didLayoutForSizeClass: didLayoutForSizeClass,
impactGenerator: impactGenerator,
dislodgeGenerator: dislodgeGenerator,
content: content)
}
}
3 changes: 3 additions & 0 deletions Sources/Drawer/Drawer.swift
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ public struct Drawer<Content>: View where Content: View {
// MARK: Haptics

internal var impactGenerator: UIImpactFeedbackGenerator?
internal var dislodgeGenerator: UIImpactFeedbackGenerator?

// MARK: View

Expand Down Expand Up @@ -98,6 +99,7 @@ internal extension Drawer {
didRest: ((_ height: CGFloat) -> ())?,
didLayoutForSizeClass: ((SizeClass) -> ())?,
impactGenerator: UIImpactFeedbackGenerator?,
dislodgeGenerator: UIImpactFeedbackGenerator?,
content: Content
) {
self._heights = heights
Expand All @@ -108,6 +110,7 @@ internal extension Drawer {
self.didLayoutForSizeClass = didLayoutForSizeClass
self.content = content
self.impactGenerator = impactGenerator
self.dislodgeGenerator = dislodgeGenerator
}
}

Expand Down