Skip to content

Commit

Permalink
run nitrogen
Browse files Browse the repository at this point in the history
  • Loading branch information
mrousavy committed Jan 14, 2025
1 parent b13d944 commit 22ed17e
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 24 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ namespace margelo::nitro::image {
using namespace facebook;

/**
* Represents the Java/Kotlin callback `(valueFromJs: String) -> Unit`.
* Represents the Java/Kotlin callback `(path: String) -> Unit`.
* This can be passed around between C++ and Java/Kotlin.
*/
struct JFunc_void_std__string: public jni::JavaClass<JFunc_void_std__string> {
Expand All @@ -29,9 +29,9 @@ namespace margelo::nitro::image {
/**
* Invokes the function this `JFunc_void_std__string` instance holds through JNI.
*/
void invoke(const std::string& valueFromJs) const {
static const auto method = getClass()->getMethod<void(jni::alias_ref<jni::JString> /* valueFromJs */)>("invoke");
method(self(), jni::make_jstring(valueFromJs));
void invoke(const std::string& path) const {
static const auto method = getClass()->getMethod<void(jni::alias_ref<jni::JString> /* path */)>("invoke");
method(self(), jni::make_jstring(path));
}
};

Expand All @@ -40,21 +40,21 @@ namespace margelo::nitro::image {
*/
struct JFunc_void_std__string_cxx final: public jni::HybridClass<JFunc_void_std__string_cxx, JFunc_void_std__string> {
public:
static jni::local_ref<JFunc_void_std__string::javaobject> fromCpp(const std::function<void(const std::string& /* valueFromJs */)>& func) {
static jni::local_ref<JFunc_void_std__string::javaobject> fromCpp(const std::function<void(const std::string& /* path */)>& func) {
return JFunc_void_std__string_cxx::newObjectCxxArgs(func);
}

public:
/**
* Invokes the C++ `std::function<...>` this `JFunc_void_std__string_cxx` instance holds.
*/
void invoke_cxx(jni::alias_ref<jni::JString> valueFromJs) {
_func(valueFromJs->toStdString());
void invoke_cxx(jni::alias_ref<jni::JString> path) {
_func(path->toStdString());
}

public:
[[nodiscard]]
inline const std::function<void(const std::string& /* valueFromJs */)>& getFunction() const {
inline const std::function<void(const std::string& /* path */)>& getFunction() const {
return _func;
}

Expand All @@ -65,11 +65,11 @@ namespace margelo::nitro::image {
}

private:
explicit JFunc_void_std__string_cxx(const std::function<void(const std::string& /* valueFromJs */)>& func): _func(func) { }
explicit JFunc_void_std__string_cxx(const std::function<void(const std::string& /* path */)>& func): _func(func) { }

private:
friend HybridBase;
std::function<void(const std::string& /* valueFromJs */)> _func;
std::function<void(const std::string& /* path */)> _func;
};

} // namespace margelo::nitro::image
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import com.margelo.nitro.core.*
import dalvik.annotation.optimization.FastNative

/**
* Represents the JavaScript callback `(valueFromJs: string) => void`.
* Represents the JavaScript callback `(path: string) => void`.
* This can be either implemented in C++ (in which case it might be a callback coming from JS),
* or in Kotlin/Java (in which case it is a native callback).
*/
Expand All @@ -28,11 +28,11 @@ fun interface Func_void_std__string: (String) -> Unit {
*/
@DoNotStrip
@Keep
override fun invoke(valueFromJs: String): Unit
override fun invoke(path: String): Unit
}

/**
* Represents the JavaScript callback `(valueFromJs: string) => void`.
* Represents the JavaScript callback `(path: string) => void`.
* This is implemented in C++, via a `std::function<...>`.
* The callback might be coming from JS.
*/
Expand All @@ -55,11 +55,11 @@ class Func_void_std__string_cxx: Func_void_std__string {
}

@FastNative
external override fun invoke(valueFromJs: String): Unit
external override fun invoke(path: String): Unit
}

/**
* Represents the JavaScript callback `(valueFromJs: string) => void`.
* Represents the JavaScript callback `(path: string) => void`.
* This is implemented in Java/Kotlin, via a `(String) -> Unit`.
* The callback is always coming from native.
*/
Expand All @@ -69,7 +69,7 @@ class Func_void_std__string_cxx: Func_void_std__string {
class Func_void_std__string_java(private val function: (String) -> Unit): Func_void_std__string {
@DoNotStrip
@Keep
override fun invoke(valueFromJs: String): Unit {
return this.function(valueFromJs)
override fun invoke(path: String): Unit {
return this.function(path)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,21 +8,21 @@
import NitroModules

/**
* Wraps a Swift `(_ valueFromJs: String) -> Void` as a class.
* Wraps a Swift `(_ path: String) -> Void` as a class.
* This class can be used from C++, e.g. to wrap the Swift closure as a `std::function`.
*/
public final class Func_void_std__string {
public typealias bridge = margelo.nitro.image.bridge.swift

private let closure: (_ valueFromJs: String) -> Void
private let closure: (_ path: String) -> Void

public init(_ closure: @escaping (_ valueFromJs: String) -> Void) {
public init(_ closure: @escaping (_ path: String) -> Void) {
self.closure = closure
}

@inline(__always)
public func call(valueFromJs: std.string) -> Void {
self.closure(String(valueFromJs))
public func call(path: std.string) -> Void {
self.closure(String(path))
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@ public class HybridImageFactorySpec_base: HybridObject {
return cxxWrapper
}
}
public var memorySize: Int { return 0 }
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@ public class HybridImageSpec_base: HybridObject {
return cxxWrapper
}
}
public var memorySize: Int { return 0 }
}

/**
Expand Down

0 comments on commit 22ed17e

Please sign in to comment.