Viewport
Viewport
provides a structured approach to organizing camera management logic into states and
transitions between them.
At any given time, the viewport is either:
- idle (not updating the camera)
- in a state (camera is being managed by a
ViewportState
) - transitioning (camera is being managed by a
ViewportTransition
)
-
Configuration options for adjusting the viewport’s behavior.
-
The current
ViewportStatus
.status
cannot be set directly. Usetransition(to:transition:completion:)
andidle()
to transition to a state or to idle.Defaults to
idle
. -
Subscribes a
ViewportStatusObserver
tostatus
changes.Viewport keeps a strong reference to registered observers. Adding the same observer again while it is already subscribed has no effect.
Note
Observers are notified of status changes asynchronously on the main queue. This means that by the time the notification is delivered, the status may have already changed again. This behavior is necessary to allow observers to trigger further transitions while avoiding out-of-order delivery of status changed notifications.See also
removeStatusObserver(_:)
-
Unsubscribes a
ViewportStatusObserver
fromstatus
changes. This causes viewport to release its strong reference to the observer. Removing an observer that is not subscribed has no effect.See also
addStatusObserver(_:)
-
Sets
status
toidle
synchronously.This cancels any active
ViewportState
orViewportTransition
. -
Executes a transition to the requested state.
If the transition fails,
status
is set toidle
.Transitioning to state
x
when the status is.state(x)
invokescompletion
synchronously withtrue
and does not modifystatus
.Transitioning to state
x
when the status is.transition(_, x)
invokescompletion
synchronously withfalse
and does not modifystatus
.Viewport
keeps a strong reference to active transitions and states. To reuse states and transitions, keep strong references to them in the consuming project. -
transition(to:transition:completion:)
uses this transition unless some non-nil value is passed to itstransition
argument.Defaults to
DefaultViewportTransition
with default options. -
Creates a new instance of
FollowPuckViewportState
with the specified options. -
Creates a new instance of
OverviewViewportState
with the specified options. -
Creates a new instance of
DefaultViewportTransition
. -
Creates a new instance of
ImmediateViewportTransition
.