Module: UnderOs::UI::Events

Included in:
View
Defined in:
lib/under_os/ui/utils/events.rb

Overview

Special, UI avare events API

Defined Under Namespace

Classes: Event

Instance Method Summary collapse

Instance Method Details

#emit(*event) ⇒ Object



21
22
23
24
25
26
27
28
29
# File 'lib/under_os/ui/utils/events.rb', line 21

def emit(*event)
  if event.is_a?(UIGestureRecognizer)
    event = Event.new(self, event)
  else
    event = Event.new(self, *event)
  end

  UnderOs::Events::Listeners.kick(self, event, {})
end

#off(event) ⇒ Object



17
18
19
# File 'lib/under_os/ui/utils/events.rb', line 17

def off(event)
  UnderOs::Events::Listeners.remove(self, event)
end

#on(event, *args, &block) ⇒ Object



6
7
8
9
10
11
12
13
14
15
# File 'lib/under_os/ui/utils/events.rb', line 6

def on(event, *args, &block)
  return event.map{|e,b| self.on(e,&b)}[0] || self if event.is_a?(Hash)

  event, recognizer = find_recognizer_from(event)

  @_.addGestureRecognizer(recognizer.alloc.initWithTarget(self, action: :emit)) if recognizer
  @_.userInteractionEnabled = true

  UnderOs::Events::Listeners.add(self, event, *args, block)
end

#on=(hash) ⇒ Object



31
32
33
# File 'lib/under_os/ui/utils/events.rb', line 31

def on=(hash)
  on hash
end