Skip to content

Commit 2e9b630

Browse files
authored
Update README.md
1 parent 13523db commit 2e9b630

1 file changed

Lines changed: 29 additions & 0 deletions

File tree

README.md

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ Features:
2727
- [`RelatableValue`](#relatablevalue), an enum used to store `.relative` or `.absolute` values.
2828
- [`SketchyLine`](#sketchyline), an animatable line `Shape` that aligns to frame edges and can extend beyond the frame.
2929
- [`.emboss()` or `.deboss()`](#emboss-or-deboss) any SwiftUI `Shape` or `View`.
30+
- [`AnimatablePack`](#animatablepack) as an alternative to `AnimatablePair` that takes any number of properties.
3031

3132

3233
# ShapeUpExample
@@ -311,3 +312,31 @@ Extensions for `InsettableShape` and `View` that create an embossed or debossed
311312

312313
<img width="205" alt="image" src="https://user-images.githubusercontent.com/2143656/157765787-a8bcdee3-fec3-40f8-8414-1c66ca073db6.png">
313314

315+
## AnimatablePack
316+
*\*iOS 17 or macOS 14 and up only*
317+
318+
Animate lots of properties in a `Shape` using `AnimatablePack` instead of nesting `AnimatablePair` types
319+
320+
Here is an example of animatableData using AnimatablePair:
321+
```swift
322+
struct MyShape: Animatable {
323+
var animatableData: AnimatablePair<CGFloat, AnimatablePair<RelatableValue, Double>> {
324+
get { AnimatablePair(insetAmount, AnimatablePair(cornerRadius, rotation)) }
325+
set {
326+
insetAmount = newValue.first
327+
cornerRadius = newValue.second.first
328+
rotation = newValue.second.second
329+
}
330+
}
331+
}
332+
```
333+
You can see how it would get quite large once you start adding more than a few properties.
334+
Here's how to use AnimatablePack instead:
335+
```swift
336+
struct MyShape: Animatable {
337+
var animatableData: AnimatablePack<CGFloat, RelatableValue, Double> {
338+
get { AnimatablePack(insetAmount, cornerRadius, rotation) }
339+
set { (insetAmount, cornerRadius, rotation) = newValue() }
340+
}
341+
}
342+
```

0 commit comments

Comments
 (0)