In React Native, how can I get the Y offset of a custom component and then scroll a ScrollView to its position?
问题 In React Native, I have a screen with a ScrollView : let scrollView; let myComponent2; function onPress() { myComponent2.measure((frameOffsetX, frameOffsetY, width, height, pageOffsetX, pageOffsetY) => { scrollView.scrollTo({ y: frameOffsetY }); } function MyScrollView() { return ( <ScrollView ref={ref => scrollView = ref}> <MyButton onPress={onPress} /> <MyComponent1 /> <MyComponent2 ref={ref => myComponent2 = ref} /> <MyComponent3 /> </ScrollView> ); }; And MyButton is defined like this: