Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 17 additions & 2 deletions Source/Configuration/YPFonts.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,15 @@

import UIKit

enum CustomFonts: String {
case karlaLight = "Karla-Light"
case karlaRegular = "Karla-Regular"
case karlaMedium = "Karla-Medium"
case karlaSemiBold = "Karla-SemiBold"
case karlaBold = "Karla-Bold"
case karlaExtraBold = "Karla-ExtraBold"
}

public struct YPFonts {

/// The font used in the picker title
Expand Down Expand Up @@ -36,8 +45,14 @@ public struct YPFonts {
public var navigationBarTitleFont: UIFont = .boldSystemFont(ofSize: 17)

/// The font used in the UINavigationBar rightBarButtonItem
public var rightBarButtonFont: UIFont?
public var rightBarButtonFont: UIFont = .init(name: CustomFonts.karlaMedium.rawValue, size: 15) ?? .systemFont(ofSize: 14, weight: .medium)

/// The font used in the UINavigationBar leftBarButtonItem
public var leftBarButtonFont: UIFont?
public var leftBarButtonFont: UIFont = .init(name: CustomFonts.karlaMedium.rawValue, size: 14) ?? .systemFont(ofSize: 14, weight: .medium)

public var editButtonFont: UIFont = .init(name: CustomFonts.karlaMedium.rawValue, size: 17) ?? UIFont.systemFont(ofSize: 17, weight: .medium)

public var selectMultipleLabelFont: UIFont = .init(name: CustomFonts.karlaMedium.rawValue, size: 14) ?? UIFont.systemFont(ofSize: 14, weight: .medium)

public var nextButtonFont: UIFont = .init(name: CustomFonts.karlaMedium.rawValue, size: 24) ?? .systemFont(ofSize: 24, weight: .medium)
}
14 changes: 7 additions & 7 deletions Source/Configuration/YPImagePickerConfiguration.swift
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,10 @@ public struct YPImagePickerConfiguration {

let windowScene = UIApplication.safeFirstWindowScene
screenWidth = windowScene?.screen.bounds.width ?? 1.0
if UIDevice.current.userInterfaceIdiom == .pad && YPImagePickerConfiguration.widthOniPad > 0 {
screenWidth = YPImagePickerConfiguration.widthOniPad
}
return screenWidth
if UIDevice.current.userInterfaceIdiom == .pad && YPImagePickerConfiguration.widthOniPad > 0 {
screenWidth = YPImagePickerConfiguration.widthOniPad
}
return screenWidth
}

/// If don't want to have logs from picker, set it to false.
Expand Down Expand Up @@ -157,7 +157,7 @@ public struct YPConfigLibrary {
/// Sets the cropping style to square or not. Ignored if `onlySquare` is true. Defaults to true.
public var isSquareByDefault = true

/// Minimum width, to prevent selectiong too high images. Have sense if onlySquare is true and the image is portrait.
/// Minimum width, to prevent selectiong too high images. Have sense if onlySquare is true and the image is portrait.
public var minWidthForItem: CGFloat?

/// Choose what media types are available in the library. Defaults to `.photo`.
Expand All @@ -178,10 +178,10 @@ public struct YPConfigLibrary {
public var minNumberOfItems = 1

/// Set the number of items per row in collection view. Defaults to 4.
public var numberOfItemsInRow: Int = 4
public var numberOfItemsInRow: Int = 3

/// Set the spacing between items in collection view. Defaults to 1.0.
public var spacingBetweenItems: CGFloat = 1.0
public var spacingBetweenItems: CGFloat = 2.0

/// Allow to skip the selections gallery when selecting the multiple media items. Defaults to false.
public var skipSelectionsGallery = false
Expand Down
6 changes: 6 additions & 0 deletions Source/Configuration/YPWordings.swift
Original file line number Diff line number Diff line change
Expand Up @@ -41,13 +41,17 @@ public struct YPWordings {
public var filter = ypLocalized("YPImagePickerFilter")
public var crop = ypLocalized("YPImagePickerCrop")
public var warningMaxItemsLimit = ypLocalized("YPImagePickerWarningItemsLimit")
public var warningMaxImagesLimit = "The limit is 5 photos"
public var warningMaxVideosLimit = "The limit is 5 videos"
public var deselectAll = ypLocalized("Deselect All")
}

public enum YPImagePickerStep {
case pick
case multipleGallary
case filter
case crop
case deselectAll
}

extension YPWordings {
Expand All @@ -67,6 +71,8 @@ extension YPWordings {
else { return wordings.next }
case .crop:
return wordings.done
case .deselectAll:
return wordings.deselectAll
}
}
}
2 changes: 0 additions & 2 deletions Source/Filters/Video/YPVideoFiltersVC.swift
Original file line number Diff line number Diff line change
Expand Up @@ -98,8 +98,6 @@ public final class YPVideoFiltersVC: UIViewController, IsMediaFilterVC {
// Set initial video cover
imageGenerator = AVAssetImageGenerator(asset: self.inputAsset)
imageGenerator?.appliesPreferredTrackTransform = true
imageGenerator?.requestedTimeToleranceAfter = CMTime.zero
imageGenerator?.requestedTimeToleranceBefore = CMTime.zero
didChangeThumbPosition(CMTime(seconds: 1, preferredTimescale: 1))
}

Expand Down
Binary file added Source/Font/Karla-Bold.ttf
Binary file not shown.
Binary file added Source/Font/Karla-ExtraBold.ttf
Binary file not shown.
Binary file added Source/Font/Karla-Light.ttf
Binary file not shown.
Binary file added Source/Font/Karla-Medium.ttf
Binary file not shown.
Binary file added Source/Font/Karla-Regular.ttf
Binary file not shown.
Binary file added Source/Font/Karla-SemiBold.ttf
Binary file not shown.
13 changes: 13 additions & 0 deletions Source/Helpers/Extensions/UIImage+Extensions.swift
Original file line number Diff line number Diff line change
Expand Up @@ -115,4 +115,17 @@ internal extension UIImage {
func toCIImage() -> CIImage? {
return self.ciImage ?? CIImage(cgImage: self.cgImage!)
}
func withInsets(_ insets: UIEdgeInsets, color: UIColor = .clear) -> UIImage? {
let size = CGSize(
width: 24 + insets.left + insets.right,
height: 17 + insets.top + insets.bottom
)
UIGraphicsBeginImageContextWithOptions(size, false, self.scale)
color.setFill()
UIRectFill(CGRect(origin: .zero, size: size))
self.draw(at: CGPoint(x: insets.left, y: insets.top))
let newImage = UIGraphicsGetImageFromCurrentImageContext()
UIGraphicsEndImageContext()
return newImage
}
}
8 changes: 3 additions & 5 deletions Source/Pages/Gallery/YPAssetZoomableView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,6 @@ final class YPAssetZoomableView: UIScrollView {
strongSelf.photoImageView.removeFromSuperview()
strongSelf.addSubview(strongSelf.videoView)
}

strongSelf.videoView.setPreviewImage(preview)

strongSelf.setAssetFrame(for: strongSelf.videoView, with: preview)
Expand Down Expand Up @@ -118,11 +117,10 @@ final class YPAssetZoomableView: UIScrollView {
strongSelf.videoView.showPlayImage(show: false)
strongSelf.videoView.deallocate()
strongSelf.addSubview(strongSelf.photoImageView)

strongSelf.photoImageView.contentMode = .scaleAspectFill
strongSelf.photoImageView.clipsToBounds = true
}

strongSelf.photoImageView.image = image

strongSelf.setAssetFrame(for: strongSelf.photoImageView, with: image)
Expand Down Expand Up @@ -150,7 +148,7 @@ final class YPAssetZoomableView: UIScrollView {
override init(frame: CGRect) {
super.init(frame: frame)

backgroundColor = YPConfig.colors.assetViewBackgroundColor
backgroundColor = .white//YPConfig.colors.assetViewBackgroundColor
clipsToBounds = true
photoImageView.frame = CGRect(origin: CGPoint.zero, size: CGSize.zero)
videoView.frame = CGRect(origin: CGPoint.zero, size: CGSize.zero)
Expand Down Expand Up @@ -185,7 +183,7 @@ fileprivate extension YPAssetZoomableView {
self.zoomScale = 1

// Calculating and setting the image view frame depending on screenWidth
let screenWidth = YPImagePickerConfiguration.screenWidth
let screenWidth = YPImagePickerConfiguration.screenWidth

let w = image.size.width
let h = image.size.height
Expand Down
3 changes: 3 additions & 0 deletions Source/Pages/Gallery/YPLibrary+LibraryChange.swift
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,9 @@ extension YPLibraryVC: PHPhotoLibraryChangeObserver {
self.mediaManager.hasResultItems == false {
self.v.assetZoomableView.clearAsset()
self.selectedItems.removeAll()
self.selectedImages.removeAll()
self.selectedVideos.removeAll()
self.delegate?.updateCount()
self.delegate?.libraryViewFinishedLoading()
}
}
Expand Down
43 changes: 32 additions & 11 deletions Source/Pages/Gallery/YPLibraryVC+CollectionView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -66,23 +66,36 @@ extension YPLibraryVC {

/// Removes cell from selection
func deselect(indexPath: IndexPath) {
if let positionIndex = selectedImages.firstIndex(where: {
$0 == mediaManager.getAsset(at: indexPath.row)
}) {
selectedImages.remove(at: positionIndex)
}

if let positionIndex = selectedVideos.firstIndex(where: {
$0 == mediaManager.getAsset(at: indexPath.row)
}) {
selectedVideos.remove(at: positionIndex)
}

if let positionIndex = selectedItems.firstIndex(where: {
$0.assetIdentifier == mediaManager.getAsset(at: indexPath.row)?.localIdentifier
}) {
}) {
selectedItems.remove(at: positionIndex)

// Refresh the numbers
let selectedIndexPaths = getSelectedIndexPaths(selectedItems: selectedItems)
v.collectionView.reloadItems(at: selectedIndexPaths)

self.delegate?.updateCount()

// Replace the current selected image with the previously selected one
if let previouslySelectedIndexPath = selectedIndexPaths.last {
v.collectionView.deselectItem(at: indexPath, animated: false)
v.collectionView.selectItem(at: previouslySelectedIndexPath, animated: false, scrollPosition: [])
currentlySelectedIndex = previouslySelectedIndexPath.row
changeAsset(mediaManager.getAsset(at: previouslySelectedIndexPath.row))
}
checkLimit()
}
}
Expand All @@ -99,14 +112,20 @@ extension YPLibraryVC {
}

let newSelection = YPLibrarySelection(index: indexPath.row, assetIdentifier: asset.localIdentifier)
selectedItems.append(newSelection)

if !isLimitExceeded {
selectedVideos.append(asset)
selectedItems.append(newSelection)
}

self.delegate?.updateCount()
checkLimit()
}

func isInSelectionPool(indexPath: IndexPath) -> Bool {
return selectedItems.contains(where: {
$0.assetIdentifier == mediaManager.getAsset(at: indexPath.row)?.localIdentifier
})
})
}

/// Checks if there can be selected more items. If no - present warning.
Expand All @@ -133,8 +152,6 @@ extension YPLibraryVC: UICollectionViewDelegate {
}

cell.representedAssetIdentifier = asset.localIdentifier
cell.multipleSelectionIndicator.selectionColor =
YPConfig.colors.multipleItemsSelectedCircleColor ?? YPConfig.colors.tintColor
mediaManager.imageManager?.requestImage(for: asset,
targetSize: v.cellSize(),
contentMode: .aspectFill,
Expand Down Expand Up @@ -199,12 +216,16 @@ extension YPLibraryVC: UICollectionViewDelegate {
addToSelection(indexPath: indexPath)
changeAsset(mediaManager.getAsset(at: indexPath.row))
}
self.delegate?.updateCount()
collectionView.reloadItems(at: [indexPath])
collectionView.reloadItems(at: [previouslySelectedIndexPath])
} else {
changeAsset(mediaManager.getAsset(at: indexPath.row))
selectedItems.removeAll()
selectedImages.removeAll()
selectedVideos.removeAll()
addToSelection(indexPath: indexPath)
self.delegate?.updateCount()

// Force deseletion of previously selected cell.
// In the case where the previous cell was loaded from iCloud, a new image was fetched
Expand Down Expand Up @@ -235,14 +256,14 @@ extension YPLibraryVC: UICollectionViewDelegateFlowLayout {
}

public func collectionView(_ collectionView: UICollectionView,
layout collectionViewLayout: UICollectionViewLayout,
minimumLineSpacingForSectionAt section: Int) -> CGFloat {
layout collectionViewLayout: UICollectionViewLayout,
minimumLineSpacingForSectionAt section: Int) -> CGFloat {
return YPConfig.library.spacingBetweenItems
}

public func collectionView(_ collectionView: UICollectionView,
layout collectionViewLayout: UICollectionViewLayout,
minimumInteritemSpacingForSectionAt section: Int) -> CGFloat {
layout collectionViewLayout: UICollectionViewLayout,
minimumInteritemSpacingForSectionAt section: Int) -> CGFloat {
return YPConfig.library.spacingBetweenItems
}
}
Loading