Skip to content

Commit 3d50945

Browse files
committed
refactor: handle for Authorization === '.limit' on iOS 14 && limit selected === 0
1 parent 723463f commit 3d50945

File tree

9 files changed

+207
-193
lines changed

9 files changed

+207
-193
lines changed

example/ios/MultipleImagePickerExample.xcodeproj/project.pbxproj

-26
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,12 @@
77
objects = {
88

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

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

9590
/* Begin PBXGroup section */
96-
00E356EF1AD99517003FC87E /* MultipleImagePickerExampleTests */ = {
97-
isa = PBXGroup;
98-
children = (
99-
00E356F21AD99517003FC87E /* MultipleImagePickerExampleTests.m */,
100-
00E356F01AD99517003FC87E /* Supporting Files */,
101-
);
102-
path = MultipleImagePickerExampleTests;
103-
sourceTree = "<group>";
104-
};
105-
00E356F01AD99517003FC87E /* Supporting Files */ = {
106-
isa = PBXGroup;
107-
children = (
108-
00E356F11AD99517003FC87E /* Info.plist */,
109-
);
110-
name = "Supporting Files";
111-
sourceTree = "<group>";
112-
};
11391
13B07FAE1A68108700A75B9A /* MultipleImagePickerExample */ = {
11492
isa = PBXGroup;
11593
children = (
11694
0E8817EC29D74E5D004363C7 /* AppDelegate.mm */,
117-
008F07F21AC5B25A0029DE68 /* main.jsbundle */,
11895
13B07FAF1A68108700A75B9A /* AppDelegate.h */,
11996
13B07FB51A68108700A75B9A /* Images.xcassets */,
12097
13B07FB61A68108700A75B9A /* Info.plist */,
@@ -156,7 +133,6 @@
156133
92E8344B25E25EBE00B0304C /* Bridge.swift */,
157134
13B07FAE1A68108700A75B9A /* MultipleImagePickerExample */,
158135
832341AE1AAA6A7D00B99B32 /* Libraries */,
159-
00E356EF1AD99517003FC87E /* MultipleImagePickerExampleTests */,
160136
83CBBA001A601CBA00E9B192 /* Products */,
161137
2D16E6871FA4F8E400B85C8A /* Frameworks */,
162138
6B9684456A2045ADE5A6E47E /* Pods */,
@@ -488,7 +464,6 @@
488464
isa = PBXSourcesBuildPhase;
489465
buildActionMask = 2147483647;
490466
files = (
491-
00E356F31AD99517003FC87E /* MultipleImagePickerExampleTests.m in Sources */,
492467
);
493468
runOnlyForDeploymentPostprocessing = 0;
494469
};
@@ -515,7 +490,6 @@
515490
isa = PBXSourcesBuildPhase;
516491
buildActionMask = 2147483647;
517492
files = (
518-
2DCD954D1E0B4F2C00145EB5 /* MultipleImagePickerExampleTests.m in Sources */,
519493
);
520494
runOnlyForDeploymentPostprocessing = 0;
521495
};

example/ios/MultipleImagePickerExample/Info.plist

+2
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
33
<plist version="1.0">
44
<dict>
5+
<key>PHPhotoLibraryPreventAutomaticLimitedAccessAlert</key>
6+
<true/>
57
<key>NSPhotoLibraryUsageDescription</key>
68
<string>Cho truy cập Photo Gallery nha baby.</string>
79
<key>NSCameraUsageDescription</key>

example/ios/Podfile.lock

+4-4
Original file line numberDiff line numberDiff line change
@@ -330,12 +330,12 @@ PODS:
330330
- React-jsinspector (0.71.5)
331331
- React-logger (0.71.5):
332332
- glog
333-
- react-native-multiple-image-picker (1.0.3):
333+
- react-native-multiple-image-picker (1.1.1):
334334
- CropViewController (= 2.6.1)
335335
- React-Core
336-
- react-native-multiple-image-picker/Viewer (= 1.0.3)
336+
- react-native-multiple-image-picker/Viewer (= 1.1.1)
337337
- TLPhotoPicker (= 2.1.9)
338-
- react-native-multiple-image-picker/Viewer (1.0.3):
338+
- react-native-multiple-image-picker/Viewer (1.1.1):
339339
- CropViewController (= 2.6.1)
340340
- React-Core
341341
- TLPhotoPicker (= 2.1.9)
@@ -618,7 +618,7 @@ SPEC CHECKSUMS:
618618
React-jsiexecutor: 1579bf3207afadc72ac3638a66a102d1bf5263e3
619619
React-jsinspector: 14a342151ab810862998dfc99e2720746734e9b3
620620
React-logger: 94ec392ae471683635e4bf874d4e82f675399d2d
621-
react-native-multiple-image-picker: 83b0fe4a14eaa7ae6fd5e5af46d7706ce26b2c7b
621+
react-native-multiple-image-picker: c55a7b2e2eb7562c6d395d09e413194d2d1c4179
622622
React-perflogger: 883a55a9a899535eaf06d0029108ef9ef22cce92
623623
React-RCTActionSheet: 1a3b8416688a3d291367be645022886f71d6842a
624624
React-RCTAnimation: e5560cb72d91ba35151d51e2eb0d467b42763f43

example/src/App.js

+2
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,8 @@ export default function App() {
5454
doneTitle: 'Xong',
5555
singleSelectedMode,
5656
isCrop: true,
57+
usedCameraButton: false,
58+
mediaType: 'video',
5759
});
5860

5961
const crop = response.crop;

ios/CustomPhotoPicker/CustomPhotoPickerViewController.swift

+29-23
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,16 @@ class CustomPhotoPickerViewController: TLPhotosPickerViewController {
2727
NotificationCenter.default.removeObserver(self)
2828
}
2929

30+
func getTotalCount() -> Int {
31+
var count = 0
32+
33+
for section in 0 ..< collectionView.numberOfSections {
34+
count += collectionView.numberOfItems(inSection: section)
35+
}
36+
37+
return count
38+
}
39+
3040
@objc func handleCellLongPress(_ notification: Notification) {
3141
if let cell = notification.object as? Cell {
3242
if let indexPath = collectionView.indexPath(for: cell) {
@@ -89,13 +99,7 @@ class CustomPhotoPickerViewController: TLPhotosPickerViewController {
8999

90100
extension CustomPhotoPickerViewController: ViewerControllerDataSource {
91101
func numberOfItemsInViewerController(_: ViewerController) -> Int {
92-
var count = 0
93-
94-
for section in 0 ..< collectionView.numberOfSections {
95-
count += collectionView.numberOfItems(inSection: section)
96-
}
97-
98-
return count
102+
return self.getTotalCount()
99103
}
100104

101105
func viewerController(_: ViewerController, viewableAt indexPath: IndexPath) -> Viewable {
@@ -123,33 +127,35 @@ extension CustomPhotoPickerViewController: PreviewHeaderViewDelegate {
123127
func headerView(_: PreviewHeaderView, didPressDoneButton _: UIButton) {
124128
DispatchQueue.main.async {
125129
self.viewerController?.dismiss {
126-
if config.singleSelectedMode || (self.selectedAssets.count == 0) {
127-
guard
128-
let indexPath = self.viewerController?.currentIndexPath,
130+
DispatchQueue.main.async {
131+
if config.singleSelectedMode || (self.selectedAssets.count == 0) {
132+
guard
133+
let indexPath = self.viewerController?.currentIndexPath,
129134

130-
let cell = self.collectionView.cellForItem(at: indexPath) as? TLPhotoCollectionViewCell,
135+
let cell = self.collectionView.cellForItem(at: indexPath) as? TLPhotoCollectionViewCell,
131136

132-
let localID = cell.asset?.localIdentifier,
137+
let localID = cell.asset?.localIdentifier,
133138

134-
var asset = TLPHAsset.asset(with: localID),
139+
var asset = TLPHAsset.asset(with: localID),
135140

136-
let phAsset = asset.phAsset,
141+
let phAsset = asset.phAsset,
137142

138-
self.canSelect(phAsset: phAsset)
143+
self.canSelect(phAsset: phAsset)
139144

140-
else { return }
145+
else { return }
141146

142-
self.logDelegate?.selectedPhoto(picker: self, at: indexPath.row)
147+
self.logDelegate?.selectedPhoto(picker: self, at: indexPath.row)
143148

144-
asset.selectedOrder = 1
145-
if !config.singleSelectedMode {
146-
cell.selectedAsset = true
147-
cell.orderLabel?.text = "\(asset.selectedOrder)"
149+
asset.selectedOrder = 1
150+
if !config.singleSelectedMode {
151+
cell.selectedAsset = true
152+
cell.orderLabel?.text = "\(asset.selectedOrder)"
153+
}
154+
self.selectedAssets = [asset]
148155
}
149156

150-
self.selectedAssets = [asset]
157+
self.dismissPhotoPicker!(self.selectedAssets)
151158
}
152-
self.dismissPhotoPicker!(self.selectedAssets)
153159
}
154160
}
155161
}

0 commit comments

Comments
 (0)