forked from MacMagazine/app-iOS
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathFeedDotsIndicatorView.swift
More file actions
43 lines (36 loc) · 1.03 KB
/
FeedDotsIndicatorView.swift
File metadata and controls
43 lines (36 loc) · 1.03 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
import SwiftUI
// MARK: - Dots Indicator
public struct FeedDotsIndicatorView: View {
let count: Int
let selectedIndex: Int
public var body: some View {
VStack(spacing: 5) {
dots
}
.padding(6)
.allowsHitTesting(false)
}
private var dots: some View {
ForEach(0..<count, id: \.self) { index in
Circle()
.fill(dotColor(for: index))
.frame(width: dotSize(for: index), height: dotSize(for: index))
.shadow(color: index == selectedIndex ? .white.opacity(0.5) : .clear, radius: 2)
.animation(.easeInOut(duration: 0.2), value: selectedIndex)
}
}
private func dotColor(for index: Int) -> Color {
index == selectedIndex ? .white : .white.opacity(0.4)
}
private func dotSize(for index: Int) -> CGFloat {
index == selectedIndex ? 8 : 5
}
}
#if DEBUG
#Preview {
ZStack {
Color.gray
FeedDotsIndicatorView(count: 10, selectedIndex: 3)
}
}
#endif