-
Notifications
You must be signed in to change notification settings - Fork 26
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: Fix passing function inside object on Android (
toCpp()
) (#453)
* chore: Add test for JS-style object as params * Image specs * Impl * fix: Use `cthis()` for function conversions * fix: Use `getFunction()`
- Loading branch information
Showing
35 changed files
with
450 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
53 changes: 53 additions & 0 deletions
53
packages/react-native-nitro-image/nitrogen/generated/android/c++/JFunc_void_double.hpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
/// | ||
/// JFunc_void_double.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> | ||
|
||
namespace margelo::nitro::image { | ||
|
||
using namespace facebook; | ||
|
||
/** | ||
* C++ representation of the callback Func_void_double. | ||
* This is a Kotlin `(num: Double) -> Unit`, backed by a `std::function<...>`. | ||
*/ | ||
struct JFunc_void_double final: public jni::HybridClass<JFunc_void_double> { | ||
public: | ||
static jni::local_ref<JFunc_void_double::javaobject> fromCpp(const std::function<void(double /* num */)>& func) { | ||
return JFunc_void_double::newObjectCxxArgs(func); | ||
} | ||
|
||
public: | ||
void call(double num) { | ||
_func(num); | ||
} | ||
|
||
public: | ||
inline const std::function<void(double /* num */)>& getFunction() const { | ||
return _func; | ||
} | ||
|
||
public: | ||
static auto constexpr kJavaDescriptor = "Lcom/margelo/nitro/image/Func_void_double;"; | ||
static void registerNatives() { | ||
registerHybrid({makeNativeMethod("call", JFunc_void_double::call)}); | ||
} | ||
|
||
private: | ||
explicit JFunc_void_double(const std::function<void(double /* num */)>& func): _func(func) { } | ||
|
||
private: | ||
friend HybridBase; | ||
std::function<void(double /* num */)> _func; | ||
}; | ||
|
||
} // namespace margelo::nitro::image |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
57 changes: 57 additions & 0 deletions
57
packages/react-native-nitro-image/nitrogen/generated/android/c++/JJsStyleStruct.hpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
/// | ||
/// JJsStyleStruct.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 "JsStyleStruct.hpp" | ||
|
||
#include "JFunc_void_double.hpp" | ||
#include <functional> | ||
|
||
namespace margelo::nitro::image { | ||
|
||
using namespace facebook; | ||
|
||
/** | ||
* The C++ JNI bridge between the C++ struct "JsStyleStruct" and the the Kotlin data class "JsStyleStruct". | ||
*/ | ||
struct JJsStyleStruct final: public jni::JavaClass<JJsStyleStruct> { | ||
public: | ||
static auto constexpr kJavaDescriptor = "Lcom/margelo/nitro/image/JsStyleStruct;"; | ||
|
||
public: | ||
/** | ||
* Convert this Java/Kotlin-based struct to the C++ struct JsStyleStruct by copying all values to C++. | ||
*/ | ||
[[maybe_unused]] | ||
JsStyleStruct toCpp() const { | ||
static const auto clazz = javaClassStatic(); | ||
static const auto fieldValue = clazz->getField<double>("value"); | ||
double value = this->getFieldValue(fieldValue); | ||
static const auto fieldOnChanged = clazz->getField<JFunc_void_double::javaobject>("onChanged"); | ||
jni::local_ref<JFunc_void_double::javaobject> onChanged = this->getFieldValue(fieldOnChanged); | ||
return JsStyleStruct( | ||
value, | ||
onChanged->cthis()->getFunction() | ||
); | ||
} | ||
|
||
public: | ||
/** | ||
* Create a Java/Kotlin-based struct by copying all values from the given C++ struct to Java. | ||
*/ | ||
[[maybe_unused]] | ||
static jni::local_ref<JJsStyleStruct::javaobject> fromCpp(const JsStyleStruct& value) { | ||
return newInstance( | ||
value.value, | ||
JFunc_void_double::fromCpp(value.onChanged) | ||
); | ||
} | ||
}; | ||
|
||
} // namespace margelo::nitro::image |
Oops, something went wrong.