// @flow import React, { Component } from 'react'; import { Linking, Text, TouchableOpacity, View } from 'react-native'; import styles from './styles'; import { Icon } from '../../base/font-icons'; import { translate } from '../../base/i18n'; type Props = { /** * The i18n label of the item. */ i18Label: string, /** * The icon of the item. */ icon: string, /** * The function to be invoked when the item is pressed * if the item is a button. */ onPress: Function, /** * The translate function. */ t: Function, /** * The URL of the link, if this item is a link. */ url: string }; /** * A component rendering an item in the system sidebar. */ class SideBarItem extends Component { /** * Contructor of the SideBarItem Component. * * @inheritdoc */ constructor(props: Props) { super(props); this._onOpenURL = this._onOpenURL.bind(this); } /** * Implements React's {@link Component#render()}, renders the sidebar item. * * @inheritdoc * @returns {ReactElement} */ render() { const { onPress, t } = this.props; const onPressCalculated = typeof onPress === 'function' ? onPress : this._onOpenURL; return ( { t(this.props.i18Label) } ); } _onOpenURL: () => void; /** * Opens the URL if one is provided. * * @private * @returns {void} */ _onOpenURL() { const { url } = this.props; if (typeof url === 'string') { Linking.openURL(url); } } } export default translate(SideBarItem);