@@ -69,7 +69,7 @@ const RCTSliderWebComponent = React.forwardRef(
69
69
const containerSize = React . useRef ( { width : 0 , height : 0 } ) ;
70
70
const containerPositionX = React . useRef ( 0 ) ;
71
71
const containerRef = forwardedRef || React . createRef ( ) ;
72
- const hasBeenResized = React . useRef ( false ) ;
72
+ const containerPositionInvalidated = React . useRef ( false ) ;
73
73
const [ value , setValue ] = React . useState ( initialValue || minimumValue ) ;
74
74
const lastInitialValue = React . useRef < number > ( ) ;
75
75
@@ -145,18 +145,36 @@ const RCTSliderWebComponent = React.forwardRef(
145
145
}
146
146
} , [ initialValue , updateValue , animatedValue ] ) ;
147
147
148
- const onResize = ( ) => {
149
- hasBeenResized . current = true ;
150
- } ;
151
148
React . useEffect ( ( ) => {
149
+ const invalidateContainerPosition = ( ) => {
150
+ containerPositionInvalidated . current = true ;
151
+ } ;
152
+ const onDocumentScroll = ( e : Event ) => {
153
+ if (
154
+ // Avoid all other checks if already invalidated
155
+ ! containerPositionInvalidated . current &&
156
+ containerRef . current &&
157
+ // @ts -ignore
158
+ e . target . contains ( containerRef . current )
159
+ ) {
160
+ invalidateContainerPosition ( ) ;
161
+ }
162
+ } ;
152
163
//@ts -ignore
153
- window . addEventListener ( 'resize' , onResize ) ;
164
+ window . addEventListener ( 'resize' , invalidateContainerPosition ) ;
165
+ //@ts -ignore
166
+ document . addEventListener ( 'scroll' , onDocumentScroll , { capture : true } ) ;
154
167
155
168
return ( ) => {
156
169
//@ts -ignore
157
- window . removeEventListener ( 'resize' , onResize ) ;
170
+ window . removeEventListener ( 'resize' , invalidateContainerPosition ) ;
171
+
172
+ //@ts -ignore
173
+ document . removeEventListener ( 'scroll' , onDocumentScroll , {
174
+ capture : true ,
175
+ } ) ;
158
176
} ;
159
- } , [ ] ) ;
177
+ } , [ containerRef ] ) ;
160
178
161
179
const containerStyle = StyleSheet . compose (
162
180
{
@@ -221,8 +239,8 @@ const RCTSliderWebComponent = React.forwardRef(
221
239
const getValueFromNativeEvent = ( pageX : number ) => {
222
240
const { width = 1 } = containerSize . current ;
223
241
224
- if ( hasBeenResized . current ) {
225
- hasBeenResized . current = false ;
242
+ if ( containerPositionInvalidated . current ) {
243
+ containerPositionInvalidated . current = false ;
226
244
updateContainerPositionX ( ) ;
227
245
}
228
246
const containerX = containerPositionX . current ;
0 commit comments