Skip to content

Commit

Permalink
Merge pull request #194 from genaris/fix/rn-build-issues
Browse files Browse the repository at this point in the history
fix(js): missing binding methods in react native
  • Loading branch information
andrewwhitehead authored Nov 9, 2023
2 parents 27ddf9b + 7a110b4 commit 9200a30
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -275,7 +275,7 @@ jsi::Value storeSetDefaultProfile(jsi::Runtime &rt, jsi::Object options) {
state->rt = &rt;

ErrorCode code = askar_store_set_default_profile(
storeHandle, profile.c_str(), callbackWithResponse, CallbackId(state));
storeHandle, profile.c_str(), callback, CallbackId(state));

return createReturnValue(rt, code, nullptr);
}
Expand Down Expand Up @@ -1040,7 +1040,7 @@ jsi::Value migrateIndySdk(jsi::Runtime &rt, jsi::Object options) {

jsi::Value stringListCount(jsi::Runtime &rt, jsi::Object options) {
auto stringListHandle =
jsiToValue<EntryListHandle>(rt, options, "stringListHandle");
jsiToValue<StringListHandle>(rt, options, "stringListHandle");

int32_t out;

Expand All @@ -1051,7 +1051,7 @@ jsi::Value stringListCount(jsi::Runtime &rt, jsi::Object options) {

jsi::Value stringListFree(jsi::Runtime &rt, jsi::Object options) {
auto stringListHandle =
jsiToValue<EntryListHandle>(rt, options, "stringListHandle");
jsiToValue<StringListHandle>(rt, options, "stringListHandle");

askar_string_list_free(stringListHandle);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -225,6 +225,15 @@ jsi::Value createReturnValue(jsi::Runtime &rt, ErrorCode code,
: createReturnValue(rt, code, std::to_string(int64_t(intptr_t(value->_0))));
}

template <>
jsi::Value createReturnValue(jsi::Runtime &rt, ErrorCode code,
StringListHandle const *value) {
auto isNullptr = value == nullptr || value->_0 == nullptr;
return isNullptr
? createReturnValue(rt, code, nullptr)
: createReturnValue(rt, code, std::to_string(int64_t(intptr_t(value->_0))));
}

template <>
jsi::Value createReturnValue(jsi::Runtime &rt, ErrorCode code,
EncryptedBuffer *value) {
Expand Down Expand Up @@ -343,6 +352,20 @@ void callbackWithResponse(CallbackId result, ErrorCode code,
});
}

template <>
void callbackWithResponse(CallbackId result, ErrorCode code,
StringListHandle response) {
invoker->invokeAsync([result, code, response]() {
State *_state = reinterpret_cast<State *>(result);
State *state = static_cast<State *>(_state);
jsi::Function *cb = &state->cb;
jsi::Runtime *rt = reinterpret_cast<jsi::Runtime *>(state->rt);

auto out = createReturnValue(*rt, code, &response);
cb->call(*rt, out);
});
}

template <>
void callbackWithResponse(CallbackId result, ErrorCode code, int8_t response) {
invoker->invokeAsync([result, code, response]() {
Expand Down Expand Up @@ -486,6 +509,17 @@ EntryListHandle jsiToValue(jsi::Runtime &rt, jsi::Object &options,
return entryListHandle;
};

template <>
StringListHandle jsiToValue(jsi::Runtime &rt, jsi::Object &options,
const char *name, bool optional) {
std::string handle = jsiToValue<std::string>(rt, options, name, optional);
FfiStringList *ffiStringListPtr =
reinterpret_cast<FfiStringList *>(std::stol(handle));
StringListHandle stringListHandle = StringListHandle{._0 = ffiStringListPtr};

return stringListHandle;
};

template <>
LocalKeyHandle jsiToValue(jsi::Runtime &rt, jsi::Object &options,
const char *name, bool optional) {
Expand Down

0 comments on commit 9200a30

Please sign in to comment.