<!--
{
  "availability" : [
    "iOS: 17.0.0 -",
    "iPadOS: 17.0.0 -",
    "macCatalyst: 17.0.0 -",
    "macOS: 14.0.0 -",
    "tvOS: 17.0.0 -",
    "visionOS: 1.0.0 -",
    "watchOS: 10.0.0 -"
  ],
  "documentType" : "symbol",
  "framework" : "SwiftUI",
  "identifier" : "/documentation/SwiftUI/CustomAnimation/shouldMerge(previous:value:time:context:)",
  "metadataVersion" : "0.1.0",
  "role" : "Instance Method",
  "symbol" : {
    "kind" : "Instance Method",
    "modules" : [
      "SwiftUI"
    ],
    "preciseIdentifier" : "s:7SwiftUI15CustomAnimationP11shouldMerge8previous5value4time7contextSbAA0D0V_qd__SdAA0D7ContextVyqd__GztAA16VectorArithmeticRd__lF"
  },
  "title" : "shouldMerge(previous:value:time:context:)"
}
-->

# shouldMerge(previous:value:time:context:)

Determines whether an instance of the animation can merge with other
running animations.

```
nonisolated func shouldMerge<V>(previous: Animation, value: V, time: TimeInterval, context: inout AnimationContext<V>) -> Bool where V : VectorArithmetic
```

## Parameters

`previous`

The previous running animation.

`value`

The vector to animate towards.

`time`

The amount of time since the start of the previous animation.

`context`

An instance of [`AnimationContext`](/documentation/SwiftUI/AnimationContext) that provides access
to state and the animation environment.

## Return Value

A Boolean value of `true` if the animation should merge with
the previous animation; otherwise, `false`.

## Discussion

When a view creates a new animation on an animatable value that already
is running an animation, the system calls the
`shouldMerge(previous:value:time:context:)` method on the new instance
to determine whether it can merge the two instances. Implement this
method if the animation can merge with other instances. The default
implementation returns `false`.

If `shouldMerge(previous:value:time:context:)` returns `true`, the
system merges the new animation instance with the previous animation.
The system provides to the new instance the state and elapsed time from
the previous one. Then it removes the previous animation.

If this method returns `false`, the system doesn’t merge the animation
with the previous one. Instead, both animations run together and the
system combines their results.

If your custom animation needs to maintain state between calls to the
`shouldMerge(previous:value:time:context:)` method, store the state
data in `context`. This makes the data available to the method next
time the system calls it. To learn more, see [`AnimationContext`](/documentation/SwiftUI/AnimationContext).

---

Copyright &copy; 2026 Apple Inc. All rights reserved. | [Terms of Use](https://www.apple.com/legal/internet-services/terms/site.html) | [Privacy Policy](https://www.apple.com/privacy/privacy-policy)