| 1 |
efrain |
1 |
//
|
|
|
2 |
// GridTopicView.swift
|
|
|
3 |
// twogetskills
|
|
|
4 |
//
|
|
|
5 |
// Created by Efrain Yanez Recanatini on 1/26/22.
|
|
|
6 |
//
|
|
|
7 |
|
|
|
8 |
import SwiftUI
|
|
|
9 |
|
|
|
10 |
struct GridTopicView: View {
|
|
|
11 |
@EnvironmentObject private var appNavigation : AppNavigation
|
|
|
12 |
@ObservedObject private var viewModel : TopicGridViewModel = TopicGridViewModel()
|
|
|
13 |
@State private var scrollToIndex : Int = 0
|
|
|
14 |
|
|
|
15 |
|
|
|
16 |
private let appData = AppData.sharedInstance
|
|
|
17 |
private let config = [
|
|
|
18 |
GridItem(.flexible()),
|
|
|
19 |
GridItem(.flexible())
|
|
|
20 |
]
|
|
|
21 |
|
|
|
22 |
|
|
|
23 |
|
|
|
24 |
var body: some View {
|
|
|
25 |
VStack(spacing: 0) {
|
|
|
26 |
HStack {
|
|
|
27 |
Image("logo")
|
|
|
28 |
.resizable()
|
|
|
29 |
.frame(width: 32, height: 32, alignment: .center)
|
|
|
30 |
.aspectRatio(contentMode: .fit)
|
|
|
31 |
.foregroundColor(Color("color_app_bar_foreground"))
|
|
|
32 |
.padding(.leading, 16)
|
|
|
33 |
|
|
|
34 |
|
|
|
35 |
Text(Config.LANG_TAB_BAR_BUTTON_TOPICS)
|
|
|
36 |
.font(Font.custom(Config.FONT_NAME_REGULAR, size: Config.FONT_SIZE_APP_BAR_HEAD1 ))
|
|
|
37 |
.foregroundColor(Color("color_app_bar_foreground"))
|
|
|
38 |
.padding(.leading, 4)
|
|
|
39 |
|
|
|
40 |
Spacer()
|
|
|
41 |
|
|
|
42 |
Button(action: {}, label: {
|
|
|
43 |
Image(uiImage: UIImage(named: "ui_refresh") ?? UIImage())
|
|
|
44 |
.resizable()
|
|
|
45 |
.frame(width: 32, height: 32, alignment: .center)
|
|
|
46 |
.aspectRatio(contentMode: .fit)
|
|
|
47 |
.foregroundColor(Color("color_app_bar_foreground"))
|
|
|
48 |
.padding(.trailing, 16)
|
|
|
49 |
})
|
|
|
50 |
|
|
|
51 |
}
|
|
|
52 |
.background(Color("color_app_bar_background"))
|
|
|
53 |
.edgesIgnoringSafeArea(.top)
|
|
|
54 |
.frame(height: 50)
|
|
|
55 |
Divider()
|
|
|
56 |
|
|
|
57 |
|
|
|
58 |
ScrollView() {
|
|
|
59 |
ScrollViewReader { proxy in
|
|
|
60 |
LazyVGrid(columns: config, alignment: /*@START_MENU_TOKEN@*/.center/*@END_MENU_TOKEN@*/, spacing: /*@START_MENU_TOKEN@*/nil/*@END_MENU_TOKEN@*/, pinnedViews: /*@START_MENU_TOKEN@*/[]/*@END_MENU_TOKEN@*/, content: {
|
|
|
61 |
ForEach(0..<self.viewModel.topics.count) { index in
|
|
|
62 |
CardTopicView(
|
|
|
63 |
topicUuid: self.viewModel.topics[index].uuid
|
|
|
64 |
)
|
|
|
65 |
.environmentObject(appNavigation)
|
|
|
66 |
.frame(
|
|
|
67 |
width: Constants.CARD_WIDTH,
|
|
|
68 |
height: Constants.CARD_HEIGHT,
|
|
|
69 |
alignment: .center
|
|
|
70 |
).id(index)
|
|
|
71 |
|
|
|
72 |
}.onChange(of: scrollToIndex, perform: { value in
|
|
|
73 |
proxy.scrollTo(value, anchor: nil)
|
|
|
74 |
})
|
|
|
75 |
})
|
|
|
76 |
}
|
|
|
77 |
}
|
|
|
78 |
.padding(.top, 5)
|
|
|
79 |
}
|
|
|
80 |
.onAppear {
|
|
|
81 |
var i : Int = 0
|
|
|
82 |
while i < self.viewModel.topics.count {
|
|
|
83 |
if appData.topicUuidActive == self.viewModel.topics[i].uuid {
|
|
|
84 |
self.scrollToIndex = i
|
|
|
85 |
}
|
|
|
86 |
i += 1
|
|
|
87 |
|
|
|
88 |
}
|
|
|
89 |
}
|
|
|
90 |
}
|
|
|
91 |
}
|
|
|
92 |
|
|
|
93 |
struct GridTopicView_Previews: PreviewProvider {
|
|
|
94 |
static var previews: some View {
|
|
|
95 |
GridTopicView()
|
|
|
96 |
}
|
|
|
97 |
}
|
|
|
98 |
|
|
|
99 |
|