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.20.6 lib/sugarcube/modal.rb
sugarcube-0.20.5 lib/sugarcube/modal.rb
sugarcube-0.20.4 lib/sugarcube/modal.rb
sugarcube-0.20.3 lib/sugarcube/modal.rb
sugarcube-0.20.1 lib/sugarcube/modal.rb
sugarcube-0.20.0 lib/sugarcube/modal.rb
sugarcube-0.19.5 lib/sugarcube/modal.rb
sugarcube-0.19.4 lib/sugarcube/modal.rb
sugarcube-0.19.2 lib/sugarcube/modal.rb
sugarcube-0.19.0 lib/sugarcube/modal.rb
sugarcube-0.18.21 lib/sugarcube/modal.rb
sugarcube-0.18.20 lib/sugarcube/modal.rb
sugarcube-0.18.19 lib/sugarcube/modal.rb
sugarcube-0.18.18 lib/sugarcube/modal.rb
sugarcube-0.18.17 lib/sugarcube/modal.rb
sugarcube-0.18.16 lib/sugarcube/modal.rb
sugarcube-0.18.12 lib/sugarcube/modal.rb
sugarcube-0.18.11 lib/sugarcube/modal.rb
sugarcube-0.18.10 lib/sugarcube/modal.rb
sugarcube-0.18.9 lib/sugarcube/modal.rb