motion-hybrid 0.0.3 → 0.0.4

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 4a5debbc27413f3816739686e3725174437fb193
4
- data.tar.gz: c39c42c2fc5cf0a45e7e434e7760c7307d9984bf
3
+ metadata.gz: 1166d97948ca1aab9c9d25fd3ad29a7246a9765c
4
+ data.tar.gz: 1354f01d5146006199177ca31b5085dcb2c80a80
5
5
  SHA512:
6
- metadata.gz: c8a7379aa14f3b508daa08db838c0034af3608ee8ad4f2f4a2c2ebcd0122b61081a8a457f20ae8557e8d3e554c601ef6119901832460e13e68521f151811565f
7
- data.tar.gz: b50b94de5d4897d29b46b5e34e7bdf9d07f8d56488d80bfc9e20862baf9a4ebe37a4a262b4dc36ef17c29849bc00c5f644c8ba530cb95df67208a5e414c6f07e
6
+ metadata.gz: 6e023a1082b61452efc640041812eb0f6736e627b5df879153731f008e3275881239c54ee6440c9bc6480e4887c5f44bf07d011e6c2a21dc8e569f4c06aeb025
7
+ data.tar.gz: 53cdaa93fe775e2c046405c44a0cb9016cbeac3a3775b59d232fbac0f393482d853763ed2fd25dd194829dda83f57f8d397a2c9f49e3b5b5bcfeafea4949976b
data/README.md CHANGED
@@ -29,17 +29,13 @@ class BaseScreen < MotionHybrid::Screen
29
29
  end
30
30
  ```
31
31
 
32
- Instantiate one or more screens and set their paths:
32
+ Instantiate a screen and set the initial path:
33
33
 
34
34
  ```ruby
35
35
  # app/app_delegate.rb
36
36
  class AppDelegate < PM::Delegate
37
37
  def on_load(app, options)
38
- BaseScreen.sync_sessions do
39
- @screen_1 = BaseScreen.new(nav_bar: true, path: '/balvig', tab_bar: { title: 'Balvig', icon: :users })
40
- @screen_2 = BaseScreen.new(nav_bar: true, path: '/rubymotion', tab-bar: { title: 'Rubymotion', icon: :gear })
41
- open_tab_bar @screen_1, @screen_2
42
- end
38
+ open BaseScreen.new(nav_bar: true, path: '/balvig'
43
39
  end
44
40
  end
45
41
  ```
@@ -121,10 +117,10 @@ class BaseScreen < MotionHybrid::Screen
121
117
  route /^mailto:/ do
122
118
  BW::Mail.compose(to: 'bob@example.com', subject: 'In app emailing', message: 'Hi!', animated: true)
123
119
  end
124
-
120
+
125
121
  # ask for push nofitication permisions when user hits '/setup' url
126
122
  route '/setup' do
127
- app_delegate.register_for_push_notifications :badge, :sound, :alert
123
+ App.delegate.register_for_push_notifications :badge, :sound, :alert
128
124
  end
129
125
  end
130
126
  ```
data/app/app_delegate.rb CHANGED
@@ -1,11 +1,6 @@
1
1
  class AppDelegate < PM::Delegate
2
2
  def on_load(app, options)
3
3
  return true if App.environment == 'test'
4
-
5
- BaseScreen.sync_sessions do
6
- @screen_1 = BaseScreen.new(nav_bar: true, path: '/index.html', tab_bar: { title: 'Welcome', icon: :users })
7
- @screen_2 = BaseScreen.new(nav_bar: true, path: '/refreshable.html', tab_bar: { title: 'Refreshable', icon: :cog })
8
- open_tab_bar @screen_1, @screen_2
9
- end
4
+ open BaseScreen.new(nav_bar: true, path: '/index.html')
10
5
  end
11
6
  end
@@ -4,6 +4,12 @@ module MotionHybrid
4
4
 
5
5
  included do
6
6
 
7
+ # Trigger dom-loaded events
8
+ route 'motionhybrid://ready' do
9
+ dom_loaded
10
+ true
11
+ end
12
+
7
13
  # All clicked GET-links are pushed
8
14
  route /.*/ do |request|
9
15
  push(request.url) if request.http_method == 'GET' && request.type == UIWebViewNavigationTypeLinkClicked
@@ -26,7 +32,7 @@ module MotionHybrid
26
32
 
27
33
  # Modals are closed if they encounter the url from which they were spawned from
28
34
  route /.*/ do |request|
29
- close_screen if presented_from?(request.url)
35
+ close if presented_from?(request.url)
30
36
  end
31
37
 
32
38
  end
@@ -41,20 +41,46 @@ module MotionHybrid
41
41
  end
42
42
 
43
43
  def set_buttons
44
- set_nav_bar_left_button nil, system_item: UIBarButtonSystemItemStop, action: 'close_screen' if bridge.nav_bar_left_button.present?
45
- set_nav_bar_right_button Icon.new(:cog, 18), action: 'on_nav_bar_right_button_click' if bridge.nav_bar_right_button.present?
44
+ set_button :left, bridge.nav_bar_buttons.left
45
+ set_button :right, bridge.nav_bar_buttons.right
46
46
  end
47
47
 
48
- def on_nav_bar_right_button_click
49
- if bridge.nav_bar_right_button.link
50
- bridge.click(:nav_bar_right_button)
51
- else
52
- UIActionSheet.alert nil, buttons: bridge.nav_bar_right_button.options do |pressed, index|
53
- bridge.click_child(:nav_bar_right_button, index)
48
+ def set_button(side, button)
49
+ return unless button
50
+ icon = button.icon ? Icon.new(button.icon, 20) : nil
51
+ send "set_nav_bar_#{side}_button", icon, action: "on_nav_bar_#{side}_button_click"
52
+ end
53
+
54
+ def on_nav_bar_button_click(side)
55
+ button = bridge.nav_bar_buttons.send(side)
56
+ if button.options.any?
57
+ UIActionSheet.alert nil, buttons: button.options do |pressed, index|
58
+ index = remap_index(index, button.options)
59
+ bridge.click_child(button.id, index)
54
60
  end
61
+ else
62
+ bridge.click(button.id)
55
63
  end
56
64
  end
57
65
 
66
+ # iOS button order and actual order of buttons on screen are not the same
67
+ def remap_index(index, options)
68
+ if index == options.length - 1
69
+ 0
70
+ else
71
+ index + 1
72
+ end
73
+ end
74
+
75
+
76
+ def on_nav_bar_left_button_click
77
+ on_nav_bar_button_click(:left)
78
+ end
79
+
80
+ def on_nav_bar_right_button_click
81
+ on_nav_bar_button_click(:right)
82
+ end
83
+
58
84
  def set_refresher
59
85
  if bridge.refreshable && !refresher
60
86
  self.refresher = UIRefreshControl.alloc.init
@@ -41,27 +41,26 @@ module MotionHybrid
41
41
  @url = current_url
42
42
  load_bridge
43
43
  reload_dependents if needs_reload?
44
- end_transitions
44
+ stop_transitions
45
45
  end
46
46
 
47
47
  def load_failed(error)
48
48
  unless [102, -999].include?(error.code) #http://stackoverflow.com/questions/19487330/failed-to-load-webpage-error-nsurlerrordomain-error-999
49
- end_transitions
50
- show_error(error)
49
+ stop_transitions
50
+ on_error(error) if respond_to?(:on_error)
51
+ PM.logger.warn error
51
52
  end
52
53
  end
53
54
 
54
- def close_screen
55
- reload_dependents if needs_reload?
56
- super
57
- end
58
-
59
55
  def reset!
60
- dismissViewControllerAnimated(false, completion: nil)
61
- navigation_controller.popToRootViewControllerAnimated(false)
56
+ return_to_root
62
57
  load_initial_url
63
58
  end
64
59
 
60
+ def return_to_root
61
+ close_nav_screen(animated: false) if nav_bar?
62
+ end
63
+
65
64
  def on_request(nsurlrequest, type)
66
65
  process_request Request.new(nsurlrequest, type)
67
66
  end
@@ -71,10 +70,16 @@ module MotionHybrid
71
70
  process_request Request.new(self.class.request_for(new_path), UIWebViewNavigationTypeLinkClicked)
72
71
  end
73
72
 
73
+ # overrides Promotion method to set more sensible timeout default
74
+ def open_url(url)
75
+ url = url.is_a?(NSURL) ? url : NSURL.URLWithString(url)
76
+ request = NSURLRequest.requestWithURL(url, cachePolicy: NSURLRequestUseProtocolCachePolicy, timeoutInterval: 20)
77
+ web.loadRequest request
78
+ end
79
+
74
80
  private
75
81
 
76
82
  def process_request(request)
77
- return dom_loaded && false if request.url == 'motionhybrid://ready'
78
83
  @needs_reload = true if request.http_method != 'GET'
79
84
 
80
85
  if router.process(request)
@@ -89,7 +94,9 @@ module MotionHybrid
89
94
  view_options = options.slice!(:hide_tab_bar)
90
95
  options[:modal] = view_options[:modal]
91
96
  view_options.reverse_merge!(url: url, modal: modal?, transition_style: transition_style)
92
- open self.class.new(view_options), options
97
+ new_view = self.class.new(view_options)
98
+ open(new_view, options)
99
+ new_view
93
100
  end
94
101
 
95
102
  def load_initial_url
@@ -104,15 +111,7 @@ module MotionHybrid
104
111
  @router ||= Router.new(self)
105
112
  end
106
113
 
107
- def show_error(error)
108
- PM.logger.warn error
109
- BW::UIAlertView.default(title: 'Could not connect', message: error.localizedDescription, buttons: ['Cancel', 'Try Again']) do |alert|
110
- reset! if alert.clicked_button.index > 0
111
- end.show
112
- end
113
-
114
114
  module ClassMethods
115
-
116
115
  def url_for(path)
117
116
  "#{root_url}#{path}"
118
117
  end
@@ -132,6 +131,5 @@ module MotionHybrid
132
131
  end
133
132
  end
134
133
  end
135
-
136
134
  end
137
135
  end
@@ -0,0 +1,16 @@
1
+ module MotionHybrid
2
+ module Releasable
3
+
4
+ def view_will_disappear(animated)
5
+ @should_release = !nav_bar? || !navigationController.viewControllers.include?(self)
6
+ end
7
+
8
+ def view_did_disappear(animated)
9
+ if @should_release
10
+ webview.removeFromSuperview
11
+ webview.release
12
+ end
13
+ end
14
+
15
+ end
16
+ end
@@ -37,7 +37,7 @@ module MotionHybrid
37
37
  end
38
38
 
39
39
  def set_tab_bar_options
40
- set_tab_bar_item title: @tab_bar[:title], icon: Icon.new(@tab_bar[:icon], 25) if @tab_bar
40
+ set_tab_bar_item title: @tab_bar[:title], icon: Icon.new(@tab_bar[:icon], 24) if @tab_bar
41
41
  end
42
42
 
43
43
  def remove_back_button_label
@@ -16,7 +16,7 @@ module MotionHybrid
16
16
  webview.scrollView.fade_out(duration: 0.2, opacity: 0.5)
17
17
  end
18
18
 
19
- def end_transitions
19
+ def stop_transitions
20
20
  @loading = false
21
21
  refresher.endRefreshing if refresher
22
22
  spinner.hide
@@ -11,9 +11,10 @@ module MotionHybrid
11
11
 
12
12
  # Inefficient, but will do for now
13
13
  def dependents
14
- dependents = all_views - [self]
15
- dependents = dependents | [parent_screen] if parent_screen
16
- dependents
14
+ #dependents = all_views - [self]
15
+ #dependents = dependents | parent_screens
16
+ #dependents
17
+ parent_screens
17
18
  end
18
19
 
19
20
  def all_views
@@ -24,5 +25,14 @@ module MotionHybrid
24
25
  @needs_reload
25
26
  end
26
27
 
28
+ def parent_screens
29
+ parent_screens = []
30
+ screen = self
31
+ while screen = screen.parent_screen
32
+ parent_screens << screen
33
+ end
34
+ parent_screens
35
+ end
36
+
27
37
  end
28
38
  end
@@ -12,9 +12,8 @@ module MotionHybrid
12
12
  js_api("clicked('#{target}')")
13
13
  end
14
14
 
15
- def click_child(parent, child_index)
16
- child_index = remap_index(child_index)
17
- js_api("clicked('#{parent}', #{child_index})") if child_index > 0
15
+ def click_child(target, index)
16
+ js_api("clicked('#{target}', #{index})") if index > 0
18
17
  end
19
18
 
20
19
  private
@@ -31,15 +30,6 @@ module MotionHybrid
31
30
  bridge_hash.send(method)
32
31
  end
33
32
 
34
- # iOS button order and actual order of buttons on screen are not the same
35
- def remap_index(index)
36
- if index == nav_bar_right_button.options.length - 1
37
- 0
38
- else
39
- index + 1
40
- end
41
- end
42
-
43
33
  def js_api(command)
44
34
  @screen.evaluate("MotionHybrid.#{command};").to_s
45
35
  end
@@ -5,6 +5,7 @@ module MotionHybrid
5
5
  include Navigatable
6
6
  include BasicRoutes
7
7
  include Presentable
8
+ include Releasable
8
9
  include Styleable
9
10
  include Syncable
10
11
  include Transitionable
@@ -1,3 +1,3 @@
1
1
  module MotionHybrid
2
- VERSION = "0.0.3"
2
+ VERSION = "0.0.4"
3
3
  end
@@ -1,6 +1,7 @@
1
1
  module MotionHybrid
2
2
  class Icon
3
3
  def self.new(name, size, options = {})
4
+ name = name.underscore.camelize(:lower) # f.ex trash-o becomes trashO
4
5
  icon = FAKFontAwesome.send("#{name}IconWithSize", size)
5
6
  icon.addAttribute(NSForegroundColorAttributeName, value: options[:color]) if options[:color]
6
7
  icon.imageWithSize(CGSizeMake(size, size))
@@ -24,7 +24,7 @@ module MotionHybrid
24
24
  end
25
25
 
26
26
  def spin_animation
27
- spin_animation = RTSpinKitView.alloc.initWithStyle(RTSpinKitViewStyleBounce, color: '#323667'.to_color) # TODO: Style from CSS
27
+ spin_animation = RTSpinKitView.alloc.initWithStyle(RTSpinKitViewStyleWanderingCubes, color: '#323667'.to_color) # TODO: Style from CSS
28
28
  spin_animation.startAnimating
29
29
  spin_animation
30
30
  end
@@ -5,17 +5,18 @@ module MotionHybrid
5
5
  def initialize(title, subtitle = nil)
6
6
  options = {
7
7
  'kCRToastTextKey' => title,
8
- 'kCRToastFontKey' => UIFont.boldSystemFontOfSize(15),
8
+ 'kCRToastFontKey' => UIFont.systemFontOfSize(18),
9
9
  'kCRToastTextColorKey' => TEXT_COLOR,
10
10
  'kCRToastBackgroundColorKey' => BACKGROUND_COLOR,
11
- 'kCRToastSubtitleFontKey' => UIFont.boldSystemFontOfSize(15),
11
+ 'kCRToastSubtitleFontKey' => UIFont.systemFontOfSize(13),
12
12
  'kCRToastSubtitleTextColorKey' => TEXT_COLOR,
13
13
  'kCRToastTextAlignmentKey' => NSTextAlignmentLeft,
14
14
  'kCRToastSubtitleTextAlignmentKey' => NSTextAlignmentLeft,
15
- 'kCRToastNotificationTypeKey' => CRToastTypeNavigationBar
15
+ 'kCRToastNotificationTypeKey' => CRToastTypeNavigationBar,
16
+ 'kCRToastImageKey' => Icon.new(:check, 20, color: TEXT_COLOR)
16
17
  }
17
18
 
18
- options.merge!('kCRToastFontKey' => UIFont.systemFontOfSize(13), 'kCRToastSubtitleTextKey' => subtitle, 'kCRToastTimeIntervalKey' => 3) if subtitle.present?
19
+ options.merge!('kCRToastFontKey' => UIFont.boldSystemFontOfSize(17), 'kCRToastSubtitleTextKey' => subtitle, 'kCRToastTimeIntervalKey' => 5) if subtitle.present?
19
20
 
20
21
  CRToastManager.showNotificationWithOptions options, completionBlock: nil
21
22
  end
data/lib/motion-hybrid.rb CHANGED
@@ -6,7 +6,6 @@ require 'motion-support'
6
6
  require 'ProMotion'
7
7
  require 'sugarcube-classic'
8
8
 
9
-
10
9
  Motion::Require.all(Dir.glob(File.expand_path('../motion-hybrid/**/*.rb', __FILE__)))
11
10
 
12
11
  Motion::Project::App.setup do |app|
@@ -5,20 +5,20 @@ class window.MotionHybrid
5
5
  params = {}
6
6
  params.title = bridge.find('h1').text()
7
7
  params.subtitle = bridge.find('h2').text()
8
- params.nav_bar_left_button = parseButton bridge.find('#nav_bar_left_button')
9
- params.nav_bar_right_button = parseButton bridge.find('#nav_bar_right_button')
10
8
  params.flash = parseFlash bridge.find('.flash')
9
+ params.nav_bar_buttons = {}
10
+ params.nav_bar_buttons.left = parseButton bridge.find('#nav_bar_left_button')
11
+ params.nav_bar_buttons.right = parseButton bridge.find('#nav_bar_right_button')
11
12
 
12
13
  params.refreshable = $('[data-refreshable]').length > 0
13
-
14
14
  JSON.stringify params
15
15
 
16
- parseButton = (button) ->
17
- { link: button.attr('href'), options: button.children().map(-> this.innerText).get() } if button.length
18
-
19
16
  parseFlash = (flash) ->
20
17
  { title: flash.find('h3').text() || flash.text().trim(), subtitle: flash.find('p').text() } if flash.length
21
18
 
19
+ parseButton = (button) ->
20
+ { id: button.attr('id'), options: button.children().map(-> this.innerText).get(), icon: button.data('icon') } if button.length
21
+
22
22
  @clicked: (target, childIndex) ->
23
23
  target = $("##{target}")
24
24
  target = target.children() if childIndex
@@ -11,29 +11,32 @@
11
11
  params = {};
12
12
  params.title = bridge.find('h1').text();
13
13
  params.subtitle = bridge.find('h2').text();
14
- params.nav_bar_left_button = parseButton(bridge.find('#nav_bar_left_button'));
15
- params.nav_bar_right_button = parseButton(bridge.find('#nav_bar_right_button'));
16
14
  params.flash = parseFlash(bridge.find('.flash'));
15
+ params.nav_bar_buttons = {};
16
+ params.nav_bar_buttons.left = parseButton(bridge.find('#nav_bar_left_button'));
17
+ params.nav_bar_buttons.right = parseButton(bridge.find('#nav_bar_right_button'));
17
18
  params.refreshable = $('[data-refreshable]').length > 0;
18
19
  return JSON.stringify(params);
19
20
  };
20
21
 
21
- parseButton = function(button) {
22
- if (button.length) {
22
+ parseFlash = function(flash) {
23
+ if (flash.length) {
23
24
  return {
24
- link: button.attr('href'),
25
- options: button.children().map(function() {
26
- return this.innerText;
27
- }).get()
25
+ title: flash.find('h3').text() || flash.text().trim(),
26
+ subtitle: flash.find('p').text()
28
27
  };
29
28
  }
30
29
  };
31
30
 
32
- parseFlash = function(flash) {
33
- if (flash.length) {
31
+ parseButton = function(button) {
32
+ if (button.length) {
34
33
  return {
35
- title: flash.find('h3').text() || flash.text().trim(),
36
- subtitle: flash.find('p').text()
34
+ id: button.attr('id'),
35
+ link: button.attr('href'),
36
+ options: button.children().map(function() {
37
+ return this.innerText;
38
+ }).get(),
39
+ icon: button.data('icon')
37
40
  };
38
41
  }
39
42
  };
@@ -26,8 +26,8 @@ Gem::Specification.new do |spec|
26
26
  spec.add_dependency 'ProMotion'
27
27
  spec.add_dependency 'sugarcube'
28
28
 
29
- spec.add_development_dependency "bundler", "~> 1.5"
30
- spec.add_development_dependency "rake"
29
+ spec.add_development_dependency 'bundler', '~> 1.5'
30
+ spec.add_development_dependency 'rake'
31
31
  spec.add_development_dependency 'motion-redgreen'
32
32
  spec.add_development_dependency 'webstub'
33
33
  end
@@ -1,7 +1,6 @@
1
1
  <!DOCTYPE html>
2
2
  <html lang="en">
3
3
  <head>
4
-
5
4
  <meta name="viewport" content="initial-scale=1, maximum-scale=1, user-scalable=no, target-densityDpi=device-dpi" />
6
5
  <link href="default.css" media="all" rel="stylesheet" />
7
6
  <link href="ratchet.css" media="all" rel="stylesheet" />
@@ -13,7 +13,7 @@
13
13
  <body>
14
14
  <div id="motion_hybrid_bridge">
15
15
  <h1>Page 2</h1>
16
- <div id="nav_bar_right_button">
16
+ <div id="nav_bar_right_button" data-icon='trash-o'>
17
17
  <a href="#">Cancel</a>
18
18
  <a href="#">Delete</a>
19
19
  <a href="index_3.html#self">Page with alert</a>
@@ -61,20 +61,6 @@ describe 'MotionHybrid::BasicRoutes' do
61
61
  end
62
62
  end
63
63
 
64
- #it "#hide_tab_bar link" do
65
- #stub_request(:get, "http://github.com/").to_return(body: '<a href="/page_2#hide_tab_bar" id="link">To page 2</a>')
66
- #stub_request(:get, "http://github.com/page_2#hide_tab_bar").to_return(body: 'This is page 2')
67
-
68
- #wait 0.6 do
69
- #@screen.evaluate('document.getElementById("link").click();')
70
- #wait 0.6 do
71
- #@screen.navigationController.viewControllers.count.should == 2
72
- #@screen.navigationController.viewControllers.last.html.include?('This is page 2').should == true
73
- #end
74
- #end
75
- #end
76
- #
77
- #
78
64
  def current_view
79
65
  top_view = @screen.navigationController.topViewController
80
66
  top_view.presentedViewController.nil? ? top_view : top_view.presentedViewController.viewControllers.last
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: motion-hybrid
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.3
4
+ version: 0.0.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jens Balvig
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-05-27 00:00:00.000000000 Z
11
+ date: 2014-07-01 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bubble-wrap
@@ -183,6 +183,7 @@ files:
183
183
  - lib/motion-hybrid/concerns/bridgeable.rb
184
184
  - lib/motion-hybrid/concerns/navigatable.rb
185
185
  - lib/motion-hybrid/concerns/presentable.rb
186
+ - lib/motion-hybrid/concerns/releasable.rb
186
187
  - lib/motion-hybrid/concerns/styleable.rb
187
188
  - lib/motion-hybrid/concerns/syncable.rb
188
189
  - lib/motion-hybrid/concerns/transitionable.rb