Skip to content

Commit

Permalink
Update Region (#2)
Browse files Browse the repository at this point in the history
  • Loading branch information
muukii authored May 6, 2023
1 parent 4534507 commit 3714fd1
Showing 1 changed file with 48 additions and 10 deletions.
58 changes: 48 additions & 10 deletions Sources/SwiftUISnapDraggingModifier/SnapDraggingModifier.swift
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ public struct SnapDraggingModifier: ViewModifier {
/// entire view
case screen
///
case edgeLeading
case edge(Edge.Set)
}

public let minimumDistance: Double
Expand Down Expand Up @@ -165,16 +165,54 @@ public struct SnapDraggingModifier: ViewModifier {
switch activation.regionToActivate {
case .screen:
return true
case .edgeLeading:
switch layoutDirection {
case .leftToRight:
return CGRect(origin: .zero, size: .init(width: 20, height: CGFloat.greatestFiniteMagnitude)).contains(startLocation)
case .rightToLeft:
// FIXME: Unimplemented
return CGRect(origin: .zero, size: .init(width: 20, height: CGFloat.greatestFiniteMagnitude)).contains(startLocation)
@unknown default:
return false
case .edge(let edge):

let space: Double = 20
let contentSize = self.contentSize

if edge.contains(.leading) {
switch layoutDirection {
case .leftToRight:
if CGRect(origin: .zero, size: .init(width: space, height: contentSize.height)).contains(startLocation) {
return true
}
case .rightToLeft:
if CGRect(origin: .init(x: contentSize.width - space, y: 0), size: .init(width: space, height: contentSize.height)).contains(startLocation) {
return true
}
@unknown default:
break
}
}

if edge.contains(.trailing) {
switch layoutDirection {
case .leftToRight:
if CGRect(origin: .init(x: contentSize.width - space, y: 0), size: .init(width: space, height: contentSize.height)).contains(startLocation) {
return true
}
case .rightToLeft:
if CGRect(origin: .zero, size: .init(width: 20, height: CGFloat.greatestFiniteMagnitude)).contains(startLocation) {
return true
}
@unknown default:
return false
}
}

if edge.contains(.top) {
if CGRect(origin: .zero, size: .init(width: contentSize.width, height: space)).contains(startLocation) {
return true
}
}

if edge.contains(.bottom) {
if CGRect(origin: .init(x: 0, y: contentSize.height - space), size: .init(width: contentSize.width, height: space)).contains(startLocation) {
return true
}
}

return false
}

}
Expand Down

0 comments on commit 3714fd1

Please sign in to comment.