@@ -5,20 +5,14 @@ import { EventBuilder } from '../event-builder';
55import { ErrorWithStack } from '../../helpers/errors' ;
66import { isHostScrollView } from '../../helpers/host-component-names' ;
77import { pick } from '../../helpers/object' ;
8- import { ContentOffset } from '../event-builder/scroll-view' ;
8+ import { nativeState } from '../../native-state' ;
9+ import { Point , Size } from '../../types' ;
910import { dispatchEvent , wait } from '../utils' ;
1011import { createScrollSteps , inertialInterpolator , linearInterpolator } from './utils' ;
11- import { getElementScrollOffset , setElementScrollOffset } from './state' ;
1212
1313interface CommonScrollToOptions {
14- contentSize ?: {
15- height : number ;
16- width : number ;
17- } ;
18- layoutMeasurement ?: {
19- height : number ;
20- width : number ;
21- } ;
14+ contentSize ?: Size ;
15+ layoutMeasurement ?: Size ;
2216}
2317
2418export interface VerticalScrollToOptions extends CommonScrollToOptions {
@@ -62,7 +56,7 @@ export async function scrollTo(
6256 options . contentSize ?. height ?? 0 ,
6357 ) ;
6458
65- const initialPosition = getElementScrollOffset ( element ) ;
59+ const initialPosition = nativeState ?. contentOffsetForElement . get ( element ) ?? { x : 0 , y : 0 } ;
6660 const dragSteps = createScrollSteps (
6761 { y : options . y , x : options . x } ,
6862 initialPosition ,
@@ -79,13 +73,13 @@ export async function scrollTo(
7973 await emitMomentumScrollEvents ( this . config , element , momentumSteps , options ) ;
8074
8175 const finalPosition = momentumSteps . at ( - 1 ) ?? dragSteps . at ( - 1 ) ?? initialPosition ;
82- setElementScrollOffset ( element , finalPosition ) ;
76+ nativeState ?. contentOffsetForElement . set ( element , finalPosition ) ;
8377}
8478
8579async function emitDragScrollEvents (
8680 config : UserEventConfig ,
8781 element : ReactTestInstance ,
88- scrollSteps : ContentOffset [ ] ,
82+ scrollSteps : Point [ ] ,
8983 scrollOptions : ScrollToOptions ,
9084) {
9185 if ( scrollSteps . length === 0 ) {
@@ -115,7 +109,7 @@ async function emitDragScrollEvents(
115109async function emitMomentumScrollEvents (
116110 config : UserEventConfig ,
117111 element : ReactTestInstance ,
118- scrollSteps : ContentOffset [ ] ,
112+ scrollSteps : Point [ ] ,
119113 scrollOptions : ScrollToOptions ,
120114) {
121115 if ( scrollSteps . length === 0 ) {
0 commit comments