Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
SilenceLove committed Dec 23, 2023
1 parent 98134de commit c97ab9b
Show file tree
Hide file tree
Showing 10 changed files with 117 additions and 24 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -223,6 +223,7 @@ open class CameraViewController: BaseViewController {
}
open override func viewDidDisappear(_ animated: Bool) {
super.viewDidDisappear(animated)
guard UIImagePickerController.isSourceTypeAvailable(.camera), let cameraManager else { return }
let isFront = cameraManager.activeCamera?.position == .front
DispatchQueue.global().async {
if let sampleBuffer = PhotoManager.shared.sampleBuffer,
Expand All @@ -240,9 +241,6 @@ open class CameraViewController: BaseViewController {
PhotoManager.shared.sampleBuffer = nil
}
}
if !UIImagePickerController.isSourceTypeAvailable(.camera) {
return
}
cameraManager.stopRunning()
if config.cameraType == .metal {
cameraManager.resetFilter()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,12 @@ extension PhotoPickerController: PhotoPickerDataDelegate {
}

public func pickerData(_ pickerData: PhotoPickerData, removeSelectedAssetWhenRemovingAssets photoAssets: [PhotoAsset]) {
previewViewController?.removeSelectedAssetWhenRemovingAssets(photoAssets)
if let presentedViewController = presentedViewController as? PhotoPickerController,
let previewViewController = presentedViewController.previewViewController {
previewViewController.removeSelectedAssetWhenRemovingAssets(photoAssets)
}else {
previewViewController?.removeSelectedAssetWhenRemovingAssets(photoAssets)
}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -403,6 +403,10 @@ open class PhotoPickerController: UINavigationController {
}
}

func resetDelegate() {
delegate = self
}

public override func present(
_ viewControllerToPresent: UIViewController,
animated flag: Bool,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@ public class PhotoPickerPageViewController: BaseViewController, PhotoPickerList
contentVCs.insert(vc, at: 0)
}
headerView.titles = titles
headerView.selectedIndex = 0

scrollView.subviews.forEach { $0.removeFromSuperview() }
children.forEach { $0.removeFromParent() }
Expand All @@ -99,6 +100,7 @@ public class PhotoPickerPageViewController: BaseViewController, PhotoPickerList
scrollView.addSubview($0.view)
}
layoutViews()
scrollView.contentOffset = .zero
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,12 +63,19 @@ extension PhotoPickerViewController {
}else {
ProgressHUD.hide(forView: self.navigationController?.view, animated: false)
}
if AssetManager.authorizationStatusIsLimited(),
self.pickerConfig.isRemoveSelectedAssetWhenRemovingAssets {
self.photoToolbar.selectedAssetDidChanged(self.pickerController.selectedAssetArray)
self.photoToolbar.updateSelectedAssets(self.pickerController.selectedAssetArray)
self.finishItem?.selectedAssetDidChanged(self.pickerController.selectedAssetArray)
self.requestSelectedAssetFileSize()
if AssetManager.authorizationStatusIsLimited() {
if self.pickerConfig.isRemoveSelectedAssetWhenRemovingAssets {
self.photoToolbar.selectedAssetDidChanged(self.pickerController.selectedAssetArray)
self.photoToolbar.updateSelectedAssets(self.pickerController.selectedAssetArray)
self.finishItem?.selectedAssetDidChanged(self.pickerController.selectedAssetArray)
self.requestSelectedAssetFileSize()
}
if let previewViewController = self.navigationController?.topViewController as? PhotoPreviewViewController {
previewViewController.updateAsstes(for: result.assets)
}else if let presentedViewController = self.presentedViewController as? PhotoPickerController,
let previewViewController = presentedViewController.previewViewController {
previewViewController.updateAsstes(for: result.assets)
}
}
}
}
Expand All @@ -87,6 +94,7 @@ extension PhotoPickerViewController {
}
assetCollection = collection
}
initView()
updateTitle()
fetchPhotoAssets()
reloadAlbumData()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -221,6 +221,9 @@ extension PhotoPickerViewController: PhotoPickerControllerDelegate {
_ pickerController: PhotoPickerController,
dismissPreviewViewForIndexAt index: Int
) -> UIView? {
if pickerController.previewAssets.isEmpty {
return nil
}
let photoAsset = pickerController.previewAssets[index]
if let cell = listView.getCell(for: photoAsset) {
listView.scrollCellToVisibleArea(cell)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ public class PhotoPickerViewController: PhotoBaseViewController {
var albumView: PhotoAlbumList!
var photoToolbar: PhotoToolBar!
var isShowToolbar: Bool = false

var didInitViews: Bool = false
var showLoading: Bool = false

var orientationDidChange: Bool = false
Expand Down Expand Up @@ -194,6 +194,7 @@ public class PhotoPickerViewController: PhotoBaseViewController {
if isShowToolbar {
photoToolbar.viewDidAppear(self)
}
weakController?.resetDelegate()
}

public override func viewWillDisappear(_ animated: Bool) {
Expand Down Expand Up @@ -221,7 +222,11 @@ public class PhotoPickerViewController: PhotoBaseViewController {

extension PhotoPickerViewController {

private func initView() {
func initView() {
if didInitViews {
return
}
didInitViews = true
extendedLayoutIncludesOpaqueBars = true
edgesForExtendedLayout = .all
if #unavailable(iOS 11.0) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,11 @@ extension PhotoPreviewViewController: PhotoToolBarDelegate {
photoToolbar.selectedAssetDidChanged(selectedAssetArray)
photoToolbar.configPreviewList(previewAssets, page: currentPreviewIndex)
}else {
photoToolbar.updateSelectedAssets(previewAssets)
if config.bottomView.isShowPreviewList {
photoToolbar.configPreviewList(previewAssets, page: currentPreviewIndex)
}else {
photoToolbar.updateSelectedAssets(previewAssets)
}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -654,4 +654,35 @@ extension PhotoPreviewViewController {
}
}
}

func updateAsstes(for assets: [PhotoAsset]) {
previewAssets = assets
collectionView.reloadData()
let count = assetCount
if count > 0 {
var page = currentPreviewIndex
if page > count - 1 {
DispatchQueue.main.async {
self.scrollToItem(count - 1)
}
page = count - 1
}else {
DispatchQueue.main.async {
self.scrollViewDidScroll(self.collectionView)
self.startRequestPreviewTimer()
}
}
if isShowToolbar {
photoToolbar.configPreviewList(assets, page: page)
configBottomViewFrame()
}
}else {
if let viewControllers = navigationController?.viewControllers,
viewControllers.count > 1 {
navigationController?.popViewController(animated: true)
}else {
dismiss(animated: true, completion: nil)
}
}
}
}
55 changes: 44 additions & 11 deletions Sources/HXPhotoPicker/Picker/View/ToolBar/PhotoToolBarView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -97,17 +97,15 @@ public class PhotoToolBarView: UIToolbar, PhotoToolBar {
case .preview:
return pickerConfig.previewView.bottomView.isShowSelectedView && pickerConfig.selectMode == .multiple && !isShowPreviewList
case .browser:
return true
return !isShowPreviewList
}
}
private var isShowPreviewList: Bool {
switch type {
case .picker:
return false
case .preview:
case .preview, .browser:
return pickerConfig.previewView.bottomView.isShowPreviewList
case .browser:
return false
}
}

Expand Down Expand Up @@ -181,8 +179,16 @@ public class PhotoToolBarView: UIToolbar, PhotoToolBar {
#endif
}else {
viewConfig = pickerConfig.previewView.bottomView
initSelectedView()
selectedView.allowDrop = false
if isShowPreviewList {
previewListView = PhotoPreviewListView(frame: .init(x: 0, y: 0, width: width, height: 55))
previewListView.dataSource = self
addSubview(previewListView)
}else {
if isShowSelectedView {
initSelectedView()
selectedView.allowDrop = false
}
}
}

if type != .browser {
Expand Down Expand Up @@ -230,6 +236,16 @@ public class PhotoToolBarView: UIToolbar, PhotoToolBar {
contentView.addSubview(finishBtn)
}
layoutSubviews()
bringSubviewToFront(contentView)
if selectedView != nil {
bringSubviewToFront(selectedView)
}
if previewListView != nil {
bringSubviewToFront(previewListView)
}
if promptView != nil {
bringSubviewToFront(promptView)
}
configColor()
}

Expand Down Expand Up @@ -313,8 +329,12 @@ public class PhotoToolBarView: UIToolbar, PhotoToolBar {

public func updateSelectedAssets(_ photoAssets: [PhotoAsset]) {
if !isShowSelectedView { return }
if isShowPrompt, selectedView.photoAssetArray.isEmpty, !photoAssets.isEmpty {
promptView.alpha = 0
if isShowPrompt {
if selectedView.photoAssetArray.isEmpty, !photoAssets.isEmpty {
promptView.alpha = 0
}else if photoAssets.isEmpty {
promptView.alpha = 1
}
}
selectedView.reloadData(photoAssets: photoAssets)
}
Expand Down Expand Up @@ -462,8 +482,15 @@ public class PhotoToolBarView: UIToolbar, PhotoToolBar {
updateFinishButtonFrame()
updateOriginalViewFrame()
}else {
selectedView.y = 0
selectedView.width = width
if isShowPreviewList {
previewListView.y = 10
previewListView.width = width
}else {
if isShowSelectedView {
selectedView.y = 0
selectedView.width = width
}
}
}
}

Expand Down Expand Up @@ -728,7 +755,13 @@ extension PhotoToolBarView {
for: .disabled
)
}else {
selectedView.tickColor = isDark ? config.selectedViewTickDarkColor : config.selectedViewTickColor
if isShowPreviewList {
previewListView.selectColor = isDark ? config.previewListTickDarkColor : config.previewListTickColor
previewListView.selectBgColor = isDark ? config.previewListTickBgDarkColor : config.previewListTickBgColor
}
if isShowSelectedView {
selectedView.tickColor = isDark ? config.selectedViewTickDarkColor : config.selectedViewTickColor
}
}
}
}
Expand Down

0 comments on commit c97ab9b

Please sign in to comment.