// @flow import * as React from 'react'; import type {cardList} from "../../components/Lists/CardList/CardList"; import CardList from "../../components/Lists/CardList/CardList"; import CustomTabBar from "../../components/Tabbar/CustomTabBar"; import {withCollapsible} from "../../utils/withCollapsible"; import {Collapsible} from "react-navigation-collapsible"; import {Animated, Image, View} from "react-native"; import {Avatar, Card, Divider, List, TouchableRipple, withTheme} from "react-native-paper"; import type {CustomTheme} from "../../managers/ThemeManager"; import i18n from 'i18n-js'; import MaterialHeaderButtons, {Item} from "../../components/Overrides/CustomHeaderButton"; import ConnectionManager from "../../managers/ConnectionManager"; import {StackNavigationProp} from "@react-navigation/stack"; import {MASCOT_STYLE} from "../../components/Mascot/Mascot"; import MascotPopup from "../../components/Mascot/MascotPopup"; import AsyncStorageManager from "../../managers/AsyncStorageManager"; import ServicesManager, {SERVICES_CATEGORIES_KEY} from "../../managers/ServicesManager"; type Props = { navigation: StackNavigationProp, collapsibleStack: Collapsible, theme: CustomTheme, } type State = { mascotDialogVisible: boolean, } export type listItem = { title: string, description: string, image: string | number, content: cardList, } class ServicesScreen extends React.Component { finalDataset: Array state = { mascotDialogVisible: AsyncStorageManager.getInstance().preferences.servicesShowBanner.current === "1" } constructor(props) { super(props); const services = new ServicesManager(props.navigation); this.finalDataset = services.getCategories([SERVICES_CATEGORIES_KEY.SPECIAL]) } componentDidMount() { this.props.navigation.setOptions({ headerRight: this.getAboutButton, }); } /** * Callback used when closing the banner. * This hides the banner and saves to preferences to prevent it from reopening */ onHideMascotDialog = () => { this.setState({mascotDialogVisible: false}); AsyncStorageManager.getInstance().savePref( AsyncStorageManager.getInstance().preferences.servicesShowBanner.key, '0' ); }; getAboutButton = () => ; onAboutPress = () => this.props.navigation.navigate('amicale-contact'); /** * Gets the list title image for the list. * * If the source is a string, we are using an icon. * If the source is a number, we are using an internal image. * * @param props Props to pass to the component * @param source The source image to display. Can be a string for icons or a number for local images * @returns {*} */ getListTitleImage(props, source: string | number) { if (typeof source === "number") return else return } /** * Redirects to the given route or to the login screen if user is not logged in. * * @param route The route to navigate to */ onAmicaleServicePress(route: string) { if (ConnectionManager.getInstance().isLoggedIn()) this.props.navigation.navigate(route); else this.props.navigation.navigate("login", {nextScreen: route}); } /** * A list item showing a list of available services for the current category * * @param item * @returns {*} */ renderItem = ({item}: { item: listItem }) => { return ( this.props.navigation.navigate("services-section", {data: item})} > this.getListTitleImage(props, item.image)} right={(props) => } /> ); }; keyExtractor = (item: listItem) => { return item.title; } render() { const {containerPaddingTop, scrollIndicatorInsetTop, onScroll} = this.props.collapsibleStack; return ( } /> ); } } export default withCollapsible(withTheme(ServicesScreen));