Skip to content

Commit 340f87c

Browse files
committed
done custom style android and refactor reponse for iOS
1 parent c14083b commit 340f87c

File tree

3 files changed

+42
-104
lines changed

3 files changed

+42
-104
lines changed

android/src/main/java/com/reactnativemultipleimagepicker/MultipleImagePickerModule.kt

Lines changed: 13 additions & 74 deletions
Original file line numberDiff line numberDiff line change
@@ -47,42 +47,18 @@ class MultipleImagePickerModule(reactContext: ReactApplicationContext) :
4747
private var maxVideo: Int = 20
4848
private var isCamera: Boolean = true
4949
private var cropOption: UCrop.Options? = null;
50+
private var primaryColor: Int = Color.BLACK;
5051

5152

5253
@ReactMethod
5354
fun openPicker(options: ReadableMap?, promise: Promise): Unit {
5455
PictureAppMaster.getInstance().app = this
5556
val activity = currentActivity
56-
setConfiguration(options)
57-
58-
//set up configration ucrop
59-
// val basicUCropConfig = UCropManager.basicOptions(appContext);
60-
//
61-
// basicUCropConfig.setShowCropFrame(true)
62-
// basicUCropConfig.setShowCropGrid(true)
63-
// basicUCropConfig.setCropDragSmoothToCenter(true)
64-
// basicUCropConfig.setHideBottomControls(false)
65-
// basicUCropConfig.setCircleDimmedLayer(isCropCircle)
66-
// if(isCropCircle){
67-
// basicUCropConfig.withAspectRatio(1F,1F)
68-
// basicUCropConfig.setShowCropFrame(false)
69-
// }else{
70-
// basicUCropConfig.setAspectRatioOptions(
71-
// 1,
72-
// AspectRatio("1:2", 1F, 2F),
73-
// AspectRatio("3:4", 3F, 4F),
74-
//// AspectRatio(
75-
//// "RATIO",
76-
//// CropImageView.DEFAULT_ASPECT_RATIO,
77-
//// CropImageView.DEFAULT_ASPECT_RATIO
78-
//// ),
79-
// AspectRatio("16:9", 16F, 9F),
80-
// AspectRatio("1:1", 1F, 1F)
81-
// )
82-
// }
83-
8457
var imageEngine = GlideEngine.createGlideEngine();
8558

59+
// set config
60+
setConfiguration(options)
61+
8662
PictureSelector.create(activity)
8763
.openGallery(if (mediaType == "video") SelectMimeType.ofVideo() else if (mediaType == "image") SelectMimeType.ofImage() else SelectMimeType.ofAll())
8864
.setImageEngine(imageEngine)
@@ -119,9 +95,6 @@ class MultipleImagePickerModule(reactContext: ReactApplicationContext) :
11995
localMedia.pushMap(media)
12096
}
12197
}
122-
123-
println("localMedia: $localMedia")
124-
12598
promise.resolve(localMedia)
12699
}
127100

@@ -153,67 +126,34 @@ class MultipleImagePickerModule(reactContext: ReactApplicationContext) :
153126
val isCrop = options.getBoolean("isCrop") && singleSelectedMode
154127

155128
if (isCrop) {
156-
buildCropOptions(options)
129+
setCropOptions(options)
157130
}
158-
159131
}
160132
}
161133

162-
private fun buildCropOptions(libOption: ReadableMap) {
134+
private fun setCropOptions(libOption: ReadableMap) {
163135
val options = UCrop.Options()
136+
val mainStyle: SelectMainStyle = style.selectMainStyle
164137

165138
options.setShowCropFrame(true)
166139
options.setShowCropGrid(true)
167140
options.setCircleDimmedLayer(libOption.getBoolean("isCropCircle"))
168-
// options.withAspectRatio(aspect_ratio_x, aspect_ratio_y)
169141
options.setCropOutputPathDir(getSandboxPath(appContext))
170142
options.isCropDragSmoothToCenter(false)
171-
// options.setSkipCropMimeType(getNotSupportCrop())
172143
options.isForbidSkipMultipleCrop(true)
173144
options.setMaxScaleMultiplier(100f)
174-
175-
println("style.selectMainStyle.statusBarColor: ${style.selectMainStyle.statusBarColor}")
176-
if (style.selectMainStyle.statusBarColor != 0) {
177-
val mainStyle: SelectMainStyle = style.selectMainStyle
178-
val isDarkStatusBarBlack: Boolean = mainStyle.isDarkStatusBarBlack
179-
val statusBarColor: Int = mainStyle.statusBarColor
180-
options.isDarkStatusBarBlack(isDarkStatusBarBlack)
181-
if (StyleUtils.checkStyleValidity(statusBarColor)) {
182-
options.setStatusBarColor(statusBarColor)
183-
options.setToolbarColor(statusBarColor)
184-
} else {
185-
options.setStatusBarColor(ContextCompat.getColor(appContext, R.color.ps_color_grey))
186-
options.setToolbarColor(ContextCompat.getColor(appContext, R.color.ps_color_grey))
187-
}
188-
val titleBarStyle: TitleBarStyle = style.titleBarStyle
189-
if (StyleUtils.checkStyleValidity(titleBarStyle.titleTextColor)) {
190-
options.setToolbarWidgetColor(titleBarStyle.titleTextColor)
191-
} else {
192-
options.setToolbarWidgetColor(
193-
ContextCompat.getColor(
194-
appContext,
195-
R.color.ps_color_white
196-
)
197-
)
198-
}
199-
} else {
200-
options.setStatusBarColor(ContextCompat.getColor(appContext, R.color.ps_color_grey))
201-
options.setToolbarColor(ContextCompat.getColor(appContext, R.color.ps_color_grey))
202-
options.setToolbarWidgetColor(
203-
ContextCompat.getColor(
204-
appContext,
205-
R.color.ps_color_white
206-
)
207-
)
208-
}
145+
options.setLogoColor(primaryColor)
146+
options.setToolbarWidgetColor(R.color.app_color_black)
147+
options.setStatusBarColor(mainStyle.statusBarColor)
148+
options.isDarkStatusBarBlack(mainStyle.isDarkStatusBarBlack)
209149

210150
cropOption = options
211151
}
212152

213153
private fun setStyle(options: ReadableMap) {
214154
val doneTitle = options.getString("doneTitle")
215155

216-
val primaryColor: Int = Color.parseColor(options.getString("selectedColor"))
156+
primaryColor = Color.parseColor(options.getString("selectedColor"))
217157

218158
// ANIMATION SLIDE FROM BOTTOM
219159
val animationStyle = PictureWindowAnimationStyle()
@@ -360,14 +300,13 @@ class MultipleImagePickerModule(reactContext: ReactApplicationContext) :
360300
media.putString("parentFolderName", item.parentFolderName)
361301
if (item.isCut) {
362302
val crop = WritableNativeMap()
363-
crop.putString("cropPath", item.cutPath)
303+
crop.putString("path", item.cutPath)
364304
crop.putDouble("width", item.cropImageWidth.toDouble())
365305
crop.putDouble("height", item.cropImageHeight.toDouble())
366306
media.putMap("crop", crop)
367307
}
368308
if (type === "video" && isExportThumbnail) {
369309
val thumbnail = createThumbnail(item.realPath)
370-
println("thumbnail: $thumbnail")
371310
media.putString("thumbnail", thumbnail)
372311
}
373312
return media

example/src/App.js

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -23,26 +23,25 @@ export default function App() {
2323

2424
const onPicker = async () => {
2525
try {
26-
const isCrop = true;
2726
const singleSelectedMode = true;
2827

2928
const response = await openPicker({
3029
selectedAssets: images,
3130
isExportThumbnail: true,
3231
maxVideo: 1,
33-
isCropCircle: true,
3432
doneTitle: 'Xong',
3533
singleSelectedMode,
36-
isCrop,
34+
isCrop: true,
35+
isCropCircle: true,
3736
});
3837

39-
if (isCrop) {
40-
response.path = response.crop.cropPath;
41-
response.width = response.crop.width;
42-
response.height = response.crop.height;
43-
}
38+
const crop = response.crop;
4439

45-
console.log('response: ', response);
40+
if (crop) {
41+
response.path = crop.path;
42+
response.width = crop.width;
43+
response.height = crop.height;
44+
}
4645

4746
setImages(response);
4847
} catch (e) {}
@@ -65,7 +64,7 @@ export default function App() {
6564
videoURLKey={'thumbnail'}
6665
/>
6766
<TouchableOpacity style={style.buttonOpen} onPress={onPicker}>
68-
<Text style={style.textOpen}>Open Gallery</Text>
67+
<Text style={style.textOpen}>Open Picker</Text>
6968
</TouchableOpacity>
7069
</View>
7170
</ScrollView>

ios/MultipleImagePicker.swift

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,8 @@ class MultipleImagePicker: NSObject, TLPhotosPickerViewControllerDelegate,UINavi
2020
var videoCount = 0
2121
var imageRequestOptions = PHImageRequestOptions();
2222
var videoRequestOptions = PHVideoRequestOptions.init()
23-
24-
23+
24+
2525
// controller
2626

2727

@@ -208,29 +208,29 @@ class MultipleImagePicker: NSObject, TLPhotosPickerViewControllerDelegate,UINavi
208208

209209
func cropViewController(_ cropViewController: CropViewController, didCropToImage image: UIImage, withRect cropRect: CGRect, angle: Int) {
210210

211-
let TLAsset = self.selectedAssets.first;
212211
let filePath = getImagePathFromUIImage(uiImage: image, prefix: "crop")
213-
214-
TLAsset?.phAsset?.setValue(image.size.width, forKey: "pixelWidth")
215-
TLAsset?.phAsset?.setValue(image.size.height, forKey: "pixelHeight")
216-
217-
let object = MediaResponse(filePath: filePath, mime: "image/jpeg", withTLAsset: TLAsset!)
212+
let TLAsset = self.selectedAssets.first;
218213

219-
if(object.data != nil){
220-
object.data!["isCrop"] = true
221-
resolve([object.data])
222-
}else{
223-
resolve([])
224-
}
225-
214+
// Dismiss twice for crop controller & picker controller
226215
DispatchQueue.main.async {
227216
self.getTopMostViewController()?.dismiss(animated: true, completion: {
228-
self.getTopMostViewController()?.dismiss(animated: true, completion: nil)
217+
self.getTopMostViewController()?.dismiss(animated: true, completion: {
218+
219+
if(filePath != "" && TLAsset != nil){
220+
self.fetchAsset(TLAsset: TLAsset!) { object in
221+
222+
object.data!["crop"] = [
223+
"height": image.size.height,
224+
"width": image.size.width,
225+
"path": filePath
226+
]
227+
228+
self.resolve([object.data]) // reolve crop data
229+
}
230+
}
231+
})
229232
})
230233
}
231-
//
232-
// self.dismissComplete()
233-
// self.dismissComplete()
234234
}
235235

236236
func presentCropViewController(image: UIImage) {
@@ -277,7 +277,7 @@ class MultipleImagePicker: NSObject, TLPhotosPickerViewControllerDelegate,UINavi
277277
dismissComplete()
278278
return;
279279
}
280-
280+
281281

282282
self.selectedAssets = withTLPHAssets
283283

0 commit comments

Comments
 (0)