A type-erased shape value.
You can use this type to dynamically switch between shape types:
struct MyClippedView: View {
var isCircular: Bool
var body: some View {
OtherView().clipShape(isCircular ?
AnyShape(Circle()) : AnyShape(Capsule()))
}
}
Members (5)
method · iOS 16.0+
sizeThatFits
TypeScript
sizeThatFits(proposal: ProposedViewSize): { width: number; height: number }
Returns the size of the view that will render the shape, given
a proposed size.
Implement this method to tell the container of the shape how
much space the shape needs to render itself, given a size
proposal.
See ``Layout/sizeThatFits(proposal:subviews:cache:)``
for more details about how the layout system chooses the size of
views.
- Parameters:
- proposal: A size proposal for the container.
- Returns: A size that indicates how much space the shape needs.
get · iOS 16.0+
animatableData
TypeScript
get animatableData(): AnyShape_AnimatableData
Swift declaration
nonisolated var animatableData: AnyShape.AnimatableData { get set }
The data to animate.
SwiftUI reads this property to capture the current vector
representation of the animatable state, and writes it back
on each animation frame with an interpolated value. The
default implementation returns ``EmptyAnimatableData``,
meaning nothing is animated.
Use the ``Animatable()`` macro to synthesize this
property automatically. Implement it by hand only when
you need custom interpolation logic such as clamping,
normalization, or mapping to a derived value.
set · iOS 16.0+
animatableData
TypeScript
set animatableData(value: AnyShape_AnimatableData)
Swift declaration
nonisolated var animatableData: AnyShape.AnimatableData { get set }
The data to animate.
SwiftUI reads this property to capture the current vector
representation of the animatable state, and writes it back
on each animation frame with an interpolated value. The
default implementation returns ``EmptyAnimatableData``,
meaning nothing is animated.
Use the ``Animatable()`` macro to synthesize this
property automatically. Implement it by hand only when
you need custom interpolation logic such as clamping,
normalization, or mapping to a derived value.
Describes this shape as a path within a rectangular frame of reference.
- Parameter rect: The frame of reference for describing this shape.
- Returns: A path that describes this shape.