jiti-meet/react/features/welcome/components/WelcomePage.native.js

300 lines
9.4 KiB
JavaScript
Raw Normal View History

import React from 'react';
2018-02-02 14:50:16 +00:00
import {
2018-02-16 16:06:03 +00:00
Animated,
2018-02-15 22:58:07 +00:00
Keyboard,
2018-02-02 14:50:16 +00:00
SafeAreaView,
Switch,
TextInput,
TouchableHighlight,
TouchableOpacity,
View
} from 'react-native';
import { connect } from 'react-redux';
2017-03-01 02:55:12 +00:00
import { translate } from '../../base/i18n';
2018-02-02 14:50:16 +00:00
import { Icon } from '../../base/font-icons';
import { MEDIA_TYPE } from '../../base/media';
2018-02-02 14:50:16 +00:00
import { updateProfile } from '../../base/profile';
import { LoadingIndicator, Header, Text } from '../../base/react';
import { ColorPalette } from '../../base/styles';
2018-02-02 14:50:16 +00:00
import {
createDesiredLocalTracks,
destroyLocalTracks
} from '../../base/tracks';
import { SettingsView } from '../../settings';
2018-02-02 14:50:16 +00:00
2017-12-20 00:49:36 +00:00
import { AbstractWelcomePage, _mapStateToProps } from './AbstractWelcomePage';
import { setSideBarVisible } from '../actions';
2017-12-20 00:49:36 +00:00
import LocalVideoTrackUnderlay from './LocalVideoTrackUnderlay';
2018-02-08 18:50:19 +00:00
import PagedList from './PagedList';
2018-02-02 14:50:16 +00:00
import styles, {
PLACEHOLDER_TEXT_COLOR,
SWITCH_THUMB_COLOR,
SWITCH_UNDER_COLOR
} from './styles';
import WelcomePageSideBar from './WelcomePageSideBar';
/**
* The native container rendering the welcome page.
*
* @extends AbstractWelcomePage
*/
class WelcomePage extends AbstractWelcomePage {
2018-02-02 14:50:16 +00:00
/**
* Constructor of the Component.
*
* @inheritdoc
*/
constructor(props) {
super(props);
2018-02-16 16:06:03 +00:00
this.state.hintBoxAnimation = new Animated.Value(0);
// Bind event handlers so they are only bound once per instance.
2018-02-16 16:06:03 +00:00
this._getHintBoxStyle = this._getHintBoxStyle.bind(this);
this._onFieldFocusChange = this._onFieldFocusChange.bind(this);
2018-02-02 14:50:16 +00:00
this._onShowSideBar = this._onShowSideBar.bind(this);
this._onStartAudioOnlyChange = this._onStartAudioOnlyChange.bind(this);
2018-02-16 16:06:03 +00:00
this._renderHintBox = this._renderHintBox.bind(this);
2018-02-02 14:50:16 +00:00
}
/**
* Implements React's {@link Component#componentWillMount()}. Invoked
* immediately before mounting occurs. Creates a local video track if none
* is available.
*
* @inheritdoc
* @returns {void}
*/
componentWillMount() {
super.componentWillMount();
2018-02-02 14:50:16 +00:00
const { dispatch } = this.props;
if (this.props._profile.startAudioOnly) {
dispatch(destroyLocalTracks());
} else {
dispatch(createDesiredLocalTracks(MEDIA_TYPE.VIDEO));
}
}
/**
* Implements React's {@link Component#render()}. Renders a prompt for
* entering a room name.
*
* @inheritdoc
* @returns {ReactElement}
*/
render() {
const { buttonStyle, pageStyle, textStyle } = Header;
2018-02-02 14:50:16 +00:00
const { t, _profile } = this.props;
return (
<LocalVideoTrackUnderlay style = { styles.welcomePage }>
<View style = { pageStyle }>
2018-02-02 14:50:16 +00:00
<Header style = { styles.header }>
<TouchableOpacity onPress = { this._onShowSideBar } >
<Icon
2018-02-02 14:50:16 +00:00
name = 'menu'
style = { buttonStyle } />
2018-02-02 14:50:16 +00:00
</TouchableOpacity>
<View style = { styles.audioVideoSwitchContainer }>
<Text style = { textStyle } >
{ t('welcomepage.audioVideoSwitch.video') }
2018-02-02 14:50:16 +00:00
</Text>
<Switch
onTintColor = { SWITCH_UNDER_COLOR }
onValueChange = { this._onStartAudioOnlyChange }
style = { styles.audioVideoSwitch }
thumbTintColor = { SWITCH_THUMB_COLOR }
value = { _profile.startAudioOnly } />
<Text style = { textStyle } >
{ t('welcomepage.audioVideoSwitch.audio') }
2018-02-02 14:50:16 +00:00
</Text>
</View>
</Header>
<SafeAreaView style = { styles.roomContainer } >
<View style = { styles.joinControls } >
2018-02-08 18:50:19 +00:00
<TextInput
accessibilityLabel = { 'Input room name.' }
autoCapitalize = 'none'
autoComplete = { false }
autoCorrect = { false }
autoFocus = { false }
onBlur = { this._onFieldFocusChange(false) }
onChangeText = { this._onRoomChange }
onFocus = { this._onFieldFocusChange(true) }
onSubmitEditing = { this._onJoin }
placeholder = { t('welcomepage.roomname') }
placeholderTextColor = {
PLACEHOLDER_TEXT_COLOR
}
returnKeyType = { 'go' }
style = { styles.textInput }
underlineColorAndroid = 'transparent'
value = { this.state.room } />
{
this._renderHintBox()
}
</View>
2018-02-02 14:50:16 +00:00
</SafeAreaView>
2018-02-08 18:50:19 +00:00
<PagedList disabled = { this.state._fieldFocused } />
<SettingsView />
</View>
2018-02-02 14:50:16 +00:00
<WelcomePageSideBar />
</LocalVideoTrackUnderlay>
);
}
2018-02-16 16:06:03 +00:00
/**
* Constructs a style array to handle the hint box animation.
*
* @private
* @returns {Array<Object>}
*/
_getHintBoxStyle() {
return [
styles.hintContainer,
{
opacity: this.state.hintBoxAnimation
}
];
}
/**
* Callback for when the room field's focus changes so the hint box
* must be rendered or removed.
*
* @private
* @param {boolean} focused - The focused state of the field.
* @returns {Function}
*/
_onFieldFocusChange(focused) {
return () => {
if (focused) {
this.setState({
_fieldFocused: true
});
}
Animated.timing(this.state.hintBoxAnimation, {
duration: 300,
toValue: focused ? 1 : 0
}).start(animationState => {
if (animationState.finished && !focused) {
this.setState({
_fieldFocused: false
});
}
});
};
}
2018-02-02 14:50:16 +00:00
/**
* Toggles the side bar.
*
* @private
* @returns {void}
*/
_onShowSideBar() {
2018-02-15 22:58:07 +00:00
Keyboard.dismiss();
this.props.dispatch(setSideBarVisible(true));
2018-02-02 14:50:16 +00:00
}
/**
* Handles the audio-video switch changes.
*
* @private
* @param {boolean} startAudioOnly - The new startAudioOnly value.
* @returns {void}
*/
_onStartAudioOnlyChange(startAudioOnly) {
const { dispatch } = this.props;
dispatch(updateProfile({
...this.props._profile,
startAudioOnly
}));
}
2018-02-16 16:06:03 +00:00
/**
* Renders the hint box if necessary.
*
* @private
* @returns {React$Node}
*/
_renderHintBox() {
if (this.state._fieldFocused) {
const { t } = this.props;
return (
<Animated.View style = { this._getHintBoxStyle() }>
2018-02-16 16:06:03 +00:00
<View style = { styles.hintTextContainer } >
<Text>
{ t('welcomepage.roomnameHint') }
2018-02-16 16:06:03 +00:00
</Text>
</View>
<View style = { styles.hintButtonContainer } >
{ this._renderJoinButton() }
2018-02-16 16:06:03 +00:00
</View>
</Animated.View>
);
}
return null;
}
/**
* Renders the join button.
*
* @private
* @returns {ReactElement}
*/
_renderJoinButton() {
let children;
/* eslint-disable no-extra-parens */
if (this.state.joining) {
// TouchableHighlight is picky about what its children can be, so
// wrap it in a native component, i.e. View to avoid having to
// modify non-native children.
children = (
<View>
2018-02-16 16:06:03 +00:00
<LoadingIndicator
color = { styles.buttonText.color }
size = 'small' />
</View>
);
} else {
children = (
<Text style = { styles.buttonText }>
{ this.props.t('welcomepage.join') }
</Text>
);
}
/* eslint-enable no-extra-parens */
2018-02-16 16:06:03 +00:00
const buttonDisabled = this._isJoinDisabled();
return (
<TouchableHighlight
accessibilityLabel = { 'Tap to Join.' }
2018-02-16 16:06:03 +00:00
disabled = { buttonDisabled }
onPress = { this._onJoin }
2018-02-16 16:06:03 +00:00
style = { [
styles.button,
buttonDisabled ? styles.buttonDisabled : null
] }
underlayColor = { ColorPalette.white }>
{
children
}
</TouchableHighlight>
);
}
}
export default translate(connect(_mapStateToProps)(WelcomePage));