Skip to content

Migrate IntersectionObserverManager to shadow node family #51147

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ void NativeIntersectionObserver::observe(

intersectionObserverManager_.observe(
intersectionObserverId,
shadowNode,
shadowNode->getFamilyShared(),
thresholds,
rootThresholds,
uiManager);
Expand All @@ -48,7 +48,8 @@ void NativeIntersectionObserver::unobserve(
IntersectionObserverObserverId intersectionObserverId,
jsi::Object targetShadowNode) {
auto shadowNode = shadowNodeFromValue(runtime, std::move(targetShadowNode));
intersectionObserverManager_.unobserve(intersectionObserverId, *shadowNode);
intersectionObserverManager_.unobserve(
intersectionObserverId, shadowNode->getFamilyShared());
}

void NativeIntersectionObserver::connect(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,13 @@ IntersectionObserverManager::IntersectionObserverManager() = default;

void IntersectionObserverManager::observe(
IntersectionObserverObserverId intersectionObserverId,
const ShadowNode::Shared& shadowNode,
const ShadowNodeFamily::Shared& shadowNodeFamily,
std::vector<Float> thresholds,
std::optional<std::vector<Float>> rootThresholds,
const UIManager& uiManager) {
TraceSection s("IntersectionObserverManager::observe");

auto surfaceId = shadowNode->getSurfaceId();
auto shadowNodeFamily = shadowNode->getFamilyShared();
auto surfaceId = shadowNodeFamily->getSurfaceId();

// The actual observer lives in the array, so we need to create it there and
// then get a reference. Otherwise we only update its state in a copy.
Expand Down Expand Up @@ -78,15 +77,13 @@ void IntersectionObserverManager::observe(

void IntersectionObserverManager::unobserve(
IntersectionObserverObserverId intersectionObserverId,
const ShadowNode& shadowNode) {
const ShadowNodeFamily::Shared& shadowNodeFamily) {
TraceSection s("IntersectionObserverManager::unobserve");

auto& shadowNodeFamily = shadowNode.getFamily();

{
std::unique_lock lock(observersMutex_);

auto surfaceId = shadowNode.getSurfaceId();
auto surfaceId = shadowNodeFamily->getSurfaceId();

auto observersIt = observersBySurfaceId_.find(surfaceId);
if (observersIt == observersBySurfaceId_.end()) {
Expand All @@ -102,7 +99,7 @@ void IntersectionObserverManager::unobserve(
[intersectionObserverId, &shadowNodeFamily](const auto& observer) {
return observer.getIntersectionObserverId() ==
intersectionObserverId &&
observer.isTargetShadowNodeFamily(shadowNodeFamily);
observer.isTargetShadowNodeFamily(*shadowNodeFamily);
}),
observers.end());

Expand All @@ -120,7 +117,7 @@ void IntersectionObserverManager::unobserve(
pendingEntries_.end(),
[intersectionObserverId, &shadowNodeFamily](const auto& entry) {
return entry.intersectionObserverId == intersectionObserverId &&
entry.sameShadowNodeFamily(shadowNodeFamily);
entry.sameShadowNodeFamily(*shadowNodeFamily);
}),
pendingEntries_.end());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,14 @@ class IntersectionObserverManager final : public UIManagerMountHook {

void observe(
IntersectionObserverObserverId intersectionObserverId,
const ShadowNode::Shared& shadowNode,
const ShadowNodeFamily::Shared& shadowNode,
std::vector<Float> thresholds,
std::optional<std::vector<Float>> rootThresholds,
const UIManager& uiManager);

void unobserve(
IntersectionObserverObserverId intersectionObserverId,
const ShadowNode& shadowNode);
const ShadowNodeFamily::Shared& shadowNode);

void connect(
UIManager& uiManager,
Expand Down
Loading