@stroke-stabilizer/react 0.2.14 → 0.2.16
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +13 -6
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -58,6 +58,8 @@ function DrawingCanvas() {
|
|
|
58
58
|
}
|
|
59
59
|
```
|
|
60
60
|
|
|
61
|
+
> **Important:** Always use `getCoalescedEvents()` to capture all pointer events between frames. Without it, browsers throttle events and you'll get choppy strokes.
|
|
62
|
+
|
|
61
63
|
### With rAF Batch Processing
|
|
62
64
|
|
|
63
65
|
For high-frequency input devices, use the underlying `StabilizedPointer`'s batch processing:
|
|
@@ -77,12 +79,17 @@ function DrawingCanvas() {
|
|
|
77
79
|
}, [pointer])
|
|
78
80
|
|
|
79
81
|
const handlePointerMove = (e: React.PointerEvent) => {
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
82
|
+
// IMPORTANT: Use getCoalescedEvents() for smoother input
|
|
83
|
+
const events = e.nativeEvent.getCoalescedEvents?.() ?? [e.nativeEvent]
|
|
84
|
+
|
|
85
|
+
for (const ce of events) {
|
|
86
|
+
pointer.queue({
|
|
87
|
+
x: ce.offsetX,
|
|
88
|
+
y: ce.offsetY,
|
|
89
|
+
pressure: ce.pressure,
|
|
90
|
+
timestamp: ce.timeStamp,
|
|
91
|
+
})
|
|
92
|
+
}
|
|
86
93
|
}
|
|
87
94
|
|
|
88
95
|
return <canvas onPointerMove={handlePointerMove} />
|