Sha256: f94328b09dd3e8b58843aec8c52b11170477f6286075e548f6954e19852576ed
Contents?: true
Size: 1.45 KB
Versions: 21
Compression:
Stored size: 1.45 KB
Contents
# @provides MotionKit::ConstraintsTarget module MotionKit class ConstraintsTarget attr :view def initialize(view) @view = view @constraints = [] end def add_constraints(constraints) @constraints.concat(constraints) end def apply_all_constraints(layout, target) @constraints.map do |mk_constraint| mk_constraint.resolve_all(layout, target).map do |constraint| base_view_class = MotionKit.base_view_class if constraint.firstItem.is_a?(base_view_class) && constraint.secondItem.is_a?(base_view_class) common_ancestor = nil ancestors = [constraint.firstItem] parent_view = constraint.firstItem while parent_view = parent_view.superview ancestors << parent_view end current_view = constraint.secondItem while current_view if ancestors.include? current_view common_ancestor = current_view break end current_view = current_view.superview end unless common_ancestor raise NoCommonAncestorError.new("No common ancestors between #{constraint.firstItem} and #{constraint.secondItem}") end else common_ancestor = constraint.firstItem end common_ancestor.addConstraint(constraint) constraint end end.flatten end end end
Version data entries
21 entries across 21 versions & 1 rubygems