Coordinate update event when litho scrolls or is shifted
Summary: See doc comment for explanation Reviewed By: lblasa Differential Revision: D40587610 fbshipit-source-id: f0909440c4e6e3cc9f5c7b557198a93ba8809bd9
This commit is contained in:
committed by
Facebook GitHub Bot
parent
a447712865
commit
b1bee28f08
@@ -24,6 +24,18 @@ export function plugin(client: PluginClient<Events>) {
|
||||
|
||||
const nodesAtom = createState<Map<Id, UINode>>(new Map());
|
||||
const snapshotsAtom = createState<Map<Id, Snapshot>>(new Map());
|
||||
|
||||
client.onMessage('coordinateUpdate', (event) => {
|
||||
nodesAtom.update((draft) => {
|
||||
const node = draft.get(event.nodeId);
|
||||
if (!node) {
|
||||
console.warn(`Coordinate update for non existing node `, event);
|
||||
} else {
|
||||
node.bounds.x = event.coordinate.x;
|
||||
node.bounds.y = event.coordinate.y;
|
||||
}
|
||||
});
|
||||
});
|
||||
client.onMessage('subtreeUpdate', (event) => {
|
||||
snapshotsAtom.update((draft) => {
|
||||
draft.set(event.rootId, event.snapshot);
|
||||
|
||||
@@ -10,9 +10,16 @@
|
||||
export type Events = {
|
||||
init: InitEvent;
|
||||
subtreeUpdate: SubtreeUpdateEvent;
|
||||
coordinateUpdate: CoordinateUpdateEvent;
|
||||
perfStats: PerfStatsEvent;
|
||||
};
|
||||
|
||||
export type CoordinateUpdateEvent = {
|
||||
observerType: String;
|
||||
nodeId: Id;
|
||||
coordinate: Coordinate;
|
||||
};
|
||||
|
||||
export type SubtreeUpdateEvent = {
|
||||
txId: number;
|
||||
rootId: Id;
|
||||
@@ -39,7 +46,7 @@ export type UINode = {
|
||||
name: string;
|
||||
attributes: Record<string, Inspectable>;
|
||||
children: Id[];
|
||||
bounds?: Bounds;
|
||||
bounds: Bounds;
|
||||
tags: Tag[];
|
||||
activeChild?: Id;
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user