Sha256: c928bfb2708817f2c5b969c4bb48e9dfdd90a17d159b53bccb899d0aff0214df

Contents?: true

Size: 1.48 KB

Versions: 1

Compression:

Stored size: 1.48 KB

Contents

motion_require "support/attr_default"

=begin
  {
    # array of assets (see asset/asset.rb) or UIViews
    assets: [{...}],
    # array of animations (see animation.rb)
    animations: [{...}]
  }
=end
module Walt
  class AnimationSet
    extend Walt::Support::AttrDefault
    
    PROPERTIES = [:animations, :assets]
    attr_accessor *PROPERTIES

    def initialize(params = {})
      params.each do |key, value|
        if PROPERTIES.include?(key.to_sym)
          self.send("#{key}=", value)
        end
      end
    end

    attr_default :animations, []
    def animations=(animations)
      _animations = animations && animations.collect do |animation|
        case animation
        when Walt::Animation
          animation
        when NSDictionary
          Walt::Animation.new(animation)
        else
          raise "Invalid class for animation #{animation.inspect}"
        end
      end
      @animations = _animations
    end

    attr_default :assets, []
    def assets=(assets)
      _assets = assets && assets.collect do |asset|
        case asset
        when Walt::Asset
          asset
        when NSDictionary
          Walt::Asset.for(asset)
        when UIView
          Walt::Asset.for(asset)
        else
          raise "Invalid class for asset #{asset.inspect}"
        end
        asset
      end
      @assets = _assets
    end

    def animate
      self.animations.each do |animation|
        animation.assets = self.assets
        animation.animate
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
walt-0.1.2 lib/walt/animation_set.rb