void EventBeatManager::beat() {
  std::lock_guard<std::mutex> lock(mutex_);

  for (const auto eventBeat : registeredEventBeats_) {
    runtimeExecutor_([=](jsi::Runtime &runtime) mutable {
      eventBeat->beat(runtime);
    });
  }
}
Example #2
0
void Scheduler::stopSurface(SurfaceId surfaceId) const {
  std::lock_guard<std::mutex> lock(mutex_);
  const auto &iterator = shadowTreeRegistry_.find(surfaceId);
  auto &shadowTree = *iterator->second;
  // As part of stopping the Surface, we have to commit an empty tree.
  shadowTree.complete(std::const_pointer_cast<SharedShadowNodeList>(
      ShadowNode::emptySharedShadowNodeSharedList()));
  shadowTree.setDelegate(nullptr);
  shadowTreeRegistry_.erase(iterator);

#ifndef ANDROID
  runtimeExecutor_([=](jsi::Runtime &runtime) {
    uiManagerBinding_->stopSurface(runtime, surfaceId);
  });
#endif
}
Example #3
0
void Scheduler::startSurface(
    SurfaceId surfaceId,
    const std::string &moduleName,
    const folly::dynamic &initialProps,
    const LayoutConstraints &layoutConstraints,
    const LayoutContext &layoutContext) const {
  std::lock_guard<std::mutex> lock(mutex_);

  auto shadowTree =
      std::make_unique<ShadowTree>(surfaceId, layoutConstraints, layoutContext);
  shadowTree->setDelegate(this);
  shadowTreeRegistry_.emplace(surfaceId, std::move(shadowTree));

#ifndef ANDROID
  runtimeExecutor_([=](jsi::Runtime &runtime) {
    uiManagerBinding_->startSurface(
        runtime, surfaceId, moduleName, initialProps);
  });
#endif
}
Example #4
0
Scheduler::Scheduler(const SharedContextContainer &contextContainer)
    : contextContainer_(contextContainer) {
  const auto asynchronousEventBeatFactory =
      contextContainer->getInstance<EventBeatFactory>("asynchronous");
  const auto synchronousEventBeatFactory =
      contextContainer->getInstance<EventBeatFactory>("synchronous");

  runtimeExecutor_ =
      contextContainer->getInstance<RuntimeExecutor>("runtime-executor");

  auto uiManager = std::make_unique<UIManager>();
  auto &uiManagerRef = *uiManager;
  uiManagerBinding_ =
      std::make_shared<UIManagerBinding>(std::move(uiManager));

  auto eventPipe = [uiManagerBinding = uiManagerBinding_.get()](
                       jsi::Runtime &runtime,
                       const EventTarget *eventTarget,
                       const std::string &type,
                       const folly::dynamic &payload) {
    uiManagerBinding->dispatchEvent(runtime, eventTarget, type, payload);
  };

  auto eventDispatcher = std::make_shared<EventDispatcher>(
      eventPipe, synchronousEventBeatFactory, asynchronousEventBeatFactory);

  componentDescriptorRegistry_ = ComponentDescriptorFactory::buildRegistry(
      eventDispatcher, contextContainer);

  uiManagerRef.setDelegate(this);
  uiManagerRef.setComponentDescriptorRegistry(componentDescriptorRegistry_);

  runtimeExecutor_([=](jsi::Runtime &runtime) {
    UIManagerBinding::install(runtime, uiManagerBinding_);
  });
}