Skip to content

Commit

Permalink
♻️ refactor: remove compress when picker -> Too Slow
Browse files Browse the repository at this point in the history
  • Loading branch information
baronha committed Dec 13, 2024
1 parent e50038b commit f6a44ab
Show file tree
Hide file tree
Showing 12 changed files with 8 additions and 182 deletions.
1 change: 0 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,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
Original file line number Diff line number Diff line change
Expand Up @@ -86,9 +86,6 @@ class MultipleImagePickerImp(reactContext: ReactApplicationContext?) :
val maxDuration = config.maxVideoDuration?.toInt()
val minDuration = config.minVideoDuration?.toInt()
val allowSwipeToSelect = config.allowSwipeToSelect ?: false
val imageQuality = config.imageQuality
val videoQuality = config.videoQuality

val isMultiple = config.selectMode == SelectMode.MULTIPLE
val selectMode = if (isMultiple) SelectModeConfig.MULTIPLE else SelectModeConfig.SINGLE

Expand Down Expand Up @@ -117,15 +114,6 @@ class MultipleImagePickerImp(reactContext: ReactApplicationContext?) :
maxFileSize?.let {
setFilterMaxFileSize(it)
}

//TODO: set compress export
// if (imageQuality != null && imageQuality != 1.0) {
// setCompressEngine(CompressEngine())
// }

if (videoQuality != null && videoQuality != 1.0) {
setVideoQuality(if (videoQuality > 0.5) 1 else 0)
}
}
.setImageSpanCount(config.numberOfColumn?.toInt() ?: 3)
.setMaxSelectNum(maxSelect)
Expand Down
26 changes: 0 additions & 26 deletions docs/docs/CONFIG.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -296,32 +296,6 @@ Enable haptic feedback on preview.

---

## Compress Quality 🤐

### `videoQuality`

Video quality setting for the picker.

- **Type**: number
- **Default**: `1`
- **Required**: No
- **Platform**: iOS, Android
- **Notes**:
- iOS: Range `0`-`1` (`0`: maximum compression, `1`: highest quality)
- Android: Only `0` (low) or `1` (high)

### `imageQuality`

Image quality setting for the picker.

- **Type**: number
- **Default**: `1`
- **Required**: No
- **Platform**: iOS
- **Notes**: Range `0`-`1` (`0`: maximum compression, `1`: highest quality)

---

## Localization 🌐

### `text`
Expand Down
2 changes: 0 additions & 2 deletions example/src/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -451,8 +451,6 @@ export default function App() {
/>
) : null}

{/* <Text style={style.title}>Compress Quality 🤐</Text> */}

<Text style={style.title}>Localization 🌐</Text>

<View style={style.section}>
Expand Down
4 changes: 2 additions & 2 deletions ios/HybridMultipleImagePicker+Result.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ import HXPhotoPicker
import Photos

extension HybridMultipleImagePicker {
func getResult(_ asset: PhotoAsset, _ compression: PhotoAsset.Compression) async throws -> Result {
let urlResult = try await asset.urlResult(compression)
func getResult(_ asset: PhotoAsset) async throws -> Result {
let urlResult = try await asset.urlResult()
let url = urlResult.url

let creationDate = Int(asset.phAsset?.creationDate?.timeIntervalSince1970 ?? 0)
Expand Down
17 changes: 2 additions & 15 deletions ios/HybridMultipleImagePicker.swift
Original file line number Diff line number Diff line change
Expand Up @@ -38,19 +38,6 @@ class HybridMultipleImagePicker: HybridMultipleImagePickerSpec {

controller.autoDismiss = false

//
let imageQuality = config.imageQuality ?? 1.0

let videoQuality: Int = {
if let quality = config.videoQuality {
return Int(quality * 10)
}

return 10
}()

let compression: PhotoAsset.Compression = .init(imageCompressionQuality: imageQuality, videoExportParameter: .init(preset: videoQuality == 10 ? .highQuality : videoQuality < 5 ? .mediumQuality : .lowQuality, quality: videoQuality))

// check crop for single
if let asset = pickerResult.photoAssets.first, config.selectMode == .single, config.crop != nil, asset.mediaType == .photo, asset.editedResult?.url == nil {
// open crop
Expand All @@ -60,7 +47,7 @@ class HybridMultipleImagePicker: HybridMultipleImagePickerSpec {
photoAsset.editedResult = .some(result)

Task {
let resultData = try await self.getResult(photoAsset, compression)
let resultData = try await self.getResult(photoAsset)

DispatchQueue.main.async {
resolved([resultData])
Expand Down Expand Up @@ -88,7 +75,7 @@ class HybridMultipleImagePicker: HybridMultipleImagePickerSpec {
for response in pickerResult.photoAssets {
group.enter()

let resultData = try await self.getResult(response, compression)
let resultData = try await self.getResult(response)

data.append(resultData)
group.leave()
Expand Down
4 changes: 2 additions & 2 deletions ios/PHAsset+Thumbnail.swift
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ extension PHAsset {
let imgRef = try generator.copyCGImage(at: time, actualTime: nil)
thumbnail = UIImage(cgImage: imgRef)
} catch {
print("Lỗi khi tạo thumbnail: \(error)")
print("Error create thumbnail: \(error)")
return nil
}

Expand All @@ -48,7 +48,7 @@ extension PHAsset {
return nil
}

let data = uiImage.jpegData(compressionQuality: 1.0)
let data = uiImage.jpegData(compressionQuality: 0.9)

let fullPath = URL(fileURLWithPath: tempDirectory).appendingPathComponent("\(prefix ?? "thumb")-\(ProcessInfo.processInfo.globallyUniqueString).jpg").path

Expand Down
8 changes: 0 additions & 8 deletions nitrogen/generated/android/c++/JNitroConfig.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -94,10 +94,6 @@ namespace margelo::nitro::multipleimagepicker {
jni::local_ref<jni::JDouble> minVideoDuration = this->getFieldValue(fieldMinVideoDuration);
static const auto fieldMaxFileSize = clazz->getField<jni::JDouble>("maxFileSize");
jni::local_ref<jni::JDouble> maxFileSize = this->getFieldValue(fieldMaxFileSize);
static const auto fieldVideoQuality = clazz->getField<jni::JDouble>("videoQuality");
jni::local_ref<jni::JDouble> videoQuality = this->getFieldValue(fieldVideoQuality);
static const auto fieldImageQuality = clazz->getField<jni::JDouble>("imageQuality");
jni::local_ref<jni::JDouble> imageQuality = this->getFieldValue(fieldImageQuality);
static const auto fieldBackgroundDark = clazz->getField<jni::JDouble>("backgroundDark");
jni::local_ref<jni::JDouble> backgroundDark = this->getFieldValue(fieldBackgroundDark);
static const auto fieldCrop = clazz->getField<JPickerCropConfig>("crop");
Expand Down Expand Up @@ -140,8 +136,6 @@ namespace margelo::nitro::multipleimagepicker {
maxVideoDuration != nullptr ? std::make_optional(maxVideoDuration->value()) : std::nullopt,
minVideoDuration != nullptr ? std::make_optional(minVideoDuration->value()) : std::nullopt,
maxFileSize != nullptr ? std::make_optional(maxFileSize->value()) : std::nullopt,
videoQuality != nullptr ? std::make_optional(videoQuality->value()) : std::nullopt,
imageQuality != nullptr ? std::make_optional(imageQuality->value()) : std::nullopt,
backgroundDark != nullptr ? std::make_optional(backgroundDark->value()) : std::nullopt,
crop != nullptr ? std::make_optional(crop->toCpp()) : std::nullopt,
text != nullptr ? std::make_optional(text->toCpp()) : std::nullopt,
Expand Down Expand Up @@ -186,8 +180,6 @@ namespace margelo::nitro::multipleimagepicker {
value.maxVideoDuration.has_value() ? jni::JDouble::valueOf(value.maxVideoDuration.value()) : nullptr,
value.minVideoDuration.has_value() ? jni::JDouble::valueOf(value.minVideoDuration.value()) : nullptr,
value.maxFileSize.has_value() ? jni::JDouble::valueOf(value.maxFileSize.value()) : nullptr,
value.videoQuality.has_value() ? jni::JDouble::valueOf(value.videoQuality.value()) : nullptr,
value.imageQuality.has_value() ? jni::JDouble::valueOf(value.imageQuality.value()) : nullptr,
value.backgroundDark.has_value() ? jni::JDouble::valueOf(value.backgroundDark.value()) : nullptr,
value.crop.has_value() ? JPickerCropConfig::fromCpp(value.crop.value()) : nullptr,
value.text.has_value() ? JText::fromCpp(value.text.value()) : nullptr,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,6 @@ data class NitroConfig(
val maxVideoDuration: Double?,
val minVideoDuration: Double?,
val maxFileSize: Double?,
val videoQuality: Double?,
val imageQuality: Double?,
val backgroundDark: Double?,
val crop: PickerCropConfig?,
val text: Text?,
Expand Down
48 changes: 1 addition & 47 deletions nitrogen/generated/ios/swift/NitroConfig.swift
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ public extension NitroConfig {
/**
* Create a new instance of `NitroConfig`.
*/
init(mediaType: MediaType, selectedAssets: [Result], selectBoxStyle: SelectBoxStyle, selectMode: SelectMode, numberOfColumn: Double?, isPreview: Bool?, primaryColor: Double?, allowedCamera: Bool?, allowSwipeToSelect: Bool?, spacing: Double?, isHiddenPreviewButton: Bool?, isHiddenOriginalButton: Bool?, isShowPreviewList: Bool?, allowHapticTouchPreview: Bool?, allowedLimit: Bool?, maxVideo: Double?, maxSelect: Double?, maxVideoDuration: Double?, minVideoDuration: Double?, maxFileSize: Double?, videoQuality: Double?, imageQuality: Double?, backgroundDark: Double?, crop: PickerCropConfig?, text: Text?, language: Language, theme: Theme, presentation: Presentation) {
init(mediaType: MediaType, selectedAssets: [Result], selectBoxStyle: SelectBoxStyle, selectMode: SelectMode, numberOfColumn: Double?, isPreview: Bool?, primaryColor: Double?, allowedCamera: Bool?, allowSwipeToSelect: Bool?, spacing: Double?, isHiddenPreviewButton: Bool?, isHiddenOriginalButton: Bool?, isShowPreviewList: Bool?, allowHapticTouchPreview: Bool?, allowedLimit: Bool?, maxVideo: Double?, maxSelect: Double?, maxVideoDuration: Double?, minVideoDuration: Double?, maxFileSize: Double?, backgroundDark: Double?, crop: PickerCropConfig?, text: Text?, language: Language, theme: Theme, presentation: Presentation) {
self.init(mediaType, { () -> bridge.std__vector_Result_ in
var __vector = bridge.create_std__vector_Result_(selectedAssets.count)
for __item in selectedAssets {
Expand Down Expand Up @@ -121,18 +121,6 @@ public extension NitroConfig {
} else {
return .init()
}
}(), { () -> bridge.std__optional_double_ in
if let __unwrappedValue = videoQuality {
return bridge.create_std__optional_double_(__unwrappedValue)
} else {
return .init()
}
}(), { () -> bridge.std__optional_double_ in
if let __unwrappedValue = imageQuality {
return bridge.create_std__optional_double_(__unwrappedValue)
} else {
return .init()
}
}(), { () -> bridge.std__optional_double_ in
if let __unwrappedValue = backgroundDark {
return bridge.create_std__optional_double_(__unwrappedValue)
Expand Down Expand Up @@ -476,40 +464,6 @@ public extension NitroConfig {
}
}

var videoQuality: Double? {
@inline(__always)
get {
return self.__videoQuality.value
}
@inline(__always)
set {
self.__videoQuality = { () -> bridge.std__optional_double_ in
if let __unwrappedValue = newValue {
return bridge.create_std__optional_double_(__unwrappedValue)
} else {
return .init()
}
}()
}
}

var imageQuality: Double? {
@inline(__always)
get {
return self.__imageQuality.value
}
@inline(__always)
set {
self.__imageQuality = { () -> bridge.std__optional_double_ in
if let __unwrappedValue = newValue {
return bridge.create_std__optional_double_(__unwrappedValue)
} else {
return .init()
}
}()
}
}

var backgroundDark: Double? {
@inline(__always)
get {
Expand Down
10 changes: 1 addition & 9 deletions nitrogen/generated/shared/c++/NitroConfig.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -76,8 +76,6 @@ namespace margelo::nitro::multipleimagepicker {
std::optional<double> maxVideoDuration SWIFT_PRIVATE;
std::optional<double> minVideoDuration SWIFT_PRIVATE;
std::optional<double> maxFileSize SWIFT_PRIVATE;
std::optional<double> videoQuality SWIFT_PRIVATE;
std::optional<double> imageQuality SWIFT_PRIVATE;
std::optional<double> backgroundDark SWIFT_PRIVATE;
std::optional<PickerCropConfig> crop SWIFT_PRIVATE;
std::optional<Text> text SWIFT_PRIVATE;
Expand All @@ -86,7 +84,7 @@ namespace margelo::nitro::multipleimagepicker {
Presentation presentation SWIFT_PRIVATE;

public:
explicit NitroConfig(MediaType mediaType, std::vector<Result> selectedAssets, SelectBoxStyle selectBoxStyle, SelectMode selectMode, std::optional<double> numberOfColumn, std::optional<bool> isPreview, std::optional<double> primaryColor, std::optional<bool> allowedCamera, std::optional<bool> allowSwipeToSelect, std::optional<double> spacing, std::optional<bool> isHiddenPreviewButton, std::optional<bool> isHiddenOriginalButton, std::optional<bool> isShowPreviewList, std::optional<bool> allowHapticTouchPreview, std::optional<bool> allowedLimit, std::optional<double> maxVideo, std::optional<double> maxSelect, std::optional<double> maxVideoDuration, std::optional<double> minVideoDuration, std::optional<double> maxFileSize, std::optional<double> videoQuality, std::optional<double> imageQuality, std::optional<double> backgroundDark, std::optional<PickerCropConfig> crop, std::optional<Text> text, Language language, Theme theme, Presentation presentation): mediaType(mediaType), selectedAssets(selectedAssets), selectBoxStyle(selectBoxStyle), selectMode(selectMode), numberOfColumn(numberOfColumn), isPreview(isPreview), primaryColor(primaryColor), allowedCamera(allowedCamera), allowSwipeToSelect(allowSwipeToSelect), spacing(spacing), isHiddenPreviewButton(isHiddenPreviewButton), isHiddenOriginalButton(isHiddenOriginalButton), isShowPreviewList(isShowPreviewList), allowHapticTouchPreview(allowHapticTouchPreview), allowedLimit(allowedLimit), maxVideo(maxVideo), maxSelect(maxSelect), maxVideoDuration(maxVideoDuration), minVideoDuration(minVideoDuration), maxFileSize(maxFileSize), videoQuality(videoQuality), imageQuality(imageQuality), backgroundDark(backgroundDark), crop(crop), text(text), language(language), theme(theme), presentation(presentation) {}
explicit NitroConfig(MediaType mediaType, std::vector<Result> selectedAssets, SelectBoxStyle selectBoxStyle, SelectMode selectMode, std::optional<double> numberOfColumn, std::optional<bool> isPreview, std::optional<double> primaryColor, std::optional<bool> allowedCamera, std::optional<bool> allowSwipeToSelect, std::optional<double> spacing, std::optional<bool> isHiddenPreviewButton, std::optional<bool> isHiddenOriginalButton, std::optional<bool> isShowPreviewList, std::optional<bool> allowHapticTouchPreview, std::optional<bool> allowedLimit, std::optional<double> maxVideo, std::optional<double> maxSelect, std::optional<double> maxVideoDuration, std::optional<double> minVideoDuration, std::optional<double> maxFileSize, std::optional<double> backgroundDark, std::optional<PickerCropConfig> crop, std::optional<Text> text, Language language, Theme theme, Presentation presentation): mediaType(mediaType), selectedAssets(selectedAssets), selectBoxStyle(selectBoxStyle), selectMode(selectMode), numberOfColumn(numberOfColumn), isPreview(isPreview), primaryColor(primaryColor), allowedCamera(allowedCamera), allowSwipeToSelect(allowSwipeToSelect), spacing(spacing), isHiddenPreviewButton(isHiddenPreviewButton), isHiddenOriginalButton(isHiddenOriginalButton), isShowPreviewList(isShowPreviewList), allowHapticTouchPreview(allowHapticTouchPreview), allowedLimit(allowedLimit), maxVideo(maxVideo), maxSelect(maxSelect), maxVideoDuration(maxVideoDuration), minVideoDuration(minVideoDuration), maxFileSize(maxFileSize), backgroundDark(backgroundDark), crop(crop), text(text), language(language), theme(theme), presentation(presentation) {}
};

} // namespace margelo::nitro::multipleimagepicker
Expand Down Expand Up @@ -121,8 +119,6 @@ namespace margelo::nitro {
JSIConverter<std::optional<double>>::fromJSI(runtime, obj.getProperty(runtime, "maxVideoDuration")),
JSIConverter<std::optional<double>>::fromJSI(runtime, obj.getProperty(runtime, "minVideoDuration")),
JSIConverter<std::optional<double>>::fromJSI(runtime, obj.getProperty(runtime, "maxFileSize")),
JSIConverter<std::optional<double>>::fromJSI(runtime, obj.getProperty(runtime, "videoQuality")),
JSIConverter<std::optional<double>>::fromJSI(runtime, obj.getProperty(runtime, "imageQuality")),
JSIConverter<std::optional<double>>::fromJSI(runtime, obj.getProperty(runtime, "backgroundDark")),
JSIConverter<std::optional<PickerCropConfig>>::fromJSI(runtime, obj.getProperty(runtime, "crop")),
JSIConverter<std::optional<Text>>::fromJSI(runtime, obj.getProperty(runtime, "text")),
Expand Down Expand Up @@ -153,8 +149,6 @@ namespace margelo::nitro {
obj.setProperty(runtime, "maxVideoDuration", JSIConverter<std::optional<double>>::toJSI(runtime, arg.maxVideoDuration));
obj.setProperty(runtime, "minVideoDuration", JSIConverter<std::optional<double>>::toJSI(runtime, arg.minVideoDuration));
obj.setProperty(runtime, "maxFileSize", JSIConverter<std::optional<double>>::toJSI(runtime, arg.maxFileSize));
obj.setProperty(runtime, "videoQuality", JSIConverter<std::optional<double>>::toJSI(runtime, arg.videoQuality));
obj.setProperty(runtime, "imageQuality", JSIConverter<std::optional<double>>::toJSI(runtime, arg.imageQuality));
obj.setProperty(runtime, "backgroundDark", JSIConverter<std::optional<double>>::toJSI(runtime, arg.backgroundDark));
obj.setProperty(runtime, "crop", JSIConverter<std::optional<PickerCropConfig>>::toJSI(runtime, arg.crop));
obj.setProperty(runtime, "text", JSIConverter<std::optional<Text>>::toJSI(runtime, arg.text));
Expand Down Expand Up @@ -188,8 +182,6 @@ namespace margelo::nitro {
if (!JSIConverter<std::optional<double>>::canConvert(runtime, obj.getProperty(runtime, "maxVideoDuration"))) return false;
if (!JSIConverter<std::optional<double>>::canConvert(runtime, obj.getProperty(runtime, "minVideoDuration"))) return false;
if (!JSIConverter<std::optional<double>>::canConvert(runtime, obj.getProperty(runtime, "maxFileSize"))) return false;
if (!JSIConverter<std::optional<double>>::canConvert(runtime, obj.getProperty(runtime, "videoQuality"))) return false;
if (!JSIConverter<std::optional<double>>::canConvert(runtime, obj.getProperty(runtime, "imageQuality"))) return false;
if (!JSIConverter<std::optional<double>>::canConvert(runtime, obj.getProperty(runtime, "backgroundDark"))) return false;
if (!JSIConverter<std::optional<PickerCropConfig>>::canConvert(runtime, obj.getProperty(runtime, "crop"))) return false;
if (!JSIConverter<std::optional<Text>>::canConvert(runtime, obj.getProperty(runtime, "text"))) return false;
Expand Down
Loading

0 comments on commit f6a44ab

Please sign in to comment.