forked from vergnet/application-amicale
Allow pull down to refresh
This commit is contained in:
parent
88478c15b5
commit
cbb0624189
1 changed files with 20 additions and 6 deletions
|
@ -1,7 +1,7 @@
|
||||||
// @flow
|
// @flow
|
||||||
|
|
||||||
import * as React from 'react';
|
import * as React from 'react';
|
||||||
import {FlatList, View} from "react-native";
|
import {FlatList, RefreshControl, View} from "react-native";
|
||||||
import AuthenticatedScreen from "../../components/Amicale/AuthenticatedScreen";
|
import AuthenticatedScreen from "../../components/Amicale/AuthenticatedScreen";
|
||||||
import {getTimeOnlyString, stringToDate} from "../../utils/Planning";
|
import {getTimeOnlyString, stringToDate} from "../../utils/Planning";
|
||||||
import VoteTitle from "../../components/Amicale/Vote/VoteTitle";
|
import VoteTitle from "../../components/Amicale/Vote/VoteTitle";
|
||||||
|
@ -9,7 +9,6 @@ import VoteTease from "../../components/Amicale/Vote/VoteTease";
|
||||||
import VoteSelect from "../../components/Amicale/Vote/VoteSelect";
|
import VoteSelect from "../../components/Amicale/Vote/VoteSelect";
|
||||||
import VoteResults from "../../components/Amicale/Vote/VoteResults";
|
import VoteResults from "../../components/Amicale/Vote/VoteResults";
|
||||||
import VoteWait from "../../components/Amicale/Vote/VoteWait";
|
import VoteWait from "../../components/Amicale/Vote/VoteWait";
|
||||||
import {Button} from "react-native-paper";
|
|
||||||
|
|
||||||
const FAKE_DATE = {
|
const FAKE_DATE = {
|
||||||
"date_begin": "2020-04-09 15:50",
|
"date_begin": "2020-04-09 15:50",
|
||||||
|
@ -59,6 +58,8 @@ const FAKE_TEAMS2 = {
|
||||||
],
|
],
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const MIN_REFRESH_TIME = 5 * 1000;
|
||||||
|
|
||||||
type Props = {
|
type Props = {
|
||||||
navigation: Object
|
navigation: Object
|
||||||
}
|
}
|
||||||
|
@ -81,6 +82,7 @@ export default class VoteScreen extends React.Component<Props, State> {
|
||||||
today: Date;
|
today: Date;
|
||||||
|
|
||||||
mainFlatListData: Array<Object>;
|
mainFlatListData: Array<Object>;
|
||||||
|
lastRefresh: Date;
|
||||||
|
|
||||||
authRef: Object;
|
authRef: Object;
|
||||||
|
|
||||||
|
@ -95,7 +97,15 @@ export default class VoteScreen extends React.Component<Props, State> {
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
|
||||||
reloadData = () => this.authRef.current.reload();
|
reloadData = () => {
|
||||||
|
let canRefresh;
|
||||||
|
if (this.lastRefresh !== undefined)
|
||||||
|
canRefresh = (new Date().getTime() - this.lastRefresh.getTime()) > MIN_REFRESH_TIME;
|
||||||
|
else
|
||||||
|
canRefresh = true;
|
||||||
|
if (canRefresh)
|
||||||
|
this.authRef.current.reload()
|
||||||
|
};
|
||||||
|
|
||||||
generateDateObject() {
|
generateDateObject() {
|
||||||
this.dates = {
|
this.dates = {
|
||||||
|
@ -146,6 +156,7 @@ export default class VoteScreen extends React.Component<Props, State> {
|
||||||
getScreen = (data: Array<Object | null>) => {
|
getScreen = (data: Array<Object | null>) => {
|
||||||
// data[0] = FAKE_TEAMS2;
|
// data[0] = FAKE_TEAMS2;
|
||||||
// data[1] = FAKE_DATE;
|
// data[1] = FAKE_DATE;
|
||||||
|
this.lastRefresh = new Date();
|
||||||
|
|
||||||
if (data[1] === null)
|
if (data[1] === null)
|
||||||
data[1] = {date_begin: null};
|
data[1] = {date_begin: null};
|
||||||
|
@ -161,12 +172,15 @@ export default class VoteScreen extends React.Component<Props, State> {
|
||||||
{/*$FlowFixMe*/}
|
{/*$FlowFixMe*/}
|
||||||
<FlatList
|
<FlatList
|
||||||
data={this.mainFlatListData}
|
data={this.mainFlatListData}
|
||||||
|
refreshControl={
|
||||||
|
<RefreshControl
|
||||||
|
refreshing={false}
|
||||||
|
onRefresh={this.reloadData}
|
||||||
|
/>
|
||||||
|
}
|
||||||
extraData={this.state.hasVoted.toString()}
|
extraData={this.state.hasVoted.toString()}
|
||||||
renderItem={this.mainRenderItem}
|
renderItem={this.mainRenderItem}
|
||||||
/>
|
/>
|
||||||
<Button onPress={this.reloadData}>
|
|
||||||
REFRESH
|
|
||||||
</Button>
|
|
||||||
</View>
|
</View>
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
Loading…
Reference in a new issue