Skip to content

Instantly share code, notes, and snippets.

View AsimKarel's full-sized avatar

AsimKarel

  • Pune
View GitHub Profile
/**
* Creator Asim Karel
* https://github.com/AsimKarel
*
*/
import React from 'react';
import {
FlatList,
Button,
currentIndex = 0;
scrollNext = () => {
if (this.currentIndex !== this.state.data.length - 1) {
this.flatListRef.scrollToIndex({
index: this.currentIndex + 1,
animated: true,
});
}
};
scrollPrevious = () => {
<View style={styles.container}>
<FlatList
ref={ref => {
this.flatListRef = ref;
}}
onViewableItemsChanged={this.onViewableItemsChanged}
.../>
<View style={styles.buttonContainer}>
<Button title={'Previous'} onPress={this.scrollPrevious} />
<Button title={'Next'} onPress={this.scrollNext} />
import React from 'react';
import {FlatList, View, StyleSheet, Dimensions} from 'react-native';
export default class MySlider extends React.Component {
...
render() {
return (
<View style={styles.container}>
<FlatList
renderItem={({item}) => <Text style={styles.item}>{item}</Text>}
import React from 'react';
import {FlatList, Text, StyleSheet} from 'react-native';
export default class MySlider extends React.Component {
state = {
data: ['A', 'B', 'C'],
};
render() {
return (
<View style={styles.container}>
<FlatList