forked from LoopKit/LoopKit
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathScheduleItemView.swift
More file actions
60 lines (50 loc) · 1.84 KB
/
ScheduleItemView.swift
File metadata and controls
60 lines (50 loc) · 1.84 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
//
// ScheduleItemView.swift
// LoopKitUI
//
// Created by Michael Pangburn on 4/24/20.
// Copyright © 2020 LoopKit Authors. All rights reserved.
//
import SwiftUI
struct ScheduleItemView<ValueContent: View, ExpandedContent: View>: View {
var time: TimeInterval
@Binding var isEditing: Bool
var valueContent: ValueContent
var expandedContent: ExpandedContent
private let fixedMidnight = Calendar.current.startOfDay(for: Date(timeIntervalSinceReferenceDate: 0))
init(
time: TimeInterval,
isEditing: Binding<Bool>,
@ViewBuilder valueContent: () -> ValueContent,
@ViewBuilder expandedContent: () -> ExpandedContent
) {
self.time = time
self._isEditing = isEditing
self.valueContent = valueContent()
self.expandedContent = expandedContent()
}
var body: some View {
ExpandableSetting(
isEditing: $isEditing,
leadingValueContent: { timeText },
trailingValueContent: { valueContent },
expandedContent: { self.expandedContent }
)
}
private var timeText: Text {
let dayAtTime = fixedMidnight.addingTimeInterval(time)
return Text(DateFormatter.localizedString(from: dayAtTime, dateStyle: .none, timeStyle: .short))
.foregroundColor(isEditing ? .accentColor : Color(.label))
}
}
extension AnyTransition {
static let fadeInFromTop = move(edge: .top).combined(with: .opacity)
.delayingInsertion(by: 0.1)
.speedingUpRemoval(by: 1.8)
func delayingInsertion(by delay: TimeInterval) -> AnyTransition {
.asymmetric(insertion: animation(Animation.default.delay(delay)), removal: self)
}
func speedingUpRemoval(by factor: Double) -> AnyTransition {
.asymmetric(insertion: self, removal: animation(Animation.default.speed(factor)))
}
}