-
Notifications
You must be signed in to change notification settings - Fork 349
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
9 changed files
with
353 additions
and
163 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
3 changes: 2 additions & 1 deletion
3
ios/MullvadVPN/Extensions/String+Split.swift → ...ullvadVPN/Extensions/String+Helpers.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
61 changes: 61 additions & 0 deletions
61
ios/MullvadVPN/View controllers/RelayFilter/ChipCollectionView.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
// | ||
// ChipCollectionView.swift | ||
// MullvadVPN | ||
// | ||
// Created by Mojgan on 2024-10-31. | ||
// Copyright © 2024 Mullvad VPN AB. All rights reserved. | ||
// | ||
|
||
import Foundation | ||
import UIKit | ||
|
||
class ChipCollectionView: UIView { | ||
private var chips: [ChipConfiguration] = [] | ||
private let cellReuseIdentifier = String(describing: ChipViewCell.self) | ||
|
||
private(set) lazy var collectionView: UICollectionView = { | ||
let collectionView = UICollectionView(frame: .zero, collectionViewLayout: ChipFlowLayout()) | ||
collectionView.contentInset = .zero | ||
collectionView.backgroundColor = .clear | ||
collectionView.translatesAutoresizingMaskIntoConstraints = false | ||
return collectionView | ||
}() | ||
|
||
init() { | ||
super.init(frame: .zero) | ||
setupCollectionView() | ||
} | ||
|
||
required init?(coder: NSCoder) { | ||
super.init(coder: coder) | ||
setupCollectionView() | ||
} | ||
|
||
private func setupCollectionView() { | ||
collectionView.dataSource = self | ||
collectionView.register(UICollectionViewCell.self, forCellWithReuseIdentifier: cellReuseIdentifier) | ||
addConstrainedSubviews([collectionView]) { | ||
collectionView.pinEdgesToSuperview() | ||
} | ||
} | ||
|
||
func setChips(_ values: [ChipConfiguration]) { | ||
chips = values | ||
collectionView.reloadData() | ||
} | ||
} | ||
|
||
extension ChipCollectionView: UICollectionViewDataSource { | ||
func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int { | ||
return chips.count | ||
} | ||
|
||
func collectionView( | ||
_ collectionView: UICollectionView, | ||
cellForItemAt indexPath: IndexPath | ||
) -> UICollectionViewCell { | ||
let cell = collectionView.dequeueReusableCell(withReuseIdentifier: cellReuseIdentifier, for: indexPath) | ||
cell.contentConfiguration = chips[indexPath.row] | ||
return cell | ||
} | ||
} |
45 changes: 45 additions & 0 deletions
45
ios/MullvadVPN/View controllers/RelayFilter/ChipFlowLayout.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
// | ||
// ChipFlowLayout.swift | ||
// MullvadVPN | ||
// | ||
// Created by Mojgan on 2024-10-31. | ||
// Copyright © 2024 Mullvad VPN AB. All rights reserved. | ||
// | ||
|
||
import UIKit | ||
|
||
class ChipFlowLayout: UICollectionViewCompositionalLayout { | ||
init() { | ||
super.init { _, _ -> NSCollectionLayoutSection? in | ||
// Create an item with flexible size | ||
let itemSize = NSCollectionLayoutSize(widthDimension: .estimated(50), heightDimension: .estimated(20)) | ||
let item = NSCollectionLayoutItem(layoutSize: itemSize) | ||
item.edgeSpacing = NSCollectionLayoutEdgeSpacing( | ||
leading: .fixed(0), | ||
top: .fixed(0), | ||
trailing: .fixed(0), | ||
bottom: .fixed(0) | ||
) | ||
|
||
// Create a group that fills the available width and wraps items with proper spacing | ||
let groupSize = NSCollectionLayoutSize( | ||
widthDimension: .fractionalWidth(1.0), | ||
heightDimension: .estimated(20) | ||
) | ||
let group = NSCollectionLayoutGroup.horizontal(layoutSize: groupSize, subitems: [item]) | ||
group.interItemSpacing = .fixed(UIMetrics.FilterView.interChipViewSpacing) | ||
group.contentInsets = .zero | ||
|
||
// Create a section with zero inter-group spacing and no content insets | ||
let section = NSCollectionLayoutSection(group: group) | ||
section.interGroupSpacing = UIMetrics.FilterView.interChipViewSpacing | ||
section.contentInsets = .zero | ||
|
||
return section | ||
} | ||
} | ||
|
||
required init?(coder: NSCoder) { | ||
fatalError("init(coder:) has not been implemented") | ||
} | ||
} |
Oops, something went wrong.