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

how to manually expand a cell? #331

Open
sciamano89 opened this issue Apr 8, 2019 · 0 comments
Open

how to manually expand a cell? #331

sciamano89 opened this issue Apr 8, 2019 · 0 comments

Comments

@sciamano89
Copy link

I'm in a situation where I reload a tableView, and if a cell was being swiped before the reload, I want to restore its overall state right after the reload.

I'm currently achieving this with:

            //check if we have a swiped cell, and store its current values
            var swipedCellInfo: (indexPath: IndexPath, offset: CGFloat, state: MGSwipeState)?

            if let cell = tableView.visibleCells.first(where: {($0 as? MGSwipeTableCell)?.swipeState != MGSwipeState.none }) as? MGSwipeTableCell, let swipedIndexPath = tableView.indexPath(for: cell)
            {
                swipedCellInfo = (swipedIndexPath, cell.swipeOffset, cell.swipeState)
            }
            
            //reload data
            tableView.reloadData()
            
            //if we were swiping a cell, restore it to its state before the reload
            if let info = swipedCellInfo, let swipedCell = (tableView.cellForRow(at: info.indexPath) as? MGSwipeTableCell), let buttonWidth = swipedCell.rightButtons.first?.bounds.width
            {
                swipedCell.setSwipeOffset(info.offset, animated: false)
                
                if info.state == MGSwipeState.expandingRightToLeft
                {
                    swipedCell.expandSwipe(.rightToLeft, animated: false)
                    swipedCell.showSwipe(.rightToLeft, animated: true)
                }
                else
                {
                    //if swipe revealed all rightButtons or went over, go back to showing swipe
                    if info.offset <= (-buttonWidth * CGFloat(swipedCell.rightButtons.count))
                    {
                        swipedCell.showSwipe(.rightToLeft, animated: true)
                    }
                    else //hide swipe
                    {
                        swipedCell.hideSwipe(animated: true)
                    }
                }
            }

It works like I want it when the cell is not expanding, (restoring its swipeOffset works perfectly) but the moment the cell is expanding, the animation becomes weird. First of all, "expandSwipe()" still animates even though animate is set to false. Is there a way to manually set the expansion offset? And a way to resume the swipe gesture? (reload data interrupts the gesture).

Thanks :)

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

1 participant