Skip to content

Commit

Permalink
fixing refresh cell
Browse files Browse the repository at this point in the history
  • Loading branch information
web3d3v committed Oct 2, 2023
1 parent 53ee72b commit ebc2f68
Show file tree
Hide file tree
Showing 9 changed files with 80 additions and 17 deletions.
4 changes: 4 additions & 0 deletions iosApp/iosApp.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -332,6 +332,7 @@
2DC2CD82A596ABBBA697D14E /* NFTsDashboardRefreshCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2DC2CE6C3DB0794556494A4D /* NFTsDashboardRefreshCell.swift */; };
2DC2CD833926C212135B8005 /* UIViewExtensions.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2DC2CD771E4261A43B284DBD /* UIViewExtensions.swift */; };
2DC2CE81DB04333AC1E6833F /* ThemeBlurView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2DC2CA1C756CB56666E04D0A /* ThemeBlurView.swift */; };
2DC2CF60440C5C9E64FCD9AF /* UIControl+Extensions.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2DC2C7C91B9C13F1D182D921 /* UIControl+Extensions.swift */; };
2DC2CFAED100073886D0644D /* CollectionView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2DC2C9A15E44BDD7C7864D81 /* CollectionView.swift */; };
D116CF3227C31ECC005542AA /* iCarousel.m in Sources */ = {isa = PBXBuildFile; fileRef = D116CF3127C31ECC005542AA /* iCarousel.m */; };
D11A990027B8615B00EDFDD0 /* GothicA1-ExtraLight.ttf in Resources */ = {isa = PBXBuildFile; fileRef = D11A98F527B8615B00EDFDD0 /* GothicA1-ExtraLight.ttf */; };
Expand Down Expand Up @@ -723,6 +724,7 @@
2DC2C4716D8E32D5CE26DDA2 /* AlertWireframe+Extensions.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "AlertWireframe+Extensions.swift"; sourceTree = "<group>"; };
2DC2C486937A338F1B4E4CFB /* UIImageExtension.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = UIImageExtension.swift; sourceTree = "<group>"; };
2DC2C4B6C92D814FB1D50384 /* Double+Extensions.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "Double+Extensions.swift"; sourceTree = "<group>"; };
2DC2C7C91B9C13F1D182D921 /* UIControl+Extensions.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "UIControl+Extensions.swift"; sourceTree = "<group>"; };
2DC2C8FA05735FD6B546BA4B /* StringExtensions.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = StringExtensions.swift; sourceTree = "<group>"; };
2DC2C9A15E44BDD7C7864D81 /* CollectionView.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = CollectionView.swift; sourceTree = "<group>"; };
2DC2CA1C756CB56666E04D0A /* ThemeBlurView.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ThemeBlurView.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -1440,6 +1442,7 @@
1C7F860828D20E490073FD95 /* UIView+Extensions.swift */,
1C5D24DE28E1A3DD007DA557 /* UIViewController+Extensions.swift */,
1C54BB3B291B9F400009F158 /* Web3walletcore+Extensions.swift */,
2DC2C7C91B9C13F1D182D921 /* UIControl+Extensions.swift */,
);
path = Extensions;
sourceTree = "<group>";
Expand Down Expand Up @@ -2436,6 +2439,7 @@
2DC2CD82A596ABBBA697D14E /* NFTsDashboardRefreshCell.swift in Sources */,
2DC2CA1BB3426CD144AE0590 /* FPSCounter.swift in Sources */,
2DC2CE81DB04333AC1E6833F /* ThemeBlurView.swift in Sources */,
2DC2CF60440C5C9E64FCD9AF /* UIControl+Extensions.swift in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
Expand Down
14 changes: 6 additions & 8 deletions iosApp/iosApp/Base.lproj/Main.storyboard
Original file line number Diff line number Diff line change
Expand Up @@ -131,38 +131,36 @@
<autoresizingMask key="autoresizingMask"/>
<subviews>
<stackView opaque="NO" contentMode="scaleToFill" axis="vertical" spacing="16" translatesAutoresizingMaskIntoConstraints="NO" id="Bzg-BP-F4L">
<rect key="frame" x="16" y="0.0" width="311" height="375"/>
<rect key="frame" x="16" y="19" width="311" height="273"/>
<subviews>
<imageView clipsSubviews="YES" userInteractionEnabled="NO" contentMode="scaleAspectFit" horizontalHuggingPriority="251" verticalHuggingPriority="251" image="overscroll_ape" translatesAutoresizingMaskIntoConstraints="NO" id="yJo-ii-w7g">
<rect key="frame" x="0.0" y="0.0" width="311" height="150"/>
</imageView>
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="Label" textAlignment="natural" lineBreakMode="tailTruncation" numberOfLines="0" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="eSX-Py-Rxk">
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="Label" textAlignment="center" lineBreakMode="tailTruncation" numberOfLines="0" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="eSX-Py-Rxk">
<rect key="frame" x="0.0" y="166" width="311" height="20.333333333333343"/>
<fontDescription key="fontDescription" type="system" pointSize="17"/>
<nil key="textColor"/>
<nil key="highlightedColor"/>
</label>
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="Label" textAlignment="natural" lineBreakMode="tailTruncation" numberOfLines="0" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="uaH-2N-vbu">
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="Label" textAlignment="center" lineBreakMode="tailTruncation" numberOfLines="0" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="uaH-2N-vbu">
<rect key="frame" x="0.0" y="202.33333333333334" width="311" height="20.333333333333343"/>
<fontDescription key="fontDescription" type="system" pointSize="17"/>
<nil key="textColor"/>
<nil key="highlightedColor"/>
</label>
<button opaque="NO" contentMode="scaleToFill" contentHorizontalAlignment="center" contentVerticalAlignment="center" buttonType="system" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="HF9-Wg-Fl8">
<rect key="frame" x="0.0" y="238.66666666666663" width="311" height="136.33333333333337"/>
<button opaque="NO" contentMode="scaleToFill" contentHorizontalAlignment="center" contentVerticalAlignment="center" buttonType="system" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="HF9-Wg-Fl8" customClass="Button" customModule="iosApp" customModuleProvider="target">
<rect key="frame" x="0.0" y="238.66666666666669" width="311" height="34.333333333333314"/>
<state key="normal" title="Button"/>
<buttonConfiguration key="configuration" style="plain" title="Button"/>
</button>
</subviews>
</stackView>
</subviews>
<constraints>
<constraint firstAttribute="bottom" relation="lessThanOrEqual" secondItem="Bzg-BP-F4L" secondAttribute="bottom" id="3cT-PO-078"/>
<constraint firstItem="Bzg-BP-F4L" firstAttribute="leading" secondItem="jYg-2z-zSZ" secondAttribute="leading" constant="16" id="858-ww-AAN"/>
<constraint firstItem="Bzg-BP-F4L" firstAttribute="centerY" secondItem="jYg-2z-zSZ" secondAttribute="centerY" id="MHq-Ht-eBn"/>
<constraint firstItem="Bzg-BP-F4L" firstAttribute="centerY" secondItem="jYg-2z-zSZ" secondAttribute="centerY" constant="-32" id="MHq-Ht-eBn"/>
<constraint firstAttribute="trailing" secondItem="Bzg-BP-F4L" secondAttribute="trailing" constant="16" id="okm-N8-uCp"/>
<constraint firstItem="Bzg-BP-F4L" firstAttribute="centerX" secondItem="jYg-2z-zSZ" secondAttribute="centerX" id="r3G-KI-axI"/>
<constraint firstItem="Bzg-BP-F4L" firstAttribute="top" relation="greaterThanOrEqual" secondItem="jYg-2z-zSZ" secondAttribute="top" id="wtM-fW-0GA"/>
</constraints>
</collectionViewCellContentView>
<size key="customSize" width="343" height="375"/>
Expand Down
5 changes: 5 additions & 0 deletions iosApp/iosApp/Common/Extensions/IndexPath+Extensions.swift
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,10 @@
import Foundation

extension IndexPath {

func isZero() -> Bool {
section == 0 && item == 0
}

static var zero: IndexPath = IndexPath(item: 0, section: 0)
}
4 changes: 0 additions & 4 deletions iosApp/iosApp/Common/Extensions/UIButton+Extensions.swift
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,6 @@ import UIKit

extension UIButton {

func removeAllTargets() {
allTargets.forEach { removeTarget($0, action: nil, for: .touchUpInside)}
}

func setActivityIndicator(_ visible: Bool = false) {
var configuration = configuration
configuration?.showsActivityIndicator = visible
Expand Down
21 changes: 21 additions & 0 deletions iosApp/iosApp/Common/Extensions/UIControl+Extensions.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
//
// Created by anon on 01/10/2023.
//

import UIKit

extension UIControl {

func addTar(
_ target: Any?,
action: Selector,
for controlEvents: UIControl.Event = .touchUpInside
) {
addTarget(self, action: action, for: controlEvents)
}

func removeAllTargets(_ controlEvents: UIControl.Event = .touchUpInside) {
allTargets.forEach { removeTarget($0, action: nil, for: controlEvents) }
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,17 @@ class ThemeCell: UICollectionViewCell {
// NOTE: To be overridden by subclasses to that this boiler plate does
// not need to be in each cell
}

func collectionView() -> UICollectionView? {
var superView = superview
while superView != nil {
if let cv = superView as? UICollectionView {
return cv
}
superView = superView?.superview
}
return nil
}
}

class CollectionViewCell: UICollectionViewCell {
Expand Down
7 changes: 5 additions & 2 deletions iosApp/iosApp/Modules/NFTsDashboard/NFTsDashboardView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,10 @@ final class NFTsDashboardViewController: UICollectionViewController,
_ collectionView: UICollectionView,
didSelectItemAt indexPath: IndexPath
) {
print("Did select item at intex path")
if indexPath.isZero() && (viewModel?.nfts_().isEmpty ?? true) {
presenter.handleEvent(.Refresh())
return
}
presenter.handleEvent(
.Select(section: indexPath.section.int32, idx: indexPath.item.int32)
)
Expand Down Expand Up @@ -188,7 +191,7 @@ private extension NFTsDashboardViewController {
let length = floor((view.bounds.width - Theme.padding * 3) / 2)
let vm = viewModel as? NFTsDashboardViewModel.Loaded
collectionCellSize = .init(width: length, height: length)
emptyCellSize = view.frame.size
emptyCellSize = view.frame.inset(by: collectionView.adjustedContentInset).size
let settings: SettingsService = AppAssembler.resolve()
let regular = settings.nftCarouselSize == .regular
carouselCellSize = .init(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ class NFTsDashboardCarouselCell: ThemeCell, iCarouselDataSource, iCarouselDelega
private var viewModel: [NFTsDashboardViewModel.Loaded.NFT]?
private var prevSize: CGSize = .zero
private var cellSize: CGSize = .zero

override func applyTheme(_ theme: ThemeProtocol) {
super.applyTheme(theme)
carouselView.visibleItemViews.forEach {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,34 @@ class NFTsDashboardRefreshCell: ThemeCell {
@IBOutlet weak var imageView: UIImageView!
@IBOutlet weak var titleLabel: UILabel!
@IBOutlet weak var subTitleLabel: UILabel!
@IBOutlet weak var button: UIButton!
@IBOutlet weak var button: Button!

override func awakeFromNib() {
super.awakeFromNib()
button.addTar(self, action: #selector(refreshAction(_:)))
}

func update() -> Self {
titleLabel.text = Localized("nfts.dashboard.noContent.title")
subTitleLabel.text = Localized("nfts.dashboard.noContent.body")
button.setTitle(Localized("nfts.dashboard.noContent.cta"), for: .normal)
return self
}
}

override func applyTheme(_ theme: ThemeProtocol) {
titleLabel.textColor = theme.color.textPrimary
subTitleLabel.textColor = theme.color.textPrimary
titleLabel.font = theme.font.title1
subTitleLabel.font = theme.font.body
button.style = .primary
super.applyTheme(theme)

}

@objc func refreshAction(_ sender: Any) {
guard let cv = collectionView(), let ip = cv.indexPath(for: self) else {
return
}
cv.delegate?.collectionView?(cv, didSelectItemAt: ip)
}
}

0 comments on commit ebc2f68

Please sign in to comment.