|
3 | 3 | #if __has_include(<jsi/jsi.h>)
|
4 | 4 | #include <jsi/jsi.h>
|
5 | 5 |
|
| 6 | +using facebook::jsi::Array; |
6 | 7 | using facebook::jsi::Runtime;
|
7 | 8 | using facebook::jsi::String;
|
8 | 9 |
|
9 |
| -std::vector<std::string> ReactTestApp::GetAppKeys(Runtime &runtime) |
| 10 | +namespace |
10 | 11 | {
|
11 |
| - std::vector<std::string> result; |
12 |
| - |
13 | 12 | constexpr char kFbBatchedBridgeId[] = "__fbBatchedBridge";
|
| 13 | + constexpr char kRNAppRegistryId[] = "RN$AppRegistry"; |
| 14 | + |
| 15 | + Array GetRegisteredAppKeys(Runtime &runtime) |
| 16 | + { |
| 17 | + auto global = runtime.global(); |
| 18 | + if (global.hasProperty(runtime, kRNAppRegistryId)) { // >= 0.73 |
| 19 | + // const appKeys = RN$AppRegistry.getAppKeys(); |
| 20 | + auto registry = global.getProperty(runtime, kRNAppRegistryId); |
| 21 | + if (registry.isObject()) { |
| 22 | + auto getAppKeys = std::move(registry).asObject(runtime).getPropertyAsFunction( |
| 23 | + runtime, "getAppKeys"); |
| 24 | + return getAppKeys.call(runtime, nullptr, 0).asObject(runtime).asArray(runtime); |
| 25 | + } |
| 26 | + } else if (global.hasProperty(runtime, kFbBatchedBridgeId)) { // < 0.73 |
| 27 | + // const appRegistry = __fbBatchedBridge.getCallableModule("AppRegistry"); |
| 28 | + auto fbBatchedBridge = global.getPropertyAsObject(runtime, kFbBatchedBridgeId); |
| 29 | + auto getCallableModule = |
| 30 | + fbBatchedBridge.getPropertyAsFunction(runtime, "getCallableModule"); |
| 31 | + auto appRegistry = |
| 32 | + getCallableModule.callWithThis(runtime, fbBatchedBridge, "AppRegistry") |
| 33 | + .asObject(runtime); |
| 34 | + |
| 35 | + // const appKeys = appRegistry.getAppKeys(); |
| 36 | + auto getAppKeys = appRegistry.getPropertyAsFunction(runtime, "getAppKeys"); |
| 37 | + return getAppKeys.callWithThis(runtime, appRegistry).asObject(runtime).asArray(runtime); |
| 38 | + } |
14 | 39 |
|
15 |
| - auto global = runtime.global(); |
16 |
| - if (!global.hasProperty(runtime, kFbBatchedBridgeId)) { |
17 |
| - return result; |
| 40 | + return Array(runtime, 0); |
18 | 41 | }
|
| 42 | +} // namespace |
19 | 43 |
|
20 |
| - try { |
21 |
| - // const appRegistry = __fbBatchedBridge.getCallableModule("AppRegistry"); |
22 |
| - auto fbBatchedBridge = global.getPropertyAsObject(runtime, kFbBatchedBridgeId); |
23 |
| - auto getCallableModule = |
24 |
| - fbBatchedBridge.getPropertyAsFunction(runtime, "getCallableModule"); |
25 |
| - auto appRegistry = getCallableModule.callWithThis(runtime, fbBatchedBridge, "AppRegistry") |
26 |
| - .asObject(runtime); |
27 |
| - |
28 |
| - // const appKeys = appRegistry.getAppKeys(); |
29 |
| - auto getAppKeys = appRegistry.getPropertyAsFunction(runtime, "getAppKeys"); |
30 |
| - auto appKeys = |
31 |
| - getAppKeys.callWithThis(runtime, appRegistry).asObject(runtime).asArray(runtime); |
| 44 | +std::vector<std::string> ReactTestApp::GetAppKeys(Runtime &runtime) |
| 45 | +{ |
| 46 | + std::vector<std::string> result; |
32 | 47 |
|
| 48 | + try { |
| 49 | + auto appKeys = GetRegisteredAppKeys(runtime); |
33 | 50 | auto length = appKeys.length(runtime);
|
34 | 51 | result.reserve(length);
|
35 | 52 |
|
|
0 commit comments