From f079360fbcb8a3730fb4cacfd36ea48660b3faad Mon Sep 17 00:00:00 2001 From: Renan Mav Date: Mon, 18 Aug 2025 18:16:48 +0000 Subject: [PATCH 1/2] fix: measureInWindow on web platform --- src/Shimmer.tsx | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/Shimmer.tsx b/src/Shimmer.tsx index 7327f7a..6099d20 100644 --- a/src/Shimmer.tsx +++ b/src/Shimmer.tsx @@ -5,6 +5,7 @@ import { type ViewStyle, Dimensions, type LayoutChangeEvent, + Platform, } from 'react-native'; import Animated, { Easing, @@ -51,7 +52,11 @@ export const Shimmer = ({ const measure = useCallback( (event: LayoutChangeEvent) => { if (componentWidth === 0) { - event.target.measureInWindow((x, _y, width) => { + const measureInWindowFn = + Platform.OS === 'web' + ? event.nativeEvent.target.measureInWindow + : event.target.measureInWindow; + measureInWindowFn((x, _y, width) => { setComponentWidth(width); setOffset(x); }); From 36455a6b925aac109434b2053086f65d0d49c916 Mon Sep 17 00:00:00 2001 From: Renan Mav Date: Mon, 1 Sep 2025 11:22:17 +0000 Subject: [PATCH 2/2] fix: simplify measureInWindow logic for Shimmer component --- src/Shimmer.tsx | 12 +++--------- 1 file changed, 3 insertions(+), 9 deletions(-) diff --git a/src/Shimmer.tsx b/src/Shimmer.tsx index 6099d20..0232b1e 100644 --- a/src/Shimmer.tsx +++ b/src/Shimmer.tsx @@ -5,7 +5,6 @@ import { type ViewStyle, Dimensions, type LayoutChangeEvent, - Platform, } from 'react-native'; import Animated, { Easing, @@ -52,14 +51,9 @@ export const Shimmer = ({ const measure = useCallback( (event: LayoutChangeEvent) => { if (componentWidth === 0) { - const measureInWindowFn = - Platform.OS === 'web' - ? event.nativeEvent.target.measureInWindow - : event.target.measureInWindow; - measureInWindowFn((x, _y, width) => { - setComponentWidth(width); - setOffset(x); - }); + const { width, x } = event.nativeEvent.layout; + setComponentWidth(width); + setOffset(x); } }, [componentWidth]