-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathMapHelper.swift
More file actions
35 lines (31 loc) · 741 Bytes
/
MapHelper.swift
File metadata and controls
35 lines (31 loc) · 741 Bytes
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
import QuartzCore
@inline(__always)
func withCATransaction(
disableActions: Bool = true,
duration: CFTimeInterval? = nil,
timingFunction: CAMediaTimingFunction? = nil,
completion: (() -> Void)? = nil,
_ body: @escaping () -> Void
) {
onMain {
CATransaction.begin()
CATransaction.setDisableActions(disableActions)
duration.map { CATransaction.setAnimationDuration($0) }
timingFunction.map { CATransaction.setAnimationTimingFunction($0) }
completion.map { CATransaction.setCompletionBlock($0) }
body()
CATransaction.commit()
}
}
@inline(__always)
func onMain(
_ block: @escaping () -> Void
) {
if Thread.isMainThread {
block()
} else {
Task { @MainActor in
block()
}
}
}