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

The action is sometimes not shown #121

Closed
SeRG1k17 opened this issue Nov 18, 2017 · 15 comments
Closed

The action is sometimes not shown #121

SeRG1k17 opened this issue Nov 18, 2017 · 15 comments

Comments

@SeRG1k17
Copy link

SeRG1k17 commented Nov 18, 2017

Everything you need can be understood from gif.
bug

    func tableView(_ tableView: UITableView, editActionsForRowAt indexPath: IndexPath, for orientation: SwipeActionsOrientation) -> [SwipeAction]? {
        guard orientation == .right else { return nil }

        let deleteAction = SwipeAction(style: .destructive, title: nil) { action, indexPath in
            // handle action by updating model with deletion
        }

        // customize the action appearance
        deleteAction.title = "Delete"
        deleteAction.image = #imageLiteral(resourceName: "trash")

        return [deleteAction]
    }

    func tableView(_ tableView: UITableView, editActionsOptionsForRowAt indexPath: IndexPath, for orientation: SwipeActionsOrientation) -> SwipeTableOptions {

        var options = SwipeTableOptions()
        options.expansionStyle = .destructive
        options.transitionStyle = .reveal
        options.backgroundColor = .red
        
        return options
    }

This is somehow connected with re-use cell. The cell is loaded from .xib

@kurabi
Copy link
Member

kurabi commented Nov 18, 2017

Are you overriding prepareForReuse() method?

@SeRG1k17
Copy link
Author

SeRG1k17 commented Nov 19, 2017

@kurabi No. The logic of the table is in a separate file with reference to the table object.

//viewDidLoad

displayManager = NotificationsDataDisplayManager(with: tableView)

@kurabi
Copy link
Member

kurabi commented Nov 19, 2017

I am referring to the ‘prepareForReuse’ method on the the ‘UITableViewCell’

@SeRG1k17
Copy link
Author

@kurabi I answered :)

@kurabi
Copy link
Member

kurabi commented Nov 20, 2017

Are you using the latest version of the library? This issue was fixed in the last release

@SeRG1k17
Copy link
Author

@kurabi From Podfile.lock : - SwiftValidator (4.0.0)

@kurabi
Copy link
Member

kurabi commented Nov 20, 2017

There is no such version

@SeRG1k17
Copy link
Author

@kurabi SwipeCellKit (2.0.0)

@kurabi
Copy link
Member

kurabi commented Nov 21, 2017

Is it possible to share code that replicates this? Its likely clipsToBounds is being turned on by you, and hence it clips the action views.

@SeRG1k17
Copy link
Author

@kurabi Thanks, the problem was in clipsToBounds.
I learned a little about the library code. For the implementation of the сornerRadius, it seems, this is impossible at the moment, since you create an actionsView that is 2x of the width of the cell and is located on one of the sides

@kurabi
Copy link
Member

kurabi commented Nov 22, 2017

You can implement what you need with a background image with cap insets

@kurabi kurabi closed this as completed Nov 22, 2017
@SeRG1k17
Copy link
Author

@kurabi Could you explain your last message a little?

@kurabi
Copy link
Member

kurabi commented Nov 23, 2017

@SeRG1k17
Copy link
Author

SeRG1k17 commented Nov 23, 2017

test

I'll try to explain how you can achieve such a result with minimal changes to the library code:

  1. set all backgrounds to clear

func configureActionsView(with actions: [SwipeAction], for orientation: SwipeActionsOrientation) {
//...

        let view = UIView()
        view.backgroundColor = .orangeRed
        view.layer.cornerRadius = layer.cornerRadius
        view.translatesAutoresizingMaskIntoConstraints = false
        insertSubview(view, belowSubview: contentView)
        
        let insets = getSwipeInsets()
        view.topAnchor.constraint(equalTo: topAnchor, constant: insets.top).isActive = true
        view.leftAnchor.constraint(equalTo: leftAnchor, constant: insets.left).isActive = true
        view.bottomAnchor.constraint(equalTo: bottomAnchor, constant: -insets.bottom).isActive = true
        
        let right = NSLayoutConstraint(item: view, attribute: .right, relatedBy: .equal, toItem: self, attribute: .right, multiplier: 1.0, constant: -insets.right)
        addConstraint(right)
        rightConstraint = right
        
        resizingView = view

}

  1. set resizingView lifeCycle logic as actionsView.

  2. after
    @objc func handlePan(gesture: UIPanGestureRecognizer) {
    // in changed case

rightConstraint?.constant = fabs(target.frame.origin.x) - insets.right
  1. and
    // case ended:
    in function animate(duration:toOffset:withInitialVelocity:completion:)
    //...
        let distance = offset - center.x
        animator.addAnimations({
            self.center = CGPoint(x: offset, y: self.center.y)
            self.rightConstraint?.constant -= distance
            self.layoutIfNeeded()
)}

//...

@genefever
Copy link

@SeRG1k17 Hi, I'm trying to change the background cell shape to conform to my custom rounded cell like you showed in the comment above. I'm having difficulties trying to implement it, however. Do you have any projects you wrote with this that I can see?

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

3 participants