Declaration
import { TimelineView } from 'swiftui-react-native';struct TimelineView<Schedule, Content> where Schedule : TimelineScheduleInitializers
One SwiftUI initializer backs <TimelineView>.
<TimelineView
schedule: SwiftUI.TimelineSchedule
>
children?: ReactNode | ((arg0: SwiftUI.TimelineViewDefaultContext) => ReactNode)
</TimelineView>@export(implementation) nonisolated init(
_ schedule: Schedule,
@ContentBuilder content: @escaping (TimelineViewDefaultContext) -> Content
)schedule*SwiftUI.TimelineScheduleA schedule that produces a sequence of dates that indicate the instances when the view should update. Use a type that conforms to
[TimelineSchedule](/docs/values/timelineschedule), likeTimelineSchedule/everyMinute, or a custom timeline schedule that you define.childrenReactNode | ((arg0: SwiftUI.TimelineViewDefaultContext) => ReactNode)A closure that generates view content at the moments indicated by the schedule. The closure takes an input of type
[TimelineViewDefaultContext](/docs/values/timelineviewdefaultcontext)that includes the date from the schedule that prompted the update, as well as aContext/Cadence-swift.enumvalue that the view can use to customize its appearance.Swift
content: (TimelineViewDefaultContext) -> Content
Also takes the common view props: modifiers, style and testID.
Overview
A timeline view acts as a container with no appearance of its own. Instead, it redraws the content it contains at scheduled points in time. For example, you can update the face of an analog timer once per second:
TimelineView(.periodic(from: startDate, by: 1)) { context in
AnalogTimerView(date: context.date)
}The closure that creates the content receives an input of type Context
that you can use to customize the content's appearance. The context includes
the Context.date that triggered the update. In the example above,
the timeline view sends that date to an analog timer that you create so the
timer view knows how to draw the hands on its face.
The context also includes a Context.cadence-swift.property
property that you can use to hide unnecessary detail. For example, you
can use the cadence to decide when it's appropriate to display the
timer's second hand:
TimelineView(.periodic(from: startDate, by: 1.0)) { context in
AnalogTimerView(
date: context.date,
showSeconds: context.cadence <= .seconds)
}The system might use a cadence that's slower than the schedule's update rate. For example, a view on watchOS might remain visible when the user lowers their wrist, but update less frequently, and thus require less detail.
You can define a custom schedule by creating a type that conforms to the
TimelineSchedule protocol, or use one of the built-in schedule types:
- Use an
TimelineSchedule.everyMinuteschedule to update at the beginning of each minute. - Use a
TimelineSchedule.periodic(from:by:)schedule to update periodically with a custom start time and interval between updates. - Use an
TimelineSchedule.explicit(_:)schedule when you need a finite number, or irregular set of updates.
For a schedule containing only dates in the past, the timeline view shows the last date in the schedule. For a schedule containing only dates in the future, the timeline draws its content using the current date until the first scheduled date arrives.
From Apple’s SwiftUI documentation. Code samples there are Swift.
Relationships
Conforms to
- Swift.Copyable
- Swift.Escapable
- View
See also
More in Views.
- ArrangementViewA view that arranges primary and secondary content using an adaptive layout that responds to the environment.
- ControlGroupA container view that displays semantically-related controls in a visually-appropriate manner for the context
- DividerA visual element that can be used to separate other content.
- EditButtonA button that toggles the edit mode environment value.
- EmptyViewA view that doesn't contain any content.
- GaugeA view that shows a value within a range.
- GroupA type that collects multiple instances of a content type --- like views, scenes, or commands --- into a single unit.
- GroupBoxA stylized view, with an optional label, that visually collects a logical grouping of content.
- RenameButtonA button that triggers a standard rename action.
- SwipeActionsSwipe actions of a list row (SwiftUI swipeActions(edge:allowsFullSwipe:content:)). Place it inside a List.
- ViewThatFitsA view that adapts to the available space by providing the first child view that fits.