Class: MotionPrime::ImageElement

Inherits:
BaseElement show all
Defined in:
motion-prime/elements/image.rb

Instance Attribute Summary

Attributes inherited from BaseElement

#name, #options, #screen, #section, #styles, #view, #view_name

Instance Method Summary collapse

Methods inherited from BaseElement

#add_target, after_render, before_render, #bind_gesture, #cell_element?, #cell_section?, #compute_options!, #computed_options, #dealloc, factory, #hide, #initialize, #notify_section_after_render, #notify_section_before_render, #reload!, #render, #render!, #rerender!, #show, #update, #update_options, #update_with_options

Methods included from HasClassFactory

#camelize_factory, #class_factory, #low_camelize_factory, #underscore_factory

Methods included from HasStyleOptions

#extract_font_from

Methods included from HasStyleChainBuilder

#build_styles_chain

Methods included from HasNormalizer

#debug_info, #element?, #normalize_object, #normalize_options, #normalize_value

Constructor Details

This class inherits a constructor from MotionPrime::BaseElement

Instance Method Details

#fetch_imageObject



9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'motion-prime/elements/image.rb', line 9

def fetch_image
  return unless computed_options[:url]
  raise "You must set default image for `#{name}`" unless computed_options[:default]

  view.setImage(computed_options[:default].uiimage)
  refs = strong_references
  BW::Reactor.schedule do
    manager = SDWebImageManager.sharedManager
    manager.downloadWithURL(computed_options[:url],
      options: 0,
      progress: lambda{ |r_size, e_size|  },
      completed: lambda{ |image, error, type, finished|
        return if !image || !refs.all?(&:weakref_alive?)

        if computed_options[:post_process].present?
          image = computed_options[:post_process][:method].to_proc.call(computed_options[:post_process][:target], image)
        end

        self.performSelectorOnMainThread :set_image, withObject: image, waitUntilDone: true
      }
    )
  end
end

#set_image(*args) ⇒ Object



33
34
35
# File 'motion-prime/elements/image.rb', line 33

def set_image(*args)
  self.view.setImage(args)
end

#strong_referencesObject



37
38
39
40
41
42
# File 'motion-prime/elements/image.rb', line 37

def strong_references
  # .compact() is required here, otherwise screen will not be released
  refs = [section, (section.collection_section if section.respond_to?(:cell_section_name))].compact
  refs += section.strong_references if section
  refs
end

#view_classObject



5
6
7
# File 'motion-prime/elements/image.rb', line 5

def view_class
  "UIImageView"
end