Skip to content

Instantly share code, notes, and snippets.

@bozzmob
Forked from melihmucuk/home.js
Created October 16, 2016 14:54
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bozzmob/2ea5f4535f32589bf44d357c8d126a3a to your computer and use it in GitHub Desktop.
Save bozzmob/2ea5f4535f32589bf44d357c8d126a3a to your computer and use it in GitHub Desktop.
react native animate listview rows while scrolling
import React, { Component } from 'react';
import {
StyleSheet,
View,
Text,
ListView
} from 'react-native';
import Icon from 'react-native-vector-icons/FontAwesome';
import * as Animatable from 'react-native-animatable';
class Home extends Component {
rows = [];
constructor(props){
super(props)
this._renderRow = this._renderRow.bind(this);
this._animateRows = this._animateRows.bind(this);
var ds = new ListView.DataSource({rowHasChanged: (r1, r2) => r1 !== r2});
this.state={
dataSource: ds.cloneWithRows(['row 1', 'row 2', 'row 3', 'row 4', 'row 1', 'row 2', 'row 3', 'row 4']),
}
}
render() {
return(
<ListView
pagingEnabled={true}
style={{flex: 1, marginTop: 64, backgroundColor: 'blue'}}
dataSource={this.state.dataSource}
renderRow={this._renderRow}
onChangeVisibleRows={this._animateRows}
/>
);
}
_animateRows(visibleRows, changedRows){
for(var k in visibleRows.s1){
if(visibleRows.s1[k]){
console.log("row animated: ", k);
this.rows[k].rubberBand(1100);
}
}
}
_renderRow(rowData, sectionID, rowID, highlightRow){
return(
<View style={{flexDirection: 'row', height: 200, backgroundColor: 'red', alignSelf: 'stretch', marginVertical: 5, padding: 5, alignItems: 'center', justifyContent: 'space-around'}}>
<Animatable.Text ref={(row) => this.rows[rowID] = row}><Icon name="mobile" size={100} color="white" /></Animatable.Text>
<Text style={{color: 'white', fontSize: 30, fontWeight: 'bold', textAlign: 'center'}}>
{rowData}
</Text>
</View>
);
}
}
const styles = StyleSheet.create({
container: {
flex: 1,
justifyContent: 'center',
alignItems: 'center'
},
})
export default Home;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment