You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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 :)
The text was updated successfully, but these errors were encountered:
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:
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 :)
The text was updated successfully, but these errors were encountered: