// @flow import React, { Component } from 'react'; import { Text, TouchableHighlight, View } from 'react-native'; import { translate } from '../../../base/i18n'; import styles, { ACTIVE_OPACITY, TOUCHABLE_UNDERLAY } from './styles'; type Props = { /** * The list of broadcasts the user can pick from. */ broadcasts: ?Array, /** * Callback to be invoked when the user picked a broadcast. To be invoked * with a single key (string). */ onChange: Function, /** * Function to be used to translate i18n labels. */ t: Function } type State = { /** * The key of the currently selected stream. */ streamKey: ?string } /** * Class to implement a stream key picker (dropdown) component to allow the user * to choose from the available Google Broadcasts/Streams. * * NOTE: This component is currently only used on mobile, but it is advised at * a later point to unify mobile and web logic for this functionality. But it's * out of the scope for now of the mobile live streaming functionality. */ class StreamKeyPicker extends Component { /** * Instantiates a new instance of StreamKeyPicker. * * @inheritdoc */ constructor(props: Props) { super(props); this.state = { streamKey: null }; this._onStreamPick = this._onStreamPick.bind(this); } /** * Renders the component. * * @inheritdoc */ render() { const { broadcasts } = this.props; if (!broadcasts || !broadcasts.length) { return null; } return ( { this.props.t('liveStreaming.choose') } { broadcasts.map((broadcast, index) => ( { broadcast.title } )) } ); } _onStreamPick: string => Function /** * Callback to be invoked when the user picks a stream from the list. * * @private * @param {string} streamKey - The key of the stream selected. * @returns {Function} */ _onStreamPick(streamKey) { return () => { this.setState({ streamKey }); this.props.onChange(streamKey); }; } } export default translate(StreamKeyPicker);