pm_swipe_cells 0.0.2 → 0.0.3

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: aee6464bf2068b46c6ce13f5c7958273cc76cad4
4
- data.tar.gz: 3941a0599b9f77c78c6640317eed2dc033d71c69
3
+ metadata.gz: 13bba2955e371e6eebd622d359bab7d84541f681
4
+ data.tar.gz: caffab3a5c8b128f21184238ea7637662c49beca
5
5
  SHA512:
6
- metadata.gz: 88361179a72a5e3122e511f159c540830bdb6dd60126bb039d82a84350f3ee94fc9afb28f5e33d67556f0f80d11c1bb8f7d123991a7b4ce05054e139eb25b346
7
- data.tar.gz: a6439286b24ee59a4d300dfe052660ded58a2639eb7f5a818551b522432829c05e7476f59f2031111534c17b134dde6260b458468f5ed8fc2eaf810674b20e88
6
+ metadata.gz: 9ac17f4f8492dcf0476f2303e0786709987589c27cdf18245ffd10b1f6e47fd37f756f64b848a7ea096c09bdb2292323c6a772fb460123033b366439442e02ea
7
+ data.tar.gz: 3589af61e92e9d024b345e1f55fdd19dc719ab15671b2f28fde69a56a0b8b9eaf6b124beecd846df994471ad17887dd6b300146935165b8e432a51dab8cd04e0
data/README.md ADDED
@@ -0,0 +1,169 @@
1
+ # PMSwipeCells
2
+
3
+ This gem provides a wrapper which easily integrates the swipeable content view and buttons of [SWTableViewCell](https://github.com/CEWendel/SWTableViewCell) into the [ProMotion](https://github.com/clearsightstudio/ProMotion) framework for RubyMotion.
4
+
5
+ <p align="center"><img src="http://i.imgur.com/njKCjK8.gif"/></p>
6
+
7
+ ## Installation
8
+
9
+ First, add to your Gemfile:
10
+ ```ruby
11
+ gem 'pm_swipe_cells'
12
+ ```
13
+
14
+ Then:
15
+
16
+ ```sh-session
17
+ $ bundle
18
+ $ rake pod:install
19
+ ```
20
+
21
+ # Functionality and Features
22
+ *Fucntionality and Features write-up (and the accompanying GIFs) is taken directly from the [SWTableViewCell] repo. All credit to [CEWendel](https://github.com/CEWendel)*
23
+
24
+ ##Functionality
25
+ ###Right Utility Buttons
26
+ Utility buttons that become visible on the right side of the Table View Cell when the user swipes left. This behavior is similar to that seen in the iOS apps Mail and Reminders.
27
+
28
+ <p align="center"><img src="http://i.imgur.com/gDZFRpr.gif"/></p>
29
+
30
+ ###Left Utility Buttons
31
+ Utility buttons that become visible on the left side of the Table View Cell when the user swipes right.
32
+
33
+ <p align="center"><img src="http://i.imgur.com/qt6aISz.gif"/></p>
34
+
35
+ ## Features
36
+ * Dynamic utility button scalling. As you add more buttons to a cell, the other buttons on that side get smaller to make room
37
+ * Smart selection: The cell will pick up touch events and either scroll the cell back to center or fire the delegate method `- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath`
38
+ <p align="center"><img src="http://i.imgur.com/TYGx9h8.gif"/></p>
39
+ So the cell will not be considered selected when the user touches the cell while utility buttons are visible, instead the cell will slide back into place (same as iOS 7 Mail App functionality)
40
+ * Create utilty buttons with either a title or an icon along with a RGB color
41
+ * Tested on iOS 6.1 and above, including iOS 7
42
+
43
+
44
+ # Usage
45
+
46
+ PMSwipeCells works by adding a custom cell class to your project and hooking into certain methods on PM::TableScreen.
47
+
48
+ To use, just add a few extra lines to the `table_data` hash in a PM:TableScreen. In each cell you'd like to be swipeable, specify the `cell_class:` as `SwipeableCell` and add a `properties:` hash which includes a `right_buttons` and/or `left_buttons` array.
49
+
50
+ Each array takes up to 4 parameters, one of which is required:
51
+
52
+ - **Required**
53
+ + *action*: The action you want that button to perform, passed as a Symbol.
54
+
55
+ * **Remember to also implement each action in your PM::TableScreen controller!**
56
+
57
+ - **Recommended**
58
+
59
+ + *color*: A UIColor for the button's background (defaults to UIColor.blueColor).
60
+
61
+ + *title*: The text displayed on the button (defaults to the action name).
62
+
63
+ - **Optional**
64
+
65
+ + *arguments*: Arguments to be passed to the action. Use a hash if multiple.
66
+
67
+ * **If no argument is set, but your cell action takes a single parameter, the cell will be passed to your action (see `remove` example)
68
+
69
+ You can add only right buttons, only left_buttons or place buttons on both sides of a cell.
70
+
71
+ # Example Code
72
+
73
+ Here's an example of it in use:
74
+
75
+ ```ruby
76
+ class TestScreen < PM::TableScreen
77
+ # This example creates 25 cells, all with swipeable button.
78
+
79
+ def table_data
80
+ [{
81
+ cells: [*0..25].map do |test|
82
+ {
83
+ cell_class: SwipeableCell,
84
+ title: "Test Cell",
85
+ properties: {
86
+ right_buttons: [
87
+ {
88
+ title: "Share",
89
+ action: :share,
90
+ color: UIColor.greenColor
91
+ }
92
+ ],
93
+ left_buttons: [
94
+ {
95
+ title: "Remove",
96
+ action: :remove,
97
+ color: UIColor.redColor
98
+ },
99
+ {
100
+ title: "Archive",
101
+ action: :archive,
102
+ color: UIColor.blueColor,
103
+ arguments:
104
+ {
105
+ foo: "bar!"
106
+ }
107
+ }
108
+ ]
109
+ }
110
+ }
111
+ end
112
+ }]
113
+ end
114
+
115
+
116
+ def share
117
+ NSLog "#{__method__.capitalize} button tapped!"
118
+ end
119
+
120
+ def remove(cell)
121
+ NSLog "#{__method__.capitalize} button tapped for cell #{cell}"
122
+ end
123
+
124
+ def archive(opts = {})
125
+ NSLog "#{__method__.capitalize} button tapped, with arguments #{opts}"
126
+ end
127
+
128
+ end
129
+ ```
130
+
131
+
132
+
133
+ # Additional Methods
134
+
135
+ Cells of the SwipeableCell class have two additional methods available; `close` and `show_buttons(:side)`. While the touch interactions to show/hide swipe buttons are automatically enabled, I find it helpful to be able to programmatically reveal them. For example, it can be helpful to show a cell sliding open and closed alongside a tooltip or walkthrough the first time a user opens a screen.
136
+
137
+ Calling `show_buttons`, which takes either `:left` or `:right` as an argument will slide the cell open, revealing the buttons on the specified side. As luck would have it, calling `close` on a cell will then slide it closed.
138
+
139
+ # Additional Notes
140
+
141
+ PMSwipeCell pre-configures your PM::TableScreen to act as the cell's delegate, however if you need to change this you can manually specific a delegate controller by passing the `delegate` arguments into the cell's `properties` hash.
142
+
143
+ - **Note that changing this requires that you then implement the delegate actions and the cell actions in your delegate controller**
144
+
145
+ You can add as many buttons to each side as you'd like, however after 3 buttons you're in danger of your cell sliding off the page. Keep to 2 or 3 buttons to be safe!
146
+
147
+ ### Cell Delegate Actions
148
+
149
+ If you decide to use your own delegate controller, there are two delegate actions which need to be implemented depending on which side(s) you placed buttons on.
150
+
151
+ ```ruby
152
+ def swipeableTableViewCell(cell, didTriggerLeftUtilityButtonWithIndex: index)
153
+ NSLog "A Left button was pressed for cell #{cell}"
154
+ NSLog "The action which should be implemented is #{cell.left_buttons[index][:action]}"
155
+ NSLog "The accompanying arguments are #{cell.left_buttons[index][:arguments]}" unless cell.left_buttons[index][:arguments].nil?
156
+ end
157
+
158
+ def swipeableTableViewCell(cell, didTriggerRightUtilityButtonWithIndex: index)
159
+ NSLog "A RIGHT button was pressed for cell #{cell}"
160
+ NSLog "The action which should be implemented is #{cell.right_buttons[index][:action]}"
161
+ NSLog "The accompanying arguments are #{cell.right_buttons[index][:arguments]}" unless cell.right_buttons[index][:arguments].nil?
162
+ end
163
+ ```
164
+
165
+ ###Gotchas
166
+
167
+ #### Seperator Insets
168
+ * If you have left utility button on iOS 7, I recommend changing your Table View's seperatorInset so the seperator stretches the length of the screen
169
+ <pre> tableView.separatorInset = UIEdgeInsetsMake(0, 0, 0, 0); </pre>
@@ -1,28 +1,32 @@
1
1
  module ProMotion
2
+
2
3
  class TableScreen < TableViewController
3
4
 
4
5
  def on_cell_created(cell, data)
5
6
  super
6
- cell.setDelegate(self)
7
- cell.config(right_cells: data[:properties][:right_cells], left_cells: data[:properties][:left_cells]) if cell.respond_to?(:config)
7
+
8
+ cell.setDelegate((data[:delegate].nil? ? self : data[:delegate])) if cell.respond_to?(:"setDelegate:")
9
+ if data[:properties]
10
+ cell.config(right_buttons: data[:properties][:right_buttons], left_buttons: data[:properties][:left_buttons]) if cell.respond_to?(:config)
11
+ end
8
12
  end
9
13
 
10
14
  def tableView(tableView, cellForRowAtIndexPath: indexPath)
11
15
  cell = super
12
- cell.index_path = indexPath
16
+ cell.index_path = indexPath if cell.respond_to?(:index_path)
13
17
  cell
14
18
  end
15
19
 
16
20
  def swipeableTableViewCell(cell, didTriggerRightUtilityButtonWithIndex: index)
17
- trigger_action(cell.right_cells[index][:action], cell.right_cells[index][:arguments], cell.index_path) if (cell.right_cells and cell.right_cells[index])
21
+ trigger_action(cell.right_buttons[index][:action], cell.right_buttons[index][:arguments], cell.index_path) if (cell.right_buttons and cell.right_buttons[index])
18
22
  end
19
23
 
20
24
 
21
- def swipeableTableViewCell(cell, didTriggerLeftUtilityButtonWithIndex: index)
22
- trigger_action(cell.left_cells[index][:action], cell.left_cells[index][:arguments], cell.index_path) if (cell.left_cells and cell.left_cells[index])
23
- end
24
-
25
+ def swipeableTableViewCell(cell, didTriggerLeftUtilityButtonWithIndex: index)
26
+ trigger_action(cell.left_buttons[index][:action], cell.left_buttons[index][:arguments], cell.index_path) if (cell.left_buttons and cell.left_buttons[index])
27
+ end
25
28
 
26
29
  end
30
+
27
31
  end
28
32
 
@@ -1,47 +1,63 @@
1
1
  class SwipeableCell < SWTableViewCell
2
2
 
3
- attr_accessor :left_cells, :right_cells, :index_path
3
+ attr_accessor :left_buttons, :right_buttons, :index_path
4
4
 
5
- def add_right_cells(cells_to_add = {})
6
- right_cells_array = Array.new
5
+
6
+ def add_right_buttons(cells_to_add = {})
7
+ @right_buttons_array = Array.new
7
8
  cells_to_add.each do |opts|
8
- right_cells_array.sw_addUtilityButtonWithColor(opts[:color], title: opts[:title].to_s.capitalize)
9
+ opts[:title] ||= opts[:action].to_s
10
+ opts[:color] ||= UIColor.blueColor
11
+ @right_buttons_array.sw_addUtilityButtonWithColor(opts[:color], title: opts[:title].to_s.capitalize)
9
12
  end
10
- right_cells_array
13
+ @right_buttons_array
11
14
  end
12
15
 
13
- def add_left_cells(cells_to_add = {})
14
- left_cells_array = Array.new
16
+ def add_left_buttons(cells_to_add = {})
17
+ @left_buttons_array = Array.new
15
18
  cells_to_add.each do |opts|
16
- left_cells_array.sw_addUtilityButtonWithColor(opts[:color], title: opts[:title].to_s.capitalize)
19
+ opts[:title] ||= opts[:action].to_s
20
+ opts[:color] ||= UIColor.blueColor
21
+ @left_buttons_array.sw_addUtilityButtonWithColor(opts[:color], title: opts[:title].to_s.capitalize)
17
22
  end
18
- left_cells_array
23
+ @left_buttons_array
19
24
  end
20
25
 
21
26
 
22
27
  def config(opts = {})
23
- @right_cells = opts[:right_cells] if opts[:right_cells]
24
- @left_cells = opts[:left_cells] if opts[:left_cells]
25
- if @right_cells
26
- self.rightUtilityButtons = add_right_cells(@right_cells)
28
+ @right_buttons = opts[:right_buttons] if opts[:right_buttons]
29
+ @left_buttons = opts[:left_buttons] if opts[:left_buttons]
30
+ [@right_buttons, @left_buttons].each {|x| add_index_path_argument(x) unless x.nil?}
31
+ if @right_buttons
32
+ self.rightUtilityButtons = add_right_buttons(@right_buttons)
27
33
  end
28
- if @left_cells
29
- self.leftUtilityButtons = add_left_cells(@left_cells)
34
+ if @left_buttons
35
+ self.leftUtilityButtons = add_left_buttons(@left_buttons)
30
36
  end
31
37
  end
32
38
 
39
+
33
40
  def close
34
41
  self.hideUtilityButtonsAnimated(true)
35
42
  end
36
43
 
37
44
 
38
45
  def show_buttons(side)
39
- case side
40
- when "right", :right
41
- showRightUtilityButtonsAnimated(true)
42
- when "left", :left
43
- showLeftUtilityButtonsAnimated(true)
46
+ self.send("show#{side.to_s.capitalize}UtilityButtonsAnimated", true) if self.respond_to?("show#{side.to_s.capitalize}UtilityButtonsAnimated")
47
+ end
48
+
49
+
50
+ private
51
+
52
+ def add_index_path_argument(buttons)
53
+ buttons.each do |x|
54
+ arity = self.delegate.method(x[:action]).arity
55
+ if arity == 1 and x[:arguments].nil?
56
+ x[:arguments] = self
57
+ end
44
58
  end
45
- end
59
+ end
60
+
61
+
46
62
 
47
63
  end
@@ -1,5 +1,5 @@
1
1
  unless defined?(Motion::Project::Config)
2
- raise "This file must be required within a RubyMotion project Rakefile."
2
+ raise "pm_swipe_cells must be required within a RubyMotion project Rakefile."
3
3
  end
4
4
 
5
5
  require 'motion-cocoapods'
@@ -7,17 +7,20 @@ require 'motion-cocoapods'
7
7
 
8
8
  Motion::Project::App.setup do |app|
9
9
 
10
- # app.name = "pm_swipe_cells"
11
-
12
- app.pods do
13
- pod 'SWTableViewCell'
14
- end
10
+ app.name = "pm_swipe_cells"
15
11
 
16
12
  # lib_dir_path = File.dirname(File.expand_path(__FILE__))
17
13
  # app.files.unshift(Dir.glob(File.join(lib_dir_path, "timestamps/**/*.rb")))
18
14
 
19
15
  Dir.glob(File.join(File.dirname(__FILE__), 'pm_swipe_cells/*.rb')).each do |file|
20
- app.files.unshift(file)
16
+ # app.files.unshift(file)
17
+ app.files << file
21
18
  end
22
19
 
23
- end
20
+ app.pods do
21
+ pod 'SWTableViewCell', '~> 0.3.7'
22
+ end
23
+
24
+
25
+ end
26
+
@@ -0,0 +1,3 @@
1
+ module PMSwipeCell
2
+ VERSION = '0.0.3'
3
+ end
metadata CHANGED
@@ -1,26 +1,111 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: pm_swipe_cells
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.0.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Brian Egan
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-07-27 00:00:00.000000000 Z
12
- dependencies: []
13
- description: It's cool. I'll add more soon.
11
+ date: 2015-08-05 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: ProMotion
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '2.0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '2.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: '1.4'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '1.4'
41
+ - !ruby/object:Gem::Dependency
42
+ name: motion-stump
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '0.3'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '0.3'
55
+ - !ruby/object:Gem::Dependency
56
+ name: motion-redgreen
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '0.1'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '0.1'
69
+ - !ruby/object:Gem::Dependency
70
+ name: rake
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ - !ruby/object:Gem::Dependency
84
+ name: motion_print
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - ">="
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - ">="
95
+ - !ruby/object:Gem::Version
96
+ version: '0'
97
+ description: Easily add animated swipeable content view to ProMotion TableScreen cells
98
+ (using pod 'SWTableViewCells')
14
99
  email: brianegan@outlook.com
15
100
  executables: []
16
101
  extensions: []
17
102
  extra_rdoc_files: []
18
103
  files:
104
+ - README.md
19
105
  - lib/pm_swipe_cells.rb
20
106
  - lib/pm_swipe_cells/pm_table_screen.rb
21
107
  - lib/pm_swipe_cells/swipeable_cell.rb
22
- - pm_swipe_cells-0.0.1.gem
23
- - pm_swipe_cells.gemspec
108
+ - lib/version/version.rb
24
109
  homepage: https://github.com/Brian-Egan/pm_swipeable_cells
25
110
  licenses:
26
111
  - MIT
@@ -44,6 +129,6 @@ rubyforge_project:
44
129
  rubygems_version: 2.4.6
45
130
  signing_key:
46
131
  specification_version: 4
47
- summary: Easily add SWTableViewCells to Rubymotion - Promotion projects
132
+ summary: Add customizable swipe actions to ProMotion table cells
48
133
  test_files: []
49
134
  has_rdoc:
Binary file
@@ -1,14 +0,0 @@
1
- # -*- encoding: utf-8 -*-
2
- Gem::Specification.new do |gem|
3
- gem.name = "pm_swipe_cells"
4
- gem.version = '0.0.2'
5
- gem.summary = "Easily add SWTableViewCells to Rubymotion - Promotion projects"
6
- gem.description = "It's cool. I'll add more soon."
7
- gem.files = `git ls-files`.split("\n")
8
- gem.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
9
- gem.require_paths = ["lib"]
10
- gem.homepage = "https://github.com/Brian-Egan/pm_swipeable_cells"
11
- gem.authors = ["Brian Egan"]
12
- gem.email = "brianegan@outlook.com"
13
- gem.license = "MIT"
14
- end