Skip to content

Commit cb0640d

Browse files
authored
Merge pull request #210 from baronha/feat/nitro-20
✨ feat: Nitro 20
2 parents a44e22f + ec0137b commit cb0640d

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

44 files changed

+622
-400
lines changed

android/src/main/java/com/margelo/nitro/multipleimagepicker/MultipleImagePicker.kt

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ class MultipleImagePicker : HybridMultipleImagePickerSpec() {
1111

1212
override fun openPicker(
1313
config: NitroConfig,
14-
resolved: (result: Array<Result>) -> Unit,
14+
resolved: (result: Array<PickerResult>) -> Unit,
1515
rejected: (reject: Double) -> Unit
1616
) {
1717
pickerModule.openPicker(config, resolved, rejected)

android/src/main/java/com/margelo/nitro/multipleimagepicker/MultipleImagePickerImp.kt

+4-4
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ class MultipleImagePickerImp(reactContext: ReactApplicationContext?) :
6060
@ReactMethod
6161
fun openPicker(
6262
options: NitroConfig,
63-
resolved: (result: Array<Result>) -> Unit,
63+
resolved: (result: Array<PickerResult>) -> Unit,
6464
rejected: (reject: Double) -> Unit
6565
) {
6666
PictureAppMaster.getInstance().app = this
@@ -150,7 +150,7 @@ class MultipleImagePickerImp(reactContext: ReactApplicationContext?) :
150150
.isPreviewFullScreenMode(true)
151151
.forResult(object : OnResultCallbackListener<LocalMedia?> {
152152
override fun onResult(localMedia: ArrayList<LocalMedia?>?) {
153-
var data: Array<Result> = arrayOf()
153+
var data: Array<PickerResult> = arrayOf()
154154
if (localMedia?.size == 0 || localMedia == null) {
155155
resolved(arrayOf())
156156
return
@@ -575,7 +575,7 @@ class MultipleImagePickerImp(reactContext: ReactApplicationContext?) :
575575
}.toMutableList()
576576
}
577577

578-
private fun getResult(item: LocalMedia): Result {
578+
private fun getResult(item: LocalMedia): PickerResult {
579579

580580
val type: ResultType =
581581
if (item.mimeType.startsWith("video/")) ResultType.VIDEO else ResultType.IMAGE
@@ -597,7 +597,7 @@ class MultipleImagePickerImp(reactContext: ReactApplicationContext?) :
597597
if (!path.startsWith("file://") && !path.startsWith("content://") && type == ResultType.IMAGE)
598598
path = "file://$path"
599599

600-
val media = Result(
600+
val media = PickerResult(
601601
localIdentifier = item.id.toString(),
602602
width,
603603
height,

docs/docs/GETTING_STARTED.mdx

+2-2
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ Install [@baronha/react-native-multiple-image-picker](https://www.npmjs.com/pack
5050

5151
```bash
5252
yarn add @baronha/react-native-multiple-image-picker
53-
yarn add -D react-native-nitro-modules@0.18.2
53+
yarn add -D react-native-nitro-modules@0.20.1
5454
cd ios && pod install
5555
```
5656

@@ -60,7 +60,7 @@ cd ios && pod install
6060

6161
```bash
6262
npx expo install @baronha/react-native-multiple-image-picker
63-
npx expo install react-native-nitro-modules@0.18.2 -- --dev
63+
npx expo install react-native-nitro-modules@0.20.1 -- --dev
6464
npx expo prebuild
6565
```
6666

example/package.json

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "multipleimagepickerexample",
3-
"version": "2.0.4",
3+
"version": "2.1.2",
44
"main": "expo/AppEntry.js",
55
"scripts": {
66
"start": "expo start",
@@ -31,7 +31,7 @@
3131
"@react-native/typescript-config": "0.75.2",
3232
"@types/react": "~18.2.45",
3333
"react-native-builder-bob": "^0.30.0",
34-
"react-native-nitro-modules": "0.18.2",
34+
"react-native-nitro-modules": "^0.20.1",
3535
"typescript": "^5.1.3"
3636
},
3737
"private": true

example/src/index.tsx

+5-5
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ import { StyleSheet } from 'react-native'
1717
import ImageGrid from '@baronha/react-native-image-grid'
1818
import {
1919
openPicker,
20-
Result,
20+
PickerResult,
2121
defaultOptions,
2222
Config,
2323
openCropper,
@@ -64,7 +64,7 @@ const parseNumber = (value: string): number | undefined => {
6464

6565
export default function App() {
6666
const { background, foreground } = useTheme()
67-
const [images, setImages] = useState<Result[]>([])
67+
const [images, setImages] = useState<PickerResult[]>([])
6868
const [options, changeOptions] = useImmer<Config>(defaultOptions)
6969

7070
const colorScheme = useColorScheme()
@@ -75,7 +75,7 @@ export default function App() {
7575
})
7676
}
7777

78-
const onPressImage = (_: Result, index: number) => {
78+
const onPressImage = (_: PickerResult, index: number) => {
7979
openPreview(images, index, {})
8080
}
8181

@@ -98,7 +98,7 @@ export default function App() {
9898
const response = await openCamera()
9999

100100
setImages((prev) => {
101-
return [response as Result, ...prev]
101+
return [response as PickerResult, ...prev]
102102
})
103103

104104
layoutEffect()
@@ -130,7 +130,7 @@ export default function App() {
130130
}
131131
}
132132

133-
const onRemovePhoto = (_: Result, index: number) => {
133+
const onRemovePhoto = (_: PickerResult, index: number) => {
134134
const data = [...images].filter((__, idx) => idx !== index)
135135
setImages(data)
136136
}

example/yarn.lock

+4-4
Original file line numberDiff line numberDiff line change
@@ -5414,10 +5414,10 @@ react-native-builder-bob@^0.30.0:
54145414
which "^2.0.2"
54155415
yargs "^17.5.1"
54165416

5417-
react-native-nitro-modules@0.18.2:
5418-
version "0.18.2"
5419-
resolved "https://registry.yarnpkg.com/react-native-nitro-modules/-/react-native-nitro-modules-0.18.2.tgz#f1172f90ecaded0e4b3306f6e7be4b54a24b310e"
5420-
integrity sha512-eHsq1cRfm/Bz1Nq7KctTqxAqhzVSNo0WGX281xARZh+vOq8633Qxn1NHRZ5/Rno2Bla6HOXlUW6RoW0wKM/7kg==
5417+
react-native-nitro-modules@0.20.0:
5418+
version "0.20.0"
5419+
resolved "https://registry.yarnpkg.com/react-native-nitro-modules/-/react-native-nitro-modules-0.20.0.tgz#3c659d4c8cbc8038b1bf35af6475e77023e70ffa"
5420+
integrity sha512-u41SaGdQ/EQFuRLFPRQ+cbEemzsARmkElXErwZlXJhr2KYmVwQMrIYGe69NuMSyvHlw3JTl09SNugt3PXa2vEQ==
54215421

54225422
react-native@0.76.5:
54235423
version "0.76.5"

ios/HybridMultipleImagePicker+Result.swift

+16-16
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import HXPhotoPicker
99
// import Photos
1010

1111
extension HybridMultipleImagePicker {
12-
func getResult(_ asset: PhotoAsset) async throws -> Result {
12+
func getResult(_ asset: PhotoAsset) async throws -> PickerResult {
1313
let urlResult = try await asset.urlResult()
1414
let url = urlResult.url
1515

@@ -22,20 +22,20 @@ extension HybridMultipleImagePicker {
2222
let type: ResultType = .init(fromString: asset.mediaType == .video ? "video" : "image")!
2323
let thumbnail = asset.phAsset?.getVideoAssetThumbnail(from: url.absoluteString, in: 1)
2424

25-
return Result(localIdentifier: phAsset!.localIdentifier,
26-
width: asset.imageSize.width,
27-
height: asset.imageSize.height,
28-
mime: mime,
29-
size: Double(asset.fileSize),
30-
bucketId: nil,
31-
realPath: nil,
32-
parentFolderName: nil,
33-
creationDate: creationDate > 0 ? Double(creationDate) : nil,
34-
crop: false,
35-
path: "file://\(url.absoluteString)",
36-
type: type,
37-
duration: asset.videoDuration,
38-
thumbnail: thumbnail,
39-
fileName: phAsset?.fileName)
25+
return PickerResult(localIdentifier: phAsset!.localIdentifier,
26+
width: asset.imageSize.width,
27+
height: asset.imageSize.height,
28+
mime: mime,
29+
size: Double(asset.fileSize),
30+
bucketId: nil,
31+
realPath: nil,
32+
parentFolderName: nil,
33+
creationDate: creationDate > 0 ? Double(creationDate) : nil,
34+
crop: false,
35+
path: "file://\(url.absoluteString)",
36+
type: type,
37+
duration: asset.videoDuration,
38+
thumbnail: thumbnail,
39+
fileName: phAsset?.fileName)
4040
}
4141
}

ios/HybridMultipleImagePicker.swift

+2-8
Original file line numberDiff line numberDiff line change
@@ -10,17 +10,11 @@ import NitroModules
1010
import Photos
1111

1212
class HybridMultipleImagePicker: HybridMultipleImagePickerSpec {
13-
var hybridContext = margelo.nitro.HybridContext()
14-
15-
var memorySize: Int {
16-
return getSizeOf(self)
17-
}
18-
1913
var selectedAssets: [PhotoAsset] = .init()
2014

2115
var config: PickerConfiguration = .init()
2216

23-
func openPicker(config: NitroConfig, resolved: @escaping (([Result]) -> Void), rejected: @escaping ((Double) -> Void)) throws {
17+
func openPicker(config: NitroConfig, resolved: @escaping (([PickerResult]) -> Void), rejected: @escaping ((Double) -> Void)) throws {
2418
setConfig(config)
2519

2620
// get selected photo
@@ -67,7 +61,7 @@ class HybridMultipleImagePicker: HybridMultipleImagePickerSpec {
6761

6862
let group = DispatchGroup()
6963

70-
var data: [Result] = []
64+
var data: [PickerResult] = []
7165

7266
self.selectedAssets = pickerResult.photoAssets
7367

nitrogen/generated/android/MultipleImagePickerOnLoad.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
#include <NitroModules/HybridObjectRegistry.hpp>
1313

1414
#include "JHybridMultipleImagePickerSpec.hpp"
15-
#include "JFunc_void_std__vector_Result_.hpp"
15+
#include "JFunc_void_std__vector_PickerResult_.hpp"
1616
#include "JFunc_void_double.hpp"
1717
#include "JFunc_void_CropResult.hpp"
1818
#include "JFunc_void_CameraResult.hpp"
@@ -29,7 +29,7 @@ int initialize(JavaVM* vm) {
2929
return facebook::jni::initialize(vm, [] {
3030
// Register native JNI methods
3131
margelo::nitro::multipleimagepicker::JHybridMultipleImagePickerSpec::registerNatives();
32-
margelo::nitro::multipleimagepicker::JFunc_void_std__vector_Result_::registerNatives();
32+
margelo::nitro::multipleimagepicker::JFunc_void_std__vector_PickerResult_::registerNatives();
3333
margelo::nitro::multipleimagepicker::JFunc_void_double::registerNatives();
3434
margelo::nitro::multipleimagepicker::JFunc_void_CropResult::registerNatives();
3535
margelo::nitro::multipleimagepicker::JFunc_void_double::registerNatives();

nitrogen/generated/android/c++/JFunc_void_CameraResult.hpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ namespace margelo::nitro::multipleimagepicker {
3434

3535
public:
3636
void call(jni::alias_ref<JCameraResult> result) {
37-
return _func(result->toCpp());
37+
_func(result->toCpp());
3838
}
3939

4040
public:

nitrogen/generated/android/c++/JFunc_void_CropResult.hpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ namespace margelo::nitro::multipleimagepicker {
3131

3232
public:
3333
void call(jni::alias_ref<JCropResult> result) {
34-
return _func(result->toCpp());
34+
_func(result->toCpp());
3535
}
3636

3737
public:

nitrogen/generated/android/c++/JFunc_void_double.hpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ namespace margelo::nitro::multipleimagepicker {
2828

2929
public:
3030
void call(double reject) {
31-
return _func(reject);
31+
_func(reject);
3232
}
3333

3434
public:
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
///
2+
/// JFunc_void_std__vector_PickerResult_.hpp
3+
/// This file was generated by nitrogen. DO NOT MODIFY THIS FILE.
4+
/// https://github.com/mrousavy/nitro
5+
/// Copyright © 2024 Marc Rousavy @ Margelo
6+
///
7+
8+
#pragma once
9+
10+
#include <fbjni/fbjni.h>
11+
#include <functional>
12+
13+
#include <functional>
14+
#include <vector>
15+
#include "PickerResult.hpp"
16+
#include "JPickerResult.hpp"
17+
#include <string>
18+
#include <optional>
19+
#include "ResultType.hpp"
20+
#include "JResultType.hpp"
21+
22+
namespace margelo::nitro::multipleimagepicker {
23+
24+
using namespace facebook;
25+
26+
/**
27+
* C++ representation of the callback Func_void_std__vector_PickerResult_.
28+
* This is a Kotlin `(result: Array<PickerResult>) -> Unit`, backed by a `std::function<...>`.
29+
*/
30+
struct JFunc_void_std__vector_PickerResult_ final: public jni::HybridClass<JFunc_void_std__vector_PickerResult_> {
31+
public:
32+
static jni::local_ref<JFunc_void_std__vector_PickerResult_::javaobject> fromCpp(const std::function<void(const std::vector<PickerResult>& /* result */)>& func) {
33+
return JFunc_void_std__vector_PickerResult_::newObjectCxxArgs(func);
34+
}
35+
36+
public:
37+
void call(jni::alias_ref<jni::JArrayClass<JPickerResult>> result) {
38+
_func([&]() {
39+
size_t __size = result->size();
40+
std::vector<PickerResult> __vector;
41+
__vector.reserve(__size);
42+
for (size_t __i = 0; __i < __size; __i++) {
43+
auto __element = result->getElement(__i);
44+
__vector.push_back(__element->toCpp());
45+
}
46+
return __vector;
47+
}());
48+
}
49+
50+
public:
51+
static auto constexpr kJavaDescriptor = "Lcom/margelo/nitro/multipleimagepicker/Func_void_std__vector_PickerResult_;";
52+
static void registerNatives() {
53+
registerHybrid({makeNativeMethod("call", JFunc_void_std__vector_PickerResult_::call)});
54+
}
55+
56+
private:
57+
explicit JFunc_void_std__vector_PickerResult_(const std::function<void(const std::vector<PickerResult>& /* result */)>& func): _func(func) { }
58+
59+
private:
60+
friend HybridBase;
61+
std::function<void(const std::vector<PickerResult>& /* result */)> _func;
62+
};
63+
64+
} // namespace margelo::nitro::multipleimagepicker

nitrogen/generated/android/c++/JFunc_void_std__vector_Result_.hpp

-64
This file was deleted.

0 commit comments

Comments
 (0)