rubymotion-community / BubbleWrap

Cocoa wrappers and helpers for RubyMotion (Ruby for iOS and OS X) - Making Cocoa APIs more Ruby like, one API at a time. Fork away and send your pull requests
Other
1.18k stars 208 forks source link

Allow dismissing presenting controller for photo picker #383

Closed Averethel closed 10 years ago

clayallsopp commented 10 years ago

I feel like self.picker.presentingViewController.presentingViewController is too specific for use in most apps

perhaps a lambda argument would be possible? ie

on_dismiss = -> { |picker|
  picker.presentingViewController.presentingViewController.dismissViewControllerAnimated(...)
}
BW::Camera.picture(source_type: :photo_library, media_types: [:image], on_dismiss: on_dismiss) do |result|
  image_view = UIImageView.alloc.initWithImage(result[:original_image])
end
Averethel commented 10 years ago

Hello @clayallsopp I checked your suggestion.

Problem is that in this particular case if I'd do it with on_dismiss lambda argument that I pass as a completion to dismissViewControllerAnimated in Camera#dismiss I'd see first the picker disappearing and then the controller that presents a picker which is not exactly the thing we'd like to achieve.

Adding a completion callback is also a good idea though. I'll create another pull request for that.

clayallsopp commented 10 years ago

Sounds good - for clarification, what I suggested should allow you to do the same thing as your PR. ie Camera#dismiss changes to this:

      def dismiss
        if @options[:on_dismiss]
          @options[:on_dismiss].call(self.picker)
          return
        end

        controller_to_dismiss = self.picker        
        controller_to_dismiss.dismissViewControllerAnimated(@options[:animated], completion: lambda {})
      end
Averethel commented 10 years ago

Refactoring done.

clayallsopp commented 10 years ago

Great, thanks!