PHP 7.4.33
Preview: ModuleRegistry.h Size: 2.70 KB
/var/www/uibuilder.cmshelp.dk/httpdocs/node_modules/react-native/ReactCommon/cxxreact/ModuleRegistry.h
/*
 * Copyright (c) Meta Platforms, Inc. and 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 <memory>
#include <unordered_set>
#include <vector>

#include <cxxreact/JSExecutor.h>
#include <folly/dynamic.h>
#include <optional>

#ifndef RN_EXPORT
#define RN_EXPORT __attribute__((visibility("default")))
#endif

namespace facebook::react {

class NativeModule;

struct ModuleConfig {
  size_t index;
  folly::dynamic config;
};

class RN_EXPORT ModuleRegistry {
 public:
  // not implemented:
  // onBatchComplete: see
  // https://our.intern.facebook.com/intern/tasks/?t=5279396 getModule: only
  // used by views getAllModules: only used for cleanup; use RAII instead
  // notifyCatalystInstanceInitialized: this is really only used by view-related
  // code notifyCatalystInstanceDestroy: use RAII instead

  using ModuleNotFoundCallback = std::function<bool(const std::string& name)>;

  ModuleRegistry(
      std::vector<std::unique_ptr<NativeModule>> modules,
      ModuleNotFoundCallback callback = nullptr);
  void registerModules(std::vector<std::unique_ptr<NativeModule>> modules);

  std::vector<std::string> moduleNames();

  std::optional<ModuleConfig> getConfig(const std::string& name);

  void callNativeMethod(
      unsigned int moduleId,
      unsigned int methodId,
      folly::dynamic&& params,
      int callId);
  MethodCallResult callSerializableNativeHook(
      unsigned int moduleId,
      unsigned int methodId,
      folly::dynamic&& args);

  std::string getModuleName(unsigned int moduleId);
  std::string getModuleSyncMethodName(
      unsigned int moduleId,
      unsigned int methodName);

 private:
  // This is always populated
  std::vector<std::unique_ptr<NativeModule>> modules_;

  // This is used to extend the population of modulesByName_ if registerModules
  // is called after moduleNames
  void updateModuleNamesFromIndex(size_t size);

  // This is only populated if moduleNames() is called.  Values are indices into
  // modules_.
  std::unordered_map<std::string, size_t> modulesByName_;

  // This is populated with modules that are requested via getConfig but are
  // unknown. An error will be thrown if they are subsequently added to the
  // registry.
  std::unordered_set<std::string> unknownModules_;

  // Function will be called if a module was requested but was not found.
  // If the function returns true, ModuleRegistry will try to find the module
  // again (assuming it's registered) If the function returns false,
  // ModuleRegistry will not try to find the module and return nullptr instead.
  ModuleNotFoundCallback moduleNotFoundCallback_;
};

} // namespace facebook::react

Directory Contents

Dirs: 1 × Files: 40
Name Size Perms Modified Actions
tests DIR
- drwxr-xr-x 2025-03-28 11:04:39
Edit Download
801 B lrw-r--r-- 2025-03-28 11:04:43
Edit Download
7.28 KB lrw-r--r-- 2025-03-28 11:04:41
Edit Download
7.83 KB lrw-r--r-- 2025-03-28 11:04:39
Edit Download
1.90 KB lrw-r--r-- 2025-03-28 11:04:41
Edit Download
1.42 KB lrw-r--r-- 2025-03-28 11:04:41
Edit Download
12.30 KB lrw-r--r-- 2025-03-28 11:04:39
Edit Download
6.16 KB lrw-r--r-- 2025-03-28 11:04:41
Edit Download
2.98 KB lrw-r--r-- 2025-03-28 11:04:41
Edit Download
4.39 KB lrw-r--r-- 2025-03-28 11:04:41
Edit Download
3.18 KB lrw-r--r-- 2025-03-28 11:04:39
Edit Download
3.22 KB lrw-r--r-- 2025-03-28 11:04:41
Edit Download
1018 B lrw-r--r-- 2025-03-28 11:04:39
Edit Download
1.75 KB lrw-r--r-- 2025-03-28 11:04:41
Edit Download
1006 B lrw-r--r-- 2025-03-28 11:04:39
Edit Download
4.40 KB lrw-r--r-- 2025-03-28 11:04:41
Edit Download
4.01 KB lrw-r--r-- 2025-03-28 11:04:39
Edit Download
1.91 KB lrw-r--r-- 2025-03-28 11:04:41
Edit Download
1.15 KB lrw-r--r-- 2025-03-28 11:04:41
Edit Download
760 B lrw-r--r-- 2025-03-28 11:04:41
Edit Download
2.42 KB lrw-r--r-- 2025-03-28 11:04:39
Edit Download
715 B lrw-r--r-- 2025-03-28 11:04:41
Edit Download
7.53 KB lrw-r--r-- 2025-03-28 11:04:39
Edit Download
2.70 KB lrw-r--r-- 2025-03-28 11:04:41
Edit Download
4.33 KB lrw-r--r-- 2025-03-28 11:04:41
Edit Download
1.09 KB lrw-r--r-- 2025-03-28 11:04:41
Edit Download
11.58 KB lrw-r--r-- 2025-03-28 11:04:39
Edit Download
4.14 KB lrw-r--r-- 2025-03-28 11:04:41
Edit Download
552 B lrw-r--r-- 2025-03-28 11:04:43
Edit Download
2.37 KB lrw-r--r-- 2025-03-28 11:04:39
Edit Download
1.63 KB lrw-r--r-- 2025-03-28 11:04:41
Edit Download
2.64 KB lrw-r--r-- 2025-03-28 11:04:43
Edit Download
3.50 KB lrw-r--r-- 2025-03-28 11:04:39
Edit Download
3.14 KB lrw-r--r-- 2025-03-28 11:04:41
Edit Download
503 B lrw-r--r-- 2025-03-28 11:04:41
Edit Download
1.09 KB lrw-r--r-- 2025-03-28 11:04:41
Edit Download
4.67 KB lrw-r--r-- 2025-03-28 11:04:39
Edit Download
1.38 KB lrw-r--r-- 2025-03-28 11:04:41
Edit Download
1.07 KB lrw-r--r-- 2025-03-28 11:04:41
Edit Download
789 B lrw-r--r-- 2025-03-28 11:04:41
Edit Download
5.11 KB lrw-r--r-- 2025-03-28 11:04:41
Edit Download
If ZipArchive is unavailable, a .tar will be created (no compression).