Skip to content

Commit

Permalink
✨ feat: add camera config, remove allowedCamera props
Browse files Browse the repository at this point in the history
  • Loading branch information
baronha committed Dec 13, 2024
1 parent f6a44ab commit b3244ef
Show file tree
Hide file tree
Showing 34 changed files with 1,246 additions and 691 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
package com.margelo.nitro.multipleimagepicker

import android.content.Context
import androidx.fragment.app.Fragment
import com.bumptech.glide.Glide
import com.luck.lib.camerax.SimpleCameraX
import com.luck.picture.lib.interfaces.OnCameraInterceptListener
import java.io.File

class CameraEngine(private val appContext: Context, val config: PickerCameraConfig) : OnCameraInterceptListener {
override fun openCamera(fragment: Fragment, cameraMode: Int, requestCode: Int) {
val camera = SimpleCameraX.of()
camera.isAutoRotation(true)
camera.setCameraMode(cameraMode)
camera.isDisplayRecordChangeTime(true)
camera.isManualFocusCameraPreview(true)
camera.isZoomCameraPreview(true)
camera.setOutputPathDir(getSandboxCameraOutputPath())
camera.setRecordVideoMaxSecond(config.videoMaximumDuration?.toInt() ?: 60)

// camera.setPermissionDeniedListener(getSimpleXPermissionDeniedListener())
// camera.setPermissionDescriptionListener(getSimpleXPermissionDescriptionListener())
camera.setImageEngine { context, url, imageView ->
Glide.with(context).load(url).into(imageView)
}
camera.start(fragment.requireActivity(), fragment, requestCode)
}

private fun getSandboxCameraOutputPath(): String {
val externalFilesDir: File? = appContext.getExternalFilesDir("")
val customFile = File(externalFilesDir?.absolutePath, "Sandbox")
if (!customFile.exists()) {
customFile.mkdirs()
}
return customFile.absolutePath + File.separator

}
}

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -8,105 +8,78 @@ import com.bumptech.glide.load.resource.bitmap.RoundedCorners
import com.luck.picture.lib.engine.ImageEngine
import com.luck.picture.lib.utils.ActivityCompatHelper


/**
* @author:luck
* @date:2019-11-13 17:02
* @describe:Glide加载引擎
*/
class GlideEngine private constructor() : ImageEngine {
/**
* 加载图片
*
* @param context 上下文
* @param url 资源url
* @param imageView 图片承载控件
*/
override fun loadImage(context: Context, url: String, imageView: ImageView) {
if (!ActivityCompatHelper.assertValidRequest(context)) {
return
}
Glide.with(context)
override fun loadImage(context: Context, url: String, imageView: ImageView) {
if (!ActivityCompatHelper.assertValidRequest(context)) {
return
}
Glide.with(context)
.load(url)
.into(imageView)
}

override fun loadImage(
context: Context,
imageView: ImageView,
url: String,
maxWidth: Int,
maxHeight: Int
) {
if (!ActivityCompatHelper.assertValidRequest(context)) {
return
}
Glide.with(context)

override fun loadImage(
context: Context,
imageView: ImageView,
url: String,
maxWidth: Int,
maxHeight: Int
) {
if (!ActivityCompatHelper.assertValidRequest(context)) {
return
}
Glide.with(context)
.load(url)
.override(maxWidth, maxHeight)
.into(imageView)
}

/**
* 加载相册目录封面
*
* @param context 上下文
* @param url 图片路径
* @param imageView 承载图片ImageView
*/
override fun loadAlbumCover(context: Context, url: String, imageView: ImageView) {
if (!ActivityCompatHelper.assertValidRequest(context)) {
return
}
Glide.with(context)

override fun loadAlbumCover(context: Context, url: String, imageView: ImageView) {
if (!ActivityCompatHelper.assertValidRequest(context)) {
return
}
Glide.with(context)
.asBitmap()
.load(url)
.override(180, 180)
.sizeMultiplier(0.5f)
.transform(CenterCrop(), RoundedCorners(8))
.into(imageView)
}

/**
* 加载图片列表图片
*
* @param context 上下文
* @param url 图片路径
* @param imageView 承载图片ImageView
*/
override fun loadGridImage(context: Context, url: String, imageView: ImageView) {
if (!ActivityCompatHelper.assertValidRequest(context)) {
return
}
Glide.with(context)

override fun loadGridImage(context: Context, url: String, imageView: ImageView) {
if (!ActivityCompatHelper.assertValidRequest(context)) {
return
}
Glide.with(context)
.load(url)
.override(200, 200)
.centerCrop()
.placeholder(com.luck.picture.lib.R.drawable.ps_image_placeholder)
.into(imageView)
}
}

override fun pauseRequests(context: Context) {
if (!ActivityCompatHelper.assertValidRequest(context)) {
return
override fun pauseRequests(context: Context) {
if (!ActivityCompatHelper.assertValidRequest(context)) {
return
}
Glide.with(context).pauseRequests()
}
Glide.with(context).pauseRequests()
}

override fun resumeRequests(context: Context) {
if (!ActivityCompatHelper.assertValidRequest(context)) {
return
override fun resumeRequests(context: Context) {
if (!ActivityCompatHelper.assertValidRequest(context)) {
return
}
Glide.with(context).resumeRequests()
}
Glide.with(context).resumeRequests()
}

private object InstanceHolder {
val instance = GlideEngine()
}
private object InstanceHolder {
val instance = GlideEngine()
}

companion object {
fun createGlideEngine(): GlideEngine {
return InstanceHolder.instance
companion object {
fun createGlideEngine(): GlideEngine {
return InstanceHolder.instance
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@ class MultipleImagePickerImp(reactContext: ReactApplicationContext?) :
.setImageEngine(imageEngine)
.setSelectedData(dataList)
.setSelectorUIStyle(style)

.apply {
if (isCrop) {
setCropOption(config.crop)
Expand All @@ -114,6 +115,13 @@ class MultipleImagePickerImp(reactContext: ReactApplicationContext?) :
maxFileSize?.let {
setFilterMaxFileSize(it)
}


isDisplayCamera(config.camera != null)

config.camera?.let {
setCameraInterceptListener(CameraEngine(appContext, it))
}
}
.setImageSpanCount(config.numberOfColumn?.toInt() ?: 3)
.setMaxSelectNum(maxSelect)
Expand All @@ -129,8 +137,6 @@ class MultipleImagePickerImp(reactContext: ReactApplicationContext?) :
// isPreview
.isPreviewImage(isPreview)
.isPreviewVideo(isPreview)
//
.isDisplayCamera(config.allowedCamera ?: true)
.isDisplayTimeAxis(true)
.setSelectionMode(selectMode)
.isOriginalControl(config.isHiddenOriginalButton == false)
Expand Down
39 changes: 30 additions & 9 deletions docs/docs/CONFIG.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -27,15 +27,6 @@ See [**Result**](/result)
- **Default**: `[]`
- **Required**: No

### `allowedCamera`

Enable camera functionality.

- **Type**: boolean
- **Default**: `true`
- **Required**: No
- **Platform**: iOS, Android

### `allowedLimit`

Display additional select more media when permission on `iOS` is limited.
Expand Down Expand Up @@ -81,6 +72,36 @@ Maximum number of videos allowed.
- **Required**: No
- **Platform**: iOS, Android

## Camera 📸

Configuration camera functionality.

- **Type**: object
- **Default**: `{}`
- **Required**: No
- **Platform**: iOS, Android

### `cameraDevice`

Camera device to be used.

- **Type**: `string`
- **Default**: `back`
- **Required**: No
- **Platform**: iOS
- **Options**:
- `back`: Back camera
- `front`: Front camera

### `videoMaximumDuration`

Maximum video duration in seconds.

- **Type**: number
- **Default**: 60
- **Required**: No
- **Platform**: iOS, Android

## Crop 🪚

Configuration for image cropping functionality.
Expand Down
1 change: 0 additions & 1 deletion docs/docs/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ React Native Multiple Image Picker **(RNMIP)** enables application to pick image
| 🎨 | UI Customization (numberOfColumn, spacing, primaryColor ... ) |
| 🌚 | Dark Mode, Light Mode |
| 🌄 | Choose multiple images/video. |
| 🤐 | Compress image after selected (new) ✨ |
| 📦 | Support smart album `(camera roll, selfies, panoramas, favorites, videos...)`. |
| 📺 | Display video duration. |
| 🎆 | Preview image/video. |
Expand Down
45 changes: 32 additions & 13 deletions example/src/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -83,13 +83,6 @@ export default function App() {
const response = await openPicker({
...options,
selectedAssets: images,
crop: {
ratio: [
{ title: 'Instagram', width: 1, height: 1 },
{ title: 'Twitter', width: 16, height: 9 },
{ title: 'Facebook', width: 12, height: 11 },
],
},
})

setImages(Array.isArray(response) ? response : [response])
Expand Down Expand Up @@ -262,13 +255,39 @@ export default function App() {
/>
) : null}

{/* allowedCamera */}
<Text style={style.title}>Camera 📸</Text>
<View style={style.section}>
<SectionView
title="camera"
description="Enable camera functionality."
>
<Switch
value={options.camera !== undefined}
onValueChange={(value) =>
setOptions('camera', value ? {} : undefined)
}
/>
</SectionView>

<SectionView
title="allowedCamera"
description="Enable camera functionality."
optionKey="allowedCamera"
/>
{/* camera videoMaximumDuration */}
<SectionView
title={'camera.videoMaximumDuration' as any}
description="The maximum duration of video that can be selected."
>
<Input
value={
options.camera?.videoMaximumDuration?.toString() ?? ''
}
placeholder="Video Duration"
onChangeText={(value) => {
setOptions('camera', {
...(options.camera ?? { cameraDevice: 'back' }),
videoMaximumDuration: parseNumber(value),
})
}}
/>
</SectionView>
</View>

{IS_IOS ? (
<>
Expand Down
Loading

0 comments on commit b3244ef

Please sign in to comment.