Skip to content

Commit 2927c1f

Browse files
committed
push duration / add iCloud loading view
1 parent ab4eea8 commit 2927c1f

File tree

11 files changed

+176
-126
lines changed

11 files changed

+176
-126
lines changed

README.md

Lines changed: 61 additions & 50 deletions
Large diffs are not rendered by default.
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
2-
package="com.reactnativemultipleimagepicker">
2+
package="com.reactnativemultipleimagepicker">
33
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
4-
4+
<application android:requestLegacyExternalStorage="true" />
55
</manifest>

android/src/main/res/values/colors.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,5 +15,5 @@
1515
<color name="app_color_9b">#9b9b9b</color>
1616
<color name="app_color_e0ff6100">#E0FF6100</color>
1717
<color name="app_color_red">#FF0000</color>
18-
<color name="app_color_pri">#30475e</color>
18+
<color name="app_color_pri">#FB9300</color>
1919
</resources>

example/ios/MultipleImagePickerExample.xcodeproj/xcshareddata/xcschemes/MultipleImagePickerExample.xcscheme

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,8 @@
5050
ReferencedContainer = "container:MultipleImagePickerExample.xcodeproj">
5151
</BuildableReference>
5252
</MacroExpansion>
53+
<Testables>
54+
</Testables>
5355
</TestAction>
5456
<LaunchAction
5557
buildConfiguration = "Debug"

example/src/App.js

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ export default function App() {
1313
selectedAssets: images,
1414
isExportThumbnail: true,
1515
maxVideo: 1,
16-
singleSelectedMode: true,
1716
usedCameraButton: false,
1817
// selectedColor: '#f9813a',
1918
});
@@ -68,9 +67,11 @@ export default function App() {
6867
renderItem={renderItem}
6968
numColumns={3}
7069
/>
71-
<TouchableOpacity style={style.openPicker} onPress={openPicker}>
72-
<Text style={style.openText}>open</Text>
73-
</TouchableOpacity>
70+
<View style={style.bottom}>
71+
<TouchableOpacity style={style.openPicker} onPress={openPicker}>
72+
<Text style={style.openText}>open</Text>
73+
</TouchableOpacity>
74+
</View>
7475
</SafeAreaView>
7576
);
7677
}
@@ -96,14 +97,19 @@ const style = StyleSheet.create({
9697
marginBottom: 6,
9798
backgroundColor: 'rgba(0,0,0,0.2)',
9899
},
100+
bottom: {
101+
padding: 24,
102+
},
99103
openText: {
100104
fontWeight: 'bold',
101105
fontSize: 16,
106+
color: '#fff',
107+
paddingVertical: 12,
102108
},
103109
openPicker: {
104-
flex: 1 / 3,
105110
justifyContent: 'center',
106111
alignItems: 'center',
112+
backgroundColor: '#000',
107113
},
108114
buttonDelete: {
109115
paddingHorizontal: 8,

ios/CustomPhotoPicker/CustomPhotoPickerViewController.swift

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,26 @@ class CustomPhotoPickerViewController: TLPhotosPickerViewController {
1717

1818
override func makeUI() {
1919
super.makeUI()
20+
self.collectionView.backgroundColor = .white
2021
self.customNavItem.leftBarButtonItem?.tintColor = .black
2122
self.customNavItem.rightBarButtonItem?.tintColor = MultipleImagePickerConfigure.selectedColor
23+
24+
for subview in self.view.subviews {
25+
guard let navbar = subview as? UINavigationBar else {
26+
break
27+
}
28+
if #available(iOS 13.0, *) {
29+
navbar.barTintColor = .systemBackground
30+
} else {
31+
navbar.barTintColor = UIColor.white
32+
}
33+
}
34+
35+
if #available(iOS 13.0, *) {
36+
self.customNavItem.leftBarButtonItem?.tintColor = .label
37+
self.collectionView.backgroundColor = .systemBackground
38+
self.view.backgroundColor = .systemBackground
39+
}
2240
}
2341

2442
override func viewWillAppear(_ animated: Bool) {

ios/MultipleImagePicker.swift

Lines changed: 77 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -49,11 +49,6 @@ class MultipleImagePicker: NSObject, TLPhotosPickerViewControllerDelegate,UINavi
4949
generator.impactOccurred()
5050
}
5151

52-
func dismissComplete() {
53-
DispatchQueue.main.async {
54-
self.getTopMostViewController()?.dismiss(animated: true, completion: nil)
55-
}
56-
}
5752

5853
@objc(openPicker:withResolver:withRejecter:)
5954
func openPicker(options: NSDictionary, resolve:@escaping RCTPromiseResolveBlock,reject:@escaping RCTPromiseRejectBlock) -> Void {
@@ -67,10 +62,13 @@ class MultipleImagePicker: NSObject, TLPhotosPickerViewControllerDelegate,UINavi
6762
viewController.configure = MultipleImagePickerConfigure
6863
viewController.selectedAssets = self.selectedAssets
6964
viewController.logDelegate = self
70-
viewController.modalTransitionStyle = .coverVertical
71-
viewController.modalPresentationStyle = .overCurrentContext
65+
66+
// viewController.navigationBar
7267

7368
DispatchQueue.main.async {
69+
viewController.modalTransitionStyle = .coverVertical
70+
viewController.modalPresentationStyle = .fullScreen
71+
7472
self.getTopMostViewController()?.present(viewController, animated: true, completion: nil)
7573
}
7674
}
@@ -124,7 +122,7 @@ class MultipleImagePicker: NSObject, TLPhotosPickerViewControllerDelegate,UINavi
124122
videoCount = selecteds.filter{ ($0 as! NSObject).value(forKey: "type") as? String == "video" }.count
125123

126124
print("assets", assetsExist.count)
127-
print("self.selectedAssets.count", self.selectedAssets.count)
125+
print("self.selectedAssets.count", self.selectedAssets)
128126
if(assetsExist.count != self.selectedAssets.count){
129127
var assets = [TLPHAsset]();
130128
for index in 0..<assetsExist.count {
@@ -143,7 +141,6 @@ class MultipleImagePicker: NSObject, TLPhotosPickerViewControllerDelegate,UINavi
143141
}
144142

145143
func createAttachmentResponse(filePath: String?, withFilename filename: String?, withType type: String?, withAsset asset: PHAsset, withTLAsset TLAsset: TLPHAsset ) -> [AnyHashable :Any]? {
146-
print("asets: ",asset, TLAsset)
147144
var media = [
148145
"path": "file://" + filePath! as String,
149146
"localIdentifier": asset.localIdentifier,
@@ -152,7 +149,7 @@ class MultipleImagePicker: NSObject, TLPhotosPickerViewControllerDelegate,UINavi
152149
"height": Int(asset.pixelHeight ) as NSNumber,
153150
"mime": type!,
154151
"creationDate": asset.creationDate!,
155-
"type": asset.mediaType == .video ? "video" : "image"
152+
"type": asset.mediaType == .video ? "video" : "image",
156153
] as [String : Any]
157154

158155
//option in video
@@ -166,6 +163,7 @@ class MultipleImagePicker: NSObject, TLPhotosPickerViewControllerDelegate,UINavi
166163
TLAsset.videoSize { Int in
167164
media["size"] = Int
168165
}
166+
media["duration"] = asset.duration
169167
}else{
170168
TLAsset.photoSize { Int in
171169
media["size"] = Int
@@ -209,16 +207,34 @@ class MultipleImagePicker: NSObject, TLPhotosPickerViewControllerDelegate,UINavi
209207

210208
}
211209

210+
func shouldDismissPhotoPicker(withTLPHAssets: [TLPHAsset]) -> Bool {
211+
return false
212+
}
213+
214+
internal func dismissLoading() {
215+
if let vc = self.getTopMostViewController()?.presentedViewController, vc is UIAlertController {
216+
self.getTopMostViewController()?.dismiss(animated: false, completion: nil)
217+
}
218+
}
219+
220+
func dismissComplete(){
221+
DispatchQueue.main.async {
222+
self.getTopMostViewController()?.dismiss(animated: true, completion: nil)
223+
}
224+
}
225+
212226
func dismissPhotoPicker(withTLPHAssets: [TLPHAsset]) {
213227
if(withTLPHAssets.count == 0){
214228
self.resolve([]);
229+
dismissComplete()
215230
return;
216231
}
217232
let withTLPHAssetsCount = withTLPHAssets.count;
218233
let selectedAssetsCount = self.selectedAssets.count;
219234

220235
//check difference
221236
if(withTLPHAssetsCount == selectedAssetsCount && withTLPHAssets[withTLPHAssetsCount - 1].phAsset?.localIdentifier == self.selectedAssets[selectedAssetsCount-1].phAsset?.localIdentifier){
237+
dismissComplete()
222238
return;
223239
}
224240

@@ -228,48 +244,66 @@ class MultipleImagePicker: NSObject, TLPhotosPickerViewControllerDelegate,UINavi
228244
let imageRequestOptions = PHImageRequestOptions();
229245
imageRequestOptions.deliveryMode = .fastFormat;
230246
imageRequestOptions.resizeMode = .fast;
247+
imageRequestOptions.isNetworkAccessAllowed = true
248+
imageRequestOptions.isSynchronous = false
231249

250+
let videoRequestOptions = PHVideoRequestOptions.init()
251+
videoRequestOptions.version = PHVideoRequestOptionsVersion.current
252+
videoRequestOptions.deliveryMode = PHVideoRequestOptionsDeliveryMode.automatic
253+
videoRequestOptions.isNetworkAccessAllowed = true
232254

233-
let group = DispatchGroup()
255+
//add loading view
256+
let alert = UIAlertController(title: nil, message: "Please wait...", preferredStyle: .alert)
234257

235-
for TLAsset in withTLPHAssets {
236-
group.enter()
237-
let asset = TLAsset.phAsset
238-
let index = TLAsset.selectedOrder - 1;
239-
240-
let videoRequestOptions = PHVideoRequestOptions.init()
241-
videoRequestOptions.version = PHVideoRequestOptionsVersion.current
242-
videoRequestOptions.deliveryMode = PHVideoRequestOptionsDeliveryMode.automatic
243-
videoRequestOptions.isNetworkAccessAllowed = true
244-
245-
TLAsset.tempCopyMediaFile(videoRequestOptions: videoRequestOptions, imageRequestOptions: imageRequestOptions, livePhotoRequestOptions: nil, exportPreset: AVAssetExportPresetHighestQuality, convertLivePhotosToJPG: true, progressBlock: { (Double) in
246-
print("progressBlock: ", Double)
247-
248-
}, completionBlock: { (filePath, fileType) in
249-
let object = NSDictionary(dictionary: self.createAttachmentResponse(
250-
filePath: filePath.absoluteString,
251-
withFilename:TLAsset.originalFileName,
252-
withType: fileType,
253-
withAsset: asset!,
254-
withTLAsset: TLAsset
255-
)!);
256-
257-
selections[index] = object as Any;
258-
group.leave();
259-
})
260-
}
261-
group.notify(queue: .main){
262-
self.resolve(selections);
258+
let loadingIndicator = UIActivityIndicatorView(frame: CGRect(x: 10, y: 5, width: 50, height: 50))
259+
loadingIndicator.hidesWhenStopped = true
260+
loadingIndicator.style = UIActivityIndicatorView.Style.gray
261+
if #available(iOS 13.0, *) {
262+
loadingIndicator.color = .secondaryLabel
263+
} else {
264+
loadingIndicator.color = .black
263265
}
266+
loadingIndicator.startAnimating();
267+
268+
alert.view.addSubview(loadingIndicator)
269+
self.getTopMostViewController()?.present(alert, animated: true, completion: {
270+
let group = DispatchGroup()
271+
for TLAsset in withTLPHAssets {
272+
group.enter()
273+
let asset = TLAsset.phAsset
274+
let index = TLAsset.selectedOrder - 1;
275+
276+
TLAsset.tempCopyMediaFile(videoRequestOptions: videoRequestOptions, imageRequestOptions: imageRequestOptions, livePhotoRequestOptions: nil, exportPreset: AVAssetExportPresetHighestQuality, convertLivePhotosToJPG: true, progressBlock: { (progress) in
277+
print("progress: ", progress)
278+
}, completionBlock: { (filePath, fileType) in
279+
let object = NSDictionary(dictionary: self.createAttachmentResponse(
280+
filePath: filePath.absoluteString,
281+
withFilename:TLAsset.originalFileName,
282+
withType: fileType,
283+
withAsset: asset!,
284+
withTLAsset: TLAsset
285+
)!);
286+
287+
selections[index] = object as Any;
288+
group.leave();
289+
})
290+
}
291+
group.notify(queue: .main){ [self] in
292+
resolve(selections);
293+
DispatchQueue.main.async {
294+
alert.dismiss(animated: true, completion: {
295+
dismissComplete()
296+
})
297+
}
298+
}
299+
})
264300
}
265301

266302
func getTopMostViewController() -> UIViewController? {
267303
var topMostViewController = UIApplication.shared.keyWindow?.rootViewController
268-
269304
while let presentedViewController = topMostViewController?.presentedViewController {
270305
topMostViewController = presentedViewController
271306
}
272-
273307
return topMostViewController
274308
}
275309

@@ -282,7 +316,8 @@ class MultipleImagePicker: NSObject, TLPhotosPickerViewControllerDelegate,UINavi
282316
func canSelectAsset(phAsset: PHAsset) -> Bool {
283317
let maxVideo = self.options["maxVideo"]
284318
if(phAsset.mediaType == .video){
285-
if(videoCount == maxVideo as! Int){
319+
320+
if(videoCount == maxVideo as! Int && !(options["singleSelectedMode"] as! Bool)){
286321
showExceededMaximumAlert(vc: self.getTopMostViewController()!, isVideo: true)
287322
return false
288323
}

ios/Viewer/Viewable.swift

Lines changed: 0 additions & 23 deletions
This file was deleted.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@baronha/react-native-multiple-image-picker",
3-
"version": "0.3.2",
3+
"version": "0.4",
44
"description": "react-native-multiple-image-picker enables application to pick images and videos from multiple smart album in iOS/Android, similar to the current facebook app.",
55
"main": "lib/commonjs/index",
66
"module": "lib/module/index",

src/index.d.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ export type Results = {
1010
type: string;
1111
thumbnail?: string;
1212
creationDate?: string;
13-
}
13+
};
1414

1515
export type Options = {
1616
isPreview?: boolean;

0 commit comments

Comments
 (0)