mirror of
https://github.com/zhigang1992/react-native.git
synced 2026-04-27 19:25:11 +08:00
Summary: When calling into JS (e.g. promise resolve/reject, callback) in TurboModule, we bypass the bridge's message queue. At times this causes race condition, where there are a bunch of pending UI operations (in RCTUImanager) waiting to be flushed, but nothing adds calls to the message queue. Usually tapping the screen will trigger the flush because we're sending down touch events to JS. Reviewed By: JoshuaGross Differential Revision: D14656466 fbshipit-source-id: cb3a174e97542bf80f0a37b4170b6a8e6780fa35
96 lines
3.2 KiB
C++
96 lines
3.2 KiB
C++
// Copyright (c) Facebook, Inc. and its affiliates.
|
|
|
|
// This source code is licensed under the MIT license found in the
|
|
// LICENSE file in the root directory of this source tree.
|
|
|
|
#pragma once
|
|
|
|
#include <condition_variable>
|
|
#include <memory>
|
|
|
|
#include <cxxreact/NativeToJsBridge.h>
|
|
|
|
#ifndef RN_EXPORT
|
|
#define RN_EXPORT __attribute__((visibility("default")))
|
|
#endif
|
|
|
|
namespace folly {
|
|
struct dynamic;
|
|
}
|
|
|
|
namespace facebook {
|
|
namespace react {
|
|
|
|
class JSBigString;
|
|
class JSExecutorFactory;
|
|
class MessageQueueThread;
|
|
class ModuleRegistry;
|
|
class RAMBundleRegistry;
|
|
|
|
struct InstanceCallback {
|
|
virtual ~InstanceCallback() {}
|
|
virtual void onBatchComplete() {}
|
|
virtual void incrementPendingJSCalls() {}
|
|
virtual void decrementPendingJSCalls() {}
|
|
};
|
|
|
|
class RN_EXPORT Instance {
|
|
public:
|
|
~Instance();
|
|
void initializeBridge(std::unique_ptr<InstanceCallback> callback,
|
|
std::shared_ptr<JSExecutorFactory> jsef,
|
|
std::shared_ptr<MessageQueueThread> jsQueue,
|
|
std::shared_ptr<ModuleRegistry> moduleRegistry);
|
|
|
|
void setSourceURL(std::string sourceURL);
|
|
|
|
void loadScriptFromString(std::unique_ptr<const JSBigString> string,
|
|
std::string sourceURL, bool loadSynchronously);
|
|
static bool isIndexedRAMBundle(const char *sourcePath);
|
|
void loadRAMBundleFromFile(const std::string& sourcePath,
|
|
const std::string& sourceURL,
|
|
bool loadSynchronously);
|
|
void loadRAMBundle(std::unique_ptr<RAMBundleRegistry> bundleRegistry,
|
|
std::unique_ptr<const JSBigString> startupScript,
|
|
std::string startupScriptSourceURL, bool loadSynchronously);
|
|
bool supportsProfiling();
|
|
void setGlobalVariable(std::string propName,
|
|
std::unique_ptr<const JSBigString> jsonValue);
|
|
void *getJavaScriptContext();
|
|
bool isInspectable();
|
|
bool isBatchActive();
|
|
void callJSFunction(std::string &&module, std::string &&method,
|
|
folly::dynamic &¶ms);
|
|
void callJSCallback(uint64_t callbackId, folly::dynamic &¶ms);
|
|
|
|
// This method is experimental, and may be modified or removed.
|
|
void registerBundle(uint32_t bundleId, const std::string& bundlePath);
|
|
|
|
const ModuleRegistry &getModuleRegistry() const;
|
|
ModuleRegistry &getModuleRegistry();
|
|
|
|
void handleMemoryPressure(int pressureLevel);
|
|
|
|
void invokeAsync(std::function<void()>&& func);
|
|
|
|
private:
|
|
void callNativeModules(folly::dynamic &&calls, bool isEndOfBatch);
|
|
void loadApplication(std::unique_ptr<RAMBundleRegistry> bundleRegistry,
|
|
std::unique_ptr<const JSBigString> startupScript,
|
|
std::string startupScriptSourceURL);
|
|
void loadApplicationSync(std::unique_ptr<RAMBundleRegistry> bundleRegistry,
|
|
std::unique_ptr<const JSBigString> startupScript,
|
|
std::string startupScriptSourceURL);
|
|
|
|
std::shared_ptr<InstanceCallback> callback_;
|
|
std::unique_ptr<NativeToJsBridge> nativeToJsBridge_;
|
|
std::shared_ptr<ModuleRegistry> moduleRegistry_;
|
|
|
|
std::mutex m_syncMutex;
|
|
std::condition_variable m_syncCV;
|
|
bool m_syncReady = false;
|
|
};
|
|
|
|
} // namespace react
|
|
} // namespace facebook
|