Skip to content

Commit 80a54f0

Browse files
committed
doing refactor README
1 parent 340f87c commit 80a54f0

File tree

5 files changed

+65
-41
lines changed

5 files changed

+65
-41
lines changed

README.md

Lines changed: 29 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,18 @@
1-
# React Native Multiple Image Picker (RNMIP)
1+
# React Native Multiple Image Picker
22

33
<p align="center">
44
<img src="./files/banner.png" width="100%">
55
</p>
66

7-
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. React Native Multiple Image Picker is based on two libraries available, [TLPhotoPicker](https://github.com/tilltue/TLPhotoPicker) and [PictureSelector](https://github.com/LuckSiege/PictureSelector)
7+
[![iOS][iOS]][iOS-URL] [![Android][Android]][Android-URL] [![Swift][Swift]][Swift-URL] [![Kotlin][Kotlin]][Kotlin-URL] [![React-Native][React-Native]][React-Native-URL] ![SmoothScroll][SmoothScroll] ![CROP-IMAGE](https://img.shields.io/badge/Crop_Image-EA4C89?style=for-the-badge)
8+
9+
## Overview
10+
11+
enables application to pick images and videos from multiple smart album in iOS/Android, similar to the current Facebook App. React Native Multiple Image Picker is based on two libraries available, [TLPhotoPicker](https://github.com/tilltue/TLPhotoPicker) and [PictureSelector](https://github.com/LuckSiege/PictureSelector)
812

913
> Related: [React Native Photo Editor](https://github.com/baronha/react-native-photo-editor)
1014
15+
1116
## Demo 👉👈
1217

1318
| iOS | Android |
@@ -169,3 +174,25 @@ MIT
169174
[TLPhotoPicker](https://github.com/tilltue/TLPhotoPicker/blob/master/LICENSE)
170175
<br>
171176
[PictureSelector](https://github.com/LuckSiege/PictureSelector/blob/master/LICENSE)
177+
178+
179+
<!-- Badge for README -->
180+
[iOS]: https://img.shields.io/badge/iOS-000000?style=for-the-badge&logo=ios&logoColor=white
181+
[iOS-URL]: https://www.apple.com/ios
182+
183+
[Android]: https://img.shields.io/badge/Android-3DDC84?style=for-the-badge&logo=android&logoColor=white
184+
[Android-URL]: https://www.android.com/
185+
186+
[React-Native]: https://img.shields.io/badge/React_Native-20232A?style=for-the-badge&logo=react&logoColor=61DAFB
187+
[React-Native-URL]: https://reactnative.dev/
188+
189+
[React-Native]: https://img.shields.io/badge/React_Native-20232A?style=for-the-badge&logo=react&logoColor=61DAFB
190+
[React-Native-URL]: https://reactnative.dev/
191+
192+
[Swift]: https://img.shields.io/badge/Swift-FA7343?style=for-the-badge&logo=swift&logoColor=white
193+
[Swift-URL]: https://developer.apple.com/swift/
194+
195+
[Kotlin]: https://img.shields.io/badge/Kotlin-0095D5?&style=for-the-badge&logo=kotlin&logoColor=white
196+
[Kotlin-URL]: https://kotlinlang.org/
197+
198+
[SmoothScroll]: https://img.shields.io/badge/Smooth_Scroll-FCC624?style=for-the-badge

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

Lines changed: 34 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -2,63 +2,61 @@ package com.reactnativemultipleimagepicker
22

33
import android.content.Context
44
import android.graphics.Bitmap
5+
import android.graphics.drawable.Drawable
56
import android.net.Uri
67
import android.widget.ImageView
78
import androidx.fragment.app.Fragment
89
import com.bumptech.glide.Glide
9-
import com.luck.picture.lib.config.PictureMimeType
10-
import com.luck.picture.lib.engine.CropEngine
11-
import com.luck.picture.lib.entity.LocalMedia
12-
import com.luck.picture.lib.utils.DateUtils
10+
import com.bumptech.glide.request.target.CustomTarget
11+
import com.bumptech.glide.request.transition.Transition
12+
import com.luck.picture.lib.engine.CropFileEngine
13+
import com.reactnativemultipleimagepicker.ImageLoaderUtils.assertValidRequest
1314
import com.yalantis.ucrop.UCrop
1415
import com.yalantis.ucrop.UCropImageEngine
1516
import java.io.File
1617

1718

18-
class CropEngine(
19-
appContext: Context,
20-
cropOption: UCrop.Options
21-
) : CropEngine {
22-
private val context = appContext
23-
private val option: UCrop.Options = cropOption
19+
class CropEngine(cropOption: UCrop.Options) : CropFileEngine {
20+
private val options: UCrop.Options = cropOption
2421
override fun onStartCrop(
25-
fragment: Fragment, currentLocalMedia: LocalMedia,
26-
dataSource: ArrayList<LocalMedia>, requestCode: Int
22+
fragment: Fragment,
23+
srcUri: Uri?,
24+
destinationUri: Uri?,
25+
dataSource: ArrayList<String?>?,
26+
requestCode: Int
2727
) {
28-
val currentCropPath = currentLocalMedia.availablePath
29-
val inputUri: Uri =
30-
if (PictureMimeType.isContent(currentCropPath) || PictureMimeType.isHasHttp(
31-
currentCropPath
32-
)
33-
) {
34-
Uri.parse(currentCropPath)
35-
} else {
36-
Uri.fromFile(File(currentCropPath))
37-
}
38-
val fileName: String = DateUtils.getCreateFileName("CROP_") + ".jpg"
39-
val destinationUri = Uri.fromFile(File(getSandboxPath(context), fileName))
40-
val dataCropSource: ArrayList<String> = ArrayList()
41-
for (i in 0 until dataSource.size) {
42-
val media = dataSource[i]
43-
dataCropSource.add(media.availablePath)
44-
}
45-
val uCrop = UCrop.of(inputUri, destinationUri, dataCropSource)
28+
val uCrop = UCrop.of(srcUri!!, destinationUri!!, dataSource)
29+
uCrop.withOptions(options)
4630
uCrop.setImageEngine(object : UCropImageEngine {
4731
override fun loadImage(context: Context, url: String, imageView: ImageView) {
48-
Glide.with(context).load(url).into(imageView)
32+
if (!assertValidRequest(context)) {
33+
return
34+
}
35+
Glide.with(context).load(url).override(180, 180).into(imageView)
4936
}
5037

5138
override fun loadImage(
52-
context: Context?,
53-
url: Uri?,
39+
context: Context,
40+
url: Uri,
5441
maxWidth: Int,
5542
maxHeight: Int,
56-
call: UCropImageEngine.OnCallbackListener<Bitmap>?
43+
call: UCropImageEngine.OnCallbackListener<Bitmap>
5744
) {
58-
TODO("Not yet implemented")
45+
Glide.with(context).asBitmap().load(url).override(maxWidth, maxHeight)
46+
.into(object : CustomTarget<Bitmap?>() {
47+
override fun onResourceReady(
48+
resource: Bitmap,
49+
transition: Transition<in Bitmap?>?
50+
) {
51+
call.onCall(resource)
52+
}
53+
54+
override fun onLoadCleared(placeholder: Drawable?) {
55+
call.onCall(null)
56+
}
57+
})
5958
}
6059
})
61-
uCrop.withOptions(option)
6260
uCrop.start(fragment.requireActivity(), fragment, requestCode)
6361
}
6462
}

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ class MultipleImagePickerModule(reactContext: ReactApplicationContext) :
105105
}
106106

107107
private fun onSetCropEngine(): CropEngine? {
108-
return cropOption?.let { CropEngine(appContext, it) }
108+
return cropOption?.let { CropEngine(it) }
109109
}
110110

111111
private fun setConfiguration(options: ReadableMap?) {
@@ -123,7 +123,7 @@ class MultipleImagePickerModule(reactContext: ReactApplicationContext) :
123123

124124
setStyle(options) // set style for UI
125125

126-
val isCrop = options.getBoolean("isCrop") && singleSelectedMode
126+
val isCrop = options.getBoolean("isCrop") && singleSelectedMode == true
127127

128128
if (isCrop) {
129129
setCropOptions(options)

example/src/App.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,6 @@ export default function App() {
3232
doneTitle: 'Xong',
3333
singleSelectedMode,
3434
isCrop: true,
35-
isCropCircle: true,
3635
});
3736

3837
const crop = response.crop;

files/banner.png

2.63 MB
Loading

0 commit comments

Comments
 (0)