tgios 0.0.24 → 0.0.25
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +8 -8
- data/Gemfile.lock +1 -1
- data/lib/tgios/ui_table_view_model_binding.rb +8 -100
- data/lib/tgios/ui_table_view_model_list_binding.rb +9 -7
- data/lib/tgios/ui_table_view_utility_binding.rb +118 -0
- data/lib/tgios/ui_text_field_binding.rb +21 -2
- data/lib/tgios/version.rb +1 -1
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,15 +1,15 @@
|
|
1
1
|
---
|
2
2
|
!binary "U0hBMQ==":
|
3
3
|
metadata.gz: !binary |-
|
4
|
-
|
4
|
+
Y2Q3OGI0NGE2MTExMzg1Y2Q4ODY3ZDJlODM3NzFmMzcwZmQ1ZmE2NQ==
|
5
5
|
data.tar.gz: !binary |-
|
6
|
-
|
6
|
+
YzNjODRlY2MzZTZhNTcxNDNmZjhjNzdhNDA0Nzc0YzcxNzgwZmY4Yg==
|
7
7
|
SHA512:
|
8
8
|
metadata.gz: !binary |-
|
9
|
-
|
10
|
-
|
11
|
-
|
9
|
+
MjA0YjY1NzYyOGU0M2Y2ZjY2OTgxYzY4YzY2NmY4NTg1NDg3OTU0ZmYxN2Yx
|
10
|
+
NmYyYTA1NTU1N2I0NDNjNjNlN2VhNWU1MTdjZTljMDNkMmI2ZThhYmM4MWU1
|
11
|
+
MjU2ZGViZTMwNzdlMmIwZmNmMGM3MDFiOTQwYjJhZGEwYTVlZDI=
|
12
12
|
data.tar.gz: !binary |-
|
13
|
-
|
14
|
-
|
15
|
-
|
13
|
+
NmQwZmZjNjI0YmZjNzI3NmYyMmE1NGIzODFkYjZmYzg1MTc3MTg5NWMzYzQz
|
14
|
+
YjI3MDVkZDQzN2YxMjEyNTgyODc5MjBjZWIyYjA4Y2YyNWFiNzFhYTY1ZTY1
|
15
|
+
ZjhiODhlYzU2YjY0YmU3ZDA2M2FjYTAyMDk5ODZlMWVjYWQzMWQ=
|
data/Gemfile.lock
CHANGED
@@ -48,6 +48,7 @@ module Tgios
|
|
48
48
|
self.model=model
|
49
49
|
@tableView.dataSource=self
|
50
50
|
@tableView.delegate=self
|
51
|
+
@table_utility_binding = UITableViewUtilityBinding.new.bind(@tableView)
|
51
52
|
self
|
52
53
|
end
|
53
54
|
|
@@ -134,7 +135,7 @@ module Tgios
|
|
134
135
|
end
|
135
136
|
text_field_binding.on(:begin_edit) do |model, field_name, event|
|
136
137
|
@events[:text_begin_edit].call(model, field_name, event) unless @events[:text_begin_edit].nil?
|
137
|
-
|
138
|
+
@table_utility_binding.will_scroll_to_index_path(index_path)
|
138
139
|
end
|
139
140
|
text_field_binding.update(ui_field, @model)
|
140
141
|
ui_field.becomeFirstResponder if field_set[:first_responder] # TODO: not work when cell is not visible, buggy
|
@@ -186,7 +187,7 @@ module Tgios
|
|
186
187
|
end
|
187
188
|
text_field_binding.on(:begin_edit) do |model, field_name, event|
|
188
189
|
@events[:text_begin_edit].call(model, field_name, event) unless @events[:text_begin_edit].nil?
|
189
|
-
|
190
|
+
@table_utility_binding.will_scroll_to_index_path(index_path)
|
190
191
|
end
|
191
192
|
text_field_binding.update(ui_field, @model)
|
192
193
|
ui_field.becomeFirstResponder if field_set[:first_responder] # TODO: not work when cell is not visible, buggy
|
@@ -228,7 +229,7 @@ module Tgios
|
|
228
229
|
@selected_field_set=field_set_at_index_path(index_path)
|
229
230
|
@events[:touch_row].call(@selected_field_set, {tableView: tableView, didSelectRowAtIndexPath:index_path}) if @events.has_key?(:touch_row)
|
230
231
|
if @selected_field_set[:scroll]
|
231
|
-
|
232
|
+
@table_utility_binding.will_scroll_to_index_path(index_path)
|
232
233
|
end
|
233
234
|
|
234
235
|
field_set = @selected_field_set
|
@@ -292,108 +293,17 @@ module Tgios
|
|
292
293
|
end
|
293
294
|
|
294
295
|
def listen_to_keyboard
|
295
|
-
@
|
296
|
-
NSNotificationCenter.defaultCenter.addObserver(self, selector: 'keyboardWillShow:', name: UIKeyboardWillShowNotification, object: nil)
|
297
|
-
NSNotificationCenter.defaultCenter.addObserver(self, selector: 'keyboardWillHide:', name: UIKeyboardWillHideNotification, object: nil)
|
296
|
+
@table_utility_binding.listen_to_keyboard
|
298
297
|
end
|
299
298
|
|
300
299
|
def stop_listen_to_keyboard
|
301
|
-
@
|
302
|
-
NSNotificationCenter.defaultCenter.removeObserver(self)
|
303
|
-
end
|
304
|
-
|
305
|
-
def keyboardWillShow(note)
|
306
|
-
shrink_table_view(note)
|
307
|
-
end
|
308
|
-
|
309
|
-
def keyboardWillHide(note)
|
310
|
-
expand_table_view(note)
|
311
|
-
end
|
312
|
-
|
313
|
-
def expand_table_view(note)
|
314
|
-
@expanding = true
|
315
|
-
offset_y = @tableView.contentOffset.y
|
316
|
-
frame_height = @tableView.frame.size.height
|
317
|
-
content_height = @tableView.contentSize.height
|
318
|
-
new_offset_height = nil
|
319
|
-
if frame_height > content_height
|
320
|
-
if offset_y != 0
|
321
|
-
new_offset_height = 0
|
322
|
-
end
|
323
|
-
else
|
324
|
-
bottom_offset = frame_height - content_height + offset_y
|
325
|
-
if bottom_offset > 0
|
326
|
-
new_offset_height = offset_y - bottom_offset
|
327
|
-
end
|
328
|
-
end
|
329
|
-
|
330
|
-
if new_offset_height.nil?
|
331
|
-
reset_content_inset_bottom
|
332
|
-
else
|
333
|
-
curve = note[UIKeyboardAnimationCurveUserInfoKey]
|
334
|
-
duration = note[UIKeyboardAnimationDurationUserInfoKey]
|
335
|
-
@animation_proc = -> {
|
336
|
-
@tableView.setContentOffset([0, new_offset_height])
|
337
|
-
}
|
338
|
-
@completion_proc = lambda { |finished|
|
339
|
-
reset_content_inset_bottom
|
340
|
-
}
|
341
|
-
UIView.animateWithDuration(duration-0.01, delay: 0, options: curve,
|
342
|
-
animations: @animation_proc,
|
343
|
-
completion: @completion_proc)
|
344
|
-
end
|
345
|
-
end
|
346
|
-
|
347
|
-
def shrink_table_view(note)
|
348
|
-
# TODO: don't shrink when table frame bottom is above the keyboard
|
349
|
-
@shrinking = true
|
350
|
-
rect = note[UIKeyboardFrameEndUserInfoKey].CGRectValue
|
351
|
-
if @expanding
|
352
|
-
@shrink_height = rect.size.height
|
353
|
-
else
|
354
|
-
set_content_inset_bottom(rect.size.height)
|
355
|
-
end
|
356
|
-
end
|
357
|
-
|
358
|
-
def reset_content_inset_bottom
|
359
|
-
@tableView.contentInset = UIEdgeInsetsZero
|
360
|
-
@tableView.scrollIndicatorInsets = UIEdgeInsetsZero
|
361
|
-
@expanding = false
|
362
|
-
if @shrink_height
|
363
|
-
set_content_inset_bottom(@shrink_height)
|
364
|
-
@shrink_height = nil
|
365
|
-
end
|
366
|
-
end
|
367
|
-
|
368
|
-
def set_content_inset_bottom(height)
|
369
|
-
@tableView.contentInset = UIEdgeInsetsMake(0,0,height,0)
|
370
|
-
@tableView.scrollIndicatorInsets = UIEdgeInsetsMake(0,0,height,0)
|
371
|
-
@shrinking = false
|
372
|
-
if @index_path_to_scroll
|
373
|
-
scroll_to_index_path(@index_path_to_scroll)
|
374
|
-
@index_path_to_scroll = nil
|
375
|
-
end
|
376
|
-
end
|
377
|
-
|
378
|
-
def will_scroll_to_index_path(index_path)
|
379
|
-
if @scroll_when_editing
|
380
|
-
if @shrinking
|
381
|
-
@index_path_to_scroll = index_path
|
382
|
-
else
|
383
|
-
scroll_to_index_path(index_path)
|
384
|
-
end
|
385
|
-
end
|
386
|
-
end
|
387
|
-
|
388
|
-
def scroll_to_index_path(index_path)
|
389
|
-
@tableView.scrollToRowAtIndexPath(index_path, atScrollPosition: UITableViewScrollPositionBottom, animated: true)
|
390
|
-
@index_path_to_scroll = nil
|
300
|
+
@table_utility_binding.stop_listen_to_keyboard
|
391
301
|
end
|
392
302
|
|
393
303
|
def bindings_prepare_release
|
394
304
|
@bindings.values.each do |binding|
|
395
305
|
binding.prepareForRelease
|
396
|
-
end if @
|
306
|
+
end if @bindings.is_a?(Hash)
|
397
307
|
@tv_bindings.values.each do |binding|
|
398
308
|
binding.prepareForRelease
|
399
309
|
end if @tv_bindings.is_a?(Hash)
|
@@ -401,9 +311,7 @@ module Tgios
|
|
401
311
|
|
402
312
|
def onPrepareForRelease
|
403
313
|
bindings_prepare_release
|
404
|
-
|
405
|
-
@animation_proc=nil
|
406
|
-
@completion_proc=nil
|
314
|
+
@table_utility_binding.prepareForRelease
|
407
315
|
@bindings=nil
|
408
316
|
@tv_bindings=nil
|
409
317
|
@events=nil
|
@@ -4,12 +4,7 @@ module Tgios
|
|
4
4
|
super
|
5
5
|
|
6
6
|
@events={}
|
7
|
-
@events[:build_cell]=->(cell_identifier) {
|
8
|
-
cell = UITableViewCell.value1(cell_identifier)
|
9
|
-
cell.detailTextLabel.adjustsFontSizeToFitWidth = true
|
10
|
-
cell.clipsToBounds = true
|
11
|
-
cell
|
12
|
-
}
|
7
|
+
@events[:build_cell]=->(cell_identifier, type) { build_cell(cell_identifier, type)}
|
13
8
|
@events[:update_cell]=->(field_set, cell, index_path) { update_field(field_set, cell, index_path)}
|
14
9
|
self
|
15
10
|
|
@@ -45,7 +40,7 @@ module Tgios
|
|
45
40
|
cell=tableView.dequeueReusableCellWithIdentifier(cell_identifier)
|
46
41
|
isReusedCell=!cell.nil?
|
47
42
|
|
48
|
-
cell=@events[:build_cell].call(cell_identifier) unless isReusedCell
|
43
|
+
cell=@events[:build_cell].call(cell_identifier, type) unless isReusedCell
|
49
44
|
|
50
45
|
@events[:update_cell].call(field_set, cell, index_path)
|
51
46
|
|
@@ -53,6 +48,13 @@ module Tgios
|
|
53
48
|
|
54
49
|
end
|
55
50
|
|
51
|
+
def build_cell(cell_identifier, type)
|
52
|
+
cell = UITableViewCell.value1(cell_identifier)
|
53
|
+
cell.detailTextLabel.adjustsFontSizeToFitWidth = true
|
54
|
+
cell.clipsToBounds = true
|
55
|
+
cell
|
56
|
+
end
|
57
|
+
|
56
58
|
def update_field(o_field_set, cell, index_path)
|
57
59
|
model = @models[index_path.section]
|
58
60
|
field_set = o_field_set
|
@@ -0,0 +1,118 @@
|
|
1
|
+
module Tgios
|
2
|
+
# common usage:
|
3
|
+
# call listen_to_keyboard in viewWillAppear
|
4
|
+
# call stop_listen_to_keyboard in viewWillDisappear
|
5
|
+
# call will_scroll_to_index_path in text field begin_edit event
|
6
|
+
class UITableViewUtilityBinding < BindingBase
|
7
|
+
def bind(table)
|
8
|
+
@table = WeakRef.new(table)
|
9
|
+
self
|
10
|
+
end
|
11
|
+
|
12
|
+
def listen_to_keyboard
|
13
|
+
@scroll_when_editing = true
|
14
|
+
NSNotificationCenter.defaultCenter.addObserver(self, selector: 'keyboardWillShow:', name: UIKeyboardWillShowNotification, object: nil)
|
15
|
+
NSNotificationCenter.defaultCenter.addObserver(self, selector: 'keyboardWillHide:', name: UIKeyboardWillHideNotification, object: nil)
|
16
|
+
end
|
17
|
+
|
18
|
+
def stop_listen_to_keyboard
|
19
|
+
@scroll_when_editing = false
|
20
|
+
NSNotificationCenter.defaultCenter.removeObserver(self)
|
21
|
+
end
|
22
|
+
|
23
|
+
def keyboardWillShow(note)
|
24
|
+
shrink_table_view(note)
|
25
|
+
end
|
26
|
+
|
27
|
+
def keyboardWillHide(note)
|
28
|
+
expand_table_view(note)
|
29
|
+
end
|
30
|
+
|
31
|
+
def expand_table_view(note)
|
32
|
+
@expanding = true
|
33
|
+
offset_y = @table.contentOffset.y
|
34
|
+
frame_height = @table.frame.size.height
|
35
|
+
content_height = @table.contentSize.height
|
36
|
+
new_offset_height = nil
|
37
|
+
if frame_height > content_height
|
38
|
+
if offset_y != 0
|
39
|
+
new_offset_height = 0
|
40
|
+
end
|
41
|
+
else
|
42
|
+
bottom_offset = frame_height - content_height + offset_y
|
43
|
+
if bottom_offset > 0
|
44
|
+
new_offset_height = offset_y - bottom_offset
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
if new_offset_height.nil?
|
49
|
+
reset_content_inset_bottom
|
50
|
+
else
|
51
|
+
curve = note[UIKeyboardAnimationCurveUserInfoKey]
|
52
|
+
duration = note[UIKeyboardAnimationDurationUserInfoKey]
|
53
|
+
@animation_proc = -> {
|
54
|
+
@table.setContentOffset([0, new_offset_height])
|
55
|
+
}
|
56
|
+
@completion_proc = lambda { |finished|
|
57
|
+
reset_content_inset_bottom
|
58
|
+
}
|
59
|
+
UIView.animateWithDuration(duration-0.01, delay: 0, options: curve,
|
60
|
+
animations: @animation_proc,
|
61
|
+
completion: @completion_proc)
|
62
|
+
end
|
63
|
+
end
|
64
|
+
|
65
|
+
def shrink_table_view(note)
|
66
|
+
# TODO: don't shrink when table frame bottom is above the keyboard
|
67
|
+
@shrinking = true
|
68
|
+
rect = note[UIKeyboardFrameEndUserInfoKey].CGRectValue
|
69
|
+
if @expanding
|
70
|
+
@shrink_height = rect.size.height
|
71
|
+
else
|
72
|
+
set_content_inset_bottom(rect.size.height)
|
73
|
+
end
|
74
|
+
end
|
75
|
+
|
76
|
+
def reset_content_inset_bottom
|
77
|
+
@table.contentInset = UIEdgeInsetsZero
|
78
|
+
@table.scrollIndicatorInsets = UIEdgeInsetsZero
|
79
|
+
@expanding = false
|
80
|
+
if @shrink_height
|
81
|
+
set_content_inset_bottom(@shrink_height)
|
82
|
+
@shrink_height = nil
|
83
|
+
end
|
84
|
+
end
|
85
|
+
|
86
|
+
def set_content_inset_bottom(height)
|
87
|
+
@table.contentInset = UIEdgeInsetsMake(0,0,height,0)
|
88
|
+
@table.scrollIndicatorInsets = UIEdgeInsetsMake(0,0,height,0)
|
89
|
+
@shrinking = false
|
90
|
+
if @index_path_to_scroll
|
91
|
+
scroll_to_index_path(@index_path_to_scroll)
|
92
|
+
@index_path_to_scroll = nil
|
93
|
+
end
|
94
|
+
end
|
95
|
+
|
96
|
+
def will_scroll_to_index_path(index_path)
|
97
|
+
if @scroll_when_editing
|
98
|
+
if @shrinking
|
99
|
+
@index_path_to_scroll = index_path
|
100
|
+
else
|
101
|
+
performSelector('scroll_to_index_path:', withObject: index_path, afterDelay:0.01)
|
102
|
+
end
|
103
|
+
end
|
104
|
+
end
|
105
|
+
|
106
|
+
def scroll_to_index_path(index_path)
|
107
|
+
@table.scrollToRowAtIndexPath(index_path, atScrollPosition: UITableViewScrollPositionBottom, animated: true)
|
108
|
+
@index_path_to_scroll = nil
|
109
|
+
end
|
110
|
+
|
111
|
+
def onPrepareForRelease
|
112
|
+
self.stop_listen_to_keyboard
|
113
|
+
@animation_proc=nil
|
114
|
+
@completion_proc=nil
|
115
|
+
@table=nil
|
116
|
+
end
|
117
|
+
end
|
118
|
+
end
|
@@ -72,6 +72,7 @@ module Tgios
|
|
72
72
|
|
73
73
|
def on(event, &block)
|
74
74
|
@events[event]=block
|
75
|
+
self
|
75
76
|
end
|
76
77
|
|
77
78
|
|
@@ -95,6 +96,24 @@ module Tgios
|
|
95
96
|
@events[:begin_edit].call(@model, @field_name, {text_field: weak_text_field}) unless @events[:begin_edit].nil?
|
96
97
|
end
|
97
98
|
|
99
|
+
def textFieldShouldBeginEditing(textField)
|
100
|
+
if @events[:should_edit].nil?
|
101
|
+
true
|
102
|
+
else
|
103
|
+
weak_text_field=WeakRef.new(textField)
|
104
|
+
@events[:should_edit].call(@model, @field_name, {text_field: weak_text_field})
|
105
|
+
end
|
106
|
+
end
|
107
|
+
|
108
|
+
def textFieldShouldClear(textField)
|
109
|
+
if @events[:should_clear].nil?
|
110
|
+
true
|
111
|
+
else
|
112
|
+
weak_text_field=WeakRef.new(textField)
|
113
|
+
@events[:should_clear].call(@model, @field_name, {text_field: weak_text_field})
|
114
|
+
end
|
115
|
+
end
|
116
|
+
|
98
117
|
def keyboardDidShow(note)
|
99
118
|
add_decimal_button if @ui_field.isFirstResponder
|
100
119
|
end
|
@@ -108,7 +127,7 @@ module Tgios
|
|
108
127
|
end
|
109
128
|
|
110
129
|
def add_decimal_button
|
111
|
-
if is_decimal? && @ui_field.delegate == self
|
130
|
+
if is_decimal? && @ui_field.delegate == self && !@options[:ignore_number_addon]
|
112
131
|
temp_window = (UIApplication.sharedApplication.windows[1] || UIApplication.sharedApplication.windows[0])
|
113
132
|
temp_window.subviews.each do |keyboard|
|
114
133
|
if keyboard.description.hasPrefix('<UIPeripheralHost')
|
@@ -186,7 +205,7 @@ module Tgios
|
|
186
205
|
@ui_field.leftViewMode = UITextFieldViewModeNever
|
187
206
|
end
|
188
207
|
|
189
|
-
if is_number_pad?
|
208
|
+
if is_number_pad? && !@options[:ignore_number_addon]
|
190
209
|
text_toolbar = PlasticCup::Base.style(UIToolbar.new, frame: CGRectMake(0,0,320,44))
|
191
210
|
done_button = UIBarButtonItem.alloc.initWithBarButtonSystemItem(UIBarButtonSystemItemDone, target: self, action: 'textFieldShouldReturn:')
|
192
211
|
text_toolbar.items=[
|
data/lib/tgios/version.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: tgios
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.25
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- April Tsang
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2014-05-
|
12
|
+
date: 2014-05-12 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: sugarcube
|
@@ -104,6 +104,7 @@ files:
|
|
104
104
|
- lib/tgios/ui_table_view_list_binding.rb
|
105
105
|
- lib/tgios/ui_table_view_model_binding.rb
|
106
106
|
- lib/tgios/ui_table_view_model_list_binding.rb
|
107
|
+
- lib/tgios/ui_table_view_utility_binding.rb
|
107
108
|
- lib/tgios/ui_text_field_binding.rb
|
108
109
|
- lib/tgios/ui_text_view_binding.rb
|
109
110
|
- lib/tgios/version.rb
|