under-os 1.3.0 → 1.4.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile +4 -0
- data/Gemfile.lock +25 -2
- data/README.md +1 -1
- data/Rakefile +2 -4
- data/lib/under-os.rb +3 -8
- data/under-os.gemspec +6 -2
- metadata +47 -191
- data/lib/assets/fontawesome-webfont.ttf +0 -0
- data/lib/assets/under-os.css +0 -115
- data/lib/under_os.rb +0 -41
- data/lib/under_os/app.rb +0 -33
- data/lib/under_os/color.rb +0 -184
- data/lib/under_os/config.rb +0 -33
- data/lib/under_os/core/array.rb +0 -5
- data/lib/under_os/core/hash.rb +0 -10
- data/lib/under_os/core/json.rb +0 -19
- data/lib/under_os/core/kernel.rb +0 -16
- data/lib/under_os/core/numeric.rb +0 -23
- data/lib/under_os/core/object.rb +0 -9
- data/lib/under_os/core/string.rb +0 -80
- data/lib/under_os/delegate.rb +0 -10
- data/lib/under_os/events.rb +0 -85
- data/lib/under_os/file.rb +0 -110
- data/lib/under_os/history.rb +0 -53
- data/lib/under_os/http.rb +0 -31
- data/lib/under_os/http/cookies.rb +0 -30
- data/lib/under_os/http/receiver.rb +0 -44
- data/lib/under_os/http/request.rb +0 -106
- data/lib/under_os/http/response.rb +0 -28
- data/lib/under_os/http/session.rb +0 -49
- data/lib/under_os/page.rb +0 -169
- data/lib/under_os/page/builder.rb +0 -96
- data/lib/under_os/page/layout.rb +0 -43
- data/lib/under_os/page/matcher.rb +0 -128
- data/lib/under_os/page/stylesheet.rb +0 -67
- data/lib/under_os/parser.rb +0 -24
- data/lib/under_os/parser/css.rb +0 -37
- data/lib/under_os/parser/html.rb +0 -97
- data/lib/under_os/point.rb +0 -47
- data/lib/under_os/screen.rb +0 -9
- data/lib/under_os/timer.rb +0 -65
- data/lib/under_os/ui.rb +0 -3
- data/lib/under_os/ui/alert.rb +0 -52
- data/lib/under_os/ui/button.rb +0 -42
- data/lib/under_os/ui/collection.rb +0 -65
- data/lib/under_os/ui/collection/cell.rb +0 -21
- data/lib/under_os/ui/collection/delegate.rb +0 -70
- data/lib/under_os/ui/collection/item.rb +0 -32
- data/lib/under_os/ui/collection/layout.rb +0 -43
- data/lib/under_os/ui/collection/styles.rb +0 -15
- data/lib/under_os/ui/div.rb +0 -3
- data/lib/under_os/ui/form.rb +0 -60
- data/lib/under_os/ui/icon.rb +0 -61
- data/lib/under_os/ui/icon/awesome.rb +0 -376
- data/lib/under_os/ui/icon/engine.rb +0 -10
- data/lib/under_os/ui/image.rb +0 -31
- data/lib/under_os/ui/input.rb +0 -140
- data/lib/under_os/ui/label.rb +0 -21
- data/lib/under_os/ui/locker.rb +0 -42
- data/lib/under_os/ui/navbar.rb +0 -123
- data/lib/under_os/ui/progress.rb +0 -17
- data/lib/under_os/ui/scroll.rb +0 -41
- data/lib/under_os/ui/select.rb +0 -95
- data/lib/under_os/ui/sidebar.rb +0 -45
- data/lib/under_os/ui/slider.rb +0 -37
- data/lib/under_os/ui/spinner.rb +0 -23
- data/lib/under_os/ui/style.rb +0 -21
- data/lib/under_os/ui/style/fonts.rb +0 -54
- data/lib/under_os/ui/style/margins.rb +0 -164
- data/lib/under_os/ui/style/outlining.rb +0 -170
- data/lib/under_os/ui/style/positioning.rb +0 -169
- data/lib/under_os/ui/switch.rb +0 -26
- data/lib/under_os/ui/textarea.rb +0 -19
- data/lib/under_os/ui/utils/animation.rb +0 -99
- data/lib/under_os/ui/utils/commons.rb +0 -70
- data/lib/under_os/ui/utils/dimensions.rb +0 -37
- data/lib/under_os/ui/utils/events.rb +0 -170
- data/lib/under_os/ui/utils/manipulation.rb +0 -44
- data/lib/under_os/ui/utils/position.rb +0 -21
- data/lib/under_os/ui/utils/size.rb +0 -21
- data/lib/under_os/ui/utils/styles.rb +0 -89
- data/lib/under_os/ui/utils/traversing.rb +0 -44
- data/lib/under_os/ui/utils/wrap.rb +0 -77
- data/lib/under_os/ui/view.rb +0 -31
- data/resources/test.png +0 -0
- data/spec/assets/app.css +0 -13
- data/spec/assets/test.css +0 -7
- data/spec/assets/test.html +0 -3
- data/spec/assets/test_page.rb +0 -2
- data/spec/lib/core/hash_spec.rb +0 -19
- data/spec/lib/core/json_spec.rb +0 -32
- data/spec/lib/core/numeric_spec.rb +0 -37
- data/spec/lib/core/string_spec.rb +0 -121
- data/spec/lib/under_os/color_spec.rb +0 -133
- data/spec/lib/under_os/events_spec.rb +0 -71
- data/spec/lib/under_os/file_spec.rb +0 -98
- data/spec/lib/under_os/http/cookies_spec.rb +0 -13
- data/spec/lib/under_os/http/request_spec.rb +0 -44
- data/spec/lib/under_os/http_spec.rb +0 -20
- data/spec/lib/under_os/page/builder_spec.rb +0 -128
- data/spec/lib/under_os/page/layout_spec.rb +0 -18
- data/spec/lib/under_os/page/matcher_spec.rb +0 -260
- data/spec/lib/under_os/page/stylesheet_spec.rb +0 -83
- data/spec/lib/under_os/page_spec.rb +0 -5
- data/spec/lib/under_os/parser/css_spec.rb +0 -77
- data/spec/lib/under_os/parser/html_spec.rb +0 -152
- data/spec/lib/under_os/parser_spec.rb +0 -16
- data/spec/lib/under_os/point_spec.rb +0 -54
- data/spec/lib/under_os/screen_spec.rb +0 -11
- data/spec/lib/under_os/timer_spec.rb +0 -93
- data/spec/lib/under_os/ui/button_spec.rb +0 -50
- data/spec/lib/under_os/ui/collection_spec.rb +0 -19
- data/spec/lib/under_os/ui/div_spec.rb +0 -24
- data/spec/lib/under_os/ui/form_spec.rb +0 -156
- data/spec/lib/under_os/ui/icon_spec.rb +0 -57
- data/spec/lib/under_os/ui/image_spec.rb +0 -39
- data/spec/lib/under_os/ui/input_spec.rb +0 -109
- data/spec/lib/under_os/ui/label_spec.rb +0 -22
- data/spec/lib/under_os/ui/locker_spec.rb +0 -31
- data/spec/lib/under_os/ui/progress_spec.rb +0 -31
- data/spec/lib/under_os/ui/scroll_spec.rb +0 -40
- data/spec/lib/under_os/ui/select_spec.rb +0 -135
- data/spec/lib/under_os/ui/sidebar_spec.rb +0 -35
- data/spec/lib/under_os/ui/slider_spec.rb +0 -69
- data/spec/lib/under_os/ui/spinner_spec.rb +0 -57
- data/spec/lib/under_os/ui/style/fonts_spec.rb +0 -73
- data/spec/lib/under_os/ui/style/margins_spec.rb +0 -106
- data/spec/lib/under_os/ui/style/outlining_spec.rb +0 -101
- data/spec/lib/under_os/ui/style/positioning_spec.rb +0 -69
- data/spec/lib/under_os/ui/style_spec.rb +0 -19
- data/spec/lib/under_os/ui/switch_spec.rb +0 -60
- data/spec/lib/under_os/ui/textarea_spec.rb +0 -34
- data/spec/lib/under_os/ui/utils/commons_spec.rb +0 -81
- data/spec/lib/under_os/ui/utils/events_spec.rb +0 -87
- data/spec/lib/under_os/ui/utils/manipulation_spec.rb +0 -130
- data/spec/lib/under_os/ui/utils/styles_spec.rb +0 -140
- data/spec/lib/under_os/ui/utils/traversing_spec.rb +0 -124
- data/spec/lib/under_os/ui/utils/wrap_spec.rb +0 -69
- data/spec/lib/under_os/ui/view_spec.rb +0 -39
@@ -1,169 +0,0 @@
|
|
1
|
-
#
|
2
|
-
# This module contains things like positions and sizes of the elements
|
3
|
-
#
|
4
|
-
module UnderOs::UI
|
5
|
-
class Style
|
6
|
-
module Positioning
|
7
|
-
def width
|
8
|
-
@view.frame.size.width
|
9
|
-
end
|
10
|
-
|
11
|
-
def width=(width)
|
12
|
-
@view.frame = [[left, top], [convert_size(width, :x), height]]
|
13
|
-
end
|
14
|
-
|
15
|
-
def height
|
16
|
-
@view.frame.size.height
|
17
|
-
end
|
18
|
-
|
19
|
-
def height=(height)
|
20
|
-
@view.frame = [[left, top], [width, convert_size(height, :y)]]
|
21
|
-
end
|
22
|
-
|
23
|
-
def top
|
24
|
-
@view.frame.origin.y
|
25
|
-
end
|
26
|
-
|
27
|
-
def top=(top)
|
28
|
-
@view.frame = [[left, convert_size(top, :y)], [width, height]]
|
29
|
-
end
|
30
|
-
|
31
|
-
def left
|
32
|
-
@view.frame.origin.x
|
33
|
-
end
|
34
|
-
|
35
|
-
def left=(left)
|
36
|
-
@view.frame = [[convert_size(left, :x), top], [width, height]]
|
37
|
-
end
|
38
|
-
|
39
|
-
def right
|
40
|
-
parent_size.x - left
|
41
|
-
end
|
42
|
-
|
43
|
-
def right=(right)
|
44
|
-
@view.frame = [[parent_size[:x] - convert_size(right, :x) - width, top], [width, height]]
|
45
|
-
end
|
46
|
-
|
47
|
-
def bottom
|
48
|
-
parent_size.y - top
|
49
|
-
end
|
50
|
-
|
51
|
-
def bottom=(bottom)
|
52
|
-
@view.frame = [[left, parent_size[:y] - convert_size(bottom, :y) - height], [width, height]]
|
53
|
-
end
|
54
|
-
|
55
|
-
def contentWidth
|
56
|
-
@view.contentSize.width rescue 0
|
57
|
-
end
|
58
|
-
|
59
|
-
def contentWidth=(value)
|
60
|
-
return unless @view.is_a?(UIScrollView)
|
61
|
-
|
62
|
-
if value == 'auto'
|
63
|
-
value = 0
|
64
|
-
@view.subviews.each do |view|
|
65
|
-
x = view.origin.x + view.size.width
|
66
|
-
value = x if x > value
|
67
|
-
end
|
68
|
-
end
|
69
|
-
|
70
|
-
@view.contentSize = CGSizeMake(value, contentHeight)
|
71
|
-
end
|
72
|
-
|
73
|
-
def contentHeight
|
74
|
-
@view.contentSize.height rescue 0
|
75
|
-
end
|
76
|
-
|
77
|
-
def contentHeight=(value)
|
78
|
-
return unless @view.is_a?(UIScrollView)
|
79
|
-
|
80
|
-
if value == 'auto'
|
81
|
-
value = 0
|
82
|
-
@view.subviews.each do |view|
|
83
|
-
y = view.origin.y + view.size.height
|
84
|
-
value = y if y > value
|
85
|
-
end
|
86
|
-
end
|
87
|
-
|
88
|
-
@view.contentSize = CGSizeMake(contentWidth, value)
|
89
|
-
end
|
90
|
-
|
91
|
-
def zIndex
|
92
|
-
@view.layer.zPosition
|
93
|
-
end
|
94
|
-
|
95
|
-
def zIndex=(number)
|
96
|
-
@view.layer.zPosition = number
|
97
|
-
end
|
98
|
-
|
99
|
-
def overflow
|
100
|
-
case "#{overflowX}-#{overflowY}"
|
101
|
-
when 'visible-visible' then :visible
|
102
|
-
when 'hidden-hidden' then :hidden
|
103
|
-
when 'visible-hidden' then :x
|
104
|
-
when 'hidden-visible' then :y
|
105
|
-
else [overflowX, overflowY]
|
106
|
-
end
|
107
|
-
end
|
108
|
-
|
109
|
-
def overflow=(value)
|
110
|
-
x, y = case value.to_s
|
111
|
-
when 'x' then ['visible', 'hidden']
|
112
|
-
when 'y' then ['hidden', 'visible']
|
113
|
-
when 'hidden' then ['hidden', 'hidden']
|
114
|
-
else ['visible', 'visible']
|
115
|
-
end
|
116
|
-
|
117
|
-
self.overflowX = x
|
118
|
-
self.overflowY = y
|
119
|
-
end
|
120
|
-
|
121
|
-
def overflowX
|
122
|
-
@view.isScrollEnabled && @view.showsHorizontalScrollIndicator ? :visible : :hidden
|
123
|
-
end
|
124
|
-
|
125
|
-
def overflowX=(value)
|
126
|
-
return unless @view.is_a?(UIScrollView)
|
127
|
-
@view.showsHorizontalScrollIndicator = value.to_s == 'visible'
|
128
|
-
@view.directionalLockEnabled = overflowY == :hidden
|
129
|
-
@view.scrollEnabled = overflowX != :hidden || overflowY != :hidden
|
130
|
-
end
|
131
|
-
|
132
|
-
def overflowY
|
133
|
-
@view.isScrollEnabled && @view.showsVerticalScrollIndicator ? :visible : :hidden
|
134
|
-
end
|
135
|
-
|
136
|
-
def overflowY=(value)
|
137
|
-
return unless @view.is_a?(UIScrollView)
|
138
|
-
@view.showsVerticalScrollIndicator = value.to_s == 'visible'
|
139
|
-
@view.directionalLockEnabled = overflowX == :hidden
|
140
|
-
@view.scrollEnabled = overflowX != :hidden || overflowY != :hidden
|
141
|
-
end
|
142
|
-
|
143
|
-
private
|
144
|
-
|
145
|
-
def convert_size(size, dim)
|
146
|
-
if size.is_a?(String)
|
147
|
-
if size.ends_with?('%')
|
148
|
-
size = size.slice(0, size.size-1).to_f
|
149
|
-
size = parent_size[dim] / 100.0 * size
|
150
|
-
end
|
151
|
-
end
|
152
|
-
|
153
|
-
size
|
154
|
-
end
|
155
|
-
|
156
|
-
def parent_size
|
157
|
-
parent = view.superview
|
158
|
-
|
159
|
-
if !parent.superview && parent == UnderOs::App.history.current_page.view._
|
160
|
-
parent = UIScreen.mainScreen.bounds.size
|
161
|
-
else
|
162
|
-
parent = parent.frame.size
|
163
|
-
end
|
164
|
-
|
165
|
-
{x: parent.width, y: parent.height}
|
166
|
-
end
|
167
|
-
end
|
168
|
-
end
|
169
|
-
end
|
data/lib/under_os/ui/switch.rb
DELETED
@@ -1,26 +0,0 @@
|
|
1
|
-
class UnderOs::UI::Switch < UnderOs::UI::Input
|
2
|
-
wraps UISwitch, tag: 'switch'
|
3
|
-
|
4
|
-
def initialize(options={})
|
5
|
-
super
|
6
|
-
self.checked = options[:checked] if options[:checked]
|
7
|
-
@_.addTarget self, action: :handle_change, forControlEvents:UIControlEventValueChanged
|
8
|
-
end
|
9
|
-
|
10
|
-
def value
|
11
|
-
@_value
|
12
|
-
end
|
13
|
-
|
14
|
-
def value=(value)
|
15
|
-
@_value = value # just saving it on the instance
|
16
|
-
end
|
17
|
-
|
18
|
-
def checked
|
19
|
-
@_.on?
|
20
|
-
end
|
21
|
-
|
22
|
-
def checked=(flag)
|
23
|
-
@_.setOn flag, animated: true
|
24
|
-
end
|
25
|
-
|
26
|
-
end
|
data/lib/under_os/ui/textarea.rb
DELETED
@@ -1,19 +0,0 @@
|
|
1
|
-
class UnderOs::UI::Textarea < UnderOs::UI::Input
|
2
|
-
wraps UITextView, tag: 'textarea'
|
3
|
-
|
4
|
-
alias :text= :value= # to get values from the HTML layouts
|
5
|
-
|
6
|
-
# delegate
|
7
|
-
|
8
|
-
def textViewDidBeginEditing(textView)
|
9
|
-
handle_focus
|
10
|
-
end
|
11
|
-
|
12
|
-
def textViewDidChange(textView)
|
13
|
-
handle_change
|
14
|
-
end
|
15
|
-
|
16
|
-
def textViewDidEndEditing(textView)
|
17
|
-
handle_blur
|
18
|
-
end
|
19
|
-
end
|
@@ -1,99 +0,0 @@
|
|
1
|
-
module UnderOs::UI::Animation
|
2
|
-
|
3
|
-
def animate(style, options={}, &block)
|
4
|
-
if block_given?
|
5
|
-
options = style
|
6
|
-
style = nil
|
7
|
-
else
|
8
|
-
[:complete, :curve, :autoreverse, :repeat, :duration, :delay].each do |key|
|
9
|
-
options[key] = style.delete(key) if style.has_key?(key)
|
10
|
-
end
|
11
|
-
|
12
|
-
block = Proc.new{ self.style = style }
|
13
|
-
end
|
14
|
-
|
15
|
-
Animation.new(self, options, &block)
|
16
|
-
|
17
|
-
self
|
18
|
-
end
|
19
|
-
|
20
|
-
def highlight(color=:yellow, options={})
|
21
|
-
old_color = style.background
|
22
|
-
|
23
|
-
animate({background: color}, {curve: :ease_out}.merge(options))
|
24
|
-
animate({background: old_color}, {curve: :ease_in}.merge(options))
|
25
|
-
end
|
26
|
-
|
27
|
-
def fade_in(options={})
|
28
|
-
animate({opacity: 1}, options)
|
29
|
-
end
|
30
|
-
|
31
|
-
def fade_out(options={})
|
32
|
-
animate({opacity: 0}, options)
|
33
|
-
end
|
34
|
-
|
35
|
-
class Animation
|
36
|
-
CURVES = {
|
37
|
-
ease_in_out: UIViewAnimationOptionCurveEaseInOut,
|
38
|
-
ease_in: UIViewAnimationOptionCurveEaseIn,
|
39
|
-
ease_out: UIViewAnimationOptionCurveEaseOut,
|
40
|
-
linear: UIViewAnimationOptionCurveLinear
|
41
|
-
}.freeze
|
42
|
-
|
43
|
-
FX_QUEUE = {}
|
44
|
-
|
45
|
-
def initialize(view, options, &block)
|
46
|
-
@view = view
|
47
|
-
@options = options
|
48
|
-
@block = block
|
49
|
-
|
50
|
-
@options[:schedule] == false ? run : schedule
|
51
|
-
end
|
52
|
-
|
53
|
-
def queue
|
54
|
-
FX_QUEUE[@view] ||= []
|
55
|
-
end
|
56
|
-
|
57
|
-
def schedule
|
58
|
-
if queue.empty?
|
59
|
-
run
|
60
|
-
else
|
61
|
-
queue << self
|
62
|
-
end
|
63
|
-
end
|
64
|
-
|
65
|
-
def run
|
66
|
-
@view.emit('animation:start')
|
67
|
-
|
68
|
-
UIView.animateWithDuration duration,
|
69
|
-
delay: delay,
|
70
|
-
options: options,
|
71
|
-
animations: ->{ @block.call },
|
72
|
-
completion: ->(finished){ run_next }
|
73
|
-
end
|
74
|
-
|
75
|
-
def duration
|
76
|
-
@options[:duration] || 0.25
|
77
|
-
end
|
78
|
-
|
79
|
-
def delay
|
80
|
-
@options[:delay] || 0.0
|
81
|
-
end
|
82
|
-
|
83
|
-
def options
|
84
|
-
options = CURVES[@options[:curve]] || @options[:curve] || UIViewAnimationCurveEaseOut
|
85
|
-
options = options | UIViewAnimationOptionAutoreverse if @options[:autoreverse]
|
86
|
-
options = options | UIViewAnimationOptionRepeat if @options[:repeat]
|
87
|
-
options | UIViewAnimationOptionAllowUserInteraction
|
88
|
-
end
|
89
|
-
|
90
|
-
def run_next
|
91
|
-
@view.emit('animation:finished')
|
92
|
-
@options[:complete].call if @options[:complete]
|
93
|
-
|
94
|
-
if next_fx = queue.shift
|
95
|
-
next_fx.run
|
96
|
-
end
|
97
|
-
end
|
98
|
-
end
|
99
|
-
end
|
@@ -1,70 +0,0 @@
|
|
1
|
-
module UnderOs::UI::Commons
|
2
|
-
def id
|
3
|
-
@_id
|
4
|
-
end
|
5
|
-
|
6
|
-
def id=(id)
|
7
|
-
@_id = id
|
8
|
-
end
|
9
|
-
|
10
|
-
def tagName
|
11
|
-
@_tag_name ||= begin
|
12
|
-
wraps = UnderOs::UI::Wrap::WRAPS_TAGS_MAP
|
13
|
-
klass = self.class; tag = 'VIEW'
|
14
|
-
|
15
|
-
while klass
|
16
|
-
if wrap = wraps.detect{|t,k| k == klass}
|
17
|
-
tag = wrap[0].upcase
|
18
|
-
break
|
19
|
-
else
|
20
|
-
klass = klass.superclass
|
21
|
-
end
|
22
|
-
end
|
23
|
-
|
24
|
-
tag
|
25
|
-
end
|
26
|
-
end
|
27
|
-
|
28
|
-
def data(key=nil)
|
29
|
-
key && @_data ? @_data[key.to_sym] : @_data
|
30
|
-
end
|
31
|
-
|
32
|
-
def data=(hash)
|
33
|
-
@_data = hash
|
34
|
-
end
|
35
|
-
|
36
|
-
def page
|
37
|
-
resp = @_
|
38
|
-
|
39
|
-
while resp = resp.nextResponder
|
40
|
-
if resp.is_a?(UIViewController)
|
41
|
-
return resp.wrapper
|
42
|
-
end
|
43
|
-
end
|
44
|
-
|
45
|
-
nil
|
46
|
-
end
|
47
|
-
|
48
|
-
def hide
|
49
|
-
style.display = :none
|
50
|
-
end
|
51
|
-
|
52
|
-
def show
|
53
|
-
style.display = :block
|
54
|
-
end
|
55
|
-
|
56
|
-
def toggle
|
57
|
-
hidden ? show : hide
|
58
|
-
end
|
59
|
-
|
60
|
-
def hidden
|
61
|
-
@_.isHidden
|
62
|
-
end
|
63
|
-
|
64
|
-
def visible
|
65
|
-
!hidden
|
66
|
-
end
|
67
|
-
|
68
|
-
alias :hidden? :hidden
|
69
|
-
alias :visible? :visible
|
70
|
-
end
|
@@ -1,37 +0,0 @@
|
|
1
|
-
#
|
2
|
-
# This module handles generic ui dimensions and positions of views
|
3
|
-
#
|
4
|
-
module UnderOs::UI::Dimensions
|
5
|
-
def size(size=nil)
|
6
|
-
if size
|
7
|
-
self.size = size
|
8
|
-
self
|
9
|
-
else
|
10
|
-
@size ||= UnderOs::UI::Size.new(self)
|
11
|
-
end
|
12
|
-
end
|
13
|
-
|
14
|
-
def size=(size)
|
15
|
-
size = UnderOs::Point.new(size) # cleaning up
|
16
|
-
|
17
|
-
self.size.x = size.x if size.x
|
18
|
-
self.size.y = size.y if size.y
|
19
|
-
end
|
20
|
-
|
21
|
-
def position(position=nil)
|
22
|
-
if position
|
23
|
-
self.position = position
|
24
|
-
self
|
25
|
-
else
|
26
|
-
@position ||= UnderOs::UI::Position.new(self)
|
27
|
-
end
|
28
|
-
end
|
29
|
-
|
30
|
-
def position=(position)
|
31
|
-
position = UnderOs::Point.new(position) # cleaning up
|
32
|
-
|
33
|
-
self.position.x = position.x if position.x
|
34
|
-
self.position.y = position.y if position.y
|
35
|
-
end
|
36
|
-
|
37
|
-
end
|
@@ -1,170 +0,0 @@
|
|
1
|
-
#
|
2
|
-
# Special, UI avare events API
|
3
|
-
#
|
4
|
-
module UnderOs::UI::Events
|
5
|
-
|
6
|
-
def on(event, *args, &block)
|
7
|
-
return event.map{|e,b| self.on(e,&b)}[0] || self if event.is_a?(Hash)
|
8
|
-
|
9
|
-
@_.userInteractionEnabled = true
|
10
|
-
|
11
|
-
event = add_ui_event_listener(event)
|
12
|
-
|
13
|
-
UnderOs::Events::Listeners.add(self, event, *args, block)
|
14
|
-
end
|
15
|
-
|
16
|
-
def off(event)
|
17
|
-
UnderOs::Events::Listeners.remove(self, event)
|
18
|
-
end
|
19
|
-
|
20
|
-
def emit(*event)
|
21
|
-
if event.is_a?(UIGestureRecognizer)
|
22
|
-
event, r = find_recognizer_from(event.class)
|
23
|
-
event = Event.new(self, event)
|
24
|
-
else
|
25
|
-
event = Event.new(self, *event)
|
26
|
-
end
|
27
|
-
|
28
|
-
UnderOs::Events::Listeners.kick(self, event, {})
|
29
|
-
end
|
30
|
-
|
31
|
-
def on=(hash)
|
32
|
-
on hash
|
33
|
-
end
|
34
|
-
|
35
|
-
class TouchListeners
|
36
|
-
def self.listeners
|
37
|
-
@listeners ||= Hash.new{ |h,k| h[k] = [] }
|
38
|
-
end
|
39
|
-
|
40
|
-
def self.add(eventname, view)
|
41
|
-
listeners[eventname] << view
|
42
|
-
end
|
43
|
-
|
44
|
-
def self.notify(eventname, event)
|
45
|
-
listeners[eventname].each do |view|
|
46
|
-
if eventname == :touchmove # being nice and throttling the touchmove events
|
47
|
-
return if @__working
|
48
|
-
@__working = true
|
49
|
-
end
|
50
|
-
|
51
|
-
touches = touches_for_view(view, event)
|
52
|
-
|
53
|
-
view.emit(eventname, touches: touches) if touches.size > 0
|
54
|
-
|
55
|
-
@__working = false
|
56
|
-
end
|
57
|
-
end
|
58
|
-
|
59
|
-
def self.touches_for_view(view, event)
|
60
|
-
frame = view._.frame
|
61
|
-
touches = []
|
62
|
-
|
63
|
-
event.allTouches.each do |touch|
|
64
|
-
if point = touch_inside_of(frame, touch)
|
65
|
-
touches << Touch.new(view, point)
|
66
|
-
end
|
67
|
-
end
|
68
|
-
|
69
|
-
touches
|
70
|
-
end
|
71
|
-
|
72
|
-
def self.touch_inside_of(frame, touch)
|
73
|
-
point = touch.locationInView(nil)
|
74
|
-
point = nil if point.x < frame.origin.x ||
|
75
|
-
point.y < frame.origin.y ||
|
76
|
-
point.x > frame.origin.x + frame.size.width ||
|
77
|
-
point.y > frame.origin.y + frame.size.height
|
78
|
-
|
79
|
-
point
|
80
|
-
end
|
81
|
-
|
82
|
-
class Touch
|
83
|
-
attr_reader :view, :position
|
84
|
-
|
85
|
-
def initialize(view, position)
|
86
|
-
@view = view
|
87
|
-
@position = position
|
88
|
-
end
|
89
|
-
|
90
|
-
def pageX
|
91
|
-
position.x
|
92
|
-
end
|
93
|
-
|
94
|
-
def pageY
|
95
|
-
position.y
|
96
|
-
end
|
97
|
-
|
98
|
-
def viewX
|
99
|
-
@position.x - view._.frame.origin.x
|
100
|
-
end
|
101
|
-
|
102
|
-
def viewY
|
103
|
-
@position.y - view._.frame.origin.y
|
104
|
-
end
|
105
|
-
|
106
|
-
def inspect
|
107
|
-
"#<Touch x=#{pageX} y=#{pageY}"
|
108
|
-
end
|
109
|
-
end
|
110
|
-
end
|
111
|
-
|
112
|
-
private
|
113
|
-
|
114
|
-
def add_ui_event_listener(event)
|
115
|
-
event = event.to_sym if event.is_a?(String)
|
116
|
-
event = try_add_touch_event_listener(event)
|
117
|
-
event, recognizer = find_recognizer_from(event)
|
118
|
-
|
119
|
-
@_.addGestureRecognizer(recognizer.alloc.initWithTarget(self, action: :emit)) if recognizer
|
120
|
-
|
121
|
-
event
|
122
|
-
end
|
123
|
-
|
124
|
-
TOUCH_EVENTS = [:touchstart, :touchmove, :touchend, :touchcancel]
|
125
|
-
|
126
|
-
def try_add_touch_event_listener(event)
|
127
|
-
if TOUCH_EVENTS.include?(event)
|
128
|
-
UnderOs::UI::Events::TouchListeners.add(event, self)
|
129
|
-
end
|
130
|
-
|
131
|
-
event
|
132
|
-
end
|
133
|
-
|
134
|
-
RECOGNIZERS = {
|
135
|
-
tap: UITapGestureRecognizer,
|
136
|
-
pinch: UIPinchGestureRecognizer,
|
137
|
-
rotate: UIRotationGestureRecognizer,
|
138
|
-
swipe: UISwipeGestureRecognizer,
|
139
|
-
pan: UIPanGestureRecognizer,
|
140
|
-
press: UILongPressGestureRecognizer
|
141
|
-
}
|
142
|
-
|
143
|
-
# tries to figure event name and gesture recognizer
|
144
|
-
def find_recognizer_from(event)
|
145
|
-
if event.is_a?(Class) && event < UIGestureRecognizer
|
146
|
-
recognizer = event
|
147
|
-
|
148
|
-
if recognizer.respond_to?(:event_name)
|
149
|
-
event = recognizer.event_name
|
150
|
-
else
|
151
|
-
RECOGNIZERS.each{ |e,r| event = e if r == recognizer }
|
152
|
-
end
|
153
|
-
|
154
|
-
elsif RECOGNIZERS[event]
|
155
|
-
recognizer = RECOGNIZERS[event]
|
156
|
-
end
|
157
|
-
|
158
|
-
[event, recognizer]
|
159
|
-
end
|
160
|
-
|
161
|
-
class Event < UnderOs::Events::Event
|
162
|
-
attr_reader :target
|
163
|
-
|
164
|
-
def initialize(view, event, params={})
|
165
|
-
@target = view
|
166
|
-
|
167
|
-
super event, params
|
168
|
-
end
|
169
|
-
end
|
170
|
-
end
|