Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add calls to flush_ui_queue for Hermes #4579

Merged
merged 1 commit into from
May 17, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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: 2 additions & 6 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 @@ -49,6 +43,8 @@ extern "C" void realm_jsi_init(fbjsi::Runtime& rt, fbjsi::Object& exports, std::
fbjsi::Function realm_constructor = js::RealmClass<realmjsi::Types>::create_constructor(env);
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
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;
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This needed to be moved to the header file so that it is visible to jsi_function.hpp, I guess this is what I missed and created some convoluted workaround for in the original!

} // namespace js
} // namespace realm

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