| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101 | // @flow
import React, { Component } from 'react';
import { Linking, Text, TouchableOpacity, View } from 'react-native';
import { Icon } from '../../base/font-icons';
import { translate } from '../../base/i18n';
import styles from './styles';
type Props = {
    /**
     * The icon of the item.
     */
    icon: string,
    /**
     * The i18n label of the item.
     */
    label: 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<Props> {
    /**
     * Initializes a new {@code SideBarItem} instance.
     *
     * @inheritdoc
     */
    constructor(props: Props) {
        super(props);
        // Bind event handlers so they are only bound once per instance.
        this._onOpenURL = this._onOpenURL.bind(this);
    }
    /**
     * Implements React's {@link Component#render()}, renders the sidebar item.
     *
     * @inheritdoc
     * @returns {ReactElement}
     */
    render() {
        const { label, onPress, t } = this.props;
        const onPressCalculated
            = typeof onPress === 'function' ? onPress : this._onOpenURL;
        return (
            <TouchableOpacity
                onPress = { onPressCalculated }
                style = { styles.sideBarItem }>
                <View style = { styles.sideBarItemButtonContainer }>
                    <Icon
                        name = { this.props.icon }
                        style = { styles.sideBarItemIcon } />
                    <Text style = { styles.sideBarItemText }>
                        { t(label) }
                    </Text>
                </View>
            </TouchableOpacity>
        );
    }
    _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);
 |