motion-horizontal-scroll 1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +15 -0
- data/.gitignore +18 -0
- data/Gemfile +8 -0
- data/Gemfile.lock +58 -0
- data/README.md +71 -0
- data/Rakefile +14 -0
- data/app/app_delegate.rb +8 -0
- data/app/constants/style_constants.rb +7 -0
- data/app/controllers/screen_controller.rb +83 -0
- data/app/models/model.rb +3 -0
- data/lib/motion-horizontal-scroll.rb +9 -0
- data/lib/motion-horizontal-scroll/basic_table_view_cell.rb +33 -0
- data/lib/motion-horizontal-scroll/basic_table_view_cell_with_title.rb +33 -0
- data/lib/motion-horizontal-scroll/control_variables.rb +6 -0
- data/lib/motion-horizontal-scroll/horizontal_table_container_cell.rb +83 -0
- data/lib/motion-horizontal-scroll/image_view_with_overlay.rb +36 -0
- data/motion-horizontal-scroll.gemspec +15 -0
- data/resources/Default-568h@2x.png +0 -0
- data/resources/img.jpeg +0 -0
- data/spec/basic_table_view_cell_spec.rb +13 -0
- data/spec/basic_table_view_cell_with_title_spec.rb +21 -0
- data/spec/horizontal_table_container_cell_spec.rb +42 -0
- data/spec/main_spec.rb +9 -0
- data/spec/screen_controller_spec.rb +22 -0
- metadata +72 -0
checksums.yaml
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
---
|
2
|
+
!binary "U0hBMQ==":
|
3
|
+
metadata.gz: !binary |-
|
4
|
+
Y2JkYjkyNWQ1YzY1YTZkYjBiNmQ2NjNkNzU0ODQ2ODE4YTU0NmFkNA==
|
5
|
+
data.tar.gz: !binary |-
|
6
|
+
MGNhNTA5MzZmMjc2OTYzNGRhODAxNjZlYmQwMWJjMzdjMzU5Mjg5ZA==
|
7
|
+
SHA512:
|
8
|
+
metadata.gz: !binary |-
|
9
|
+
ZTNlM2FiY2I2OTg5YWI1NTI5NDE5YWRkMzFjYjMwYzNmYmM2ZDRhMWM5ZDI0
|
10
|
+
YzU3M2ZmN2Q4ZGFmNmNjOWM1ZTM2M2Y3NGU2ZmI3NDMzNzg2Zjk5OGY5NzRj
|
11
|
+
NDk2ZTlmYjlmNzUwZDNhNjU5MDkxZTJlNzA4ZTgwNGRmMTdmNTM=
|
12
|
+
data.tar.gz: !binary |-
|
13
|
+
ODRhZDY4N2E1ZmQwNTc1ZDMzNGZiMDFlZDY4ZDZkNTRjYTFhZjBlM2M3OTVi
|
14
|
+
ZDkyYWU0NGUyNjk2NjhmMjU1NTZmZDMzYWQzNTYxZjdlNTA2MjI1MGNiYjI5
|
15
|
+
YTRhOTVmMGIwOTY1ZGQxOWJmNzgxNmI2Y2MwZTk3YTBjZWM2ZDY=
|
data/.gitignore
ADDED
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
@@ -0,0 +1,58 @@
|
|
1
|
+
GEM
|
2
|
+
remote: https://rubygems.org/
|
3
|
+
specs:
|
4
|
+
activesupport (3.2.17)
|
5
|
+
i18n (~> 0.6, >= 0.6.4)
|
6
|
+
multi_json (~> 1.0)
|
7
|
+
afmotion (2.1.1)
|
8
|
+
motion-cocoapods (~> 1.4.0)
|
9
|
+
motion-require (~> 0.1.0)
|
10
|
+
alerter (1.0)
|
11
|
+
bubble-wrap (1.4.0)
|
12
|
+
claide (0.4.0)
|
13
|
+
cocoapods (0.29.0)
|
14
|
+
activesupport (>= 3.2.15, < 4)
|
15
|
+
claide (~> 0.4.0)
|
16
|
+
cocoapods-core (= 0.29.0)
|
17
|
+
cocoapods-downloader (~> 0.3.0)
|
18
|
+
cocoapods-try-release-fix (~> 0.1.1)
|
19
|
+
colored (~> 1.2)
|
20
|
+
escape (~> 0.0.4)
|
21
|
+
json_pure (~> 1.8)
|
22
|
+
nap (~> 0.5)
|
23
|
+
open4 (~> 1.3)
|
24
|
+
xcodeproj (~> 0.14.1)
|
25
|
+
cocoapods-core (0.29.0)
|
26
|
+
activesupport (>= 3.2.15, < 4)
|
27
|
+
fuzzy_match (~> 2.0.4)
|
28
|
+
json_pure (~> 1.8)
|
29
|
+
nap (~> 0.5)
|
30
|
+
cocoapods-downloader (0.3.0)
|
31
|
+
cocoapods-try-release-fix (0.1.2)
|
32
|
+
colored (1.2)
|
33
|
+
escape (0.0.4)
|
34
|
+
fuzzy_match (2.0.4)
|
35
|
+
horizontal_scroll_controller (1.0)
|
36
|
+
i18n (0.6.9)
|
37
|
+
json_pure (1.8.1)
|
38
|
+
motion-cocoapods (1.4.0)
|
39
|
+
cocoapods (>= 0.26.2)
|
40
|
+
motion-require (0.1.1)
|
41
|
+
multi_json (1.8.4)
|
42
|
+
nap (0.6.0)
|
43
|
+
open4 (1.3.2)
|
44
|
+
rake (10.1.1)
|
45
|
+
xcodeproj (0.14.1)
|
46
|
+
activesupport (~> 3.0)
|
47
|
+
colored (~> 1.2)
|
48
|
+
rake
|
49
|
+
|
50
|
+
PLATFORMS
|
51
|
+
ruby
|
52
|
+
|
53
|
+
DEPENDENCIES
|
54
|
+
afmotion
|
55
|
+
alerter
|
56
|
+
bubble-wrap
|
57
|
+
horizontal_scroll_controller
|
58
|
+
rake
|
data/README.md
ADDED
@@ -0,0 +1,71 @@
|
|
1
|
+
iOS (RubyMotion) Horizontal Scroll Controller
|
2
|
+
============================
|
3
|
+
|
4
|
+
This is a horizontal scroll controller for iOS, that mimics the Pulse UI. The basic functionality is borrowed from a [codebase](https://github.com/Bodacious/HorizontalScrollingTablesInRubyMotion) and it is the reason why we were able to come up with this gem, so hats off to the authors! Also, a ton of thanks to [lorempixel](http://lorempixel.com/) from where we have pulled in images to feed the sample app.
|
5
|
+
|
6
|
+
![Screenshot 1 of Sample Implementation](https://dl.dropboxusercontent.com/s/p3ecjgjlk7mrc7d/horizontal_scroll_1.png)
|
7
|
+
|
8
|
+
![Screenshot 2 of Sample Implementation](https://dl.dropboxusercontent.com/s/pb2qqp8vgopkfvn/horizontal_scroll_2.png)
|
9
|
+
|
10
|
+
Below is a description of how you can integrate and use this gem in your codebase.
|
11
|
+
|
12
|
+
### Add to Gemfile
|
13
|
+
|
14
|
+
```ruby
|
15
|
+
gem "motion-horizontal-scroll"
|
16
|
+
```
|
17
|
+
|
18
|
+
### How to use it
|
19
|
+
|
20
|
+
I have included a sample app for reference. To execute it, clone the repo to your local folder and run the following:
|
21
|
+
|
22
|
+
```ruby
|
23
|
+
bundle install
|
24
|
+
rake
|
25
|
+
```
|
26
|
+
|
27
|
+
Nevertheless, the basic setup for a single row can be achieved as follows:
|
28
|
+
|
29
|
+
```ruby
|
30
|
+
horizontal_row = HorizontalTableContainerCell.alloc.initWithStyle(UITableViewCellStyleSubtitle, reuseIdentifier: <REUSE_IDENTIFIER>)
|
31
|
+
horizontal_row.delegate = <DELEGATE>
|
32
|
+
horizontal_row.vertical_row_offset = <VERTICAL_ROW_OFFSET>
|
33
|
+
cell = horizontal_row.set_dimensions_with_row_offset
|
34
|
+
cell.items_list = <DATA ARRAY>
|
35
|
+
cell.selectionStyle = UITableViewCellSelectionStyleNone
|
36
|
+
cell
|
37
|
+
```
|
38
|
+
|
39
|
+
###Supplying the title and image
|
40
|
+
|
41
|
+
The data required for a single cell has two properties, namely a name and an image. The name is the title that appears underneath the image in the cell. The image itself can be fed in two formats:
|
42
|
+
|
43
|
+
1. An instance of UIImage with initialized with an image.
|
44
|
+
|
45
|
+
2. A URL to an image along with a placeholder image; this requires either the gem *afmotion* or the pod *AFNetworking*. The pod on its own may be insufficient, but there's a category called UIImageView+AFNetworking that can start an asynchronous download of an image when given an NSURLRequest.
|
46
|
+
|
47
|
+
###Available delegate methods
|
48
|
+
#### Cell Selection
|
49
|
+
This refers to a callback that indicates a particular cell has been tapped. The syntax of the method for the same is as follows:
|
50
|
+
```ruby
|
51
|
+
horizontal_scroll_cell_selected(item, index)
|
52
|
+
```
|
53
|
+
#### Setting Cell Details
|
54
|
+
The specifics of a cell that need to be set are the title and image. The delegate method for setting cell details is:
|
55
|
+
```ruby
|
56
|
+
set_item_details_for_horizontal_scroll_cell(cell, item)
|
57
|
+
```
|
58
|
+
To set the cell title, you can use the following method:
|
59
|
+
```ruby
|
60
|
+
cell.set_title_label_text text
|
61
|
+
```
|
62
|
+
To set the image, there are two possible methods based on the format as specified above.
|
63
|
+
|
64
|
+
* The first method involves directly providing an instance of UIImage:
|
65
|
+
```ruby
|
66
|
+
cell.set_thumbnail_image image # image is an instance of UIImage
|
67
|
+
```
|
68
|
+
|
69
|
+
* And the second is probably the method that would be more commonly used for apps that use images pulled from a network. This would require the ```setImageWithURL``` method for the ```UIImageView``` class which can be availed by installing the ```afmotion``` gem (in Objective-C, this would be available in the ```UIImageView+AFNetworking``` category). The two arguments it takes are the URL to the image and the name of a locally available placeholder image. The syntax is:
|
70
|
+
```ruby
|
71
|
+
cell.set_thumbnail_image_with_url image_url, placeholder # image_url is a URL in form of a string and the placeholder is a local image that can take the place of the image until it loads
|
data/Rakefile
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
# -*- coding: utf-8 -*-
|
2
|
+
$:.unshift("/Library/RubyMotion/lib")
|
3
|
+
require 'motion/project/template/ios'
|
4
|
+
|
5
|
+
begin
|
6
|
+
require 'bundler'
|
7
|
+
Bundler.require
|
8
|
+
rescue LoadError
|
9
|
+
end
|
10
|
+
|
11
|
+
Motion::Project::App.setup do |app|
|
12
|
+
# Use `rake config' to see complete project settings.
|
13
|
+
app.name = 'horizontal scroll sample app'
|
14
|
+
end
|
data/app/app_delegate.rb
ADDED
@@ -0,0 +1,8 @@
|
|
1
|
+
class AppDelegate
|
2
|
+
def application(application, didFinishLaunchingWithOptions:launchOptions)
|
3
|
+
@window = UIWindow.alloc.initWithFrame(UIScreen.mainScreen.bounds)
|
4
|
+
@window.makeKeyAndVisible
|
5
|
+
@window.rootViewController = ScreenController.alloc.initWithNibName(nil, bundle: nil)
|
6
|
+
true
|
7
|
+
end
|
8
|
+
end
|
@@ -0,0 +1,83 @@
|
|
1
|
+
class ScreenController < UIViewController
|
2
|
+
include AppConstants
|
3
|
+
|
4
|
+
attr_accessor :items
|
5
|
+
|
6
|
+
def viewDidLoad
|
7
|
+
super
|
8
|
+
self.items = []
|
9
|
+
self.view.backgroundColor = UIColor.whiteColor
|
10
|
+
@table_view = UITableView.alloc.initWithFrame([[0, STATUS_BAR_HEIGHT],[Device.screen.width, Device.screen.height - STATUS_BAR_HEIGHT]], style: UITableViewStylePlain)
|
11
|
+
@table_view.delegate = self
|
12
|
+
@table_view.dataSource = self
|
13
|
+
self.view.addSubview(@table_view)
|
14
|
+
fetch_data
|
15
|
+
end
|
16
|
+
|
17
|
+
def tableView(table_view, cellForRowAtIndexPath: index_path)
|
18
|
+
cell = table_view.dequeueReusableCellWithIdentifier(self.class.name)
|
19
|
+
unless cell
|
20
|
+
cell = create_new_horizontal_scroll_cell index_path.row
|
21
|
+
end
|
22
|
+
cell.reload_content
|
23
|
+
cell
|
24
|
+
end
|
25
|
+
|
26
|
+
def create_new_horizontal_scroll_cell row_number
|
27
|
+
horizontal_row = HorizontalTableContainerCell.alloc.initWithStyle(UITableViewCellStyleSubtitle, reuseIdentifier: self.class.name)
|
28
|
+
horizontal_row.delegate = self
|
29
|
+
horizontal_row.vertical_row_offset = VERTICAL_ROW_OFFSET
|
30
|
+
cell = horizontal_row.set_dimensions_with_row_offset
|
31
|
+
cell.items_list = extract_subset_of_data row_number
|
32
|
+
cell.selectionStyle = UITableViewCellSelectionStyleNone
|
33
|
+
cell
|
34
|
+
end
|
35
|
+
|
36
|
+
def extract_subset_of_data row_number
|
37
|
+
start_index = ITEMS_PER_ROW * row_number
|
38
|
+
end_index = start_index + ITEMS_PER_ROW - 1
|
39
|
+
self.items[start_index..end_index]
|
40
|
+
end
|
41
|
+
|
42
|
+
def horizontal_scroll_cell_selected(item, index)
|
43
|
+
App.alert "#{item.name} at index #{index}"
|
44
|
+
end
|
45
|
+
|
46
|
+
def set_item_details_for_horizontal_scroll_cell cell, item
|
47
|
+
cell.set_title_label_text item.name
|
48
|
+
cell.set_thumbnail_image_with_url item.image_url, "img.jpeg"
|
49
|
+
end
|
50
|
+
|
51
|
+
def tableView(table_view, heightForRowAtIndexPath: index_path)
|
52
|
+
ROW_HEIGHT
|
53
|
+
end
|
54
|
+
|
55
|
+
def tableView(table_view, numberOfRowsInSection: section)
|
56
|
+
get_row_count
|
57
|
+
end
|
58
|
+
|
59
|
+
def get_row_count
|
60
|
+
return 1 if self.items.nil?
|
61
|
+
(self.items.count.to_f/5).ceil
|
62
|
+
end
|
63
|
+
|
64
|
+
def numberOfSectionsInTableView(table_view)
|
65
|
+
NUMBER_OF_SECTIONS
|
66
|
+
end
|
67
|
+
|
68
|
+
def fetch_data
|
69
|
+
generate_sample_models "city"
|
70
|
+
generate_sample_models "transport"
|
71
|
+
generate_sample_models "cats"
|
72
|
+
@table_view.reloadData
|
73
|
+
end
|
74
|
+
|
75
|
+
def generate_sample_models category
|
76
|
+
5.times do |n|
|
77
|
+
model = Model.new
|
78
|
+
model.name = "#{category} #{n}"
|
79
|
+
model.image_url = "http://lorempixel.com/130/207/#{category}/#{n}"
|
80
|
+
self.items << model
|
81
|
+
end
|
82
|
+
end
|
83
|
+
end
|
data/app/models/model.rb
ADDED
@@ -0,0 +1,9 @@
|
|
1
|
+
unless defined?(Motion::Project::Config)
|
2
|
+
raise "This file must be required within a RubyMotion project Rakefile."
|
3
|
+
end
|
4
|
+
|
5
|
+
Motion::Project::App.setup do |app|
|
6
|
+
Dir.glob(File.join(File.dirname(__FILE__), "motion-horizontal-scroll/*.rb")).each do |file|
|
7
|
+
app.files.unshift(file)
|
8
|
+
end
|
9
|
+
end
|
@@ -0,0 +1,33 @@
|
|
1
|
+
class BasicTableViewCell < UITableViewCell
|
2
|
+
include ControlVariables
|
3
|
+
|
4
|
+
attr_accessor :thumbnail
|
5
|
+
|
6
|
+
def initWithFrame(frame)
|
7
|
+
if super
|
8
|
+
self.thumbnail = ImageViewWithOverlay.alloc.initWithFrame(CGRectMake(15, 23, 115, 145))
|
9
|
+
self.thumbnail.userInteractionEnabled = true
|
10
|
+
self.thumbnail.opaque = true
|
11
|
+
self.contentView.addSubview(thumbnail)
|
12
|
+
self.backgroundColor = CELL_BACKGROUND_COLOR
|
13
|
+
self.selectedBackgroundView = UIView.alloc.initWithFrame(self.thumbnail.frame)
|
14
|
+
self.selectedBackgroundView.backgroundColor = HORIZONTAL_VIEW_SELECTED_BACKGROUND_COLOR
|
15
|
+
self.transform = CGAffineTransformMakeRotation(Math::PI * 0.5)
|
16
|
+
after_frame_initialization
|
17
|
+
end
|
18
|
+
self
|
19
|
+
end
|
20
|
+
|
21
|
+
def after_frame_initialization
|
22
|
+
|
23
|
+
end
|
24
|
+
|
25
|
+
def set_thumbnail_image image
|
26
|
+
self.thumbnail.setImage image
|
27
|
+
end
|
28
|
+
|
29
|
+
def set_thumbnail_image_with_url image_url, placeholder
|
30
|
+
self.thumbnail.setImageWithURL(NSURL.URLWithString(image_url), placeholderImage: UIImage.imageNamed(placeholder))
|
31
|
+
end
|
32
|
+
|
33
|
+
end
|
@@ -0,0 +1,33 @@
|
|
1
|
+
class BasicTableViewCellWithTitle < BasicTableViewCell
|
2
|
+
attr_accessor :title_label
|
3
|
+
|
4
|
+
def after_frame_initialization
|
5
|
+
setup_title_label
|
6
|
+
end
|
7
|
+
|
8
|
+
def setup_title_label
|
9
|
+
label_frame = CGRectMake(15, CELL_HEIGHT - 55, 85, 50)
|
10
|
+
self.title_label = UILabel.alloc.initWithFrame(label_frame)
|
11
|
+
self.title_label.text = ""
|
12
|
+
self.title_label.font = UIFont.boldSystemFontOfSize(12)
|
13
|
+
self.title_label.numberOfLines = 2
|
14
|
+
self.title_label.backgroundColor = UIColor.clearColor
|
15
|
+
self.title_label.baselineAdjustment = UIBaselineAdjustmentAlignBaselines
|
16
|
+
self.title_label.textAlignment = NSTextAlignmentCenter
|
17
|
+
self.title_label.textColor = "#3d4040".to_color
|
18
|
+
self.thumbnail.addSubview(self.title_label)
|
19
|
+
end
|
20
|
+
|
21
|
+
def set_title_label_text text
|
22
|
+
self.title_label.text = text
|
23
|
+
reset_title_label_frame
|
24
|
+
end
|
25
|
+
|
26
|
+
def reset_title_label_frame
|
27
|
+
self.title_label.sizeToFit
|
28
|
+
frame = self.title_label.frame
|
29
|
+
frame.size.width = 85
|
30
|
+
self.title_label.frame = frame
|
31
|
+
end
|
32
|
+
|
33
|
+
end
|
@@ -0,0 +1,6 @@
|
|
1
|
+
module ControlVariables
|
2
|
+
CELL_HEIGHT = 207
|
3
|
+
CELL_WIDTH = 130
|
4
|
+
CELL_BACKGROUND_COLOR = UIColor.colorWithRed(0, green: 0.10784314, blue: 0.21568627, alpha: 0.4)
|
5
|
+
HORIZONTAL_VIEW_SELECTED_BACKGROUND_COLOR = UIColor.colorWithRed(0.0, green: 0.59607843, blue: 0.37254902, alpha:1.0)
|
6
|
+
end
|
@@ -0,0 +1,83 @@
|
|
1
|
+
class HorizontalTableContainerCell < UITableViewCell
|
2
|
+
include ControlVariables
|
3
|
+
|
4
|
+
attr_accessor :horizontal_table_view, :items_list, :delegate, :vertical_row_offset
|
5
|
+
|
6
|
+
def tableView(table_view, numberOfRowsInSection: section)
|
7
|
+
self.items_list.count
|
8
|
+
end
|
9
|
+
|
10
|
+
def tableView(table_view, cellForRowAtIndexPath: index_path)
|
11
|
+
cell = get_reusable_cell table_view
|
12
|
+
current_item = self.items_list[index_path.row]
|
13
|
+
self.delegate.set_item_details_for_horizontal_scroll_cell cell, current_item
|
14
|
+
cell.selectionStyle = UITableViewCellSelectionStyleNone
|
15
|
+
cell
|
16
|
+
end
|
17
|
+
|
18
|
+
def tableView(table_view, willDisplayCell: cell, forRowAtIndexPath: index_path)
|
19
|
+
cell.backgroundColor = UIColor.clearColor
|
20
|
+
end
|
21
|
+
|
22
|
+
def tableView(table_view, didSelectRowAtIndexPath: index_path)
|
23
|
+
self.delegate.horizontal_scroll_cell_selected(self.items_list[index_path.row], index_path.row) if self.delegate
|
24
|
+
end
|
25
|
+
|
26
|
+
def set_dimensions_with_row_offset
|
27
|
+
@scroll_view = setup_background_scroll_view
|
28
|
+
self.backgroundColor = UIColor.clearColor
|
29
|
+
self.horizontal_table_view = setup_horizontal_tableview
|
30
|
+
@scroll_view.addSubview(self.horizontal_table_view)
|
31
|
+
self.addSubview @scroll_view
|
32
|
+
end
|
33
|
+
|
34
|
+
def setup_background_scroll_view
|
35
|
+
scroll_view = UIScrollView.alloc.initWithFrame(get_wrapping_scroll_view_frame)
|
36
|
+
scroll_view.contentSize = CGSizeMake(Device.screen.width, CELL_HEIGHT + vertical_row_offset)
|
37
|
+
scroll_view.bounces = true
|
38
|
+
scroll_view.alwaysBounceHorizontal = true
|
39
|
+
scroll_view.backgroundColor = UIColor.clearColor
|
40
|
+
scroll_view
|
41
|
+
end
|
42
|
+
|
43
|
+
def setup_horizontal_tableview
|
44
|
+
horizontal_table_view = UITableView.alloc.initWithFrame(get_horizontal_table_view_frame)
|
45
|
+
horizontal_table_view.transform = CGAffineTransformMakeRotation( - (Math::PI * 0.5))
|
46
|
+
horizontal_table_view.rowHeight = CELL_WIDTH
|
47
|
+
horizontal_table_view.showsVerticalScrollIndicator = false
|
48
|
+
horizontal_table_view.showsHorizontalScrollIndicator = false
|
49
|
+
horizontal_table_view.backgroundColor = UIColor.clearColor
|
50
|
+
horizontal_table_view.separatorStyle = UITableViewCellSeparatorStyleSingleLine
|
51
|
+
horizontal_table_view.separatorColor = UIColor.clearColor
|
52
|
+
horizontal_table_view.dataSource = self
|
53
|
+
horizontal_table_view.bounces = true
|
54
|
+
horizontal_table_view.delegate = self
|
55
|
+
horizontal_table_view.alwaysBounceVertical = true
|
56
|
+
horizontal_table_view
|
57
|
+
end
|
58
|
+
|
59
|
+
def get_origin_before_transformation
|
60
|
+
[60 - vertical_row_offset, -60 + vertical_row_offset]
|
61
|
+
end
|
62
|
+
|
63
|
+
def get_wrapping_scroll_view_frame
|
64
|
+
[[0,0],[Device.screen.width, CELL_HEIGHT + vertical_row_offset]]
|
65
|
+
end
|
66
|
+
|
67
|
+
def get_horizontal_table_view_frame
|
68
|
+
[get_origin_before_transformation, [CELL_HEIGHT + vertical_row_offset, Device.screen.width]]
|
69
|
+
end
|
70
|
+
|
71
|
+
def reload_content
|
72
|
+
self.horizontal_table_view.reloadData
|
73
|
+
end
|
74
|
+
|
75
|
+
def get_reusable_cell table_view
|
76
|
+
cell = table_view.dequeueReusableCellWithIdentifier(BasicTableViewCellWithTitle.name)
|
77
|
+
if cell.nil?
|
78
|
+
cell = BasicTableViewCellWithTitle.alloc.initWithFrame(CGRectMake(0, 0, CELL_WIDTH, CELL_HEIGHT + vertical_row_offset))
|
79
|
+
end
|
80
|
+
cell
|
81
|
+
end
|
82
|
+
|
83
|
+
end
|
@@ -0,0 +1,36 @@
|
|
1
|
+
class ImageViewWithOverlay < UIImageView
|
2
|
+
OVERLAY_VIEW_TAG = 100
|
3
|
+
|
4
|
+
def touchesBegan(touches,withEvent: event)
|
5
|
+
overlay = UIView.alloc.initWithFrame(self.bounds)
|
6
|
+
overlay.tag = OVERLAY_VIEW_TAG
|
7
|
+
overlay.alpha = 0.5
|
8
|
+
overlay.backgroundColor = UIColor.blackColor
|
9
|
+
self.addSubview(overlay)
|
10
|
+
self.superview.touchesBegan(touches,withEvent: event)
|
11
|
+
end
|
12
|
+
|
13
|
+
def touchesEnded(touches,withEvent: event)
|
14
|
+
overlay = self.viewWithTag(OVERLAY_VIEW_TAG)
|
15
|
+
unless overlay.nil? == true
|
16
|
+
UIView.animateWithDuration(0.4, animations: lambda{
|
17
|
+
overlay.alpha = 0
|
18
|
+
},completion: lambda{|done|
|
19
|
+
overlay.removeFromSuperview
|
20
|
+
})
|
21
|
+
end
|
22
|
+
self.superview.touchesEnded(touches,withEvent: event)
|
23
|
+
end
|
24
|
+
|
25
|
+
def touchesCancelled(touches,withEvent: event)
|
26
|
+
overlay = self.viewWithTag(OVERLAY_VIEW_TAG)
|
27
|
+
unless overlay.nil? == true
|
28
|
+
UIView.animateWithDuration(0.4, animations: lambda{
|
29
|
+
overlay.alpha = 0
|
30
|
+
},completion: lambda{|done|
|
31
|
+
overlay.removeFromSuperview
|
32
|
+
})
|
33
|
+
end
|
34
|
+
self.superview.touchesCancelled(touches,withEvent: event)
|
35
|
+
end
|
36
|
+
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
Gem::Specification.new do |gem|
|
3
|
+
gem.authors = ["Multunus"]
|
4
|
+
gem.email = ["info@multunus.com"]
|
5
|
+
gem.description = "This RubyMotion gem provides a means of horizontally scrolling through items as opposed to the standard iOS vertical scroll"
|
6
|
+
gem.summary = "Horizontal scroll container for iOS (RubyMotion)"
|
7
|
+
gem.homepage = "https://github.com/multunus/motion-horizontal-scroll"
|
8
|
+
|
9
|
+
gem.files = `git ls-files`.split($\)
|
10
|
+
gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
|
11
|
+
gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
|
12
|
+
gem.name = "motion-horizontal-scroll"
|
13
|
+
gem.require_paths = ["lib"]
|
14
|
+
gem.version = "1.0"
|
15
|
+
end
|
Binary file
|
data/resources/img.jpeg
ADDED
Binary file
|
@@ -0,0 +1,13 @@
|
|
1
|
+
describe BasicTableViewCell do
|
2
|
+
|
3
|
+
before do
|
4
|
+
@cell = BasicTableViewCell.alloc.initWithFrame(CGRectMake(0, 0, 130, 207))
|
5
|
+
end
|
6
|
+
|
7
|
+
it "should initialize and apply image overlay" do
|
8
|
+
@cell.thumbnail.class.should == ImageViewWithOverlay
|
9
|
+
@cell.thumbnail.userInteractionEnabled = true
|
10
|
+
@cell.thumbnail.opaque = true
|
11
|
+
end
|
12
|
+
|
13
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
describe BasicTableViewCellWithTitle do
|
2
|
+
before do
|
3
|
+
@cell = BasicTableViewCellWithTitle.alloc.initWithFrame(CGRectMake(0, 0, 130, 207))
|
4
|
+
end
|
5
|
+
|
6
|
+
it "should set up the title label" do
|
7
|
+
@cell.setup_title_label
|
8
|
+
@cell.thumbnail.subviews.last.class.should == UILabel
|
9
|
+
end
|
10
|
+
|
11
|
+
it "should set the title label text" do
|
12
|
+
@cell.set_title_label_text "title"
|
13
|
+
@cell.title_label.text.should == "title"
|
14
|
+
end
|
15
|
+
|
16
|
+
it "should set the title label frame width on reset" do
|
17
|
+
@cell.title_label.text = "title"
|
18
|
+
@cell.reset_title_label_frame
|
19
|
+
@cell.title_label.frame.size.width.should == 85
|
20
|
+
end
|
21
|
+
end
|
@@ -0,0 +1,42 @@
|
|
1
|
+
describe HorizontalTableContainerCell do
|
2
|
+
before do
|
3
|
+
horizontal_row = HorizontalTableContainerCell.alloc.initWithStyle(UITableViewCellStyleSubtitle, reuseIdentifier: self.class.name)
|
4
|
+
horizontal_row.delegate = self
|
5
|
+
horizontal_row.vertical_row_offset = 0
|
6
|
+
@cell = horizontal_row.set_dimensions_with_row_offset
|
7
|
+
@cell.items_list = [Model.new(:name => "test_name_1", :image_url => "test_url_1"), Model.new(:name => "test_name_2", :image_url => "test_url_2")]
|
8
|
+
end
|
9
|
+
|
10
|
+
it "should have transparent background" do
|
11
|
+
@cell.backgroundColor.should == UIColor.clearColor
|
12
|
+
end
|
13
|
+
|
14
|
+
it "should set up a scroll view to hold the table" do
|
15
|
+
scroll_view = @cell.instance_variable_get(:@scroll_view)
|
16
|
+
scroll_view.class.should == UIScrollView
|
17
|
+
scroll_view.backgroundColor.should == UIColor.clearColor
|
18
|
+
end
|
19
|
+
|
20
|
+
it "should set up the horizontal table view" do
|
21
|
+
@cell.horizontal_table_view.class.should == UITableView
|
22
|
+
@cell.horizontal_table_view.backgroundColor.should == UIColor.clearColor
|
23
|
+
@cell.horizontal_table_view.delegate.should == @cell
|
24
|
+
end
|
25
|
+
|
26
|
+
it "should return the right origin for the rotation transformation" do
|
27
|
+
@cell.get_origin_before_transformation.should == [60,-60]
|
28
|
+
end
|
29
|
+
|
30
|
+
it "should return the frame for the wrapping scroll view" do
|
31
|
+
@cell.get_wrapping_scroll_view_frame.should == [[0,0],[320,207]]
|
32
|
+
end
|
33
|
+
|
34
|
+
it "should return the frame for the inner horizontal table view" do
|
35
|
+
@cell.get_horizontal_table_view_frame.should == [[60,-60],[207,320]]
|
36
|
+
end
|
37
|
+
|
38
|
+
it "should return a cell for the table view" do
|
39
|
+
returned_cell = @cell.get_reusable_cell(@cell.horizontal_table_view)
|
40
|
+
returned_cell.class.should == BasicTableViewCellWithTitle
|
41
|
+
end
|
42
|
+
end
|
data/spec/main_spec.rb
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
describe ScreenController do
|
2
|
+
before do
|
3
|
+
@screen = ScreenController.new
|
4
|
+
@items = [Model.new(:name => "test_name_1", :image_url => "test_url_1"), Model.new(:name => "test_name_2", :image_url => "test_url_2")]
|
5
|
+
@screen.items = @items
|
6
|
+
end
|
7
|
+
|
8
|
+
it "should create a new horizontal scroll cell" do
|
9
|
+
cell = @screen.create_new_horizontal_scroll_cell 0
|
10
|
+
cell.class.should == HorizontalTableContainerCell
|
11
|
+
cell.items_list.count.should == @items.count
|
12
|
+
end
|
13
|
+
|
14
|
+
it "should extract the required subset of data" do
|
15
|
+
items = @screen.extract_subset_of_data 0
|
16
|
+
items.count.should == 2
|
17
|
+
end
|
18
|
+
|
19
|
+
it "should have the right number of rows" do
|
20
|
+
@screen.get_row_count.should == 1
|
21
|
+
end
|
22
|
+
end
|
metadata
ADDED
@@ -0,0 +1,72 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: motion-horizontal-scroll
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: '1.0'
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Multunus
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2014-03-03 00:00:00.000000000 Z
|
12
|
+
dependencies: []
|
13
|
+
description: This RubyMotion gem provides a means of horizontally scrolling through
|
14
|
+
items as opposed to the standard iOS vertical scroll
|
15
|
+
email:
|
16
|
+
- info@multunus.com
|
17
|
+
executables: []
|
18
|
+
extensions: []
|
19
|
+
extra_rdoc_files: []
|
20
|
+
files:
|
21
|
+
- .gitignore
|
22
|
+
- Gemfile
|
23
|
+
- Gemfile.lock
|
24
|
+
- README.md
|
25
|
+
- Rakefile
|
26
|
+
- app/app_delegate.rb
|
27
|
+
- app/constants/style_constants.rb
|
28
|
+
- app/controllers/screen_controller.rb
|
29
|
+
- app/models/model.rb
|
30
|
+
- lib/motion-horizontal-scroll.rb
|
31
|
+
- lib/motion-horizontal-scroll/basic_table_view_cell.rb
|
32
|
+
- lib/motion-horizontal-scroll/basic_table_view_cell_with_title.rb
|
33
|
+
- lib/motion-horizontal-scroll/control_variables.rb
|
34
|
+
- lib/motion-horizontal-scroll/horizontal_table_container_cell.rb
|
35
|
+
- lib/motion-horizontal-scroll/image_view_with_overlay.rb
|
36
|
+
- motion-horizontal-scroll.gemspec
|
37
|
+
- resources/Default-568h@2x.png
|
38
|
+
- resources/img.jpeg
|
39
|
+
- spec/basic_table_view_cell_spec.rb
|
40
|
+
- spec/basic_table_view_cell_with_title_spec.rb
|
41
|
+
- spec/horizontal_table_container_cell_spec.rb
|
42
|
+
- spec/main_spec.rb
|
43
|
+
- spec/screen_controller_spec.rb
|
44
|
+
homepage: https://github.com/multunus/motion-horizontal-scroll
|
45
|
+
licenses: []
|
46
|
+
metadata: {}
|
47
|
+
post_install_message:
|
48
|
+
rdoc_options: []
|
49
|
+
require_paths:
|
50
|
+
- lib
|
51
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
52
|
+
requirements:
|
53
|
+
- - ! '>='
|
54
|
+
- !ruby/object:Gem::Version
|
55
|
+
version: '0'
|
56
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
57
|
+
requirements:
|
58
|
+
- - ! '>='
|
59
|
+
- !ruby/object:Gem::Version
|
60
|
+
version: '0'
|
61
|
+
requirements: []
|
62
|
+
rubyforge_project:
|
63
|
+
rubygems_version: 2.2.2
|
64
|
+
signing_key:
|
65
|
+
specification_version: 4
|
66
|
+
summary: Horizontal scroll container for iOS (RubyMotion)
|
67
|
+
test_files:
|
68
|
+
- spec/basic_table_view_cell_spec.rb
|
69
|
+
- spec/basic_table_view_cell_with_title_spec.rb
|
70
|
+
- spec/horizontal_table_container_cell_spec.rb
|
71
|
+
- spec/main_spec.rb
|
72
|
+
- spec/screen_controller_spec.rb
|