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

Fix/app crash #782

Open
wants to merge 38 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
38 commits
Select commit Hold shift + click to select a range
24f02eb
added functionality to determine the correct aspect ratio
Jan 30, 2022
b5cbfb7
added mini-fix for library flow
Jan 31, 2022
dee2ba8
changed first zoom state of selected asset
Feb 1, 2022
c6799e6
Merge branch 'Yummypets:master' into master
StasKovalov Jun 1, 2022
22c55bc
fixed aspect ratios
SKovalov Jun 1, 2022
fbe6108
fixed aspect ratio
SKovalov Jun 1, 2022
f598363
fixed bug with drag and next action
SKovalov Jun 2, 2022
cb8da04
fixed zoom observe
SKovalov Jun 3, 2022
3046a4e
add fiting media boolean
SKovalov Jun 5, 2022
9d30ec1
added space
SKovalov Jun 5, 2022
607e9db
added dynamic ratios | added ratio for video
SKovalov Jun 5, 2022
de76ebc
added left button navigation color
SKovalov Jun 30, 2022
6e99a6b
added carousel feature
SKovalov Jul 31, 2022
8766ea6
removed borders from frames
SKovalov Jul 31, 2022
87a9c0a
fixed bug
SKovalov Aug 1, 2022
ae6e100
fixed one more bug
SKovalov Aug 1, 2022
127c6b6
fixed bug with multiple selection (default selection first media)
SKovalov Aug 1, 2022
848a057
fixed multipleSelection frame change with video
SKovalov Aug 3, 2022
a5f0364
fixed multipleSelection frame change with video
SKovalov Aug 3, 2022
cd223c0
fixed multipleSelection frame change with video
SKovalov Aug 3, 2022
5cf6870
fixed multipleSelection frame change with video
SKovalov Aug 3, 2022
5d55c6d
removed safe area view
SKovalov Aug 7, 2022
47c86ca
change initial album to recent and made media sorting like in instagram
SKovalov Oct 27, 2022
d11d853
fixed build error
SKovalov Oct 27, 2022
d1b9eed
changed init default album after permission checked
SKovalov Oct 27, 2022
cb038f3
changed init default album after permission checked
SKovalov Oct 27, 2022
c8ba07a
minifix
SKovalov Oct 27, 2022
efe0467
finished with draft fast posts version
Dec 11, 2022
f6bc02f
refactored draft version
Dec 12, 2022
acd53b6
added the ability to distinguish between carousel and quick posts
Dec 12, 2022
5811e74
reverted last commit
Dec 15, 2022
acbd105
added state by condition for quick posts
Dec 15, 2022
7a5994e
added default hiding for multipleSelection icon
Dec 15, 2022
5d66430
fixed bug with first open
Dec 25, 2022
cbf915d
fixed bug with first open
Dec 25, 2022
726c524
fixed bug with first open
Dec 25, 2022
0713dd2
Merge pull request #1 from StasKovalov/feature/multiple-post-add
StasKovalov Feb 12, 2023
fe90112
fixed app crash when recent album is unavailable
Feb 12, 2023
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
2 changes: 2 additions & 0 deletions Source/Configuration/YPIcons.swift
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ public struct YPIcons {
public var loopIcon: UIImage = imageFromBundle("yp_iconLoop")
public var multipleSelectionOffIcon: UIImage = imageFromBundle("yp_multiple")
public var multipleSelectionOnIcon: UIImage = imageFromBundle("yp_multiple_colored")
public var fastPostsSelectionOffIcon: UIImage = imageFromBundle("yp_fast_posts")
public var fastPostsSelectionOnIcon: UIImage = imageFromBundle("yp_fast_posts_colored")
public var capturePhotoImage: UIImage = imageFromBundle("yp_iconCapture")
public var captureVideoImage: UIImage = imageFromBundle("yp_iconVideoCapture")
public var captureVideoOnImage: UIImage = imageFromBundle("yp_iconVideoCaptureRecording")
Expand Down
17 changes: 17 additions & 0 deletions Source/Configuration/YPImagePickerConfiguration.swift
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,23 @@ public struct YPImagePickerConfiguration {

public init() {}

/// Include post aspect ratio
public var isPost = false

/// Include post aspect ratio
public var isQuickPosts = false

/// for updating carousel album
public var isCarouselAlbumUpdating = false
public var carouselAlbumAspectRatio = 0.805
public var carouselAlbumAssetType = 0 // 0: Portrait, 1: Landscape, 2: Square


// for unerstanding why ratios has such values, look at the calculateSquaredZoomScale func
public var portraitRatio = 0.805
public var photoLandscapeRatio = 0.5263
public var videoLandscapeRatio = 0.5625

/// Library configuration
public var library = YPConfigLibrary()

Expand Down
4 changes: 2 additions & 2 deletions Source/Helpers/Extensions/IndexSet+Extensions.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,11 @@
import Foundation

internal extension IndexSet {
func aapl_indexPathsFromIndexesWithSection(_ section: Int) -> [IndexPath] {
func aapl_indexPathsFromIndexesWithSection(_ section: Int, _ index: Int = 0) -> [IndexPath] {
var indexPaths: [IndexPath] = []
indexPaths.reserveCapacity(count)
(self as NSIndexSet).enumerate({idx, _ in
indexPaths.append(IndexPath(item: idx, section: section))
indexPaths.append(IndexPath(item: index - idx - 1, section: section))
})
return indexPaths
}
Expand Down
2 changes: 1 addition & 1 deletion Source/Pages/Gallery/LibraryMediaManager.swift
Original file line number Diff line number Diff line change
Expand Up @@ -228,6 +228,6 @@ class LibraryMediaManager {
print("FetchResult not contain this index: \(index)")
return nil
}
return fetchResult.object(at: index)
return fetchResult.object(at: fetchResult.count - index - 1)
}
}
128 changes: 121 additions & 7 deletions Source/Pages/Gallery/YPAssetViewContainer.swift
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import AVFoundation

/// The container for asset (video or image). It containts the YPGridView and YPAssetZoomableView.
final class YPAssetViewContainer: UIView {

public var zoomableView: YPAssetZoomableView
public var itemOverlay: UIView?
public let curtain = UIView()
Expand All @@ -30,15 +31,22 @@ final class YPAssetViewContainer: UIView {
private let spinner = UIActivityIndicatorView(style: .white)
private var shouldCropToSquare = YPConfig.library.isSquareByDefault
private var isMultipleSelectionEnabled = false

private var isFastPostsSelectionEnabled = false

// carousel
private var currentZoomableViewWidthAnchor: NSLayoutConstraint! = nil
private var currentZoomableViewHeightAnchor: NSLayoutConstraint! = nil

private var currentViewWidthAnchor: NSLayoutConstraint! = nil
private var currentViewHeightAnchor: NSLayoutConstraint! = nil

public var itemOverlayType = YPConfig.library.itemOverlayType

init(frame: CGRect, zoomableView: YPAssetZoomableView) {
self.zoomableView = zoomableView
super.init(frame: frame)

self.zoomableView.zoomableViewDelegate = self

switch itemOverlayType {
case .grid:
itemOverlay = YPGridView()
Expand All @@ -50,7 +58,7 @@ final class YPAssetViewContainer: UIView {
addSubview(itemOverlay)
itemOverlay.frame = frame
clipsToBounds = true

itemOverlay.alpha = 0
}

Expand Down Expand Up @@ -78,7 +86,7 @@ final class YPAssetViewContainer: UIView {
curtain.backgroundColor = UIColor.ypLabel.withAlphaComponent(0.7)
curtain.alpha = 0

if !onlySquare {
if ((!YPConfig.isCarouselAlbumUpdating && !YPConfig.library.defaultMultipleSelection) && !onlySquare) {
// Crop Button
squareCropButton.setImage(YPConfig.icons.cropIcon, for: .normal)
sv(squareCropButton)
Expand Down Expand Up @@ -106,14 +114,26 @@ final class YPAssetViewContainer: UIView {
shouldCropToSquare = (z >= 1 && z < zoomableView.squaredZoomScale)
zoomableView.fitImage(shouldCropToSquare, animated: true)
}

/// Update only UI of square crop button.
public func updateSquareCropButtonState() {
if(YPConfig.isCarouselAlbumUpdating || YPConfig.library.defaultMultipleSelection) {
squareCropButton.isHidden = true
}

guard !isMultipleSelectionEnabled else {
// If multiple selection enabled, the squareCropButton is not visible
squareCropButton.isHidden = true
return
}


guard !isFastPostsSelectionEnabled else {
// If multiple selection enabled, the squareCropButton is not visible
squareCropButton.isHidden = true
return
}

guard !onlySquare else {
// If only square enabled, than the squareCropButton is not visible
squareCropButton.isHidden = true
Expand All @@ -134,9 +154,103 @@ final class YPAssetViewContainer: UIView {
/// Use this to update the multiple selection mode UI state for the YPAssetViewContainer
public func setMultipleSelectionMode(on: Bool) {
isMultipleSelectionEnabled = on
let image = on ? YPConfig.icons.multipleSelectionOnIcon : YPConfig.icons.multipleSelectionOffIcon
multipleSelectionButton.setImage(image, for: .normal)

if(isFastPostsSelectionEnabled) {
isFastPostsSelectionEnabled = false
let fastPostsSelectionImageState = YPConfig.icons.fastPostsSelectionOffIcon
}

let multipleSelectionImageState = on ? YPConfig.icons.multipleSelectionOnIcon : YPConfig.icons.multipleSelectionOffIcon

multipleSelectionButton.setImage(multipleSelectionImageState, for: .normal)

updateSquareCropButtonState()

if(!YPConfig.isCarouselAlbumUpdating && !YPConfig.library.defaultMultipleSelection) {
changeFrameDimensionsToSelectedMediaAspectRatio()
}
}

/// Use this to update the fast posts selection mode UI state for the YPAssetViewContainer
// public func setFastPostsSelection(on: Bool) {
// isFastPostsSelectionEnabled = on
//
// if(isMultipleSelectionEnabled) {
// isMultipleSelectionEnabled = false
// let multipleSelectionImageState = YPConfig.icons.multipleSelectionOffIcon
// multipleSelectionButton.setImage(multipleSelectionImageState, for: .normal)
// changeFrameDimensionsToSelectedMediaAspectRatio()
// }
// let fastPostsSelectionImageState = on ? YPConfig.icons.fastPostsSelectionOnIcon : YPConfig.icons.fastPostsSelectionOffIcon
//
// updateSquareCropButtonState()
// }


public func changeFrameDimensionsToSelectedMediaAspectRatio () {
let selectedMedia = self.zoomableView.isVideoMode ? self.zoomableView.videoView : self.zoomableView.assetImageView

if(isMultipleSelectionEnabled) {
self.zoomableView.isMultipleSelectionEnabled = true
if(selectedMedia.frame.size.width < YPImagePickerConfiguration.screenWidth) {
let carouselAlbumMediaWidth = selectedMedia.frame.size.width
let carouselAlbumMediaHeight = YPImagePickerConfiguration.screenWidth
self.zoomableView.multipleSelectionAspectRatio = selectedMedia.frame.size.width / YPImagePickerConfiguration.screenWidth
self.zoomableView.multipleSelectionAssetType = 0

if(self.currentZoomableViewWidthAnchor == nil && self.currentZoomableViewHeightAnchor == nil) {
self.currentZoomableViewWidthAnchor = self.zoomableView.widthAnchor.constraint(equalToConstant: carouselAlbumMediaWidth)
self.currentZoomableViewWidthAnchor.isActive = true
self.currentZoomableViewHeightAnchor = self.zoomableView.heightAnchor.constraint(equalToConstant: carouselAlbumMediaHeight)
self.currentZoomableViewHeightAnchor.isActive = true
} else {
self.currentZoomableViewWidthAnchor.constant = carouselAlbumMediaWidth
self.currentZoomableViewHeightAnchor.constant = carouselAlbumMediaHeight
}

self.zoomableView.centerHorizontally()
selectedMedia.frame.origin.x = 0

} else if (selectedMedia.frame.size.width > selectedMedia.frame.size.height && selectedMedia.frame.size.height < YPImagePickerConfiguration.screenWidth) {
let carouselAlbumMediaWidth = YPImagePickerConfiguration.screenWidth
let carouselAlbumMediaHeight = selectedMedia.frame.size.height
self.zoomableView.multipleSelectionAspectRatio = carouselAlbumMediaHeight / carouselAlbumMediaWidth
self.zoomableView.multipleSelectionAssetType = 1
if(self.currentZoomableViewWidthAnchor == nil && self.currentZoomableViewHeightAnchor == nil) {
self.currentZoomableViewWidthAnchor = self.zoomableView.widthAnchor.constraint(equalToConstant: carouselAlbumMediaWidth)
self.currentZoomableViewWidthAnchor.isActive = true
self.currentZoomableViewHeightAnchor = self.zoomableView.heightAnchor.constraint(equalToConstant: carouselAlbumMediaHeight)
self.currentZoomableViewHeightAnchor.isActive = true
} else {
self.currentZoomableViewWidthAnchor.constant = carouselAlbumMediaWidth
self.currentZoomableViewHeightAnchor.constant = carouselAlbumMediaHeight
}
if(self.currentViewWidthAnchor == nil && self.currentViewHeightAnchor == nil) {
self.currentViewWidthAnchor = self.widthAnchor.constraint(equalToConstant: YPImagePickerConfiguration.screenWidth)
self.currentViewWidthAnchor.isActive = true
self.currentViewHeightAnchor = self.heightAnchor.constraint(equalToConstant: YPImagePickerConfiguration.screenWidth)
self.currentViewHeightAnchor.isActive = true
} else {
self.currentViewWidthAnchor.constant = YPImagePickerConfiguration.screenWidth
self.currentViewHeightAnchor.constant = YPImagePickerConfiguration.screenWidth
}

selectedMedia.frame.origin.y = 0
self.zoomableView.centerVertically()
} else if (selectedMedia.frame.size.width >= YPImagePickerConfiguration.screenWidth) {
self.zoomableView.multipleSelectionAssetType = 2
}

} else {
self.zoomableView.isMultipleSelectionEnabled = false
if(self.currentZoomableViewWidthAnchor != nil && self.currentZoomableViewHeightAnchor != nil) {
self.currentZoomableViewWidthAnchor.constant = YPImagePickerConfiguration.screenWidth
self.currentZoomableViewHeightAnchor.constant = YPImagePickerConfiguration.screenWidth
self.zoomableView.centerVertically()
self.zoomableView.fitImage(true, animated:true)
}
}
self.zoomableView.layoutIfNeeded()
}
}

Expand Down
Loading