JSINativeModules.h 972 B

12345678910111213141516171819202122232425262728293031323334353637383940
  1. /*
  2. * Copyright (c) Facebook, Inc. and its affiliates.
  3. *
  4. * This source code is licensed under the MIT license found in the
  5. * LICENSE file in the root directory of this source tree.
  6. */
  7. #pragma once
  8. #include <memory>
  9. #include <string>
  10. #include <cxxreact/ModuleRegistry.h>
  11. #include <folly/Optional.h>
  12. #include <jsi/jsi.h>
  13. namespace facebook {
  14. namespace react {
  15. /**
  16. * Holds and creates JS representations of the modules in ModuleRegistry
  17. */
  18. class JSINativeModules {
  19. public:
  20. explicit JSINativeModules(std::shared_ptr<ModuleRegistry> moduleRegistry);
  21. jsi::Value getModule(jsi::Runtime &rt, const jsi::PropNameID &name);
  22. void reset();
  23. private:
  24. folly::Optional<jsi::Function> m_genNativeModuleJS;
  25. std::shared_ptr<ModuleRegistry> m_moduleRegistry;
  26. std::unordered_map<std::string, jsi::Object> m_objects;
  27. folly::Optional<jsi::Object> createModule(
  28. jsi::Runtime &rt,
  29. const std::string &name);
  30. };
  31. } // namespace react
  32. } // namespace facebook