ProMotion 0.4.1 → 0.5.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.
- data/.gitignore +0 -1
- data/Gemfile +1 -1
- data/README.md +336 -92
- data/Rakefile +1 -1
- data/lib/ProMotion.rb +14 -0
- data/lib/ProMotion/app_delegate.rb +63 -0
- data/lib/ProMotion/cocoatouch/NavigationController.rb +4 -0
- data/lib/ProMotion/cocoatouch/TableViewCell.rb +16 -0
- data/lib/ProMotion/cocoatouch/TableViewController.rb +50 -0
- data/lib/ProMotion/cocoatouch/ViewController.rb +52 -0
- data/lib/ProMotion/helpers/console.rb +24 -0
- data/lib/ProMotion/helpers/measure_helper.rb +20 -0
- data/lib/ProMotion/helpers/system_helper.rb +29 -0
- data/lib/ProMotion/helpers/tab_bar.rb +115 -0
- data/lib/ProMotion/helpers/view_helper.rb +39 -0
- data/lib/ProMotion/pro_motion.rb +3 -0
- data/lib/ProMotion/screen_helpers/_tables/_searchable_table.rb +66 -0
- data/lib/ProMotion/screen_helpers/_tables/_sectioned_table.rb +265 -0
- data/lib/ProMotion/screen_helpers/_tables/grouped_table.rb +13 -0
- data/lib/ProMotion/screen_helpers/_tables/plain_table.rb +14 -0
- data/lib/ProMotion/screen_helpers/screen_elements.rb +43 -0
- data/lib/ProMotion/screen_helpers/screen_navigation.rb +106 -0
- data/lib/ProMotion/screen_helpers/screen_tabs.rb +92 -0
- data/lib/ProMotion/screens/_screen_module.rb +222 -0
- data/lib/ProMotion/screens/_table_screen_module.rb +30 -0
- data/lib/ProMotion/screens/screen.rb +7 -0
- data/lib/ProMotion/screens/table_screen.rb +15 -0
- data/lib/ProMotion/version.rb +3 -0
- metadata +43 -63
- data/app/app_delegate.rb +0 -5
- data/app/screens/home_screen.rb +0 -21
- data/app/screens/test_screen.rb +0 -26
data/Rakefile
CHANGED
@@ -15,7 +15,7 @@ Motion::Project::App.setup do |app|
|
|
15
15
|
app.deployment_target = "5.0"
|
16
16
|
app.device_family = [:iphone, :ipad]
|
17
17
|
|
18
|
-
app.detect_dependencies =
|
18
|
+
app.detect_dependencies = true
|
19
19
|
|
20
20
|
# Preload screens
|
21
21
|
# app.files = Dir.glob(File.join(app.project_dir, 'lib/**/*.rb')) | app.files
|
data/lib/ProMotion.rb
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
unless defined?(Motion::Project::Config)
|
2
|
+
raise "This file must be required within a RubyMotion project Rakefile."
|
3
|
+
end
|
4
|
+
|
5
|
+
require "ProMotion/version"
|
6
|
+
|
7
|
+
Motion::Project::App.setup do |app|
|
8
|
+
# app_delegate = Dir.glob(File.join(File.dirname(__FILE__), 'ProMotion/app_delegate.rb'))
|
9
|
+
# app.files = Dir.glob(File.join(File.dirname(__FILE__), 'ProMotion/**/*.rb')) | app_delegate | app.files
|
10
|
+
|
11
|
+
original_files = app.files
|
12
|
+
app.files = FileList[File.join(File.dirname(__FILE__), 'ProMotion/**/*.rb')].exclude(File.join(File.dirname(__FILE__), 'ProMotion/app_delegate.rb'))
|
13
|
+
app.files = app.files | Dir.glob(File.join(File.dirname(__FILE__), 'ProMotion/app_delegate.rb')) | original_files
|
14
|
+
end
|
@@ -0,0 +1,63 @@
|
|
1
|
+
module ProMotion
|
2
|
+
class AppDelegateParent
|
3
|
+
include ProMotion::ScreenTabs
|
4
|
+
attr_accessor :window
|
5
|
+
|
6
|
+
def application(application, didFinishLaunchingWithOptions:launch_options)
|
7
|
+
return true if RUBYMOTION_ENV == "test"
|
8
|
+
|
9
|
+
Console.log(" Your AppDelegate (usually in app_delegate.rb) needs an on_load(options) method.", with_color: Console::RED_COLOR) unless self.respond_to?("on_load:")
|
10
|
+
|
11
|
+
on_load(application, launch_options)
|
12
|
+
|
13
|
+
open_home_screen if has_home_screen
|
14
|
+
|
15
|
+
true
|
16
|
+
end
|
17
|
+
|
18
|
+
def app_delegate
|
19
|
+
UIApplication.sharedApplication.delegate
|
20
|
+
end
|
21
|
+
|
22
|
+
def app_window
|
23
|
+
self.app_delegate.window
|
24
|
+
end
|
25
|
+
|
26
|
+
def load_root_screen(new_screen)
|
27
|
+
new_screen = new_screen.main_controller if new_screen.respond_to?(:main_controller)
|
28
|
+
|
29
|
+
self.window ||= UIWindow.alloc.initWithFrame(UIScreen.mainScreen.bounds)
|
30
|
+
self.window.rootViewController = new_screen
|
31
|
+
self.window.makeKeyAndVisible
|
32
|
+
end
|
33
|
+
|
34
|
+
def open_screen(screen)
|
35
|
+
home(screen)
|
36
|
+
end
|
37
|
+
alias :open :open_screen
|
38
|
+
|
39
|
+
def home(screen)
|
40
|
+
screen = screen.new if screen.respond_to?(:new)
|
41
|
+
@home_screen = screen
|
42
|
+
end
|
43
|
+
|
44
|
+
def open_root_screen(new_screen)
|
45
|
+
home(new_screen)
|
46
|
+
open_home_screen
|
47
|
+
end
|
48
|
+
alias :fresh_start :open_root_screen
|
49
|
+
|
50
|
+
def open_home_screen
|
51
|
+
get_home_screen.send(:on_load) if get_home_screen.respond_to?(:on_load)
|
52
|
+
load_root_screen get_home_screen
|
53
|
+
end
|
54
|
+
|
55
|
+
def get_home_screen
|
56
|
+
@home_screen
|
57
|
+
end
|
58
|
+
|
59
|
+
def has_home_screen
|
60
|
+
@home_screen.nil? == false
|
61
|
+
end
|
62
|
+
end
|
63
|
+
end
|
@@ -0,0 +1,16 @@
|
|
1
|
+
module ProMotion
|
2
|
+
class TableViewCell < UITableViewCell
|
3
|
+
attr_accessor :image_size
|
4
|
+
|
5
|
+
def layoutSubviews
|
6
|
+
super
|
7
|
+
|
8
|
+
if self.image_size && self.imageView.image && self.imageView.image.size && self.imageView.image.size.width > 0
|
9
|
+
f = self.imageView.frame
|
10
|
+
size_inset_x = (self.imageView.size.width - self.image_size) / 2
|
11
|
+
size_inset_y = (self.imageView.size.height - self.image_size) / 2
|
12
|
+
self.imageView.frame = CGRectInset(f, size_inset_x, size_inset_y)
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
@@ -0,0 +1,50 @@
|
|
1
|
+
module ProMotion
|
2
|
+
class TableViewController < UITableViewController
|
3
|
+
def self.new(args = {})
|
4
|
+
s = self.alloc.initWithNibName(nil, bundle:nil)
|
5
|
+
s.on_create(args) if s.respond_to?(:on_create)
|
6
|
+
s
|
7
|
+
end
|
8
|
+
|
9
|
+
def viewDidLoad
|
10
|
+
super
|
11
|
+
self.view_did_load if self.respond_to?(:view_did_load)
|
12
|
+
end
|
13
|
+
|
14
|
+
def viewWillAppear(animated)
|
15
|
+
super
|
16
|
+
self.view_will_appear(animated) if self.respond_to?("view_will_appear:")
|
17
|
+
end
|
18
|
+
|
19
|
+
def viewDidAppear(animated)
|
20
|
+
super
|
21
|
+
self.view_did_appear(animated) if self.respond_to?("view_did_appear:")
|
22
|
+
end
|
23
|
+
|
24
|
+
def viewWillDisappear(animated)
|
25
|
+
self.view_will_disappear(animated) if self.respond_to?("view_will_disappear:")
|
26
|
+
super
|
27
|
+
end
|
28
|
+
|
29
|
+
def viewDidDisappear(animated)
|
30
|
+
self.view_did_disappear(animated) if self.respond_to?("view_did_disappear:")
|
31
|
+
super
|
32
|
+
end
|
33
|
+
|
34
|
+
def shouldAutorotateToInterfaceOrientation(orientation)
|
35
|
+
self.should_rotate(orientation)
|
36
|
+
end
|
37
|
+
|
38
|
+
def shouldAutorotate
|
39
|
+
self.should_autorotate
|
40
|
+
end
|
41
|
+
|
42
|
+
def willRotateToInterfaceOrientation(orientation, duration:duration)
|
43
|
+
self.will_rotate(orientation, duration)
|
44
|
+
end
|
45
|
+
|
46
|
+
def didRotateFromInterfaceOrientation(orientation)
|
47
|
+
self.on_rotate
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
@@ -0,0 +1,52 @@
|
|
1
|
+
module ProMotion
|
2
|
+
class ViewController < UIViewController
|
3
|
+
def self.new(args = {})
|
4
|
+
s = self.alloc.initWithNibName(nil, bundle:nil)
|
5
|
+
s.on_create(args) if s.respond_to?(:on_create)
|
6
|
+
s
|
7
|
+
end
|
8
|
+
|
9
|
+
def viewDidLoad
|
10
|
+
super
|
11
|
+
self.view_did_load if self.respond_to?(:view_did_load)
|
12
|
+
end
|
13
|
+
|
14
|
+
def viewWillAppear(animated)
|
15
|
+
super
|
16
|
+
self.view_will_appear(animated) if self.respond_to?("view_will_appear:")
|
17
|
+
end
|
18
|
+
|
19
|
+
def viewDidAppear(animated)
|
20
|
+
super
|
21
|
+
self.view_did_appear(animated) if self.respond_to?("view_did_appear:")
|
22
|
+
end
|
23
|
+
|
24
|
+
def viewWillDisappear(animated)
|
25
|
+
self.view_will_disappear(animated) if self.respond_to?("view_will_disappear:")
|
26
|
+
super
|
27
|
+
end
|
28
|
+
|
29
|
+
def viewDidDisappear(animated)
|
30
|
+
if self.respond_to?("view_did_disappear:")
|
31
|
+
self.view_did_disappear(animated)
|
32
|
+
end
|
33
|
+
super
|
34
|
+
end
|
35
|
+
|
36
|
+
def shouldAutorotateToInterfaceOrientation(orientation)
|
37
|
+
self.should_rotate(orientation)
|
38
|
+
end
|
39
|
+
|
40
|
+
def shouldAutorotate
|
41
|
+
self.should_autorotate
|
42
|
+
end
|
43
|
+
|
44
|
+
def willRotateToInterfaceOrientation(orientation, duration:duration)
|
45
|
+
self.will_rotate(orientation, duration)
|
46
|
+
end
|
47
|
+
|
48
|
+
def didRotateFromInterfaceOrientation(orientation)
|
49
|
+
self.on_rotate
|
50
|
+
end
|
51
|
+
end
|
52
|
+
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
module ProMotion
|
2
|
+
class Console
|
3
|
+
NAME = "RubyMotion::Console: "
|
4
|
+
DEFAULT_COLOR = [ '', '' ]
|
5
|
+
RED_COLOR = [ "\e[0;31m", "\e[0m" ] # Must be in double quotes
|
6
|
+
GREEN_COLOR = [ "\e[0;32m", "\e[0m" ]
|
7
|
+
PURPLE_COLOR = [ "\e[0;35m", "\e[0m" ]
|
8
|
+
|
9
|
+
class << self
|
10
|
+
def log(log, with_color:color)
|
11
|
+
puts color[0] + NAME + log + color[1]
|
12
|
+
end
|
13
|
+
|
14
|
+
def log(log, withColor:color)
|
15
|
+
warn "[DEPRECATION] `log(log, withColor:color)` is deprecated. Use `log(log, with_color:color)`"
|
16
|
+
self.log(log, with_color:color)
|
17
|
+
end
|
18
|
+
|
19
|
+
def log(log)
|
20
|
+
log(log, with_color: DEFAULT_COLOR)
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
module ProMotion
|
2
|
+
class MeasureHelper
|
3
|
+
class << self
|
4
|
+
def content_height(view)
|
5
|
+
warn "[DEPRECATION] `MeasureHelper.content_height` is deprecated. Include the module `ScreenElements` to get access to this method (already included in Screen)."
|
6
|
+
|
7
|
+
height = 0
|
8
|
+
view.subviews.each do |subview|
|
9
|
+
next if subview.isHidden
|
10
|
+
y = subview.frame.origin.y
|
11
|
+
h = subview.frame.size.height
|
12
|
+
if (y + h) > height
|
13
|
+
height = y + h
|
14
|
+
end
|
15
|
+
end
|
16
|
+
height
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
@@ -0,0 +1,29 @@
|
|
1
|
+
module ProMotion
|
2
|
+
module SystemHelper
|
3
|
+
module_function
|
4
|
+
|
5
|
+
def ios_version
|
6
|
+
UIDevice.currentDevice.systemVersion
|
7
|
+
end
|
8
|
+
|
9
|
+
def ios_version_is?(version)
|
10
|
+
ios_version == version
|
11
|
+
end
|
12
|
+
|
13
|
+
def ios_version_greater?(version)
|
14
|
+
ios_version > version
|
15
|
+
end
|
16
|
+
|
17
|
+
def ios_version_greater_eq?(version)
|
18
|
+
ios_version >= version
|
19
|
+
end
|
20
|
+
|
21
|
+
def ios_version_less?(version)
|
22
|
+
ios_version < version
|
23
|
+
end
|
24
|
+
|
25
|
+
def ios_version_less_eq?(version)
|
26
|
+
ios_version <= version
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
@@ -0,0 +1,115 @@
|
|
1
|
+
# [DEPRECATED]
|
2
|
+
# Replaced by ScreenTabs module.
|
3
|
+
module ProMotion
|
4
|
+
class TabBar
|
5
|
+
class << self
|
6
|
+
def create_tab_bar_controller_from_data(data)
|
7
|
+
warn "[DEPRECATION] `create_tab_bar_controller_from_data` is deprecated. Use `open_tab_bar` instead."
|
8
|
+
|
9
|
+
data = self.set_tags(data)
|
10
|
+
|
11
|
+
tab_bar_controller = UITabBarController.alloc.init
|
12
|
+
tab_bar_controller.viewControllers = self.tab_controllers_from_data(data)
|
13
|
+
|
14
|
+
return tab_bar_controller
|
15
|
+
end
|
16
|
+
|
17
|
+
def set_tags(data)
|
18
|
+
warn "[DEPRECATION] `set_tags` is deprecated."
|
19
|
+
tag_number = 0
|
20
|
+
|
21
|
+
data.each do |d|
|
22
|
+
d[:tag] = tag_number
|
23
|
+
tag_number += 1
|
24
|
+
end
|
25
|
+
|
26
|
+
return data
|
27
|
+
end
|
28
|
+
|
29
|
+
def tab_bar_icon(icon, tag)
|
30
|
+
warn "[DEPRECATION] `TabBar.tab_bar_icon` is deprecated. Use `create_tab_bar_icon` in ScreenTabs instead."
|
31
|
+
return UITabBarItem.alloc.initWithTabBarSystemItem(icon, tag: tag)
|
32
|
+
end
|
33
|
+
|
34
|
+
def tab_bar_icon_custom(title, image_name, tag)
|
35
|
+
warn "[DEPRECATION] `TabBar.tab_bar_icon_custom` is deprecated. Use `create_tab_bar_icon_custom` in ScreenTabs instead."
|
36
|
+
icon_image = UIImage.imageNamed(image_name)
|
37
|
+
return UITabBarItem.alloc.initWithTitle(title, image:icon_image, tag:tag)
|
38
|
+
end
|
39
|
+
|
40
|
+
def tab_controllers_from_data(data)
|
41
|
+
warn "[DEPRECATION] `tab_controllers_from_data` is deprecated. Use `open_tab_bar` instead."
|
42
|
+
tab_controllers = []
|
43
|
+
|
44
|
+
data.each do |tab|
|
45
|
+
tab_controllers << self.controller_from_tab_data(tab)
|
46
|
+
end
|
47
|
+
|
48
|
+
return tab_controllers
|
49
|
+
end
|
50
|
+
|
51
|
+
def controller_from_tab_data(tab)
|
52
|
+
warn "[DEPRECATION] `controller_from_tab_data` is deprecated. Use `open_tab_bar` instead."
|
53
|
+
tab[:badge_number] ||= tab[:badgeNumber]
|
54
|
+
tab[:navigation_controller] ||= tab[:navigationController]
|
55
|
+
|
56
|
+
tab[:badge_number] = 0 unless tab[:badge_number]
|
57
|
+
tab[:tag] = 0 unless tab[:tag]
|
58
|
+
|
59
|
+
view_controller = tab[:view_controller]
|
60
|
+
view_controller = tab[:view_controller].alloc.init if tab[:view_controller].respond_to?(:alloc)
|
61
|
+
|
62
|
+
if tab[:navigation_controller]
|
63
|
+
controller = UINavigationController.alloc.initWithRootViewController(view_controller)
|
64
|
+
else
|
65
|
+
controller = view_controller
|
66
|
+
end
|
67
|
+
|
68
|
+
view_controller.tabBarItem = self.tabBarItem(tab)
|
69
|
+
view_controller.tabBarItem.title = view_controller.title unless tab[:title]
|
70
|
+
|
71
|
+
return controller
|
72
|
+
end
|
73
|
+
|
74
|
+
def tab_bar_item(tab)
|
75
|
+
warn "[DEPRECATION] `TabBar.tab_bar_item` is deprecated. Use `tab_bar_item` in ScreenTabs instead."
|
76
|
+
title = "Untitled"
|
77
|
+
title = tab[:title] if tab[:title]
|
78
|
+
tab[:tag] ||= @current_tag ||= 0
|
79
|
+
@current_tag = tab[:tag] + 1
|
80
|
+
|
81
|
+
tab_bar_item = tab_bar_icon(tab[:system_icon], tab[:tag]) if tab[:system_icon]
|
82
|
+
tab_bar_item = tab_bar_icon_custom(title, tab[:icon], tab[:tag]) if tab[:icon]
|
83
|
+
|
84
|
+
tab_bar_item.badgeValue = tab[:badge_number].to_s unless tab[:badge_number].nil? || tab[:badge_number] <= 0
|
85
|
+
|
86
|
+
return tab_bar_item
|
87
|
+
end
|
88
|
+
|
89
|
+
def select(tab_bar_controller, title: title)
|
90
|
+
warn "[DEPRECATION] `TabBar.select` is deprecated. Use `open_tab` in ScreenTabs instead."
|
91
|
+
root_controller = nil
|
92
|
+
tab_bar_controller.viewControllers.each do |vc|
|
93
|
+
if vc.tabBarItem.title == title
|
94
|
+
tab_bar_controller.selectedViewController = vc
|
95
|
+
root_controller = vc
|
96
|
+
break
|
97
|
+
end
|
98
|
+
end
|
99
|
+
root_controller
|
100
|
+
end
|
101
|
+
|
102
|
+
def select(tab_bar_controller, tag: tag)
|
103
|
+
warn "[DEPRECATION] `TabBar.select:tag:` is deprecated. Use `open_tab` in ScreenTabs instead."
|
104
|
+
tab_bar_controller.selectedIndex = tag
|
105
|
+
end
|
106
|
+
|
107
|
+
def replace_current_item(tab_bar_controller, view_controller: vc)
|
108
|
+
warn "[DEPRECATION] `TabBar.replace_current_item` is deprecated. Use `replace_current_item` in ScreenTabs instead."
|
109
|
+
controllers = NSMutableArray.arrayWithArray(tab_bar_controller.viewControllers)
|
110
|
+
controllers.replaceObjectAtIndex(tab_bar_controller.selectedIndex, withObject: vc)
|
111
|
+
tab_bar_controller.viewControllers = controllers
|
112
|
+
end
|
113
|
+
end
|
114
|
+
end
|
115
|
+
end
|
@@ -0,0 +1,39 @@
|
|
1
|
+
module ProMotion
|
2
|
+
module ViewHelper
|
3
|
+
def set_attributes(element, args = {})
|
4
|
+
args.each do |k, v|
|
5
|
+
if v.is_a? Hash
|
6
|
+
# TODO: Do this recursively
|
7
|
+
v.each do |k2, v2|
|
8
|
+
sub_element = element.send("#{k}")
|
9
|
+
sub_element.send("#{k2}=", v2) if sub_element.respond_to?("#{k2}=")
|
10
|
+
end
|
11
|
+
elsif v.is_a? Array
|
12
|
+
element.send("#{k}", *v) if element.respond_to?("#{k}")
|
13
|
+
else
|
14
|
+
element.send("#{k}=", v) if element.respond_to?("#{k}=")
|
15
|
+
end
|
16
|
+
end
|
17
|
+
element
|
18
|
+
end
|
19
|
+
|
20
|
+
def frame_from_array(array)
|
21
|
+
return CGRectMake(array[0], array[1], array[2], array[3]) if array.length == 4
|
22
|
+
Console.log(" - frame_from_array expects an array with four elements: [x, y, width, height]", withColor: Console::RED_COLOR)
|
23
|
+
CGRectZero
|
24
|
+
end
|
25
|
+
|
26
|
+
def content_height(view)
|
27
|
+
height = 0
|
28
|
+
view.subviews.each do |sub_view|
|
29
|
+
next if sub_view.isHidden
|
30
|
+
y = sub_view.frame.origin.y
|
31
|
+
h = sub_view.frame.size.height
|
32
|
+
if (y + h) > height
|
33
|
+
height = y + h
|
34
|
+
end
|
35
|
+
end
|
36
|
+
height
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|