forked from BasedHardware/omi
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathFloatingBarNotchTransition.swift
More file actions
36 lines (32 loc) · 1019 Bytes
/
Copy pathFloatingBarNotchTransition.swift
File metadata and controls
36 lines (32 loc) · 1019 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
36
import CoreGraphics
enum FloatingBarNotchTransition {
static func revealProgress(_ rawProgress: CGFloat) -> CGFloat {
let progress = min(max(rawProgress, 0), 1)
return 1 - pow(1 - progress, 2)
}
static func hiddenFrame(for targetFrame: CGRect) -> CGRect {
CGRect(
x: targetFrame.midX - 1,
y: targetFrame.maxY - 1,
width: 2,
height: 1
)
}
static func growFrame(targetFrame: CGRect, progress rawProgress: CGFloat) -> CGRect {
let eased = revealProgress(rawProgress)
let width = max(2, targetFrame.width * eased)
let height = max(1, targetFrame.height * eased)
return CGRect(
x: targetFrame.midX - width / 2,
y: targetFrame.maxY - height,
width: width,
height: height
)
}
static func growFrames(targetFrame: CGRect, steps: Int) -> [CGRect] {
let frameCount = max(1, steps)
return (1...frameCount).map { step in
growFrame(targetFrame: targetFrame, progress: CGFloat(step) / CGFloat(frameCount))
}
}
}