Skip to content

Commit

Permalink
Fix #33, make menu animations faster
Browse files Browse the repository at this point in the history
  • Loading branch information
aheze committed Apr 29, 2022
1 parent a845bdf commit 6723e19
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 12 deletions.
8 changes: 1 addition & 7 deletions Sources/PopoverUtilities.swift
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ public extension View {
size(newValue)
}
}
.onValueChange(of: transaction) { _, _ in
.onValueChange(of: transaction?.animation) { _, _ in
DispatchQueue.main.async {
size(geometry.size)
}
Expand All @@ -68,12 +68,6 @@ public extension View {
}
}

extension Transaction: Equatable {
public static func == (lhs: Transaction, rhs: Transaction) -> Bool {
lhs.animation == rhs.animation
}
}

struct ContentFrameReaderPreferenceKey: PreferenceKey {
static var defaultValue: CGRect { return CGRect() }
static func reduce(value: inout CGRect, nextValue: () -> CGRect) { value = nextValue() }
Expand Down
10 changes: 5 additions & 5 deletions Sources/Templates/Menu.swift
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ public extension Templates {
/// A set of attributes for the popover menu.
struct MenuConfiguration {
public var holdDelay = CGFloat(0.2) /// The duration of a long press to activate the menu.
public var presentationAnimation = Animation.spring(response: 0.4, dampingFraction: 0.7, blendDuration: 1)
public var dismissalAnimation = Animation.spring(response: 0.5, dampingFraction: 0.9, blendDuration: 1)
public var presentationAnimation = Animation.spring(response: 0.3, dampingFraction: 0.7, blendDuration: 1)
public var dismissalAnimation = Animation.spring(response: 0.4, dampingFraction: 0.9, blendDuration: 1)
public var labelFadeAnimation = Animation.default /// The animation used when calling the `fadeLabel`.
public var clipContent = true /// Replicate the system's default clipping animation.
public var sourceFrameInset = UIEdgeInsets(top: -8, left: -8, bottom: -8, right: -8)
Expand All @@ -33,8 +33,8 @@ public extension Templates {
/// Create the default attributes for the popover menu.
public init(
holdDelay: CGFloat = CGFloat(0.2),
presentationAnimation: Animation = .spring(response: 0.4, dampingFraction: 0.7, blendDuration: 1),
dismissalAnimation: Animation = .spring(response: 0.5, dampingFraction: 0.9, blendDuration: 1),
presentationAnimation: Animation = .spring(response: 0.3, dampingFraction: 0.7, blendDuration: 1),
dismissalAnimation: Animation = .spring(response: 0.4, dampingFraction: 0.9, blendDuration: 1),
labelFadeAnimation: Animation = .easeOut,
sourceFrameInset: UIEdgeInsets = .init(top: -8, left: -8, bottom: -8, right: -8),
originAnchor: Popover.Attributes.Position.Anchor = .bottom,
Expand Down Expand Up @@ -302,7 +302,7 @@ public extension Templates {
.frame(width: configuration.width)
.fixedSize() /// Hug the width of the inner content.
.modifier(ClippedBackgroundModifier(context: context, configuration: configuration, expanded: expanded)) /// Clip the content if desired.
.scaleEffect(expanded ? 1 : 0.1, anchor: configuration.scaleAnchor?.unitPoint ?? model.getScaleAnchor(from: context))
.scaleEffect(expanded ? 1 : 0.2, anchor: configuration.scaleAnchor?.unitPoint ?? model.getScaleAnchor(from: context))
.scaleEffect(model.scale, anchor: configuration.scaleAnchor?.unitPoint ?? model.getScaleAnchor(from: context))
.simultaneousGesture(
DragGesture(minimumDistance: 0, coordinateSpace: .global)
Expand Down

0 comments on commit 6723e19

Please sign in to comment.