@@ -76,7 +76,7 @@ const RCTSliderWebComponent = React.forwardRef(
76
76
const containerSize = React . useRef ( { width : 0 , height : 0 } ) ;
77
77
const containerPositionX = React . useRef ( 0 ) ;
78
78
const containerRef = forwardedRef || React . createRef ( ) ;
79
- const hasBeenResized = React . useRef ( false ) ;
79
+ const containerPositionInvalidated = React . useRef ( false ) ;
80
80
const [ value , setValue ] = React . useState ( initialValue || minimumValue ) ;
81
81
const lastInitialValue = React . useRef < number > ( ) ;
82
82
const animationValues = React . useRef < AnimationValues > ( {
@@ -166,18 +166,36 @@ const RCTSliderWebComponent = React.forwardRef(
166
166
}
167
167
} , [ initialValue , updateValue , animationValues ] ) ;
168
168
169
- const onResize = ( ) => {
170
- hasBeenResized . current = true ;
171
- } ;
172
169
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
+ } ;
173
184
//@ts -ignore
174
- window . addEventListener ( 'resize' , onResize ) ;
185
+ window . addEventListener ( 'resize' , invalidateContainerPosition ) ;
186
+ //@ts -ignore
187
+ document . addEventListener ( 'scroll' , onDocumentScroll , { capture : true } ) ;
175
188
176
189
return ( ) => {
177
190
//@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
+ } ) ;
179
197
} ;
180
- } , [ ] ) ;
198
+ } , [ containerRef ] ) ;
181
199
182
200
const containerStyle = StyleSheet . compose (
183
201
{
@@ -242,8 +260,8 @@ const RCTSliderWebComponent = React.forwardRef(
242
260
const getValueFromNativeEvent = ( pageX : number ) => {
243
261
const { width = 1 } = containerSize . current ;
244
262
245
- if ( hasBeenResized . current ) {
246
- hasBeenResized . current = false ;
263
+ if ( containerPositionInvalidated . current ) {
264
+ containerPositionInvalidated . current = false ;
247
265
updateContainerPositionX ( ) ;
248
266
}
249
267
const containerX = containerPositionX . current ;
0 commit comments