React native 如何传递分区列表';s滚动到子组件的位置?
我正在构建一个React本机应用程序,它有一个用户需要填写的流程指南。当用户选择了一个选项后,我想让他在屏幕上向下滚动到新选项出现的位置 为了实现这一点,我需要在按钮的onClick中提供SectionList的功能React native 如何传递分区列表';s滚动到子组件的位置?,react-native,sections,React Native,Sections,我正在构建一个React本机应用程序,它有一个用户需要填写的流程指南。当用户选择了一个选项后,我想让他在屏幕上向下滚动到新选项出现的位置 为了实现这一点,我需要在按钮的onClick中提供SectionList的功能 42 const sectionData = [ 43 { 44 data: [ 45 { 46 key: "1", 47 program: [ 48 <Question 49
42 const sectionData = [
43 {
44 data: [
45 {
46 key: "1",
47 program: [
48 <Question
49 key={1}
50 onAnswerSubmit={() => {
51 scrollToLocation(1);
/*
How do I access scrollToLocation from
SectionList and pass it along as a prop here?
*/
52 }}
53 />,
54 <Question
55 key={2}
56 onAnswerSubmit={() => {
57 scrollToLocation(1);
58 }}
130 public render() {
131
132 return (
133 <SectionList
135 sections={ sectionData }
136 renderItem={ renderItem }
137 renderSectionHeader={ sectionHeader }
138 keyExtractor={ keyExtractor }
139 >
140 </SectionList>
42 const sectionData=[
43 {
44数据:[
45 {
46键:“1”,
47方案:[
48 {
51滚动定位(1);
/*
如何从中访问scrollToLocation
把它作为道具传递到这里?
*/
52 }}
53 />,
54 {
57个位置(1);
58 }}
130公共渲染(){
131
132返回(
133
140
问题。tsx
28 public render() {
29 return (
30 <Question
31 {...this.props}
32 onPress={this.props.onAnswerSubmit}
33 />
34 );
28公共呈现(){
29返回(
30
34 );
您可以像这样将ref添加到SectionList中
ref = "foo"
叫它
this.refs.foo.scrollToLocation(params);
this.sectionListRef.scrollToLocation(params);
或
叫它
this.refs.foo.scrollToLocation(params);
this.sectionListRef.scrollToLocation(params);