홈>
양방향으로 무한 스크롤 뷰를 구현하고 싶습니다. 또한 데이터는 동적으로로드되어야합니다.
목록에 SectionList 구성 요소를 사용하고 있습니다. 앞으로 무한 스크롤을 구현했습니다. 즉, 사용자가 아래로 스크롤하면 데이터가 목록에 자동으로 추가됩니다.
이를 위해 onMomentumScrollEnd 이벤트를 사용했습니다. 사용자가 스크롤을 중지 할 때 스크롤이 Up 방향이면 End에 데이터가 추가되고 Down 방향이면 데이터가 Top에 추가됩니다.
이제 문제는 목록 상단에 데이터를 추가 할 때 현재 모든 목록 데이터를 뒤로 이동하는 것입니다. 데이터가 업데이트 되어도 현재 목록을 이동하고 싶지 않습니다. 할 방법이 있습니까?
다음은 내 code입니다.
import React, {Component} from 'react';
import {
Text,
View,
StyleSheet,
SectionList,
} from 'react-native';
import CardComponent from './CardComponent'
export default class Schedule extends Component {
constructor(props) {
super(props);
this.state= {
sectionData: [],
loading: false,
}
this.contentOffsetY= 0;
this._onScroll= this._onScroll.bind(this)
}
componentDidMount() {
this.setState({ sectionData: this.props.data })
}
renderItem= ({item})=> (
<CardComponent
data={item}
key={item}
/> );
renderDateSeparator(text) {
return (
<Text style={{
paddingVertical: 15,
fontSize: 14,
flex: 1,
textAlign: 'center',
textAlignVertical: 'center',
}}> {text}
<Text> )
}
_onScroll(e){
let contentOffset= e.nativeEvent.contentOffset.y;
this.contentOffsetY < contentOffset ? this.loadMoreOnBottom() : this.loadMoreOnTop();
this.contentOffsetY= contentOffset;
}
loadMoreOnTop() {
this.setState({ lodaing: true });
//code to append data on top of list
this.setState({ lodaing: false });
}
loadMoreOnBottom() {
//code to append data at bottom of list
}
render() {
const sectionData= this.state.sectionData;
return(
<View style={{flex: 1}}> <SectionList
onMomentumScrollEnd={this._onScroll}
automaticallyAdjustContentInsets={false}
itemShouldUpdate={false}
renderItem={this.renderItem}
renderSectionHeader={({section})=> this.renderDateSeparator(section.date)}
sections={sectionData}
stickySectionHeadersEnabled={false}
refreshing={this.state.loading}
onRefresh={()=> this.loadMoreOnTop()}
onEndReachedThreshold={0.3}
onEndReached={()=> this.loadMoreOnBottom()}
keyExtractor={(item)=> item.key}
/> </View> )
}
}
미리 감사합니다.
관련 자료
- android - RxJava로 무한 루프를 구현하는 방법은 무엇입니까?
- data structures - C ++에서 include (#pragma로 한 번 없음)의 순환 호출로 인한 무한 루프 입력을 피하는 재귀 함수 구현
- 반응 네이티브에서 커스텀 피커를 구현하는 방법은 무엇입니까?
- javascript - 반응 네이티브에서 스크래치 카드 /보기를 구현하는 방법은 무엇입니까?
- java - 크기가 지정되지 않은 경우 배열 목록에서 무한 for 루프를 구현하는 방법
- javascript - Github API 리포지토리 목록으로 무한 스크롤을 구현하는 방법
- javascript - rxjs로 무한 스크롤 구현
- 파이썬에서 무한 while 루프를 올바르게 구현하는 방법은 무엇입니까?
- Rust에서 From 특성으로 양방향 변환을 구현하는 방법은 무엇입니까?
트렌드
- OpenCv의 폴더에서 여러 이미지 읽기 (python)
- 파이썬 셀레늄 모든 "href"속성 가져 오기
- html - 자바 스크립트 - 클릭 후 변경 버튼 텍스트 변경
- git commit - 자식 - 로컬 커밋 된 파일에 대한 변경을 취소하는 방법
- JSP에 대한 클래스를 컴파일 할 수 없습니다
- javascript - 현재 URL에서 특정 div 만 새로 고침/새로 고침
- jquery - JavaScript로 현재 세션 값을 얻으시겠습니까?
- javascript - swiperjs에서 정지, 재생 버튼 추가
- python - 문자열에서 특정 문자 제거
- JavaScript 변수를 HTML div에 '출력'하는 방법