Skip to content

Commit

Permalink
Action builders also need to be on main actor
Browse files Browse the repository at this point in the history
  • Loading branch information
nighthawk committed Feb 29, 2024
1 parent 9f99210 commit b4439c8
Show file tree
Hide file tree
Showing 5 changed files with 10 additions and 4 deletions.
1 change: 1 addition & 0 deletions Examples/TripKitUIExample/ExampleCustomizer.swift
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ extension ExampleCustomizer {
}
}

@MainActor
private static func buildFavoriteStopAction(stop: TKUIStopAnnotation) -> TKUITimetableCard.Action {

func isFavorite() -> Bool { InMemoryFavoriteManager.shared.hasFavorite(for: stop) }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ public extension TKUIServiceCard {

static let empty = Configuration()

public var serviceActionsFactory: ((EmbarkationPair) -> [TKUICardAction<TKUIServiceCard, EmbarkationPair>])?
public var serviceActionsFactory: (@MainActor (EmbarkationPair) -> [TKUICardAction<TKUIServiceCard, EmbarkationPair>])?
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ public extension TKUITimetableCard {
/// Set this to add a list of action buttons to a timeable card.
///
/// Called when a timetable card gets presented.
public var timetableActionsFactory: (([TKUIStopAnnotation]) -> [Action])?
public var timetableActionsFactory: (@MainActor ([TKUIStopAnnotation])-> [Action])?

/// This controls whether the title is visible underneath an action icon.
///
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ public extension TKUITripOverviewCard {
/// more than that will be ignored.
///
/// Called when a trip overview card gets presented.
public var tripActionsFactory: ((Trip) -> [TripAction])?
public var tripActionsFactory: (@MainActor (Trip) -> [TripAction])?

/// This controls whether the title is visible underneath an action icon.
///
Expand All @@ -88,7 +88,7 @@ public extension TKUITripOverviewCard {
/// more than that will be ignored.
///
/// Called when a trip overview card gets presented.
public var segmentActionsfactory: ((TKSegment) -> [SegmentAction])?
public var segmentActionsfactory: (@MainActor (TKSegment) -> [SegmentAction])?

/// Set this to limit how many alerts are shown for a segment
public var maximumAlertsPerSegment: Int = 3
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -274,6 +274,7 @@ fileprivate extension TKSegment {
return TKUITripOverviewViewModel.TimeInfo(actualTime: arrivalTime, timetableTime: self.scheduledTimetableEndTime)
}

@MainActor
func toTerminal(previous: TKSegment?, next: TKSegment?) -> TKUITripOverviewViewModel.TerminalItem {
let isStart = order == .start
let subtitle = platformInfo(previous: previous, next: next)
Expand All @@ -292,6 +293,7 @@ fileprivate extension TKSegment {
}

/// Create a stationary item for a stationary segment
@MainActor
func toStationary(previous: TKSegment?, next: TKSegment?) -> TKUITripOverviewViewModel.StationaryItem {
assert(isStationary)

Expand Down Expand Up @@ -343,6 +345,7 @@ fileprivate extension TKSegment {
}

/// Create a stationary item (bridge) for a non-stationary segment
@MainActor
func toStationaryBridge(to next: TKSegment) -> TKUITripOverviewViewModel.StationaryItem {
assert(!isStationary && !next.isStationary)

Expand All @@ -365,10 +368,12 @@ fileprivate extension TKSegment {
)
}

@MainActor
func toAlert() -> TKUITripOverviewViewModel.AlertItem {
return TKUITripOverviewViewModel.AlertItem(connection: line, segment: self)
}

@MainActor
func toMoving() -> TKUITripOverviewViewModel.MovingItem {
var accessories: [TKUITripOverviewViewModel.SegmentAccessory] = []

Expand Down

0 comments on commit b4439c8

Please sign in to comment.