Module: RMXViewControllerPresentation::FactoryMethods
- Included in:
- RMXViewControllerPresentation
- Defined in:
- lib/motion/RMXViewControllerPresentation.rb
Instance Method Summary collapse
-
#dismiss(opts) ⇒ Object
remove the controller from the display heirarchy, taking into account how it is currently presented.
-
#present(opts) ⇒ Object
presentViewController should always be called on the next runloop to avoid quirks.
Instance Method Details
#dismiss(opts) ⇒ Object
remove the controller from the display heirarchy, taking into account how it is currently presented. avoid nesting animations and corrupting the UI by using whenOrIfViewState and executing on the main thread async to ensure it is not yanked out of the UI during existing animations
25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 |
# File 'lib/motion/RMXViewControllerPresentation.rb', line 25 def dismiss(opts) unless [ :view_controller, :animated, :completion ].all? { |x| opts.key?(x) } raise "Missing RMXViewControllerPresentation.dismiss opts: #{opts.inspect}" end animated = opts[:animated] block = opts[:completion] view_controller = opts[:view_controller] = view_controller. if view_controller.presentingViewController Dispatch::Queue.main.async do view_controller.dismissViewControllerAnimated(animated, completion:block) end elsif if index = .viewControllers.index(view_controller) before_index = index - 1 before_index = 0 if index < 0 pop_to_controller = .viewControllers[before_index] if pop_to_controller && pop_to_controller != .viewControllers.last # p "pop_to_controller", pop_to_controller # p "navigationController.popToViewController(pop_to_controller, animated:animated)" Dispatch::Queue.main.async do RMX.new().once(:done_animating, &block) if block .popToViewController(pop_to_controller, animated:animated) end end end end end |
#present(opts) ⇒ Object
presentViewController should always be called on the next runloop to avoid quirks. this just wraps that behavior
12 13 14 15 16 17 18 19 |
# File 'lib/motion/RMXViewControllerPresentation.rb', line 12 def present(opts) unless [ :origin, :view_controller, :animated, :completion ].all? { |x| opts.key?(x) } raise "Missing RMXViewControllerPresentation.present opts: #{opts.inspect}" end Dispatch::Queue.main.async do opts[:origin].presentViewController(opts[:view_controller], animated:opts[:animated], completion:opts[:completion]) end end |