Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

UICollectionViewCell gets draggable when elements are binded via rx.items(dataSource:) #1081

Closed
5 of 17 tasks
ishkawa opened this issue Jan 24, 2017 · 3 comments
Closed
5 of 17 tasks

Comments

@ishkawa
Copy link
Contributor

ishkawa commented Jan 24, 2017

Short description of the issue:

UICollectionViewCell gets draggable when elements are binded via rx.items(dataSource:), even if the delegate does not have implementation of collectionView(_:canMoveItemAtIndexPath:).

Expected outcome:

UICollectionViewCell is not draggable by default.

What actually happens:

UICollectionViewCell is draggable by default.

Self contained code example that reproduces the issue:

import UIKit
import RxSwift
import RxCocoa

class Cell: UICollectionViewCell {
    @IBOutlet weak var label: UILabel!
}

class ViewController: UICollectionViewController {
    private let dataSource = DataSource()
    private let disposeBag = DisposeBag()
    
    override func viewDidLoad() {
        super.viewDidLoad()

        let values = Array(1...100)

        Observable
            .just(values)
            .bindTo(collectionView!.rx.items(dataSource: dataSource))
            .addDisposableTo(disposeBag)
    }

    class DataSource: NSObject, UICollectionViewDataSource, RxCollectionViewDataSourceType {
        typealias Element = [Int]

        var values = [Int]()

        func collectionView(_ collectionView: UICollectionView, observedEvent: Event<Element>) {
            if case .next(let element) = observedEvent {
                values = element
                collectionView.reloadData()
            }
        }

        func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
            return values.count
        }

        func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
            let cell = collectionView.dequeueReusableCell(withReuseIdentifier: "Cell", for: indexPath) as! Cell
            cell.label.text = String(indexPath.row)

            return cell
        }
    }
}

Entire project is available here. Run carthage bootstrap and open RxCocoaReorderIssue/Demo.xcodeproj to reproduce the issue.

RxSwift/RxCocoa/RxBlocking/RxTest version/commit

3.1.0

Platform/Environment

  • iOS
  • macOS
  • tvOS
  • watchOS
  • playgrounds

How easy is to reproduce? (chances of successful reproduce after running the self contained code)

  • easy, 100% repro
  • sometimes, 10%-100%
  • hard, 2% - 10%
  • extremely hard, %0 - 2%

Xcode version:

8.2.1

Installation method:

  • CocoaPods
  • Carthage
  • Git submodules

I have multiple versions of Xcode installed:
(so we can know if this is a potential cause of your issue)

  • yes (8.2.1 and 7.3.1)
  • no

Level of RxSwift knowledge:
(this is so we can understand your level of knowledge
and formulate the response in an appropriate manner)

  • just starting
  • I have a small code base
  • I have a significant code base
@kzaher
Copy link
Member

kzaher commented Jan 25, 2017

Hi @ishkawa,

I think you can temporarily use self.installsStandardGestureForInteractiveMovement = false to solve this issue.

Long term solution would require modifying RxCollectionViewDataSourceProxy to use something like

#907
c005b1a

It would probably make sense to make CachedCommitForRowAt more generic.

Do you maybe have time to help out with this?

@ishkawa
Copy link
Contributor Author

ishkawa commented Jan 26, 2017

Yes, I'll try to fix this issue.

@kzaher
Copy link
Member

kzaher commented Feb 6, 2017

HI @ishkawa ,

I think #1087 is related to this issue also. It looks like it might be worth solving this in delegate proxy layer.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants