Skip to content

Commit

Permalink
chore: onbatchlayout callback implementation
Browse files Browse the repository at this point in the history
  • Loading branch information
azimgd committed May 21, 2024
1 parent df6ff01 commit a98fbf3
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,20 @@
namespace facebook::react {

void ShadowListContainerEventEmitter::onVisibleChange(VisibleMetrics $event) const {
dispatchEvent("visibleChange", [$event=std::move($event)](jsi::Runtime &runtime) {
dispatchEvent("visibleChange", [$event = std::move($event)](jsi::Runtime &runtime) {
auto $payload = jsi::Object(runtime);
$payload.setProperty(runtime, "start", $event.start);
$payload.setProperty(runtime, "end", $event.end);
return $payload;
});
}

void ShadowListContainerEventEmitter::onBatchLayout(BatchLayout $event) const {
dispatchEvent("batchLayout", [$event = std::move($event)](jsi::Runtime &runtime) {
auto $payload = jsi::Object(runtime);
$payload.setProperty(runtime, "size", $event.size);
return $payload;
});
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,12 @@ class ShadowListContainerEventEmitter : public ViewEventEmitter {
int end;
};

struct BatchLayout {
int size;
};

void onVisibleChange(VisibleMetrics value) const;
void onBatchLayout(BatchLayout value) const;
};

}
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,10 @@ void ShadowListContainerShadowNode::layout(LayoutContext layoutContext) {
state.scrollContentTree = scrollContentTree_;
setStateData(std::move(state));
}

getConcreteEventEmitter().onBatchLayout({
.size = static_cast<int>(scrollContentTree_.size())
});
}

/*
Expand Down
5 changes: 5 additions & 0 deletions src/ShadowListContainerNativeComponent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,11 @@ export interface NativeProps extends ViewProps {
end: Int32;
}>
>;
onBatchLayout?: DirectEventHandler<
Readonly<{
size: Int32;
}>
>;
}

export interface NativeCommands {
Expand Down

0 comments on commit a98fbf3

Please sign in to comment.