From a2af02762151b5bb720bf608cf479c1c3b8418b5 Mon Sep 17 00:00:00 2001 From: Tom Duncalf Date: Tue, 17 May 2022 11:41:18 +0100 Subject: [PATCH] Add calls to flush_ui_queue for Hermes --- src/jsi/jsi_function.hpp | 20 +++++++++++++++----- src/jsi/jsi_init.cpp | 8 ++------ src/jsi/jsi_init.hpp | 8 ++++++++ 3 files changed, 25 insertions(+), 11 deletions(-) diff --git a/src/jsi/jsi_function.hpp b/src/jsi/jsi_function.hpp index cccbc4ad55..484a321b64 100644 --- a/src/jsi/jsi_function.hpp +++ b/src/jsi/jsi_function.hpp @@ -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 diff --git a/src/jsi/jsi_init.cpp b/src/jsi/jsi_init.cpp index 14fcf96dc8..a5cee1a6d1 100644 --- a/src/jsi/jsi_init.cpp +++ b/src/jsi/jsi_init.cpp @@ -19,12 +19,6 @@ #include "jsi_init.hpp" -namespace realm { -namespace js { -std::function flush_ui_queue; -} // namespace js -} // namespace realm - #if !REALM_ENABLE_SYNC #pragma comment(lib, "ws2_32.lib") #pragma comment(lib, "crypt32") @@ -49,6 +43,8 @@ extern "C" void realm_jsi_init(fbjsi::Runtime& rt, fbjsi::Object& exports, std:: fbjsi::Function realm_constructor = js::RealmClass::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() diff --git a/src/jsi/jsi_init.hpp b/src/jsi/jsi_init.hpp index 28e787359d..5ef4dc7efd 100644 --- a/src/jsi/jsi_init.hpp +++ b/src/jsi/jsi_init.hpp @@ -18,6 +18,14 @@ #pragma once +#include + +namespace realm { +namespace js { +std::function flush_ui_queue; +} // namespace js +} // namespace realm + #include "jsi_string.hpp" #include "jsi_protected.hpp" #include "jsi_function.hpp"