forked from amirdew/CollectionViewPagingLayout
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathGalleryViewController.swift
More file actions
86 lines (62 loc) · 2.31 KB
/
GalleryViewController.swift
File metadata and controls
86 lines (62 loc) · 2.31 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
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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
//
// GalleryViewController.swift
// CollectionViewPagingLayout
//
// Created by Amir Khorsandi on 12/27/19.
// Copyright © 2019 Amir Khorsandi. All rights reserved.
//
import Foundation
import UIKit
import CollectionViewPagingLayout
class GalleryViewController: UIViewController, NibBased, ViewModelBased {
// MARK: Properties
var viewModel: GalleryViewModel!
override var preferredStatusBarStyle: UIStatusBarStyle {
.lightContent
}
private let layout = CollectionViewPagingLayout()
@IBOutlet private weak var backButton: UIButton!
@IBOutlet private weak var collectionView: UICollectionView!
// MARK: UIViewController
override func viewDidLoad() {
super.viewDidLoad()
configureViews()
}
// MARK: Event listener
@IBAction private func onBackTouched() {
navigationController?.popViewController(animated: true)
}
@IBAction private func onNextTouched() {
layout.goToNextPage()
}
@IBAction private func onPreviousTouched() {
layout.goToPreviousPage()
}
// MARK: Private functions
private func configureViews() {
view.backgroundColor = .black
view.clipsToBounds = true
configureCollectionView()
}
private func configureCollectionView() {
collectionView.register(PhotoCollectionViewCell.self)
collectionView.isPagingEnabled = true
collectionView.dataSource = self
layout.numberOfVisibleItems = 10
collectionView.collectionViewLayout = layout
collectionView.showsHorizontalScrollIndicator = false
collectionView.clipsToBounds = false
collectionView.backgroundColor = .clear
}
}
extension GalleryViewController: UICollectionViewDataSource {
func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
viewModel.itemViewModels.count
}
func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
let itemViewModel = viewModel.itemViewModels[indexPath.row]
let cell: PhotoCollectionViewCell = collectionView.dequeueReusableCell(for: indexPath)
cell.viewModel = itemViewModel
return cell
}
}