-
-
Notifications
You must be signed in to change notification settings - Fork 4
/
ContentView.swift
69 lines (60 loc) · 1.91 KB
/
ContentView.swift
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
61
62
63
64
65
66
67
68
69
//
// SwiftUIView.swift
//
//
// Created by Igor Ferreira on 25/04/2022.
//
import SwiftUI
import GIFImage
struct ListItem: Identifiable {
let id: UUID
let source: GIFSource
init(_ source: GIFSource) {
self.id = UUID()
self.source = source
}
}
struct ContentView: View {
@State var items: [ListItem]
@State var placeholder = UIImage(systemName: "photo.circle.fill")!
@State var error: UIImage?
@State var animate: Bool = true
@State var loop: Bool = true
init(items: [GIFSource]? = nil) {
self.items = items?.map { ListItem($0) } ?? [
ListItem(.remote(url: URL(string: "https://raw.githubusercontent.com/igorcferreira/GIFImage/main/Tests/test.gif")!)),
ListItem(.local(filePath: Bundle.main.path(forResource: "test", ofType: "gif")!))
]
}
var body: some View {
VStack(alignment: .center) {
Toggle("Animate", isOn: $animate).padding([.leading, .trailing, .top])
Toggle("Loop", isOn: $loop).padding([.leading, .trailing, .bottom])
List(items) { item in
GIFImage(
source: item.source,
animate: $animate,
loop: $loop,
placeholder: placeholder,
errorImage: error,
frameRate: .dynamic,
loopAction: loopAction(source:)
).frame(height: 175.0, alignment: .center)
}
}
}
@MainActor
@Sendable private func loopAction(source: GIFSource) async {
print("Loop for source: \(source)")
}
}
struct ContentViewPreviews: PreviewProvider {
static var previews: some View {
Group {
ContentView()
.environment(\.locale, .init(identifier: "en"))
ContentView()
.environment(\.locale, .init(identifier: "pt"))
}
}
}