Sha256: 2376f4c364e06f45fae93495b9f56a085f680244645f69ef35da47f73ccb5a50

Contents?: true

Size: 927 Bytes

Versions: 1

Compression:

Stored size: 927 Bytes

Contents

module ProMotion
  module Table
    module Longpressable

      def make_longpressable(params={})
        params = {
          min_duration: 1.0
        }.merge(params)

        long_press_gesture = UILongPressGestureRecognizer.alloc.initWithTarget(self, action:"on_long_press:")
        long_press_gesture.minimumPressDuration = params[:min_duration]
        long_press_gesture.delegate = self
        self.table_view.addGestureRecognizer(long_press_gesture)
      end

      def on_long_press(gesture)
        return unless gesture.state == UIGestureRecognizerStateBegan
        gesture_point = gesture.locationInView(table_view)
        index_path = table_view.indexPathForRowAtPoint(gesture_point)
        data_cell = self.promotion_table_data.cell(index_path: index_path)
        trigger_action(data_cell[:long_press_action], data_cell[:arguments], index_path) if data_cell[:long_press_action]
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
ProMotion-2.2.0 lib/ProMotion/table/extensions/longpressable.rb