// @flow import * as React from 'react'; import {Avatar, Card, List, ProgressBar, Subheading, withTheme} from "react-native-paper"; import {FlatList, StyleSheet} from "react-native"; import i18n from 'i18n-js'; type Props = { teams: Array, dateEnd: string, } class VoteResults extends React.Component { totalVotes: number; winnerId: number; colors: Object; constructor(props) { super(); this.colors = props.theme.colors; props.teams.sort(this.sortByVotes); this.getTotalVotes(props.teams); this.getWinnerId(props.teams); } shouldComponentUpdate() { return false; } sortByVotes = (a: Object, b: Object) => b.votes - a.votes; getTotalVotes(teams: Array) { this.totalVotes = 0; for (let i = 0; i < teams.length; i++) { this.totalVotes += teams[i].votes; } } getWinnerId(teams: Array) { this.winnerId = teams[0].id; } voteKeyExtractor = (item: Object) => item.id.toString(); resultRenderItem = ({item}: Object) => { const isWinner = this.winnerId === item.id; return ( isWinner ? : null} titleStyle={{ color: isWinner ? this.colors.primary : this.colors.text }} style={{padding: 0}} /> ); }; render() { return ( } /> {i18n.t('voteScreen.results.totalVotes') + ' ' +this.totalVotes} {/*$FlowFixMe*/} ); } } const styles = StyleSheet.create({ card: { margin: 10, }, icon: { backgroundColor: 'transparent' }, }); export default withTheme(VoteResults);