formotion 0.0.2 → 0.0.3

Sign up to get free protection for your applications and to get access to all the features.
data/LICENSE ADDED
@@ -0,0 +1,26 @@
1
+ LICENCE
2
+
3
+ MIT: http://clayallsopp.mit-license.org
4
+
5
+ ------------------------------------------------
6
+
7
+ The MIT License (MIT)
8
+ Copyright © 2012 Clay Allsopp <clay.allsopp@gmail.com>
9
+
10
+ Permission is hereby granted, free of charge, to any person obtaining a copy
11
+ of this software and associated documentation files (the “Software”), to deal
12
+ in the Software without restriction, including without limitation the rights
13
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
14
+ copies of the Software, and to permit persons to whom the Software is
15
+ furnished to do so, subject to the following conditions:
16
+
17
+ The above copyright notice and this permission notice shall be included in
18
+ all copies or substantial portions of the Software.
19
+
20
+ THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
21
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
22
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
23
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
24
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
25
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
26
+ THE SOFTWARE.
@@ -74,10 +74,11 @@ class AppDelegate
74
74
  }]
75
75
  })
76
76
 
77
- @navigation_controller = UINavigationController.alloc.init
77
+ @navigation_controller = UINavigationController.alloc.init
78
78
 
79
79
  @view_controller = Formotion::FormController.alloc.initWithForm(@form)
80
80
  @view_controller.form.on_submit do |form|
81
+ form.active_row && form.active_row.text_field.resignFirstResponder
81
82
  alert = UIAlertView.alloc.init
82
83
  alert.title = "@form.render"
83
84
  alert.message = @form.render.to_s
@@ -6,15 +6,14 @@
6
6
  #
7
7
  #################
8
8
  module Formotion
9
- class FormController < UIViewController
9
+ class FormController < UITableViewController
10
10
  attr_accessor :form
11
- attr_reader :table_view
12
11
 
13
12
  # Initializes controller with a form
14
13
  # PARAMS form.is_a? [Hash, Formotion::Form]
15
14
  # RETURNS An instance of Formotion::FormController
16
15
  def initWithForm(form)
17
- self.initWithNibName(nil, bundle: nil)
16
+ self.initWithStyle(UITableViewStyleGrouped)
18
17
  self.form = form
19
18
  self
20
19
  end
@@ -33,22 +32,9 @@ module Formotion
33
32
  def viewDidLoad
34
33
  super
35
34
 
36
- # via https://gist.github.com/330916, could be wrong.
37
- navBarHeight = self.navigationController && (self.navigationController.isNavigationBarHidden ? 0.0 : self.navigationController.navigationBar.bounds.size.height)
38
- navBarHeight ||= 0
39
- frame = self.view.frame
40
- frame.size.height = frame.size.height - navBarHeight - tab_bar_height
41
- self.view.frame = frame
42
-
43
35
  self.title = self.form.title
44
36
 
45
- NSNotificationCenter.defaultCenter.addObserver(self, selector:'keyboardWillHideOrShow:', name:UIKeyboardWillHideNotification, object:nil);
46
- NSNotificationCenter.defaultCenter.addObserver(self, selector:'keyboardWillHideOrShow:', name:UIKeyboardWillShowNotification, object:nil);
47
-
48
- @table_view = UITableView.alloc.initWithFrame(self.view.bounds, style: UITableViewStyleGrouped)
49
- self.view.addSubview @table_view
50
-
51
- # Triggers this block when the enter key is pressed
37
+ # Triggers this block when the enter key is pressed
52
38
  # while editing the last text field.
53
39
  @form.sections[-1] && @form.sections[-1].rows[-1].on_enter do |row|
54
40
  if row.text_field
@@ -62,46 +48,5 @@ module Formotion
62
48
  # and reloads the data.
63
49
  @form.controller = self
64
50
  end
65
-
66
- # This re-sizes + scrolls the tableview to account for the keyboard size.
67
- # TODO: Test this on iPads, etc.
68
- def keyboardWillHideOrShow(note)
69
- last_note = @keyboard_state
70
- @keyboard_state = note.name
71
- if last_note == @keyboard_state
72
- return
73
- end
74
-
75
- userInfo = note.userInfo
76
- duration = userInfo[UIKeyboardAnimationDurationUserInfoKey].doubleValue
77
- curve = userInfo[UIKeyboardAnimationCurveUserInfoKey].intValue
78
- keyboardFrame = userInfo[UIKeyboardFrameEndUserInfoKey].CGRectValue
79
-
80
- view_frame = self.view.frame;
81
-
82
- if @keyboard_state == UIKeyboardWillHideNotification
83
- view_frame.size.height = self.view.bounds.size.height
84
- else
85
- view_frame.size.height -= keyboardFrame.size.height
86
- view_frame.size.height += tab_bar_height
87
- end
88
-
89
- UIView.beginAnimations(nil, context: nil)
90
- UIView.setAnimationDuration(duration)
91
- UIView.setAnimationDelay(0)
92
- UIView.setAnimationCurve(curve)
93
- UIView.setAnimationBeginsFromCurrentState(true)
94
-
95
- @table_view.frame = view_frame
96
- @form.active_row = @form.active_row
97
-
98
- UIView.commitAnimations
99
- end
100
-
101
- private
102
- def tab_bar_height
103
- tabBarHeight = self.tabBarController && self.tabBarController.tabBar.bounds.size.height
104
- tabBarHeight ||= 0
105
- end
106
51
  end
107
52
  end
@@ -17,7 +17,7 @@ module Formotion
17
17
  # Table Methods
18
18
  def controller=(controller)
19
19
  @controller = controller
20
- self.table = controller.table_view
20
+ self.table = controller.respond_to?(:table_view) ? controller.table_view : controller.tableView
21
21
  end
22
22
 
23
23
  def table=(table_view)
@@ -1,3 +1,3 @@
1
1
  module Formotion
2
- VERSION = "0.0.2"
2
+ VERSION = "0.0.3"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: formotion
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.0.3
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-07-01 00:00:00.000000000 Z
12
+ date: 2012-07-03 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: bubble-wrap
@@ -52,6 +52,7 @@ extra_rdoc_files: []
52
52
  files:
53
53
  - .gitignore
54
54
  - Formotion.gemspec
55
+ - LICENSE
55
56
  - README.md
56
57
  - Rakefile
57
58
  - app/app_delegate.rb