swipe_action_cell 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +17 -0
- data/.rspec +2 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +22 -0
- data/README.md +29 -0
- data/Rakefile +1 -0
- data/lib/swipe_action_cell/swipe_action_cell.rb +145 -0
- data/lib/swipe_action_cell/ui_color.rb +23 -0
- data/lib/swipe_action_cell/version.rb +3 -0
- data/lib/swipe_action_cell.rb +11 -0
- data/spec/spec_helper.rb +2 -0
- data/spec/swipe_action_cell_spec.rb +9 -0
- data/swipe_action_cell.gemspec +22 -0
- metadata +83 -0
data/.gitignore
ADDED
data/.rspec
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2013 DmitryTsepelev
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,29 @@
|
|
1
|
+
# SwipeActionCell
|
2
|
+
|
3
|
+
TODO: Write a gem description
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
gem 'swipe_action_cell'
|
10
|
+
|
11
|
+
And then execute:
|
12
|
+
|
13
|
+
$ bundle
|
14
|
+
|
15
|
+
Or install it yourself as:
|
16
|
+
|
17
|
+
$ gem install swipe_action_cell
|
18
|
+
|
19
|
+
## Usage
|
20
|
+
|
21
|
+
TODO: Write usage instructions here
|
22
|
+
|
23
|
+
## Contributing
|
24
|
+
|
25
|
+
1. Fork it
|
26
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
27
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
28
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
29
|
+
5. Create new Pull Request
|
data/Rakefile
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require "bundler/gem_tasks"
|
@@ -0,0 +1,145 @@
|
|
1
|
+
class SwipeActionCell < UITableViewCell
|
2
|
+
|
3
|
+
attr_accessor :leftImage
|
4
|
+
attr_accessor :rightImage
|
5
|
+
|
6
|
+
attr_accessor :leftSwipeColor
|
7
|
+
attr_accessor :rightSwipeColor
|
8
|
+
|
9
|
+
attr_accessor :basicAlpha
|
10
|
+
|
11
|
+
attr_accessor :swipeView
|
12
|
+
|
13
|
+
def initWithStyle style, reuseIdentifier: reuseIdentifier
|
14
|
+
super
|
15
|
+
|
16
|
+
self.basicAlpha = 0
|
17
|
+
|
18
|
+
self.leftSwipeColor = UIColor.whiteColor
|
19
|
+
self.rightSwipeColor = UIColor.whiteColor
|
20
|
+
|
21
|
+
@swipeView = UIView.alloc.initWithFrame(CGRectZero).tap do |v|
|
22
|
+
v.backgroundColor = UIColor.whiteColor
|
23
|
+
end
|
24
|
+
|
25
|
+
@leftImageView = UIImageView.alloc.initWithFrame(CGRectZero)
|
26
|
+
@rightImageView = UIImageView.alloc.initWithFrame(CGRectZero)
|
27
|
+
|
28
|
+
@singleTap = UITapGestureRecognizer.alloc.initWithTarget(self, action:'singleTap')
|
29
|
+
|
30
|
+
@scrollView = UIScrollView.alloc.initWithFrame(CGRectZero).tap do |v|
|
31
|
+
v.showsHorizontalScrollIndicator = false
|
32
|
+
v.delegate = self
|
33
|
+
|
34
|
+
v.addGestureRecognizer @singleTap
|
35
|
+
|
36
|
+
v.addSubview @leftImageView
|
37
|
+
v.addSubview @rightImageView
|
38
|
+
v.addSubview @swipeView
|
39
|
+
end
|
40
|
+
|
41
|
+
contentView.addSubview @scrollView
|
42
|
+
|
43
|
+
self
|
44
|
+
end
|
45
|
+
|
46
|
+
def singleTap
|
47
|
+
self.selected = !self.isSelected
|
48
|
+
end
|
49
|
+
|
50
|
+
def leftImage= image
|
51
|
+
@leftImageView.image = image
|
52
|
+
end
|
53
|
+
|
54
|
+
def rightImage= image
|
55
|
+
@rightImageView.image = image
|
56
|
+
end
|
57
|
+
|
58
|
+
def scrollToContent
|
59
|
+
point = CGPointMake(frame.size.width, 0)
|
60
|
+
scrollView.setContentOffset point, animated: true
|
61
|
+
end
|
62
|
+
|
63
|
+
def scrollViewDidEndDragging scrollView, willDecelerate: decelerate
|
64
|
+
moveToEdges
|
65
|
+
end
|
66
|
+
|
67
|
+
def scrollViewDidScroll scrollView
|
68
|
+
x = scrollView.contentOffset.x
|
69
|
+
|
70
|
+
if x == 0 || x == frame.size.width || x == 2 * frame.size.width
|
71
|
+
@scrollView.scrollEnabled = true
|
72
|
+
end
|
73
|
+
|
74
|
+
if !respond_to?(:leftSwipeAction) && x < frame.size.width
|
75
|
+
point = CGPointMake(frame.size.width, 0)
|
76
|
+
scrollView.setContentOffset point, animated: false
|
77
|
+
@scrollView.scrollEnabled = true
|
78
|
+
return
|
79
|
+
end
|
80
|
+
|
81
|
+
if !respond_to?(:rightSwipeAction) && x > frame.size.width
|
82
|
+
point = CGPointMake(frame.size.width, 0)
|
83
|
+
scrollView.setContentOffset point, animated: false
|
84
|
+
@scrollView.scrollEnabled = true
|
85
|
+
return
|
86
|
+
end
|
87
|
+
|
88
|
+
if x == 0
|
89
|
+
leftSwipeAction
|
90
|
+
elsif x == 2 * frame.size.width
|
91
|
+
rightSwipeAction
|
92
|
+
else
|
93
|
+
@scrollView.backgroundColor = if x < @scrollView.frame.size.width
|
94
|
+
alpha = basicAlpha + (1 - basicAlpha) * (@scrollView.frame.size.width - x) / @scrollView.frame.size.width
|
95
|
+
|
96
|
+
UIColor.colorWithRed leftSwipeColor.red,
|
97
|
+
green: leftSwipeColor.green,
|
98
|
+
blue: leftSwipeColor.blue,
|
99
|
+
alpha: alpha
|
100
|
+
else
|
101
|
+
alpha = basicAlpha + (1 - basicAlpha) * (x - @scrollView.frame.size.width) / (@scrollView.frame.size.width)
|
102
|
+
|
103
|
+
UIColor.colorWithRed rightSwipeColor.red,
|
104
|
+
green: rightSwipeColor.green,
|
105
|
+
blue: rightSwipeColor.blue,
|
106
|
+
alpha: alpha
|
107
|
+
end
|
108
|
+
end
|
109
|
+
end
|
110
|
+
|
111
|
+
def scrollViewWillBeginDecelerating scrollView
|
112
|
+
scrollView.setContentOffset scrollView.contentOffset, animated: true
|
113
|
+
moveToEdges
|
114
|
+
end
|
115
|
+
|
116
|
+
def moveToEdges
|
117
|
+
x = @scrollView.contentOffset.x
|
118
|
+
|
119
|
+
point = if x < @scrollView.frame.size.width / 2
|
120
|
+
CGPointMake(0, 0)
|
121
|
+
elsif x > @scrollView.contentSize.width / 2
|
122
|
+
CGPointMake(2 * frame.size.width, 0)
|
123
|
+
else
|
124
|
+
CGPointMake(frame.size.width, 0)
|
125
|
+
end
|
126
|
+
|
127
|
+
@scrollView.scrollEnabled = x == frame.size.width
|
128
|
+
@scrollView.setContentOffset point, animated: true
|
129
|
+
end
|
130
|
+
|
131
|
+
def layoutSubviews
|
132
|
+
super
|
133
|
+
|
134
|
+
size = frame.size.height - 10
|
135
|
+
@leftImageView.frame = [[frame.size.width - size - 5, 5], [size, size]]
|
136
|
+
@rightImageView.frame = [[2 * frame.size.width + 5, 5], [size, size]]
|
137
|
+
|
138
|
+
@scrollView.frame = [[0, 0], [frame.size.width, frame.size.height]]
|
139
|
+
@scrollView.contentSize = [3 * frame.size.width, frame.size.height]
|
140
|
+
@scrollView.contentOffset = [frame.size.width, 0]
|
141
|
+
|
142
|
+
@swipeView.frame = [[frame.size.width, 0], [frame.size.width, frame.size.height]]
|
143
|
+
end
|
144
|
+
|
145
|
+
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
class UIColor
|
2
|
+
|
3
|
+
def red
|
4
|
+
c = CGColorGetComponents(self.CGColor)
|
5
|
+
c[0]
|
6
|
+
end
|
7
|
+
|
8
|
+
def green
|
9
|
+
c = CGColorGetComponents(self.CGColor)
|
10
|
+
c[1]
|
11
|
+
end
|
12
|
+
|
13
|
+
def blue
|
14
|
+
c = CGColorGetComponents(self.CGColor)
|
15
|
+
c[2]
|
16
|
+
end
|
17
|
+
|
18
|
+
def alpha
|
19
|
+
c = CGColorGetComponents(self.CGColor)
|
20
|
+
c[CGColorGetNumberOfComponents(self.CGColor) - 1]
|
21
|
+
end
|
22
|
+
|
23
|
+
end
|
@@ -0,0 +1,11 @@
|
|
1
|
+
require "swipe_action_cell/version"
|
2
|
+
|
3
|
+
if defined?(Motion::Project::Config)
|
4
|
+
Motion::Project::App.setup do |app|
|
5
|
+
app.files.unshift File.join(File.dirname(__FILE__), 'swipe_action_cell/swipe_action_cell.rb')
|
6
|
+
app.files.unshift File.join(File.dirname(__FILE__), 'swipe_action_cell/ui_color.rb')
|
7
|
+
end
|
8
|
+
end
|
9
|
+
|
10
|
+
module SwipeActionCell
|
11
|
+
end
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'swipe_action_cell/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |gem|
|
7
|
+
gem.name = "swipe_action_cell"
|
8
|
+
gem.version = SwipeActionCell::VERSION
|
9
|
+
gem.authors = ["DmitryTsepelev"]
|
10
|
+
gem.email = ["dmitry.a.tsepelev@gmail.com"]
|
11
|
+
gem.description = "UITableViewCell subclass with swipe initiated actions"
|
12
|
+
gem.summary = "Cell controlled by left and/or right swipe"
|
13
|
+
gem.homepage = ""
|
14
|
+
gem.license = "MIT"
|
15
|
+
|
16
|
+
gem.files = `git ls-files`.split($/)
|
17
|
+
gem.executables = gem.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
18
|
+
gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
|
19
|
+
gem.require_paths = ["lib"]
|
20
|
+
|
21
|
+
gem.add_development_dependency "rake"
|
22
|
+
end
|
metadata
ADDED
@@ -0,0 +1,83 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: swipe_action_cell
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- DmitryTsepelev
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2013-02-11 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: rake
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
18
|
+
requirements:
|
19
|
+
- - ! '>='
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: '0'
|
22
|
+
type: :development
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
26
|
+
requirements:
|
27
|
+
- - ! '>='
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: '0'
|
30
|
+
description: UITableViewCell subclass with swipe initiated actions
|
31
|
+
email:
|
32
|
+
- dmitry.a.tsepelev@gmail.com
|
33
|
+
executables: []
|
34
|
+
extensions: []
|
35
|
+
extra_rdoc_files: []
|
36
|
+
files:
|
37
|
+
- .gitignore
|
38
|
+
- .rspec
|
39
|
+
- Gemfile
|
40
|
+
- LICENSE.txt
|
41
|
+
- README.md
|
42
|
+
- Rakefile
|
43
|
+
- lib/swipe_action_cell.rb
|
44
|
+
- lib/swipe_action_cell/swipe_action_cell.rb
|
45
|
+
- lib/swipe_action_cell/ui_color.rb
|
46
|
+
- lib/swipe_action_cell/version.rb
|
47
|
+
- spec/spec_helper.rb
|
48
|
+
- spec/swipe_action_cell_spec.rb
|
49
|
+
- swipe_action_cell.gemspec
|
50
|
+
homepage: ''
|
51
|
+
licenses:
|
52
|
+
- MIT
|
53
|
+
post_install_message:
|
54
|
+
rdoc_options: []
|
55
|
+
require_paths:
|
56
|
+
- lib
|
57
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
58
|
+
none: false
|
59
|
+
requirements:
|
60
|
+
- - ! '>='
|
61
|
+
- !ruby/object:Gem::Version
|
62
|
+
version: '0'
|
63
|
+
segments:
|
64
|
+
- 0
|
65
|
+
hash: -1636049322108541902
|
66
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
67
|
+
none: false
|
68
|
+
requirements:
|
69
|
+
- - ! '>='
|
70
|
+
- !ruby/object:Gem::Version
|
71
|
+
version: '0'
|
72
|
+
segments:
|
73
|
+
- 0
|
74
|
+
hash: -1636049322108541902
|
75
|
+
requirements: []
|
76
|
+
rubyforge_project:
|
77
|
+
rubygems_version: 1.8.24
|
78
|
+
signing_key:
|
79
|
+
specification_version: 3
|
80
|
+
summary: Cell controlled by left and/or right swipe
|
81
|
+
test_files:
|
82
|
+
- spec/spec_helper.rb
|
83
|
+
- spec/swipe_action_cell_spec.rb
|