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

Crash when drag card #22

Closed
RoshaniDias opened this issue Jul 12, 2017 · 4 comments
Closed

Crash when drag card #22

RoshaniDias opened this issue Jul 12, 2017 · 4 comments
Assignees

Comments

@RoshaniDias
Copy link

Hello,
When I keep dragging the card here and there without moving it down, app crash in this line
collectionView?.bringSubview(toFront: cell!)

in this method

//Define what card should we drag
    fileprivate func findDraggingCellByCoordinate(_ touchCoordinate: CGPoint) {
        if let indexPath = collectionView?.indexPathForItem(at: touchCoordinate) {
            if indexPath.item >= index {
                //top stack
                draggedCellPath = IndexPath(item: index, section: 0)
                initialCellCenter = collectionView?.cellForItem(at: draggedCellPath!)?.center
            } else {
                //bottomStack
                if (index > 0 ) {
                    draggedCellPath = IndexPath(item: index - 1, section: 0)
                }
                initialCellCenter = collectionView?.cellForItem(at: draggedCellPath!)?.center
            }
            
            //workaround for fix issue with zIndex
            let cell = collectionView!.cellForItem(at: draggedCellPath!)
            collectionView?.bringSubview(toFront: cell!)
            
        }
    }

How to overcome this issue. Please help me.

@oNguyenNgocBan
Copy link

oNguyenNgocBan commented Jul 31, 2017

you can unwrap like this:
if let draggedCellPath = draggedCellPath, let cell = collectionView?.cellForItem(at: draggedCellPath) { collectionView?.bringSubview(toFront: cell) }

@adudenamedruby
Copy link

This does not actually fix the issue. It causes weird behaviour with the index such that cards start appearing on top of others and cards simply disappear as well. I will look more into it to see if I can find someway to fix the crash but first I have to go through and understand the code.

@Pitsko Pitsko self-assigned this Aug 15, 2017
@Pitsko
Copy link
Member

Pitsko commented Aug 15, 2017

@RoshaniDias Fix is the next
just add if to check if index > 0
in method
internal func handleSwipe(_ sender: UISwipeGestureRecognizer) {
switch sender.direction {
case UISwipeGestureRecognizerDirection.up:
if index > 0 {
index -= 1
}
}}

I will publish new version as soon as I can

Pitsko added a commit that referenced this issue Aug 15, 2017
@Pitsko
Copy link
Member

Pitsko commented Aug 15, 2017

Fixed in 1.0.1

@Pitsko Pitsko closed this as completed Aug 15, 2017
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

4 participants