Skip to content

Idea: Swipeable table cells #129

Open
@markrickert

Description

So I get requests from clients on almost EVERY project that they want to be able to have multiple buttons on either side of a tableview cell to do different things. I'm standardized on using MGSwipeTableCell as the tool of choice because it works well and is easy to understand.

Wondering if anyone else ever sees a need for this and if a DSL would be useful and maybe integrate into redpotion?

Here's a typical cell class:

class ChatCell < MGSwipeTableCell
  def on_load
    delete = MGSwipeButton.buttonWithTitle(
      "Delete",
      backgroundColor: color.grass,
      padding: 20,
      callback: -> sender { delete_action }
    )

    block = MGSwipeButton.buttonWithTitle(
      "Block User",
      backgroundColor: color.red,
      padding: 20,
      callback: -> sender { block_action }
    )

    self.rightButtons = [delete, block]
    self.rightSwipeSettings.transition = MGSwipeTransitionDrag
    self.rightExpansion.buttonIndex = 0
    self.rightExpansion.fillOnTrigger = true
  end

  def will_display
  end

  def delete_action
    mp "deleted!"
  end

  def block_action
    mp "blocked!"
  end
end

I'm thinking that this could be shortened to something like we do in ProMotion for the left and right titlebar buttons:

class ChatCell < PM::SwipeTableCell
  def on_load
    set_right_buttons([{
      title: "Delete",
      background_color: color.grass,
      padding: 20,
      action: :delete_action,
    }, {
      title: "Block User",
      background_color: color.red,
      padding: 20,
      action: :block_action,
    }], {
     # Options
     transition: MGSwipeTransitionDrag,
     expansion_index: 0,
     fill_on_trigger: true
    })
  end

  # ...
end

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions