@@ -76,7 +76,7 @@ const RCTSliderWebComponent = React.forwardRef(
7676 const containerSize = React . useRef ( { width : 0 , height : 0 } ) ;
7777 const containerPositionX = React . useRef ( 0 ) ;
7878 const containerRef = forwardedRef || React . createRef ( ) ;
79- const hasBeenResized = React . useRef ( false ) ;
79+ const containerPositionInvalidated = React . useRef ( false ) ;
8080 const [ value , setValue ] = React . useState ( initialValue || minimumValue ) ;
8181 const lastInitialValue = React . useRef < number > ( ) ;
8282 const animationValues = React . useRef < AnimationValues > ( {
@@ -166,18 +166,36 @@ const RCTSliderWebComponent = React.forwardRef(
166166 }
167167 } , [ initialValue , updateValue , animationValues ] ) ;
168168
169- const onResize = ( ) => {
170- hasBeenResized . current = true ;
171- } ;
172169 React . useEffect ( ( ) => {
170+ const invalidateContainerPosition = ( ) => {
171+ containerPositionInvalidated . current = true ;
172+ } ;
173+ const onDocumentScroll = ( e : Event ) => {
174+ const isAlreadyInvalidated = ! containerPositionInvalidated . current ;
175+ if (
176+ isAlreadyInvalidated &&
177+ containerRef . current &&
178+ // @ts -ignore
179+ e . target . contains ( containerRef . current )
180+ ) {
181+ invalidateContainerPosition ( ) ;
182+ }
183+ } ;
173184 //@ts -ignore
174- window . addEventListener ( 'resize' , onResize ) ;
185+ window . addEventListener ( 'resize' , invalidateContainerPosition ) ;
186+ //@ts -ignore
187+ document . addEventListener ( 'scroll' , onDocumentScroll , { capture : true } ) ;
175188
176189 return ( ) => {
177190 //@ts -ignore
178- window . removeEventListener ( 'resize' , onResize ) ;
191+ window . removeEventListener ( 'resize' , invalidateContainerPosition ) ;
192+
193+ //@ts -ignore
194+ document . removeEventListener ( 'scroll' , onDocumentScroll , {
195+ capture : true ,
196+ } ) ;
179197 } ;
180- } , [ ] ) ;
198+ } , [ containerRef ] ) ;
181199
182200 const containerStyle = StyleSheet . compose (
183201 {
@@ -242,8 +260,8 @@ const RCTSliderWebComponent = React.forwardRef(
242260 const getValueFromNativeEvent = ( pageX : number ) => {
243261 const { width = 1 } = containerSize . current ;
244262
245- if ( hasBeenResized . current ) {
246- hasBeenResized . current = false ;
263+ if ( containerPositionInvalidated . current ) {
264+ containerPositionInvalidated . current = false ;
247265 updateContainerPositionX ( ) ;
248266 }
249267 const containerX = containerPositionX . current ;
0 commit comments