Sha256: cc51c9d5462500c3f052b6156f189d699ac83cc216008c898c571c8ad3977d5d

Contents?: true

Size: 1.28 KB

Versions: 42

Compression:

Stored size: 1.28 KB

Contents

module SugarCube
  module Modal
    module_function
    def present_modal(view_ctlr, options={}, &block)
      target = options.fetch(:target, UIApplication.sharedApplication.keyWindow.rootViewController)
      animated = options.fetch(:animated, true)
      target.presentViewController(view_ctlr, animated:animated, completion:block)
    end

    def present_modal_in_nav(view_ctlr, options={}, &block)
      ctlr = UINavigationController.alloc.initWithRootViewController(view_ctlr)
      ctlr.modalTransitionStyle = UIModalTransitionStyleCoverVertical

      SugarCube::Modal.present_modal(ctlr, options, &block)
      ctlr
    end

    def dismiss_modal(options={}, &block)
      target = options.fetch(:target, UIApplication.sharedApplication.keyWindow.rootViewController)
      target.dismissViewControllerAnimated(true, completion:block)
    end
  end
end


class UIViewController

  def present_modal(view_ctlr, options={}, &block)
    options = options.merge(target: self)
    super(view_ctlr, options, &block)
  end

  def present_modal_in_nav(view_ctlr, options={}, &block)
    options = options.merge(target: self)
    super(view_ctlr, options, &block)
  end

  def dismiss_modal(view_ctlr, options={}, &block)
    options = options.merge(target: self)
    super(view_ctlr, options, &block)
  end

end

Version data entries

42 entries across 42 versions & 1 rubygems

Version Path
sugarcube-0.18.8 lib/sugarcube/modal.rb
sugarcube-0.18.7 lib/sugarcube/modal.rb
sugarcube-0.18.6 lib/sugarcube/modal.rb
sugarcube-0.18.5 lib/sugarcube/modal.rb
sugarcube-0.18.4 lib/sugarcube/modal.rb
sugarcube-0.18.3 lib/sugarcube/modal.rb
sugarcube-0.18.2 lib/sugarcube/modal.rb
sugarcube-0.18.1 lib/sugarcube/modal.rb
sugarcube-0.18.0 lib/sugarcube/modal.rb
sugarcube-0.16.9 lib/sugarcube/modal.rb
sugarcube-0.16.5 lib/sugarcube/modal.rb
sugarcube-0.16.2 lib/sugarcube/modal.rb
sugarcube-0.16 lib/sugarcube/modal.rb
sugarcube-0.15.5 lib/sugarcube/modal.rb
sugarcube-0.15.3 lib/sugarcube/modal.rb
sugarcube-0.15.0 lib/sugarcube/modal.rb
sugarcube-0.14.0 lib/sugarcube/modal.rb
sugarcube-0.13.7 lib/sugarcube/modal.rb
sugarcube-0.13.5 lib/sugarcube/modal.rb
sugarcube-0.13.4 lib/sugarcube/modal.rb