Skip to content

Commit

Permalink
refactor: handle for Authorization === '.limit' on iOS 14 && limit se…
Browse files Browse the repository at this point in the history
…lected === 0
  • Loading branch information
baronha committed Sep 19, 2023
1 parent 723463f commit 3d50945
Show file tree
Hide file tree
Showing 9 changed files with 207 additions and 193 deletions.
26 changes: 0 additions & 26 deletions example/ios/MultipleImagePickerExample.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,12 @@
objects = {

/* Begin PBXBuildFile section */
00E356F31AD99517003FC87E /* MultipleImagePickerExampleTests.m in Sources */ = {isa = PBXBuildFile; fileRef = 00E356F21AD99517003FC87E /* MultipleImagePickerExampleTests.m */; };
0E8817ED29D74E5D004363C7 /* AppDelegate.mm in Sources */ = {isa = PBXBuildFile; fileRef = 0E8817EC29D74E5D004363C7 /* AppDelegate.mm */; };
0E8817EE29D74E5D004363C7 /* AppDelegate.mm in Sources */ = {isa = PBXBuildFile; fileRef = 0E8817EC29D74E5D004363C7 /* AppDelegate.mm */; };
13B07FBF1A68108700A75B9A /* Images.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 13B07FB51A68108700A75B9A /* Images.xcassets */; };
13B07FC11A68108700A75B9A /* main.m in Sources */ = {isa = PBXBuildFile; fileRef = 13B07FB71A68108700A75B9A /* main.m */; };
2D02E4BD1E0B4A84006451C7 /* Images.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 13B07FB51A68108700A75B9A /* Images.xcassets */; };
2D02E4BF1E0B4AB3006451C7 /* main.m in Sources */ = {isa = PBXBuildFile; fileRef = 13B07FB71A68108700A75B9A /* main.m */; };
2DCD954D1E0B4F2C00145EB5 /* MultipleImagePickerExampleTests.m in Sources */ = {isa = PBXBuildFile; fileRef = 00E356F21AD99517003FC87E /* MultipleImagePickerExampleTests.m */; };
4B1BF0EBD93A640887A28207 /* libPods-MultipleImagePickerExample.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 25B29AFF6CDF9F98D64E16A6 /* libPods-MultipleImagePickerExample.a */; };
81AB9BB82411601600AC10FF /* LaunchScreen.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 81AB9BB72411601600AC10FF /* LaunchScreen.storyboard */; };
92E8344C25E25EBE00B0304C /* Bridge.swift in Sources */ = {isa = PBXBuildFile; fileRef = 92E8344B25E25EBE00B0304C /* Bridge.swift */; };
Expand All @@ -38,10 +36,7 @@
/* End PBXContainerItemProxy section */

/* Begin PBXFileReference section */
008F07F21AC5B25A0029DE68 /* main.jsbundle */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = main.jsbundle; sourceTree = "<group>"; };
00E356EE1AD99517003FC87E /* MultipleImagePickerExampleTests.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = MultipleImagePickerExampleTests.xctest; sourceTree = BUILT_PRODUCTS_DIR; };
00E356F11AD99517003FC87E /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = "<group>"; };
00E356F21AD99517003FC87E /* MultipleImagePickerExampleTests.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = MultipleImagePickerExampleTests.m; sourceTree = "<group>"; };
0E8817EC29D74E5D004363C7 /* AppDelegate.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; name = AppDelegate.mm; path = MultipleImagePickerExample/AppDelegate.mm; sourceTree = "<group>"; };
13B07F961A680F5B00A75B9A /* MultipleImagePickerExample.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = MultipleImagePickerExample.app; sourceTree = BUILT_PRODUCTS_DIR; };
13B07FAF1A68108700A75B9A /* AppDelegate.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = AppDelegate.h; path = MultipleImagePickerExample/AppDelegate.h; sourceTree = "<group>"; };
Expand Down Expand Up @@ -93,28 +88,10 @@
/* End PBXFrameworksBuildPhase section */

/* Begin PBXGroup section */
00E356EF1AD99517003FC87E /* MultipleImagePickerExampleTests */ = {
isa = PBXGroup;
children = (
00E356F21AD99517003FC87E /* MultipleImagePickerExampleTests.m */,
00E356F01AD99517003FC87E /* Supporting Files */,
);
path = MultipleImagePickerExampleTests;
sourceTree = "<group>";
};
00E356F01AD99517003FC87E /* Supporting Files */ = {
isa = PBXGroup;
children = (
00E356F11AD99517003FC87E /* Info.plist */,
);
name = "Supporting Files";
sourceTree = "<group>";
};
13B07FAE1A68108700A75B9A /* MultipleImagePickerExample */ = {
isa = PBXGroup;
children = (
0E8817EC29D74E5D004363C7 /* AppDelegate.mm */,
008F07F21AC5B25A0029DE68 /* main.jsbundle */,
13B07FAF1A68108700A75B9A /* AppDelegate.h */,
13B07FB51A68108700A75B9A /* Images.xcassets */,
13B07FB61A68108700A75B9A /* Info.plist */,
Expand Down Expand Up @@ -156,7 +133,6 @@
92E8344B25E25EBE00B0304C /* Bridge.swift */,
13B07FAE1A68108700A75B9A /* MultipleImagePickerExample */,
832341AE1AAA6A7D00B99B32 /* Libraries */,
00E356EF1AD99517003FC87E /* MultipleImagePickerExampleTests */,
83CBBA001A601CBA00E9B192 /* Products */,
2D16E6871FA4F8E400B85C8A /* Frameworks */,
6B9684456A2045ADE5A6E47E /* Pods */,
Expand Down Expand Up @@ -488,7 +464,6 @@
isa = PBXSourcesBuildPhase;
buildActionMask = 2147483647;
files = (
00E356F31AD99517003FC87E /* MultipleImagePickerExampleTests.m in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
Expand All @@ -515,7 +490,6 @@
isa = PBXSourcesBuildPhase;
buildActionMask = 2147483647;
files = (
2DCD954D1E0B4F2C00145EB5 /* MultipleImagePickerExampleTests.m in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
Expand Down
2 changes: 2 additions & 0 deletions example/ios/MultipleImagePickerExample/Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>PHPhotoLibraryPreventAutomaticLimitedAccessAlert</key>
<true/>
<key>NSPhotoLibraryUsageDescription</key>
<string>Cho truy cập Photo Gallery nha baby.</string>
<key>NSCameraUsageDescription</key>
Expand Down
8 changes: 4 additions & 4 deletions example/ios/Podfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -330,12 +330,12 @@ PODS:
- React-jsinspector (0.71.5)
- React-logger (0.71.5):
- glog
- react-native-multiple-image-picker (1.0.3):
- react-native-multiple-image-picker (1.1.1):
- CropViewController (= 2.6.1)
- React-Core
- react-native-multiple-image-picker/Viewer (= 1.0.3)
- react-native-multiple-image-picker/Viewer (= 1.1.1)
- TLPhotoPicker (= 2.1.9)
- react-native-multiple-image-picker/Viewer (1.0.3):
- react-native-multiple-image-picker/Viewer (1.1.1):
- CropViewController (= 2.6.1)
- React-Core
- TLPhotoPicker (= 2.1.9)
Expand Down Expand Up @@ -618,7 +618,7 @@ SPEC CHECKSUMS:
React-jsiexecutor: 1579bf3207afadc72ac3638a66a102d1bf5263e3
React-jsinspector: 14a342151ab810862998dfc99e2720746734e9b3
React-logger: 94ec392ae471683635e4bf874d4e82f675399d2d
react-native-multiple-image-picker: 83b0fe4a14eaa7ae6fd5e5af46d7706ce26b2c7b
react-native-multiple-image-picker: c55a7b2e2eb7562c6d395d09e413194d2d1c4179
React-perflogger: 883a55a9a899535eaf06d0029108ef9ef22cce92
React-RCTActionSheet: 1a3b8416688a3d291367be645022886f71d6842a
React-RCTAnimation: e5560cb72d91ba35151d51e2eb0d467b42763f43
Expand Down
2 changes: 2 additions & 0 deletions example/src/App.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,8 @@ export default function App() {
doneTitle: 'Xong',
singleSelectedMode,
isCrop: true,
usedCameraButton: false,
mediaType: 'video',
});

const crop = response.crop;
Expand Down
52 changes: 29 additions & 23 deletions ios/CustomPhotoPicker/CustomPhotoPickerViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,16 @@ class CustomPhotoPickerViewController: TLPhotosPickerViewController {
NotificationCenter.default.removeObserver(self)
}

func getTotalCount() -> Int {
var count = 0

for section in 0 ..< collectionView.numberOfSections {
count += collectionView.numberOfItems(inSection: section)
}

return count
}

@objc func handleCellLongPress(_ notification: Notification) {
if let cell = notification.object as? Cell {
if let indexPath = collectionView.indexPath(for: cell) {
Expand Down Expand Up @@ -89,13 +99,7 @@ class CustomPhotoPickerViewController: TLPhotosPickerViewController {

extension CustomPhotoPickerViewController: ViewerControllerDataSource {
func numberOfItemsInViewerController(_: ViewerController) -> Int {
var count = 0

for section in 0 ..< collectionView.numberOfSections {
count += collectionView.numberOfItems(inSection: section)
}

return count
return self.getTotalCount()
}

func viewerController(_: ViewerController, viewableAt indexPath: IndexPath) -> Viewable {
Expand Down Expand Up @@ -123,33 +127,35 @@ extension CustomPhotoPickerViewController: PreviewHeaderViewDelegate {
func headerView(_: PreviewHeaderView, didPressDoneButton _: UIButton) {
DispatchQueue.main.async {
self.viewerController?.dismiss {
if config.singleSelectedMode || (self.selectedAssets.count == 0) {
guard
let indexPath = self.viewerController?.currentIndexPath,
DispatchQueue.main.async {
if config.singleSelectedMode || (self.selectedAssets.count == 0) {
guard
let indexPath = self.viewerController?.currentIndexPath,

let cell = self.collectionView.cellForItem(at: indexPath) as? TLPhotoCollectionViewCell,
let cell = self.collectionView.cellForItem(at: indexPath) as? TLPhotoCollectionViewCell,

let localID = cell.asset?.localIdentifier,
let localID = cell.asset?.localIdentifier,

var asset = TLPHAsset.asset(with: localID),
var asset = TLPHAsset.asset(with: localID),

let phAsset = asset.phAsset,
let phAsset = asset.phAsset,

self.canSelect(phAsset: phAsset)
self.canSelect(phAsset: phAsset)

else { return }
else { return }

self.logDelegate?.selectedPhoto(picker: self, at: indexPath.row)
self.logDelegate?.selectedPhoto(picker: self, at: indexPath.row)

asset.selectedOrder = 1
if !config.singleSelectedMode {
cell.selectedAsset = true
cell.orderLabel?.text = "\(asset.selectedOrder)"
asset.selectedOrder = 1
if !config.singleSelectedMode {
cell.selectedAsset = true
cell.orderLabel?.text = "\(asset.selectedOrder)"
}
self.selectedAssets = [asset]
}

self.selectedAssets = [asset]
self.dismissPhotoPicker!(self.selectedAssets)
}
self.dismissPhotoPicker!(self.selectedAssets)
}
}
}
Expand Down
Loading

0 comments on commit 3d50945

Please sign in to comment.