Sha256: 9d6be69aa8aa88ad320f28799555b9d56166642a895087722b0c5d31e04d501c

Contents?: true

Size: 1.94 KB

Versions: 32

Compression:

Stored size: 1.94 KB

Contents

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

      presentation_style = options[:presentation]
      if presentation_style
        if presentation_style.respond_to?(:presentationstyle)
          presentation_style = presentation_style.presentationstyle
        end
        view_ctlr.modalPresentationStyle = presentation_style
      end

      transition_style = options[:transition]
      if transition_style
        if transition_style.respond_to?(:transitionstyle)
          transition_style = transition_style.transitionstyle
        end
        view_ctlr.modalTransitionStyle = transition_style
      end

      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)
      animated = options.fetch(:animated, true)
      target.dismissViewControllerAnimated(animated, completion:block)
    end
  end
end


class UIViewController

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

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

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

end

Version data entries

32 entries across 32 versions & 1 rubygems

Version Path
sugarcube-4.0.0 lib/ios/sugarcube-modal/modal.rb
sugarcube-3.5.0 lib/ios/sugarcube-modal/modal.rb
sugarcube-3.4.2 lib/ios/sugarcube-modal/modal.rb
sugarcube-3.4.1 lib/ios/sugarcube-modal/modal.rb
sugarcube-3.4.0 lib/ios/sugarcube-modal/modal.rb
sugarcube-3.3.7 lib/ios/sugarcube-modal/modal.rb
sugarcube-3.3.6 lib/ios/sugarcube-modal/modal.rb
sugarcube-3.3.5 lib/ios/sugarcube-modal/modal.rb
sugarcube-3.3.4 lib/ios/sugarcube-modal/modal.rb
sugarcube-3.3.3 lib/ios/sugarcube-modal/modal.rb
sugarcube-3.3.2 lib/ios/sugarcube-modal/modal.rb
sugarcube-3.3.1 lib/ios/sugarcube-modal/modal.rb
sugarcube-3.3.0 lib/ios/sugarcube-modal/modal.rb
sugarcube-3.2.0 lib/ios/sugarcube-modal/modal.rb
sugarcube-3.1.1 lib/ios/sugarcube-modal/modal.rb
sugarcube-3.1.0 lib/ios/sugarcube-modal/modal.rb
sugarcube-3.0.8 lib/ios/sugarcube-modal/modal.rb
sugarcube-3.0.7 lib/ios/sugarcube-modal/modal.rb
sugarcube-3.0.6 lib/ios/sugarcube-modal/modal.rb
sugarcube-3.0.5 lib/ios/sugarcube-modal/modal.rb