Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Live Preview #39

Merged
merged 24 commits into from
Apr 9, 2019
Merged

Live Preview #39

merged 24 commits into from
Apr 9, 2019

Conversation

daveluong
Copy link
Contributor

@daveluong daveluong commented Apr 4, 2019

  1. This PR introduces a new configurable to enable live camera view in place of the camera icon view in PhotoGalleryViewController if there is camera access permission
public protocol ImagePickerConfigurable {
....
 /// Configure to enable/disable live camera view in place of the camera icon cell
    var liveCameraViewEnabled: Bool { get }
....
}
  1. This PR introduces a 2 way communication between custom camera view controller and PhotoGalleryViewController that allows selectedAssets to be passed between the 2, using:
  • new delegate method in ImagePickerControllerDelegate
 @objc optional func imagePickerController(_ picker: ImagePickerController, didFinishLaunchingCameraWith assets: [PHAsset])
  • new function call updateSelectedAssets(_ assets: [PHAsset]) that will replace existing assets in ImagePickerControlelr since custom camera controller can modify selected assets as well

IMG_0042

@daveluong daveluong requested a review from bcylin April 4, 2019 05:50
@carouselljenkins
Copy link

@HungnguyenVN, can you review this pull request?

@carouselljenkins
Copy link

carouselljenkins commented Apr 4, 2019

1 Error
🚫 Please rebase to get rid of the merge commits in this PR
Please update CHANGELOG.md.

Generated by 🚫 Danger

@daveluong
Copy link
Contributor Author

26.66s$ make -B carthage
set -o pipefail && carthage build --no-skip-current --verbose | bundle exec xcpretty -c
A shell task (/usr/bin/xcrun xcodebuild -project /Users/travis/build/carousell/pickle/Example/Pods/Pods.xcodeproj CODE_SIGNING_REQUIRED=NO CODE_SIGN_IDENTITY= CARTHAGE=YES -list) failed with exit code 74:
xcodebuild: error: Unable to read project 'Pods.xcodeproj' from folder '/Users/travis/build/carousell/pickle/Example/Pods'.
	Reason: Project /Users/travis/build/carousell/pickle/Example/Pods/Pods.xcodeproj cannot be opened because it is missing its project.pbxproj file.

@bcylin It seems that the project directories update broke Carthage

Copy link
Collaborator

@bcylin bcylin left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Carthage build fails due to the /Users/travis/build/carousell/pickle/Example/Pods/* cache. Example/Pods/* are now ignored on the master branch.

CI should pass after removing the ignored directories:
https://travis-ci.org/bcylin/pickle/builds/515880016 @ f9fc024

Pickle/Classes/PhotoGalleryLiveViewCell.swift Show resolved Hide resolved
Pickle/Classes/ImagePickerConfigurable.swift Outdated Show resolved Hide resolved
Pickle/Classes/PhotoGalleryLiveViewCell.swift Outdated Show resolved Hide resolved
Pickle.podspec Outdated Show resolved Hide resolved
Copy link
Collaborator

@bcylin bcylin left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good 👍 just left some minor suggestions.

Pickle/Classes/LiveView.swift Show resolved Hide resolved
Pickle/Classes/LiveView.swift Outdated Show resolved Hide resolved
@daveluong
Copy link
Contributor Author

hey @bcylin, thank you for taking your time to review the PR, I've made the changes requested. In addition, I've modified a few other things that need your opinion on. I have commented in the code

@@ -122,7 +122,7 @@ open class ImagePickerController: UINavigationController {
}
}

fileprivate var selectedAssets: [PHAsset]
public private(set) var selectedAssets: [PHAsset]
Copy link
Contributor Author

@daveluong daveluong Apr 8, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Our new gallery design requires passing selected assets from photo gallery view to camera view so I need to make selectedAssets in ImagePickerViewController publicly accessible

Basically we need a way to pass selectedAssets between a custom camera controller and ImagePickerController, please refer to the PR's description for details. Let me know if you have a better way to do this, thanks!

func startSession() throws {
guard hasPermssion else {
throw CameraSessionError.noPermission
}
guard
let input = AVCaptureDevice.default(for: .video),
let deviceInput = try? AVCaptureDeviceInput(device: input) else {
throw CameraSessionError.noDeviceInput
Copy link
Contributor Author

@daveluong daveluong Apr 8, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Accessing AVCaptureDeviceInput in the initializer will prematurely prompt user for permission, so I have moved it to startSession() instead. We only use the live view when user has already granted permission previously

@daveluong daveluong requested a review from bcylin April 8, 2019 06:22
Copy link
Collaborator

@bcylin bcylin left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Quite an interesting camera flow!

@@ -19,6 +19,9 @@ public protocol ImagePickerControllerDelegate: UINavigationControllerDelegate {
/// Asks the delegate if the image picker should launch camera with certain permission status.
func imagePickerController(_ picker: ImagePickerController, shouldLaunchCameraWithAuthorization status: AVAuthorizationStatus) -> Bool

/// Tells the delegate that picker has finished launching camera with an array of selected assets
@objc optional func imagePickerController(_ picker: ImagePickerController, didFinishLaunchingCameraWith assets: [PHAsset])
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should this be imagePickerControllerdidFinishLaunchingCamera(_:) since the selectedAssets is now accessible from ImagePickerController?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh no, I have changed it back to private since we already have this delegate

if traitCollection.forceTouchCapability == .available {
registerForPreviewing(with: self, sourceView: collectionView)
}
if configuration?.isLiveCameraViewEnabled == .some(true) {
sessionHandler = try? CameraSessionHandler()
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The AVCaptureDeviceInput is moved to startSession(), maybe the initializer doesn't have to throw an error?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's throwing .noPermission error if there is no permission, should I change it to just return nil with init?()?

@@ -209,6 +209,10 @@ open class ImagePickerController: UINavigationController {
showPermissionErrorIfNeeded?()
}

public func updateSelectedAssets(with assets: [PHAsset]) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It'd be good to have the documentation of this method, also worth mentioning that this method won't trigger the didSelect and didDeselectImageAsset delegate methods.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have updated README

@daveluong
Copy link
Contributor Author

Thanks @bcylin! I'll merge it and create a new release

@daveluong daveluong merged commit 889000b into master Apr 9, 2019
@daveluong daveluong deleted the feature/live-preview branch April 9, 2019 05:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants