Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions ViewLifecycle/LifecycleMonitor.swift
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ struct LifecycleMonitor: View {
var label: String
@State private var stateTimestamp: Date = .now
@State private var onAppearTimestamp: Date? = nil
@State private var taskStartTimestamp: Date? = nil
@State private var onDisappearTimestamp: Date? = nil
@State private var color: Color = .random()

Expand Down Expand Up @@ -35,6 +36,14 @@ struct LifecycleMonitor: View {
.monospacedDigit()
}
.help("When onDisappear was last called for this view")

GridRow(alignment: .firstTextBaseline) {
Text("task")
Text(timestampLabel(for: taskStartTimestamp))
.monospacedDigit()
}
.help("When task was last called for this view")

}
.font(.callout)
}
Expand All @@ -60,6 +69,14 @@ struct LifecycleMonitor: View {
onDisappearTimestamp = timestamp
}
}
.task {
let timestamp = Date.now
print("\(timestamp) \(label): task started")
let animation: Animation? = taskStartTimestamp == nil ? nil : .easeOut(duration: 1)
withAnimation(animation) {
taskStartTimestamp = timestamp
}
}
}

private func timestampLabel(for timestamp: Date?) -> LocalizedStringKey {
Expand Down