Skip to content

Instantly share code, notes, and snippets.

@spencercarli
Created April 17, 2017 16:56
Show Gist options
  • Save spencercarli/85c289a686c518d63368a37908e8ca9c to your computer and use it in GitHub Desktop.
Save spencercarli/85c289a686c518d63368a37908e8ca9c to your computer and use it in GitHub Desktop.
import { AppRegistry } from "react-native";
import FlatListDemo from "./FlatListDemo";
AppRegistry.registerComponent("FlatListDemo", () => FlatListDemo);
import { AppRegistry } from "react-native";
import FlatListDemo from "./FlatListDemo";
AppRegistry.registerComponent("FlatListDemo", () => FlatListDemo);
@MANAYATHU
Copy link

MANAYATHU commented Dec 13, 2021

import { AppRegistry) from " react-native";
import FlatListDemo from"./FlatListDemo";
import { List, ListItem, SearchBar } from "react-native-elements";

class FlatListDemo extends Component {
constructor(props) {
super(props);

this.state = {
  loading: false,
  data: [],
  page: 1,
  seed: 1,
  error: null,
  refreshing: false
};

}

componentDidMount() {
this.makeRemoteRequest();
}

makeRemoteRequest = () => {
const { page, seed } = this.state;
const url = https://randomuser.me/api/?seed=${seed}&page=${page}&results=20;
this.setState({ loading: true });

fetch(url)
  .then(res => res.json())
  .then(res => {
    this.setState({
      data: page === 1 ? res.results : [...this.state.data, ...res.results],
      error: res.error || null,
      loading: false,
      refreshing: false
    });
  })
  .catch(error => {
    this.setState({ error, loading: false });
  });

};

handleRefresh = () => {
this.setState(
{
page: 1,
seed: this.state.seed + 1,
refreshing: true
},
() => {
this.makeRemoteRequest();
}
);
};

handleLoadMore = () => {
this.setState(
{
page: this.state.page + 1
},
() => {
this.makeRemoteRequest();
}
);
};

renderSeparator = () => {
return (
<View
style={{
height: 1,
width: "86%",
backgroundColor: "#CED0CE",
marginLeft: "14%"
}}
/>
);
};

renderHeader = () => {
return ;
};

renderFooter = () => {
if (!this.state.loading) return null;

return (
  <View
    style={{
      paddingVertical: 20,
      borderTopWidth: 1,
      borderColor: "#CED0CE"
    }}
  >
    <ActivityIndicator animating size="large" />
  </View>
);

};

render() {
return (
<List containerStyle={{ borderTopWidth: 0, borderBottomWidth: 0 }}>
<FlatList
data={this.state.data}
renderItem={({ item }) => (
<ListItem
roundAvatar
title={${item.name.first} ${item.name.last}}
subtitle={item.email}
avatar={{ uri: item.picture.thumbnail }}
containerStyle={{ borderBottomWidth: 0 }}
/>
)}
keyExtractor={item => item.email}
ItemSeparatorComponent={this.renderSeparator}
ListHeaderComponent={this.renderHeader}
ListFooterComponent={this.renderFooter}
onRefresh={this.handleRefresh}
refreshing={this.state.refreshing}
onEndReached={this.handleLoadMore}
onEndReachedThreshold={50}
/>

);
}
}

@MANAYATHU
Copy link

what is the reason and please fixing code

@MANAYATHU
Copy link

iam a trainee of redbytes software company please reslove issue

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment