forked from organicmaps/organicmaps
[release-76-ios-xc] [ios] Fixed crash on iOS 9.
This commit is contained in:
parent
0a34c7c185
commit
243cb10482
2 changed files with 8 additions and 31 deletions
|
@ -2,9 +2,6 @@
|
|||
final class UGCYourReviewCell: MWMTableViewCell {
|
||||
private enum Config {
|
||||
static let defaultReviewBottomOffset: CGFloat = 16
|
||||
static let minimumInteritemSpacing: CGFloat = 16
|
||||
static let minItemsPerRow: CGFloat = 3
|
||||
static let estimatedItemSize = CGSize(width: 96, height: 32)
|
||||
}
|
||||
|
||||
@IBOutlet private weak var titleLabel: UILabel! {
|
||||
|
@ -36,8 +33,6 @@ final class UGCYourReviewCell: MWMTableViewCell {
|
|||
@IBOutlet private weak var ratingCollectionView: UICollectionView! {
|
||||
didSet {
|
||||
ratingCollectionView.register(cellClass: UGCSummaryRatingStarsCell.self)
|
||||
let layout = ratingCollectionView.collectionViewLayout as! UICollectionViewFlowLayout
|
||||
layout.estimatedItemSize = Config.estimatedItemSize
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -46,7 +41,7 @@ final class UGCYourReviewCell: MWMTableViewCell {
|
|||
override var frame: CGRect {
|
||||
didSet {
|
||||
if frame.size != oldValue.size {
|
||||
updateCollectionView(nil)
|
||||
updateCollectionView()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -57,36 +52,18 @@ final class UGCYourReviewCell: MWMTableViewCell {
|
|||
reviewLabel.text = yourReview.text
|
||||
reviewBottomOffset.constant = yourReview.text.isEmpty ? 0 : Config.defaultReviewBottomOffset
|
||||
reviewLabel.onUpdate = onUpdate
|
||||
updateCollectionView { [weak self] in
|
||||
self?.ratingCollectionView.reloadSections(IndexSet(integer: 0))
|
||||
}
|
||||
updateCollectionView()
|
||||
isSeparatorHidden = true
|
||||
}
|
||||
|
||||
override func didMoveToSuperview() {
|
||||
super.didMoveToSuperview()
|
||||
updateCollectionView(nil)
|
||||
updateCollectionView()
|
||||
}
|
||||
|
||||
private func updateCollectionView(_ updates: (() -> Void)?) {
|
||||
guard let sv = superview else { return }
|
||||
private func updateCollectionView() {
|
||||
DispatchQueue.main.async {
|
||||
let layout = self.ratingCollectionView.collectionViewLayout as! UICollectionViewFlowLayout
|
||||
let inset = layout.sectionInset
|
||||
let viewWidth = sv.size.width - inset.left - inset.right
|
||||
let maxItemWidth = layout.estimatedItemSize.width
|
||||
|
||||
let ratingsCount = CGFloat(self.yourReview?.ratings.count ?? 0)
|
||||
let itemsPerRow = floor(min(max(viewWidth / maxItemWidth, Config.minItemsPerRow), ratingsCount))
|
||||
let itemWidth = floor(min((viewWidth - (itemsPerRow - 1) * Config.minimumInteritemSpacing) / itemsPerRow, maxItemWidth))
|
||||
let interitemSpacing = floor((viewWidth - itemWidth * itemsPerRow) / (itemsPerRow - 1))
|
||||
layout.minimumInteritemSpacing = interitemSpacing
|
||||
layout.itemSize = CGSize(width: itemWidth, height: Config.estimatedItemSize.height)
|
||||
|
||||
assert(itemsPerRow > 0);
|
||||
let rowsCount = ceil(ratingsCount / itemsPerRow)
|
||||
self.ratingCollectionViewHeight.constant = rowsCount * Config.estimatedItemSize.height + (rowsCount - 1) * layout.minimumLineSpacing + inset.top + inset.bottom
|
||||
self.ratingCollectionView.performBatchUpdates(updates, completion: nil)
|
||||
self.ratingCollectionView.reloadData()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -5,7 +5,7 @@
|
|||
</device>
|
||||
<dependencies>
|
||||
<deployment identifier="iOS"/>
|
||||
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="13173"/>
|
||||
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="13174"/>
|
||||
<capability name="documents saved in the Xcode 8 format" minToolsVersion="8.0"/>
|
||||
</dependencies>
|
||||
<objects>
|
||||
|
@ -63,13 +63,13 @@
|
|||
<constraint firstItem="nht-6C-S3i" firstAttribute="top" secondItem="M3q-L0-4Y7" secondAttribute="top" constant="16" id="v5J-lZ-cdA"/>
|
||||
</constraints>
|
||||
</view>
|
||||
<collectionView clipsSubviews="YES" multipleTouchEnabled="YES" contentMode="scaleToFill" bounces="NO" scrollEnabled="NO" showsHorizontalScrollIndicator="NO" showsVerticalScrollIndicator="NO" dataMode="none" prefetchingEnabled="NO" translatesAutoresizingMaskIntoConstraints="NO" id="w6j-GC-6Bv">
|
||||
<collectionView clipsSubviews="YES" multipleTouchEnabled="YES" contentMode="scaleToFill" bounces="NO" pagingEnabled="YES" showsHorizontalScrollIndicator="NO" showsVerticalScrollIndicator="NO" dataMode="none" prefetchingEnabled="NO" translatesAutoresizingMaskIntoConstraints="NO" id="w6j-GC-6Bv">
|
||||
<rect key="frame" x="0.0" y="135" width="320" height="55.5"/>
|
||||
<color key="backgroundColor" white="1" alpha="1" colorSpace="calibratedWhite"/>
|
||||
<constraints>
|
||||
<constraint firstAttribute="height" priority="999" constant="56" id="2hn-mr-UAw"/>
|
||||
</constraints>
|
||||
<collectionViewFlowLayout key="collectionViewLayout" minimumLineSpacing="12" minimumInteritemSpacing="16" id="MWR-PM-MMO">
|
||||
<collectionViewFlowLayout key="collectionViewLayout" scrollDirection="horizontal" minimumLineSpacing="12" minimumInteritemSpacing="16" id="MWR-PM-MMO">
|
||||
<size key="itemSize" width="120" height="32"/>
|
||||
<size key="headerReferenceSize" width="0.0" height="0.0"/>
|
||||
<size key="footerReferenceSize" width="0.0" height="0.0"/>
|
||||
|
|
Loading…
Add table
Reference in a new issue