import * as React from 'react'; import {FlatList, StyleSheet, View} from "react-native"; import {Avatar, Button, Card, Divider, List, withTheme} from 'react-native-paper'; import AuthenticatedScreen from "../../components/AuthenticatedScreen"; import {openBrowser} from "../../utils/WebBrowser"; import HeaderButton from "../../components/HeaderButton"; import i18n from 'i18n-js'; import LogoutDialog from "../../components/LogoutDialog"; type Props = { navigation: Object, theme: Object, } type State = { dialogVisible: boolean, } class ProfileScreen extends React.Component { state = { dialogVisible: false, }; colors: Object; data: Object; flatListData: Array; constructor(props) { super(props); this.colors = props.theme.colors; this.flatListData = [ {id: '0'}, {id: '1'}, {id: '2'}, ] } componentDidMount() { const rightButton = this.getHeaderButtons.bind(this); this.props.navigation.setOptions({ headerRight: rightButton, }); } showDisconnectDialog = () => this.setState({ dialogVisible: true }); hideDisconnectDialog = () => this.setState({ dialogVisible: false }); getHeaderButtons() { return ; } getScreen(data: Object) { this.data = data; return ( this.getRenderItem(item)} keyExtractor={item => item.id} data={this.flatListData} /> ) } getRenderItem({item}: Object) { switch (item.id) { case '0': return this.getPersonalCard(); case '1': return this.getClubCard(); case '2': return this.getMembershipCar(); } } getPersonalCard() { return ( } /> {i18n.t("profileScreen.personalInformation")} {this.getPersonalListItem(this.data.birthday, "cake-variant")} {this.getPersonalListItem(this.data.phone, "phone")} {this.getPersonalListItem(this.data.email, "email")} {this.getPersonalListItem(this.data.branch, "school")} ); } getClubCard() { return ( } /> {this.getClubList(this.data.clubs)} ); } getMembershipCar() { return ( } /> {this.getMembershipItem(this.data.validity)} ); } getClubList(list: Array) { let dataset = []; for (let i = 0; i < list.length; i++) { dataset.push({name: list[i]}); } return ( } /> } keyExtractor={item => item.name} data={dataset} /> ); } getMembershipItem(state: boolean) { return ( } /> ); } isFieldAvailable(field: ?string) { return field !== null; } getFieldValue(field: ?string) { return this.isFieldAvailable(field) ? field : i18n.t("profileScreen.noData"); } getFieldColor(field: ?string) { return this.isFieldAvailable(field) ? this.colors.text : this.colors.textDisabled; } getPersonalListItem(field: ?string, icon: string) { return ( } titleStyle={{color: this.getFieldColor(field)}} /> ); } render() { return ( this.getScreen(data)} /> ); } } const styles = StyleSheet.create({ card: { margin: 10, }, icon: { backgroundColor: 'transparent' }, editButton: { marginLeft: 'auto' } }); export default withTheme(ProfileScreen);