motion/core/device/ios/camera.rb in bubble-wrap-1.6.0 vs motion/core/device/ios/camera.rb in bubble-wrap-1.7.0
- old
+ new
@@ -43,11 +43,11 @@
def any
@any ||= Camera.new
end
alias_method "photo_library", "any"
end
-
+
def popover_from(view)
@popover_in_view = view
self
end
@@ -65,21 +65,22 @@
def flash?
return false if self.location == :none
UIImagePickerController.isFlashAvailableForCameraDevice(camera_device)
end
- # @param [Hash] options to open the UIImagePickerController with
+ # @param [Hash] options to open the UIImagePickerController with
# the form {
# source_type: :photo_library, :camera, or :saved_photos_album; default :photo_library
# media_types: [] containing :image and/or :movie; default [:image]
# allows_editing: true/false; default false
# animated: true/false; default true
+ # on_dismiss: lambda; default nil
# }
- #
+ #
# @param [UIViewController] view controller from which to present the image picker;
# if nil, uses the keyWindow's rootViewController.
- #
+ #
# @block for callback. takes one argument.
# - On error or cancelled, is called with a hash {error: BW::Camera::Error::<Type>}
# - On success, is called with a hash with a possible set of keys
# [:media_type, :original_image, :edited_image, :crop_rect, :media_url,
# :reference_url, :media_metadata]
@@ -90,14 +91,17 @@
# end
def picture(options = {}, presenting_controller = nil, &block)
@callback = block
@callback.weak! if @callback && BubbleWrap.use_weak_callbacks?
- @options = options
- @options[:allows_editing] = false if not @options.has_key? :allows_editing
- @options[:animated] = true if not @options.has_key? :animated
- @options[:media_types] = [:image] if not @options.has_key? :media_types
+ @options = {
+ allows_editing: false,
+ animated: true,
+ on_dismiss: false,
+ media_types: [:image],
+ dismiss_completed: nil
+ }.merge(options)
# If we're using Camera.any, by default use photo library
if !@options.has_key?(:source_type) and self.location == :none
@options[:source_type] = :photo_library
# If we're using a real Camera, by default use the camera.
@@ -135,20 +139,20 @@
self.picker.cameraDevice = camera_device
end
presenting_controller ||= App.window.rootViewController.presentedViewController # May be nil, but handles use case of container views
presenting_controller ||= App.window.rootViewController
-
+
# use popover for iPad (ignore on iPhone)
if Device.ipad? and source_type==UIImagePickerControllerSourceTypePhotoLibrary and @popover_in_view
@popover = UIPopoverController.alloc.initWithContentViewController(picker)
@popover.presentPopoverFromRect(@popover_in_view.bounds, inView:@popover_in_view, permittedArrowDirections:UIPopoverArrowDirectionAny, animated:@options[:animated])
else
presenting_controller.presentViewController(self.picker, animated:@options[:animated], completion: lambda {})
end
end
-
+
# iPad popover is dismissed
def popoverControllerDidDismissPopover(popoverController)
@popover = nil
end
@@ -192,10 +196,15 @@
@picker_klass ||= UIImagePickerController
@picker ||= @picker_klass.alloc.init
end
def dismiss
- self.picker.dismissViewControllerAnimated(@options[:animated], completion: lambda {})
+ if @options[:on_dismiss]
+ @options[:on_dismiss].call(self.picker)
+ return
+ end
+
+ self.picker.dismissViewControllerAnimated(@options[:animated], completion: @options[:dismiss_completed])
end
# @param [UIImagePickerControllerSourceType] source_type to check
def self.source_type_available?(source_type)
UIImagePickerController.isSourceTypeAvailable(source_type)