Skip to content

Commit

Permalink
Merge pull request #210 from baronha/feat/nitro-20
Browse files Browse the repository at this point in the history
✨ feat: Nitro 20
  • Loading branch information
baronha authored Dec 23, 2024
2 parents a44e22f + ec0137b commit cb0640d
Show file tree
Hide file tree
Showing 44 changed files with 622 additions and 400 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ class MultipleImagePicker : HybridMultipleImagePickerSpec() {

override fun openPicker(
config: NitroConfig,
resolved: (result: Array<Result>) -> Unit,
resolved: (result: Array<PickerResult>) -> Unit,
rejected: (reject: Double) -> Unit
) {
pickerModule.openPicker(config, resolved, rejected)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ class MultipleImagePickerImp(reactContext: ReactApplicationContext?) :
@ReactMethod
fun openPicker(
options: NitroConfig,
resolved: (result: Array<Result>) -> Unit,
resolved: (result: Array<PickerResult>) -> Unit,
rejected: (reject: Double) -> Unit
) {
PictureAppMaster.getInstance().app = this
Expand Down Expand Up @@ -150,7 +150,7 @@ class MultipleImagePickerImp(reactContext: ReactApplicationContext?) :
.isPreviewFullScreenMode(true)
.forResult(object : OnResultCallbackListener<LocalMedia?> {
override fun onResult(localMedia: ArrayList<LocalMedia?>?) {
var data: Array<Result> = arrayOf()
var data: Array<PickerResult> = arrayOf()
if (localMedia?.size == 0 || localMedia == null) {
resolved(arrayOf())
return
Expand Down Expand Up @@ -575,7 +575,7 @@ class MultipleImagePickerImp(reactContext: ReactApplicationContext?) :
}.toMutableList()
}

private fun getResult(item: LocalMedia): Result {
private fun getResult(item: LocalMedia): PickerResult {

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

val media = Result(
val media = PickerResult(
localIdentifier = item.id.toString(),
width,
height,
Expand Down
4 changes: 2 additions & 2 deletions docs/docs/GETTING_STARTED.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ Install [@baronha/react-native-multiple-image-picker](https://www.npmjs.com/pack

```bash
yarn add @baronha/react-native-multiple-image-picker
yarn add -D react-native-nitro-modules@0.18.2
yarn add -D react-native-nitro-modules@0.20.1
cd ios && pod install
```

Expand All @@ -60,7 +60,7 @@ cd ios && pod install

```bash
npx expo install @baronha/react-native-multiple-image-picker
npx expo install react-native-nitro-modules@0.18.2 -- --dev
npx expo install react-native-nitro-modules@0.20.1 -- --dev
npx expo prebuild
```

Expand Down
4 changes: 2 additions & 2 deletions example/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "multipleimagepickerexample",
"version": "2.0.4",
"version": "2.1.2",
"main": "expo/AppEntry.js",
"scripts": {
"start": "expo start",
Expand Down Expand Up @@ -31,7 +31,7 @@
"@react-native/typescript-config": "0.75.2",
"@types/react": "~18.2.45",
"react-native-builder-bob": "^0.30.0",
"react-native-nitro-modules": "0.18.2",
"react-native-nitro-modules": "^0.20.1",
"typescript": "^5.1.3"
},
"private": true
Expand Down
10 changes: 5 additions & 5 deletions example/src/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import { StyleSheet } from 'react-native'
import ImageGrid from '@baronha/react-native-image-grid'
import {
openPicker,
Result,
PickerResult,
defaultOptions,
Config,
openCropper,
Expand Down Expand Up @@ -64,7 +64,7 @@ const parseNumber = (value: string): number | undefined => {

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

const colorScheme = useColorScheme()
Expand All @@ -75,7 +75,7 @@ export default function App() {
})
}

const onPressImage = (_: Result, index: number) => {
const onPressImage = (_: PickerResult, index: number) => {
openPreview(images, index, {})
}

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

setImages((prev) => {
return [response as Result, ...prev]
return [response as PickerResult, ...prev]
})

layoutEffect()
Expand Down Expand Up @@ -130,7 +130,7 @@ export default function App() {
}
}

const onRemovePhoto = (_: Result, index: number) => {
const onRemovePhoto = (_: PickerResult, index: number) => {
const data = [...images].filter((__, idx) => idx !== index)
setImages(data)
}
Expand Down
8 changes: 4 additions & 4 deletions example/yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -5414,10 +5414,10 @@ react-native-builder-bob@^0.30.0:
which "^2.0.2"
yargs "^17.5.1"

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

[email protected]:
version "0.76.5"
Expand Down
32 changes: 16 additions & 16 deletions ios/HybridMultipleImagePicker+Result.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import HXPhotoPicker
// import Photos

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

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

return Result(localIdentifier: phAsset!.localIdentifier,
width: asset.imageSize.width,
height: asset.imageSize.height,
mime: mime,
size: Double(asset.fileSize),
bucketId: nil,
realPath: nil,
parentFolderName: nil,
creationDate: creationDate > 0 ? Double(creationDate) : nil,
crop: false,
path: "file://\(url.absoluteString)",
type: type,
duration: asset.videoDuration,
thumbnail: thumbnail,
fileName: phAsset?.fileName)
return PickerResult(localIdentifier: phAsset!.localIdentifier,
width: asset.imageSize.width,
height: asset.imageSize.height,
mime: mime,
size: Double(asset.fileSize),
bucketId: nil,
realPath: nil,
parentFolderName: nil,
creationDate: creationDate > 0 ? Double(creationDate) : nil,
crop: false,
path: "file://\(url.absoluteString)",
type: type,
duration: asset.videoDuration,
thumbnail: thumbnail,
fileName: phAsset?.fileName)
}
}
10 changes: 2 additions & 8 deletions ios/HybridMultipleImagePicker.swift
Original file line number Diff line number Diff line change
Expand Up @@ -10,17 +10,11 @@ import NitroModules
import Photos

class HybridMultipleImagePicker: HybridMultipleImagePickerSpec {
var hybridContext = margelo.nitro.HybridContext()

var memorySize: Int {
return getSizeOf(self)
}

var selectedAssets: [PhotoAsset] = .init()

var config: PickerConfiguration = .init()

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

// get selected photo
Expand Down Expand Up @@ -67,7 +61,7 @@ class HybridMultipleImagePicker: HybridMultipleImagePickerSpec {

let group = DispatchGroup()

var data: [Result] = []
var data: [PickerResult] = []

self.selectedAssets = pickerResult.photoAssets

Expand Down
4 changes: 2 additions & 2 deletions nitrogen/generated/android/MultipleImagePickerOnLoad.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
#include <NitroModules/HybridObjectRegistry.hpp>

#include "JHybridMultipleImagePickerSpec.hpp"
#include "JFunc_void_std__vector_Result_.hpp"
#include "JFunc_void_std__vector_PickerResult_.hpp"
#include "JFunc_void_double.hpp"
#include "JFunc_void_CropResult.hpp"
#include "JFunc_void_CameraResult.hpp"
Expand All @@ -29,7 +29,7 @@ int initialize(JavaVM* vm) {
return facebook::jni::initialize(vm, [] {
// Register native JNI methods
margelo::nitro::multipleimagepicker::JHybridMultipleImagePickerSpec::registerNatives();
margelo::nitro::multipleimagepicker::JFunc_void_std__vector_Result_::registerNatives();
margelo::nitro::multipleimagepicker::JFunc_void_std__vector_PickerResult_::registerNatives();
margelo::nitro::multipleimagepicker::JFunc_void_double::registerNatives();
margelo::nitro::multipleimagepicker::JFunc_void_CropResult::registerNatives();
margelo::nitro::multipleimagepicker::JFunc_void_double::registerNatives();
Expand Down
2 changes: 1 addition & 1 deletion nitrogen/generated/android/c++/JFunc_void_CameraResult.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ namespace margelo::nitro::multipleimagepicker {

public:
void call(jni::alias_ref<JCameraResult> result) {
return _func(result->toCpp());
_func(result->toCpp());
}

public:
Expand Down
2 changes: 1 addition & 1 deletion nitrogen/generated/android/c++/JFunc_void_CropResult.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ namespace margelo::nitro::multipleimagepicker {

public:
void call(jni::alias_ref<JCropResult> result) {
return _func(result->toCpp());
_func(result->toCpp());
}

public:
Expand Down
2 changes: 1 addition & 1 deletion nitrogen/generated/android/c++/JFunc_void_double.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ namespace margelo::nitro::multipleimagepicker {

public:
void call(double reject) {
return _func(reject);
_func(reject);
}

public:
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
///
/// JFunc_void_std__vector_PickerResult_.hpp
/// This file was generated by nitrogen. DO NOT MODIFY THIS FILE.
/// https://github.com/mrousavy/nitro
/// Copyright © 2024 Marc Rousavy @ Margelo
///

#pragma once

#include <fbjni/fbjni.h>
#include <functional>

#include <functional>
#include <vector>
#include "PickerResult.hpp"
#include "JPickerResult.hpp"
#include <string>
#include <optional>
#include "ResultType.hpp"
#include "JResultType.hpp"

namespace margelo::nitro::multipleimagepicker {

using namespace facebook;

/**
* C++ representation of the callback Func_void_std__vector_PickerResult_.
* This is a Kotlin `(result: Array<PickerResult>) -> Unit`, backed by a `std::function<...>`.
*/
struct JFunc_void_std__vector_PickerResult_ final: public jni::HybridClass<JFunc_void_std__vector_PickerResult_> {
public:
static jni::local_ref<JFunc_void_std__vector_PickerResult_::javaobject> fromCpp(const std::function<void(const std::vector<PickerResult>& /* result */)>& func) {
return JFunc_void_std__vector_PickerResult_::newObjectCxxArgs(func);
}

public:
void call(jni::alias_ref<jni::JArrayClass<JPickerResult>> result) {
_func([&]() {
size_t __size = result->size();
std::vector<PickerResult> __vector;
__vector.reserve(__size);
for (size_t __i = 0; __i < __size; __i++) {
auto __element = result->getElement(__i);
__vector.push_back(__element->toCpp());
}
return __vector;
}());
}

public:
static auto constexpr kJavaDescriptor = "Lcom/margelo/nitro/multipleimagepicker/Func_void_std__vector_PickerResult_;";
static void registerNatives() {
registerHybrid({makeNativeMethod("call", JFunc_void_std__vector_PickerResult_::call)});
}

private:
explicit JFunc_void_std__vector_PickerResult_(const std::function<void(const std::vector<PickerResult>& /* result */)>& func): _func(func) { }

private:
friend HybridBase;
std::function<void(const std::vector<PickerResult>& /* result */)> _func;
};

} // namespace margelo::nitro::multipleimagepicker
64 changes: 0 additions & 64 deletions nitrogen/generated/android/c++/JFunc_void_std__vector_Result_.hpp

This file was deleted.

Loading

0 comments on commit cb0640d

Please sign in to comment.