prime_sliding_action 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +15 -0
- data/README.md +26 -0
- data/lib/prime_sliding_action.rb +12 -0
- data/lib/prime_sliding_action/config.rb +3 -0
- data/lib/prime_sliding_action/sliding_cell_container_mixin.rb +28 -0
- data/lib/prime_sliding_action/sliding_cell_element.rb +7 -0
- data/lib/prime_sliding_action/sliding_cell_section_mixin.rb +24 -0
- data/lib/prime_sliding_action/sliding_cell_view.rb +133 -0
- data/lib/prime_sliding_action/version.rb +3 -0
- metadata +94 -0
checksums.yaml
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
---
|
|
2
|
+
!binary "U0hBMQ==":
|
|
3
|
+
metadata.gz: !binary |-
|
|
4
|
+
M2M3NzEwNDNlMjdjN2VlNDA3ZmMwMmNjNmZiYjExODRjZTEwOWI4Ng==
|
|
5
|
+
data.tar.gz: !binary |-
|
|
6
|
+
N2Q0MTRlZjAwZDI2NDA4MjRiOTIyOWE5YTYyOTk5NTgwYTkxZGY5Zg==
|
|
7
|
+
!binary "U0hBNTEy":
|
|
8
|
+
metadata.gz: !binary |-
|
|
9
|
+
Njg2ZGU4OTg2ZmIxZWU3YTM1OTUwMWYxOWM1ZDJhMjY2MTJkMWI1MTE5NzBh
|
|
10
|
+
YzQ5NTlkYmUwZTY2MTMyYjUzOWExNTdkNzk2NTc3Nzg1MWFlYWViODI2NTg2
|
|
11
|
+
ZDg4MTk2MTNiY2FiYWY0MDdhZDJkYThlNDcwODY3Yzc3MzM1MDM=
|
|
12
|
+
data.tar.gz: !binary |-
|
|
13
|
+
OGFmODQ1NzdhZWRlNmFkOWY3YWZiYjg1NGM3YzkxZTZhY2JmM2YxZTA3ODk4
|
|
14
|
+
YTc5MDQyZDUzZDNiMjMwMzcyYzhlNDY4NzY2ZTg0YmNiZWZkZmJlMzc1Yzhh
|
|
15
|
+
OWQwN2RmYzY3Y2MxNGQ1YTE3MjI1NjM3ZTc0NzJmYjBmNjNiNGQ=
|
data/README.md
ADDED
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
# PrimeSlidingAction
|
|
2
|
+
|
|
3
|
+
Add sliding action cells support to MotionPrime.
|
|
4
|
+
|
|
5
|
+
## Installation
|
|
6
|
+
|
|
7
|
+
Add this line to your application's Gemfile:
|
|
8
|
+
|
|
9
|
+
gem 'prime_sliding_action'
|
|
10
|
+
|
|
11
|
+
And then execute:
|
|
12
|
+
|
|
13
|
+
$ bundle
|
|
14
|
+
|
|
15
|
+
Or install it yourself as:
|
|
16
|
+
|
|
17
|
+
$ gem install prime_sliding_action
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
## Contributing
|
|
21
|
+
|
|
22
|
+
1. Fork it
|
|
23
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
|
24
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
|
25
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
|
26
|
+
5. Create new Pull Request
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
require 'motion-cocoapods'
|
|
2
|
+
require 'motion-prime'
|
|
3
|
+
|
|
4
|
+
unless defined?(Motion::Project::Config)
|
|
5
|
+
raise "This file must be required within a RubyMotion project Rakefile."
|
|
6
|
+
end
|
|
7
|
+
|
|
8
|
+
Motion::Require.all(Dir.glob(File.expand_path('../prime_sliding_action/**/*.rb', __FILE__)))
|
|
9
|
+
|
|
10
|
+
Motion::Project::App.setup do |app|
|
|
11
|
+
|
|
12
|
+
end
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
module SlidingCellContainerMixin
|
|
2
|
+
|
|
3
|
+
def self.included(base)
|
|
4
|
+
base.class_eval do
|
|
5
|
+
unless @sliding_cell_container_included
|
|
6
|
+
@sliding_cell_container_included = true
|
|
7
|
+
alias_method :init_container_element_old, :init_container_element
|
|
8
|
+
def init_container_element(options = {})
|
|
9
|
+
if has_sliding_actions?
|
|
10
|
+
@container_element ||= begin
|
|
11
|
+
options.merge!({
|
|
12
|
+
screen: screen,
|
|
13
|
+
section: self.weak_ref,
|
|
14
|
+
has_drawn_content: true
|
|
15
|
+
})
|
|
16
|
+
options[:styles] ||= []
|
|
17
|
+
options[:styles] = [:"#{table.name}_first_cell"] if table.data.first == self
|
|
18
|
+
options[:styles] = [:"#{table.name}_last_cell"] if table.data.last == self
|
|
19
|
+
MotionPrime::BaseElement.factory(:sliding_cell, options)
|
|
20
|
+
end
|
|
21
|
+
else
|
|
22
|
+
init_container_element_old(options)
|
|
23
|
+
end
|
|
24
|
+
end
|
|
25
|
+
end
|
|
26
|
+
end
|
|
27
|
+
end
|
|
28
|
+
end
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
module SlidingCellSectionMixin
|
|
2
|
+
extend ::MotionSupport::Concern
|
|
3
|
+
|
|
4
|
+
def sliding_action_buttons
|
|
5
|
+
self.class.sliding_action_buttons || {}
|
|
6
|
+
end
|
|
7
|
+
|
|
8
|
+
def has_sliding_actions?
|
|
9
|
+
sliding_action_buttons.present?
|
|
10
|
+
end
|
|
11
|
+
|
|
12
|
+
module ClassMethods
|
|
13
|
+
def sliding_action_buttons
|
|
14
|
+
@sliding_action_buttons || {}
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
def add_sliding_action_button(name, options = {})
|
|
18
|
+
@sliding_action_buttons ||= {}
|
|
19
|
+
@sliding_action_buttons[name] = options
|
|
20
|
+
end
|
|
21
|
+
end
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
Prime::Section.send :include, SlidingCellSectionMixin
|
|
@@ -0,0 +1,133 @@
|
|
|
1
|
+
class SlidingCellView < MPCellWithSection
|
|
2
|
+
attr_accessor :pan_recognizer, :tap_recognizer
|
|
3
|
+
|
|
4
|
+
def setSection(section)
|
|
5
|
+
@section = section.try(:weak_ref)
|
|
6
|
+
self.content_view.setSection(@section)
|
|
7
|
+
if section
|
|
8
|
+
# init section
|
|
9
|
+
@table = @section.table.table_view
|
|
10
|
+
@table.directionalLockEnabled = true
|
|
11
|
+
|
|
12
|
+
unless @sliding_action_buttons_rendered
|
|
13
|
+
@sliding_action_buttons_offset = 0
|
|
14
|
+
@section.sliding_action_buttons.each do |action, options|
|
|
15
|
+
styles = [:"#{@section.name}_action_button", :"#{@section.name}_action_button_#{action}"]
|
|
16
|
+
button = @section.screen.add_view MPButton,
|
|
17
|
+
top: 0,
|
|
18
|
+
width: 80,
|
|
19
|
+
left: 320 + @sliding_action_buttons_offset,
|
|
20
|
+
height: cell_height,
|
|
21
|
+
title_color: :white,
|
|
22
|
+
title: options[:title],
|
|
23
|
+
background_color: options[:color] || :red
|
|
24
|
+
@section.screen.setup button, styles: styles
|
|
25
|
+
@sliding_action_buttons_offset += button.width
|
|
26
|
+
button.on :touch do
|
|
27
|
+
button.off(:touch) if options[:unbind]
|
|
28
|
+
@section.send(options[:action])
|
|
29
|
+
hide_actions unless (options.has_key?(:hide_on_finish) && !options[:hide_on_finish])
|
|
30
|
+
end
|
|
31
|
+
|
|
32
|
+
self.scroll_view.addSubview button
|
|
33
|
+
end
|
|
34
|
+
self.scroll_view.setContentSize CGSizeMake(320 + @sliding_action_buttons_offset, cell_height)
|
|
35
|
+
|
|
36
|
+
@sliding_action_buttons_rendered = true
|
|
37
|
+
@sliding_action_buttons_state = :hidden
|
|
38
|
+
end
|
|
39
|
+
else
|
|
40
|
+
@sliding_action_buttons_rendered = nil
|
|
41
|
+
end
|
|
42
|
+
end
|
|
43
|
+
|
|
44
|
+
def initialize_content
|
|
45
|
+
self.scroll_view = self.subviews.first
|
|
46
|
+
self.scroll_view.subviews.first.removeFromSuperview
|
|
47
|
+
self.content_view = MPTableViewCellContentView.alloc.initWithFrame(CGRectMake(0,0,320, self.height))
|
|
48
|
+
self.content_view.setBackgroundColor(:white.uicolor)
|
|
49
|
+
self.content_view.autoresizingMask = UIViewAutoresizingFlexibleHeight
|
|
50
|
+
|
|
51
|
+
self.scroll_view.addSubview(content_view)
|
|
52
|
+
self.scroll_view.setDelegate self
|
|
53
|
+
self.scroll_view.setScrollEnabled true
|
|
54
|
+
self.scroll_view.setContentSize CGSizeMake(320, self.height)
|
|
55
|
+
self.scroll_view.autoresizingMask = UIViewAutoresizingFlexibleHeight
|
|
56
|
+
|
|
57
|
+
self.scroll_view.setShowsHorizontalScrollIndicator false
|
|
58
|
+
self.scroll_view.setScrollsToTop false
|
|
59
|
+
self.scroll_view.setPagingEnabled true
|
|
60
|
+
|
|
61
|
+
self.pan_recognizer = UIPanGestureRecognizer.alloc.initWithTarget(self, action: 'pan')
|
|
62
|
+
self.pan_recognizer.setMinimumNumberOfTouches 1
|
|
63
|
+
self.pan_recognizer.setMaximumNumberOfTouches 1
|
|
64
|
+
self.pan_recognizer.delegate = self
|
|
65
|
+
self.addGestureRecognizer pan_recognizer
|
|
66
|
+
|
|
67
|
+
self.tap_recognizer = UITapGestureRecognizer.alloc.initWithTarget(self, action: 'tap')
|
|
68
|
+
self.tap_recognizer.delegate = self
|
|
69
|
+
self.addGestureRecognizer tap_recognizer
|
|
70
|
+
end
|
|
71
|
+
|
|
72
|
+
def pan
|
|
73
|
+
offset = @sliding_action_buttons_offset || 0
|
|
74
|
+
translation = pan_recognizer.translationInView self
|
|
75
|
+
velocity = pan_recognizer.velocityInView self
|
|
76
|
+
if pan_recognizer.state == UIGestureRecognizerStateEnded
|
|
77
|
+
if velocity.x < -1000
|
|
78
|
+
show_actions
|
|
79
|
+
elsif velocity.x > 1000
|
|
80
|
+
hide_actions
|
|
81
|
+
elsif self.scroll_view.contentOffset.x > (offset / 2)
|
|
82
|
+
show_actions
|
|
83
|
+
else
|
|
84
|
+
hide_actions
|
|
85
|
+
end
|
|
86
|
+
else
|
|
87
|
+
if pan_recognizer.state == UIGestureRecognizerStateBegan
|
|
88
|
+
@sliding_action_buttons_x = self.scroll_view.contentOffset.x
|
|
89
|
+
end
|
|
90
|
+
current_x = @sliding_action_buttons_x - translation.x
|
|
91
|
+
if translation.x < 0 || current_x > 0
|
|
92
|
+
self.scroll_view.setContentOffset CGPointMake(current_x, 0)
|
|
93
|
+
end
|
|
94
|
+
end
|
|
95
|
+
end
|
|
96
|
+
|
|
97
|
+
def tap
|
|
98
|
+
if @sliding_action_buttons_state == :hidden && @table
|
|
99
|
+
cell_index = @table.indexPathForCell(self)
|
|
100
|
+
@table.delegate.tableView(@table, didSelectRowAtIndexPath: cell_index)
|
|
101
|
+
else
|
|
102
|
+
hide_actions
|
|
103
|
+
end
|
|
104
|
+
end
|
|
105
|
+
|
|
106
|
+
def show_actions
|
|
107
|
+
offset = @sliding_action_buttons_offset || 0
|
|
108
|
+
self.scroll_view.setContentOffset(CGPointMake(offset, 0), animated: true)
|
|
109
|
+
@sliding_action_buttons_state = :visible
|
|
110
|
+
end
|
|
111
|
+
|
|
112
|
+
def hide_actions
|
|
113
|
+
self.scroll_view.setContentOffset(CGPointMake(0, 0), animated: true)
|
|
114
|
+
@sliding_action_buttons_state = :hidden
|
|
115
|
+
end
|
|
116
|
+
|
|
117
|
+
def actions_visible?
|
|
118
|
+
@sliding_action_buttons_state == :visible
|
|
119
|
+
end
|
|
120
|
+
|
|
121
|
+
def cell_height
|
|
122
|
+
section ? section.container_options[:height] : self.height
|
|
123
|
+
end
|
|
124
|
+
|
|
125
|
+
def gestureRecognizer(gestureRecognizer, shouldRecognizeSimultaneouslyWithGestureRecognizer: otherGestureRecognizer)
|
|
126
|
+
if gestureRecognizer.is_a?(UIPanGestureRecognizer)
|
|
127
|
+
yVelocity = (gestureRecognizer.velocityInView gestureRecognizer.view).y
|
|
128
|
+
yVelocity.abs >= 10
|
|
129
|
+
else
|
|
130
|
+
true
|
|
131
|
+
end
|
|
132
|
+
end
|
|
133
|
+
end
|
metadata
ADDED
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
|
2
|
+
name: prime_sliding_action
|
|
3
|
+
version: !ruby/object:Gem::Version
|
|
4
|
+
version: 0.1.0
|
|
5
|
+
platform: ruby
|
|
6
|
+
authors:
|
|
7
|
+
- Iskander Haziev
|
|
8
|
+
autorequire:
|
|
9
|
+
bindir: bin
|
|
10
|
+
cert_chain: []
|
|
11
|
+
date: 2014-01-21 00:00:00.000000000 Z
|
|
12
|
+
dependencies:
|
|
13
|
+
- !ruby/object:Gem::Dependency
|
|
14
|
+
name: cocoapods
|
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
|
16
|
+
requirements:
|
|
17
|
+
- - ! '>='
|
|
18
|
+
- !ruby/object:Gem::Version
|
|
19
|
+
version: '0'
|
|
20
|
+
type: :runtime
|
|
21
|
+
prerelease: false
|
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
23
|
+
requirements:
|
|
24
|
+
- - ! '>='
|
|
25
|
+
- !ruby/object:Gem::Version
|
|
26
|
+
version: '0'
|
|
27
|
+
- !ruby/object:Gem::Dependency
|
|
28
|
+
name: motion-cocoapods
|
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
|
30
|
+
requirements:
|
|
31
|
+
- - ! '>='
|
|
32
|
+
- !ruby/object:Gem::Version
|
|
33
|
+
version: '0'
|
|
34
|
+
type: :runtime
|
|
35
|
+
prerelease: false
|
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
37
|
+
requirements:
|
|
38
|
+
- - ! '>='
|
|
39
|
+
- !ruby/object:Gem::Version
|
|
40
|
+
version: '0'
|
|
41
|
+
- !ruby/object:Gem::Dependency
|
|
42
|
+
name: motion-require
|
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
|
44
|
+
requirements:
|
|
45
|
+
- - ! '>='
|
|
46
|
+
- !ruby/object:Gem::Version
|
|
47
|
+
version: '0'
|
|
48
|
+
type: :runtime
|
|
49
|
+
prerelease: false
|
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
51
|
+
requirements:
|
|
52
|
+
- - ! '>='
|
|
53
|
+
- !ruby/object:Gem::Version
|
|
54
|
+
version: '0'
|
|
55
|
+
description: Add sliding action cells support to MotionPrime.
|
|
56
|
+
email:
|
|
57
|
+
- gvalmon@gmail.com
|
|
58
|
+
executables: []
|
|
59
|
+
extensions: []
|
|
60
|
+
extra_rdoc_files: []
|
|
61
|
+
files:
|
|
62
|
+
- lib/prime_sliding_action/config.rb
|
|
63
|
+
- lib/prime_sliding_action/sliding_cell_container_mixin.rb
|
|
64
|
+
- lib/prime_sliding_action/sliding_cell_element.rb
|
|
65
|
+
- lib/prime_sliding_action/sliding_cell_section_mixin.rb
|
|
66
|
+
- lib/prime_sliding_action/sliding_cell_view.rb
|
|
67
|
+
- lib/prime_sliding_action/version.rb
|
|
68
|
+
- lib/prime_sliding_action.rb
|
|
69
|
+
- README.md
|
|
70
|
+
homepage: ''
|
|
71
|
+
licenses:
|
|
72
|
+
- MIT
|
|
73
|
+
metadata: {}
|
|
74
|
+
post_install_message:
|
|
75
|
+
rdoc_options: []
|
|
76
|
+
require_paths:
|
|
77
|
+
- lib
|
|
78
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
|
79
|
+
requirements:
|
|
80
|
+
- - ! '>='
|
|
81
|
+
- !ruby/object:Gem::Version
|
|
82
|
+
version: '0'
|
|
83
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
84
|
+
requirements:
|
|
85
|
+
- - ! '>='
|
|
86
|
+
- !ruby/object:Gem::Version
|
|
87
|
+
version: '0'
|
|
88
|
+
requirements: []
|
|
89
|
+
rubyforge_project:
|
|
90
|
+
rubygems_version: 2.0.5
|
|
91
|
+
signing_key:
|
|
92
|
+
specification_version: 4
|
|
93
|
+
summary: Add sliding action cells support to MotionPrime.
|
|
94
|
+
test_files: []
|