Skip to content

Commit

Permalink
updated
Browse files Browse the repository at this point in the history
  • Loading branch information
flocked committed Feb 3, 2024
1 parent 5d2b888 commit 095afc0
Show file tree
Hide file tree
Showing 4 changed files with 109 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,9 @@ extension NSLayoutConstraint: AnimatablePropertyProvider {
widthConstraint.animator.constant = 50.0
```

### Accessing Animations
### Accessing Animation

To access the animation for a property, use ``animation(for:)``:
To access the animation for `constant`, use ``animation(for:)``:

```swift
if let animation = widthConstraint.animator.animation(for: \.constant) {
Expand All @@ -50,7 +50,7 @@ extension NSLayoutConstraint: AnimatablePropertyProvider {

### Accessing Animation Velocity

To access the animation velocity for a property, use ``animationVelocity(for:)``.
To access the animation velocity for `constant`, use ``animationVelocity(for:)``.

```swift
if let velocity = widthConstraint.animator.animation(for: \.constant) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
//
// PropertyAnimator+Popover.swift
//
//
// Created by Florian Zand on 03.02.24.
//

#if os(macOS)

import AppKit

extension NSPopover: AnimatablePropertyProvider {
/**
Provides the animatable content size.

To animate the property change it's value inside an ``Anima`` animation block, To stop its animation and to change the value imminently, update it outside an animation block.
*/
public var animator: PopoverAnimator { getAssociatedValue(key: "PropertyAnimator", object: self, initialValue: PopoverAnimator(self)) }
}

/**
Provides the animatable content size.

To animate the `contentSize` of a popover, change it's value inside an ``Anima`` animation block:

```swift
Anima.animate(withSpring: .smooth) {
popover.animator.contentSize = CGSize(width: 200, height: 200)
}
```
To stop the animation and to change the constant immediately, change it's value outside an animation block:

```swift
popover.animator.contentSize = CGSize(width: 100, height: 100)
```

### Accessing Animation

To access the animation for `contentSize`, use ``animation(for:)``:

```swift
if let animation = popover.animator.animation(for: \.contentSize) {
animation.stop()
}
```

### Accessing Animation Velocity

To access the animation velocity for `contentSize`, use ``animationVelocity(for:)``.

```swift
if let velocity = popover.animator.animation(for: \.contentSize) {

}
```
*/
public class PopoverAnimator: PropertyAnimator<NSPopover> {
/// The content size of the popover.
public var contentSize: CGSize {
get { self[\.contentSize] }
set { self[\.contentSize] = newValue }
}
}

public extension PopoverAnimator {
/**
The current animation for the property at the specified keypath, or `nil` if the property isn't animated.

- Parameter keyPath: The keypath to an animatable property.
*/
func animation<Value: AnimatableProperty>(for keyPath: WritableKeyPath<PopoverAnimator, Value>) -> AnimationProviding? {
lastAccessedPropertyKey = ""
_ = self[keyPath: keyPath]
return animations[lastAccessedPropertyKey != "" ? lastAccessedPropertyKey : keyPath.stringValue]
}

/**
The current animation velocity for the property at the specified keypath, or `nil` if the property isn't animated or doesn't support velocity values.

- Parameter keyPath: The keypath to an animatable property.
*/
func animationVelocity<Value: AnimatableProperty>(for keyPath: WritableKeyPath<PopoverAnimator, Value>) -> Value? {
var velocity: Value?
Anima.updateVelocity {
velocity = self[keyPath: keyPath]
}
return velocity
}
}


#endif
1 change: 1 addition & 0 deletions Sources/Anima/Documentation/Anima.docc/Anima.md
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,7 @@ Subclassing ``PropertyAnimation`` let's you create your own animations. Itself i
- ``LayerAnimator``
- ``LayoutAnimator``
- ``ViewAnimator``
- ``PopoverAnimator``
- ``WindowAnimator``

### Animations
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# ``PopoverAnimator``

## Topics

### Accessing animations

- ``PropertyAnimator/animations``
- ``animation(for:)``
- ``animationVelocity(for:)``

### Animatable properties

- ``contentSize``

0 comments on commit 095afc0

Please sign in to comment.