Skip to content

Commit

Permalink
Add calls to flush_ui_queue for Hermes
Browse files Browse the repository at this point in the history
  • Loading branch information
Tom Duncalf committed May 17, 2022
1 parent 612095d commit 34c6d0e
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 12 deletions.
20 changes: 15 additions & 5 deletions src/jsi/jsi_function.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,33 +26,43 @@ namespace js {
template <>
inline JsiVal realmjsi::Function::call(JsiEnv env, const JsiFunc& function, size_t argc, const JsiVal arguments[])
{
return env(function->call(env, env.args(arguments, argc), argc));
auto result = env(function->call(env, env.args(arguments, argc), argc));
flush_ui_queue();
return result;
}

template <>
inline JsiVal realmjsi::Function::call(JsiEnv env, const JsiFunc& function, const JsiObj& this_object, size_t argc,
const JsiVal arguments[])
{
return env(function->callWithThis(env, this_object, env.args(arguments, argc), argc));
auto result = env(function->callWithThis(env, this_object, env.args(arguments, argc), argc));
flush_ui_queue();
return result;
}

template <>
inline JsiVal realmjsi::Function::callback(JsiEnv env, const JsiFunc& function, size_t argc, const JsiVal arguments[])
{
return env(function->call(env, env.args(arguments, argc), argc));
auto result = env(function->call(env, env.args(arguments, argc), argc));
flush_ui_queue();
return result;
}
template <>
inline JsiVal realmjsi::Function::callback(JsiEnv env, const JsiFunc& function, const JsiObj& this_object,
size_t argc, const JsiVal arguments[])
{
return env(function->callWithThis(env, this_object, env.args(arguments, argc), argc));
auto result = env(function->callWithThis(env, this_object, env.args(arguments, argc), argc));
flush_ui_queue();
return result;
}

template <>
inline JsiObj realmjsi::Function::construct(JsiEnv env, const JsiFunc& function, size_t argc,
const JsiVal arguments[])
{
return env(function->callAsConstructor(env, env.args(arguments, argc), argc).asObject(env));
auto result = env(function->callAsConstructor(env, env.args(arguments, argc), argc).asObject(env));
flush_ui_queue();
return result;
}

} // namespace js
Expand Down
8 changes: 1 addition & 7 deletions src/jsi/jsi_init.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,6 @@

#include "jsi_init.hpp"

namespace realm {
namespace js {
std::function<void()> flush_ui_queue;
} // namespace js
} // namespace realm

#if !REALM_ENABLE_SYNC
#pragma comment(lib, "ws2_32.lib")
#pragma comment(lib, "crypt32")
Expand All @@ -47,7 +41,7 @@ extern "C" void realm_jsi_init(fbjsi::Runtime& rt, fbjsi::Object& exports, std::
auto name = realm_constructor.getProperty(env, "name").asString(env);
exports.setProperty(env, std::move(name), std::move(realm_constructor));
// Store the function used to flush React Native microtask queue
js::flush_ui_queue = flush_ui_queue;
realm::js::flush_ui_queue = flush_ui_queue;
}

extern "C" void realm_jsi_invalidate_caches()
Expand Down
8 changes: 8 additions & 0 deletions src/jsi/jsi_init.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,14 @@

#pragma once

#include <functional>

namespace realm {
namespace js {
std::function<void()> flush_ui_queue;
} // namespace js
} // namespace realm

#include "jsi_string.hpp"
#include "jsi_protected.hpp"
#include "jsi_function.hpp"
Expand Down

0 comments on commit 34c6d0e

Please sign in to comment.