Closed N1nomiya closed 4 years ago
Hello @imzark , thanks you for raising this issue! I completely re-developed the library using a custom collection view layout and I tried my best to implement your logic with the velocity/scroll threshold. Please take a look and let me know if it behaves as expected. If that's the case feel free to close this issue 👍
@MaherKSantina Good morning Maher! thanks for your library it's amazing, but in this new version I'm having the following issue http://www.giphy.com/gifs/j45AZB2dGj3FGJvFJH Any suggestion? ty!
Hello @Sk8er22 ! Thank you for your feedback really appreciated! And thank you for raising this issue.
I'm not able to see the gif, I'm getting this error:
Done! When I drag just a little bit to left side it goes to right...
I will upload a better gif in seconds
Ohh that is very bad... I'm sorry you're experiencing this, so let's see how we can fix it. I can't investigate this from the gif as I don't know what's causing this. Are you able to copy the content of the collection view in the example project and see if the issue is still there? This way we can isolate the issue and work on it
Here is the gif:
And the vc:
//
// HomeViewController.swift
//
import Foundation
import MSPeekCollectionViewDelegateImplementation
class HomeViewController: BaseViewController, Storyboarded {
//MVVM
var viewModel : HomeViewModel!
//UI
@IBOutlet weak var collectionView: UICollectionView!
//var delegate: MSPeekCollectionViewDelegateImplementation!
var behavior: MSCollectionViewPeekingBehavior!
//List of rewards
override func viewDidLoad() {
super.viewDidLoad()
bindUI()
// Register NIB FROM POD
collectionView.register(LargeDisplayCard.nib, forCellWithReuseIdentifier: "LargeDisplayCard")
// Required by MSPeekCollectionViewDelegateImplementation
behavior = MSCollectionViewPeekingBehavior(cellSpacing: 12, cellPeekWidth: 12, scrollDirection: .horizontal)
collectionView.configureForPeekingBehavior(behavior: behavior)
// delegate.delegate = self
collectionView.delegate = self
collectionView.dataSource = self
}
override func viewWillAppear(_ animated: Bool) {
super.viewWillAppear(animated)
// MARK: Create Navigation bar
if let navigationController = navigationController {
navigationController.configureGC(baseViewController: self, hideBackButton: true, title: "".localized(), hideSearch: false, searchAction: nil, hideProfile: false, profileAction: nil)
//Tab Bar title
navigationController.title = "Rewards".localized()
}
}
func bindUI(){
// viewModel.state.rewardsList.subscribe(onNext: { (rewards) in
// //What heppen if i get the list before the table
// }).disposed(by: disposeBag)
}
override var preferredStatusBarStyle: UIStatusBarStyle {
return .lightContent
}
}
// MARK: PeekCollectionView
extension HomeViewController: MSPeekImplementationDelegate {
func peekImplementation(_ peekImplementation: MSPeekCollectionViewDelegateImplementation, didChangeActiveIndexTo activeIndex: Int) {
print("change to \(activeIndex)")
}
func peekImplementation(_ peekImplementation: MSPeekCollectionViewDelegateImplementation, didSelectItemAt indexPath: IndexPath) {
// if let selectedReward = try? self.viewModel.state.rewardsList.value()[indexPath.row] {
// Logg.d(selectedReward)
// self.viewModel.event.onNext(RewardsEvent.tapOnFeatured(reward: selectedReward)) }
// }
}
}
extension HomeViewController: UICollectionViewDataSource, UICollectionViewDelegate {
func numberOfSections(in collectionView: UICollectionView) -> Int {
return 1
}
func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
return 5
}
func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
let cell = collectionView.dequeueReusableCell(withReuseIdentifier: "LargeDisplayCard", for: indexPath) as! LargeDisplayCard
//var cell = Bundle.main.loadNibNamed("LargeDisplayCard", owner: nil, options: nil)?.first as! LargeDisplayCard
cell.imageView.backgroundColor = .lightGray
cell.overline.text = "API?"
cell.overline.label.textColor = .primaryActive
cell.headLine.text = "Complete your first campaign?"
cell.body.text = "Start your first campaign, a curated group of actions targeting to solve the world's biggest issues.?"
cell.bottomLabel.text = "2518 Citizens have viewed this story?"
// if let rewards = try? viewModel.state.rewardsList.value(){
// cell.setupGC(fromReward: rewards[indexPath.row])
// cell.dropShadow()
// }
return cell
}
func scrollViewWillEndDragging(_ scrollView: UIScrollView, withVelocity velocity: CGPoint, targetContentOffset: UnsafeMutablePointer<CGPoint>) {
behavior.scrollViewWillEndDragging(scrollView, withVelocity: velocity, targetContentOffset: targetContentOffset)
}
}
I'm doing somthing wrong?
Thanks for your fast answer 👍
Hello @Sk8er22 , it looks like you're configuring the behavior properly. I can't see any issue from the code you wrote. I'm assuming it's a UI issue where the each cell frame is not computed properly. Are you using a library for the cell items UI? I noticed that when you long press one of them it's becoming smaller, or is it just the selection style?
Just right now I was trying it commenting the highlighting behavior... but the error persists...
import Foundation
import UIKit
public class LargeDisplayCard: UICollectionViewCell, NibLoadable {
@IBOutlet public weak var imageView: UIImageView!
@IBOutlet public weak var overline: Overline!
@IBOutlet public weak var headLine: RHeadline!
@IBOutlet public weak var body: SBody!
@IBOutlet public weak var bottomLabel: UILabel!
override init(frame: CGRect) {
super.init(frame: frame)
xibSetup()
}
required init?(coder aDecoder: NSCoder) {
super.init(coder: aDecoder)
xibSetup()
}
func xibSetup() {
// view = loadViewFromNib()
// view.frame = bounds
// view.autoresizingMask = [.flexibleWidth, .flexibleHeight]
//
// addSubview(view)
}
func loadViewFromNib() -> UIView {
let bundle = Bundle(for: type(of: self))
let nib = UINib(nibName: "LargeDisplayCard", bundle: bundle)
let view = nib.instantiate(withOwner: self, options: nil).first as! UIView
return view
}
// override public var isHighlighted: Bool {
// didSet {
// UIView.animate(withDuration: 0.5) {
// let scale: CGFloat = 0.9
// self.transform = self.isHighlighted ? CGAffineTransform(scaleX: scale, y: scale) : .identity
// }
// }
// }
//Needed to get AUTORESIZED XIB
override public func preferredLayoutAttributesFitting(_ layoutAttributes: UICollectionViewLayoutAttributes) -> UICollectionViewLayoutAttributes {
setNeedsLayout()
layoutIfNeeded()
let size = contentView.systemLayoutSizeFitting(layoutAttributes.size)
frame.size.height = ceil(size.height)
layoutAttributes.frame = frame
return layoutAttributes
}
}
Hmm... so the highlighting is not the issue, and you're not using an external library. Can I bother you to import the collection view code and item UI to the example app and test there? It would be very easy for me to debug the issue if it's in the example project. You can fork the repo and push the UI code and I can pull your branch and investigate it
@Sk8er22 thank you soo much for sponsoring me!! 🎉 🎉 🎉 🎉 It really motivates me to pursue my vision and help others with their UI challenges! <3
The pod with the Large display card is this one... https://github.com/levin-riegner/LRDesignSystem ios 11 on podfile and with the above code my examples should it work
Ohh okayy I'll have a try and will let you know how it goes
@Sk8er22 I was able to reproduce the issue in the example project! I'll try to investigate and work on a fix now
@Sk8er22 I've released a new version of the pod that fixes this issue! Thank you so much for helping me investigate this! I also found another issue related to this but I wanted to push an update for you so you don't have to wait for the other fix. I'll create another ticket for the other issue
Have a good day! 😄
Thank you so much! :)
Hello @imzark , I'm going to close this issue as there has been another thread going on for another issue, but feel free to open a new issue if you noticed that it's not working as intended! Thank you very much for raising this issue and contributing ❤️
Act more like isPagingEnabled.
If the velocity of EndDragging is zero, use "if scrollDistance more than half the page width" to decide destinationIndex, instead of "scrollThreshold". #52 #