2016-10-05 14:36:59 +00:00
|
|
|
import React from 'react';
|
2022-11-08 15:46:46 +00:00
|
|
|
import { Animated, SafeAreaView, TouchableHighlight, View } from 'react-native';
|
2016-10-05 14:36:59 +00:00
|
|
|
|
2020-06-04 14:09:13 +00:00
|
|
|
import { getName } from '../../app/functions';
|
2017-03-01 02:55:12 +00:00
|
|
|
import { translate } from '../../base/i18n';
|
2022-07-28 07:28:29 +00:00
|
|
|
import { Icon, IconWarning } from '../../base/icons';
|
2021-11-11 14:32:56 +00:00
|
|
|
import { LoadingIndicator, Text } from '../../base/react';
|
2019-03-21 16:38:29 +00:00
|
|
|
import { connect } from '../../base/redux';
|
2022-11-08 15:46:46 +00:00
|
|
|
import BaseTheme from '../../base/ui/components/BaseTheme.native';
|
2022-11-09 10:59:17 +00:00
|
|
|
import Button from '../../base/ui/components/native/Button';
|
2022-11-08 15:46:46 +00:00
|
|
|
import Input from '../../base/ui/components/native/Input';
|
2022-11-09 10:59:17 +00:00
|
|
|
import { BUTTON_TYPES } from '../../base/ui/constants.native';
|
2022-01-25 12:55:57 +00:00
|
|
|
import WelcomePageTabs
|
|
|
|
from '../../mobile/navigation/components/welcome/components/WelcomePageTabs';
|
2019-06-26 14:59:20 +00:00
|
|
|
|
2019-03-05 17:41:39 +00:00
|
|
|
import {
|
2022-09-27 07:10:28 +00:00
|
|
|
type Props as AbstractProps,
|
2019-03-05 17:41:39 +00:00
|
|
|
AbstractWelcomePage,
|
2022-09-27 07:10:28 +00:00
|
|
|
_mapStateToProps as _abstractMapStateToProps
|
2019-03-05 17:41:39 +00:00
|
|
|
} from './AbstractWelcomePage';
|
2022-11-08 15:46:46 +00:00
|
|
|
import styles from './styles';
|
2016-11-29 20:04:56 +00:00
|
|
|
|
2021-11-11 14:32:56 +00:00
|
|
|
type Props = AbstractProps & {
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Default prop for navigating between screen components(React Navigation).
|
|
|
|
*/
|
|
|
|
navigation: Object,
|
|
|
|
|
|
|
|
/**
|
|
|
|
* The translate function.
|
|
|
|
*/
|
|
|
|
t: Function
|
|
|
|
};
|
|
|
|
|
2016-10-05 14:36:59 +00:00
|
|
|
/**
|
|
|
|
* The native container rendering the welcome page.
|
|
|
|
*
|
2021-11-04 21:10:43 +00:00
|
|
|
* @augments AbstractWelcomePage
|
2016-10-05 14:36:59 +00:00
|
|
|
*/
|
2021-11-11 14:32:56 +00:00
|
|
|
class WelcomePage extends AbstractWelcomePage<*> {
|
2018-02-02 14:50:16 +00:00
|
|
|
/**
|
|
|
|
* Constructor of the Component.
|
|
|
|
*
|
|
|
|
* @inheritdoc
|
|
|
|
*/
|
2021-11-11 14:32:56 +00:00
|
|
|
constructor(props: Props) {
|
2018-02-02 14:50:16 +00:00
|
|
|
super(props);
|
|
|
|
|
2018-04-04 12:50:12 +00:00
|
|
|
this.state._fieldFocused = false;
|
2021-11-11 14:32:56 +00:00
|
|
|
|
2022-07-28 07:28:29 +00:00
|
|
|
this.state.isSettingsScreenFocused = false;
|
|
|
|
|
|
|
|
this.state.roomNameInputAnimation = new Animated.Value(1);
|
|
|
|
|
2018-02-16 16:06:03 +00:00
|
|
|
this.state.hintBoxAnimation = new Animated.Value(0);
|
|
|
|
|
2018-02-26 16:14:46 +00:00
|
|
|
// Bind event handlers so they are only bound once per instance.
|
2018-02-16 16:06:03 +00:00
|
|
|
this._onFieldFocusChange = this._onFieldFocusChange.bind(this);
|
|
|
|
this._renderHintBox = this._renderHintBox.bind(this);
|
2018-05-29 12:51:55 +00:00
|
|
|
|
|
|
|
// Specially bind functions to avoid function definition on render.
|
|
|
|
this._onFieldBlur = this._onFieldFocusChange.bind(this, false);
|
|
|
|
this._onFieldFocus = this._onFieldFocusChange.bind(this, true);
|
2022-07-28 07:28:29 +00:00
|
|
|
this._onSettingsScreenFocused = this._onSettingsScreenFocused.bind(this);
|
2018-02-02 14:50:16 +00:00
|
|
|
}
|
|
|
|
|
2021-11-11 14:32:56 +00:00
|
|
|
_onFieldBlur: () => void;
|
|
|
|
|
|
|
|
_onFieldFocus: () => void;
|
|
|
|
|
|
|
|
_onJoin: () => void;
|
|
|
|
|
|
|
|
_onRoomChange: (string) => void;
|
|
|
|
|
|
|
|
_updateRoomname: () => void;
|
|
|
|
|
2017-08-17 13:50:49 +00:00
|
|
|
/**
|
2018-10-29 19:27:12 +00:00
|
|
|
* Implements React's {@link Component#componentDidMount()}. Invoked
|
|
|
|
* immediately after mounting occurs. Creates a local video track if none
|
2018-07-12 09:23:26 +00:00
|
|
|
* is available and the camera permission was already granted.
|
2017-08-17 13:50:49 +00:00
|
|
|
*
|
|
|
|
* @inheritdoc
|
|
|
|
* @returns {void}
|
|
|
|
*/
|
2018-10-29 19:27:12 +00:00
|
|
|
componentDidMount() {
|
|
|
|
super.componentDidMount();
|
2017-09-14 09:46:35 +00:00
|
|
|
|
2021-11-11 14:32:56 +00:00
|
|
|
const {
|
2022-06-16 09:49:07 +00:00
|
|
|
navigation,
|
|
|
|
t
|
2021-11-11 14:32:56 +00:00
|
|
|
} = this.props;
|
|
|
|
|
|
|
|
navigation.setOptions({
|
2022-06-16 09:49:07 +00:00
|
|
|
headerTitle: t('welcomepage.headerTitle')
|
2021-11-11 14:32:56 +00:00
|
|
|
});
|
2022-01-25 12:55:57 +00:00
|
|
|
|
|
|
|
navigation.addListener('focus', () => {
|
|
|
|
this._updateRoomname();
|
|
|
|
});
|
|
|
|
|
|
|
|
navigation.addListener('blur', () => {
|
|
|
|
this._clearTimeouts();
|
|
|
|
|
|
|
|
this.setState({
|
|
|
|
generatedRoomname: '',
|
|
|
|
insecureRoomName: false,
|
|
|
|
room: ''
|
|
|
|
});
|
|
|
|
});
|
2017-08-17 13:50:49 +00:00
|
|
|
}
|
2016-12-01 01:52:39 +00:00
|
|
|
|
2016-10-05 14:36:59 +00:00
|
|
|
/**
|
2017-09-14 09:46:35 +00:00
|
|
|
* Implements React's {@link Component#render()}. Renders a prompt for
|
|
|
|
* entering a room name.
|
2016-10-05 14:36:59 +00:00
|
|
|
*
|
2017-09-14 09:46:35 +00:00
|
|
|
* @inheritdoc
|
2016-10-05 14:36:59 +00:00
|
|
|
* @returns {ReactElement}
|
|
|
|
*/
|
|
|
|
render() {
|
2019-07-23 14:07:55 +00:00
|
|
|
// We want to have the welcome page support the reduced UI layout,
|
|
|
|
// but we ran into serious issues enabling it so we disable it
|
|
|
|
// until we have a proper fix in place. We leave the code here though, because
|
|
|
|
// this part should be fine when the bug is fixed.
|
|
|
|
//
|
|
|
|
// NOTE: when re-enabling, don't forget to uncomment the respective _mapStateToProps line too
|
|
|
|
|
|
|
|
/*
|
2019-06-26 14:59:20 +00:00
|
|
|
const { _reducedUI } = this.props;
|
2017-09-05 22:45:20 +00:00
|
|
|
|
2019-06-26 14:59:20 +00:00
|
|
|
if (_reducedUI) {
|
|
|
|
return this._renderReducedUI();
|
|
|
|
}
|
2019-07-23 14:07:55 +00:00
|
|
|
*/
|
2019-06-26 14:59:20 +00:00
|
|
|
|
|
|
|
return this._renderFullUI();
|
2016-11-29 20:04:56 +00:00
|
|
|
}
|
|
|
|
|
2020-05-18 12:07:09 +00:00
|
|
|
/**
|
|
|
|
* Renders the insecure room name warning.
|
|
|
|
*
|
|
|
|
* @inheritdoc
|
|
|
|
*/
|
|
|
|
_doRenderInsecureRoomNameWarning() {
|
|
|
|
return (
|
|
|
|
<View
|
|
|
|
style = { [
|
|
|
|
styles.messageContainer,
|
|
|
|
styles.insecureRoomNameWarningContainer
|
|
|
|
] }>
|
|
|
|
<Icon
|
|
|
|
src = { IconWarning }
|
|
|
|
style = { styles.insecureRoomNameWarningIcon } />
|
|
|
|
<Text style = { styles.insecureRoomNameWarningText }>
|
|
|
|
{ this.props.t('security.insecureRoomNameWarning') }
|
|
|
|
</Text>
|
|
|
|
</View>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2018-02-16 16:06:03 +00:00
|
|
|
/**
|
|
|
|
* Constructs a style array to handle the hint box animation.
|
|
|
|
*
|
|
|
|
* @private
|
|
|
|
* @returns {Array<Object>}
|
|
|
|
*/
|
|
|
|
_getHintBoxStyle() {
|
|
|
|
return [
|
2020-05-18 12:07:09 +00:00
|
|
|
styles.messageContainer,
|
2018-02-16 16:06:03 +00:00
|
|
|
styles.hintContainer,
|
|
|
|
{
|
|
|
|
opacity: this.state.hintBoxAnimation
|
|
|
|
}
|
|
|
|
];
|
|
|
|
}
|
|
|
|
|
2021-11-11 14:32:56 +00:00
|
|
|
_onFieldFocusChange: (boolean) => void;
|
|
|
|
|
2018-02-16 16:06:03 +00:00
|
|
|
/**
|
|
|
|
* 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.
|
2018-05-29 12:51:55 +00:00
|
|
|
* @returns {void}
|
2018-02-16 16:06:03 +00:00
|
|
|
*/
|
|
|
|
_onFieldFocusChange(focused) {
|
2021-01-12 13:37:44 +00:00
|
|
|
if (focused) {
|
|
|
|
// Stop placeholder animation.
|
|
|
|
this._clearTimeouts();
|
|
|
|
this.setState({
|
|
|
|
_fieldFocused: true,
|
|
|
|
roomPlaceholder: ''
|
2018-05-29 12:51:55 +00:00
|
|
|
});
|
2021-01-12 13:37:44 +00:00
|
|
|
} else {
|
|
|
|
// Restart room placeholder animation.
|
|
|
|
this._updateRoomname();
|
|
|
|
}
|
2018-05-29 12:51:55 +00:00
|
|
|
|
|
|
|
Animated.timing(
|
2021-11-11 14:32:56 +00:00
|
|
|
|
2018-05-29 12:51:55 +00:00
|
|
|
this.state.hintBoxAnimation,
|
2021-11-11 14:32:56 +00:00
|
|
|
|
2018-05-29 12:51:55 +00:00
|
|
|
{
|
|
|
|
duration: 300,
|
2022-01-07 13:22:49 +00:00
|
|
|
toValue: focused ? 1 : 0,
|
|
|
|
useNativeDriver: true
|
2018-05-29 12:51:55 +00:00
|
|
|
})
|
|
|
|
.start(animationState =>
|
2021-11-11 14:32:56 +00:00
|
|
|
|
2018-05-29 12:51:55 +00:00
|
|
|
animationState.finished
|
2021-11-11 14:32:56 +00:00
|
|
|
|
|
|
|
&& !focused
|
2018-05-29 12:51:55 +00:00
|
|
|
&& this.setState({
|
|
|
|
_fieldFocused: false
|
|
|
|
}));
|
2018-02-16 16:06:03 +00:00
|
|
|
}
|
|
|
|
|
2022-07-28 07:28:29 +00:00
|
|
|
_onSettingsScreenFocused: boolean => void;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Callback for when the settings screen is focused.
|
|
|
|
*
|
|
|
|
* @private
|
|
|
|
* @param {boolean} focused - The focused state of the screen.
|
|
|
|
* @returns {void}
|
|
|
|
*/
|
|
|
|
_onSettingsScreenFocused(focused) {
|
|
|
|
this.setState({
|
|
|
|
isSettingsScreenFocused: focused
|
|
|
|
});
|
|
|
|
|
|
|
|
this.props.navigation.setOptions({
|
|
|
|
headerShown: !focused
|
|
|
|
});
|
|
|
|
|
|
|
|
Animated.timing(
|
|
|
|
this.state.roomNameInputAnimation,
|
|
|
|
{
|
|
|
|
toValue: focused ? 0 : 1,
|
|
|
|
duration: 500,
|
|
|
|
useNativeDriver: true
|
|
|
|
})
|
|
|
|
.start();
|
|
|
|
}
|
|
|
|
|
2022-11-08 15:46:46 +00:00
|
|
|
_renderHintBox: () => React.ReactElement;
|
2018-02-02 14:50:16 +00:00
|
|
|
|
2018-02-16 16:06:03 +00:00
|
|
|
/**
|
|
|
|
* Renders the hint box if necessary.
|
|
|
|
*
|
|
|
|
* @private
|
|
|
|
* @returns {React$Node}
|
|
|
|
*/
|
|
|
|
_renderHintBox() {
|
2021-11-11 14:32:56 +00:00
|
|
|
const { t } = this.props;
|
2018-02-16 16:06:03 +00:00
|
|
|
|
2021-11-11 14:32:56 +00:00
|
|
|
if (this.state._fieldFocused) {
|
2018-02-16 16:06:03 +00:00
|
|
|
return (
|
2018-02-26 16:14:46 +00:00
|
|
|
<Animated.View style = { this._getHintBoxStyle() }>
|
2018-02-16 16:06:03 +00:00
|
|
|
<View style = { styles.hintTextContainer } >
|
2018-04-04 12:50:12 +00:00
|
|
|
<Text style = { styles.hintText }>
|
2018-02-26 16:14:46 +00:00
|
|
|
{ t('welcomepage.roomnameHint') }
|
2018-02-16 16:06:03 +00:00
|
|
|
</Text>
|
|
|
|
</View>
|
|
|
|
<View style = { styles.hintButtonContainer } >
|
2018-02-26 16:14:46 +00:00
|
|
|
{ this._renderJoinButton() }
|
2018-02-16 16:06:03 +00:00
|
|
|
</View>
|
|
|
|
</Animated.View>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
2017-09-14 09:46:35 +00:00
|
|
|
/**
|
|
|
|
* Renders the join button.
|
|
|
|
*
|
|
|
|
* @private
|
|
|
|
* @returns {ReactElement}
|
|
|
|
*/
|
|
|
|
_renderJoinButton() {
|
2018-06-07 20:32:18 +00:00
|
|
|
const { t } = this.props;
|
2022-11-09 10:59:17 +00:00
|
|
|
let joinButton;
|
2017-09-14 09:46:35 +00:00
|
|
|
|
|
|
|
|
|
|
|
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.
|
2022-11-09 10:59:17 +00:00
|
|
|
joinButton = (
|
|
|
|
<TouchableHighlight
|
|
|
|
accessibilityLabel =
|
|
|
|
{ t('welcomepage.accessibilityLabel.join') }
|
|
|
|
onPress = { this._onJoin }
|
|
|
|
style = { styles.button }>
|
|
|
|
<View>
|
|
|
|
<LoadingIndicator
|
|
|
|
color = { BaseTheme.palette.icon01 }
|
|
|
|
size = 'small' />
|
|
|
|
</View>
|
|
|
|
</TouchableHighlight>
|
2017-09-14 09:46:35 +00:00
|
|
|
);
|
|
|
|
} else {
|
2022-11-09 10:59:17 +00:00
|
|
|
joinButton = (
|
|
|
|
<Button
|
|
|
|
accessibilityLabel = { 'welcomepage.accessibilityLabel.join' }
|
|
|
|
labelKey = { 'welcomepage.join' }
|
|
|
|
labelStyle = { styles.joinButtonLabel }
|
|
|
|
onClick = { this._onJoin }
|
|
|
|
style = { styles.buttonText }
|
|
|
|
type = { BUTTON_TYPES.PRIMARY } />
|
2017-09-14 09:46:35 +00:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2022-11-09 10:59:17 +00:00
|
|
|
return joinButton;
|
2017-09-14 09:46:35 +00:00
|
|
|
}
|
2019-06-26 14:59:20 +00:00
|
|
|
|
|
|
|
/**
|
2022-07-28 07:28:29 +00:00
|
|
|
* Renders the room name input.
|
2019-06-26 14:59:20 +00:00
|
|
|
*
|
2022-07-28 07:28:29 +00:00
|
|
|
* @private
|
2019-06-26 14:59:20 +00:00
|
|
|
* @returns {ReactElement}
|
|
|
|
*/
|
2022-07-28 07:28:29 +00:00
|
|
|
_renderRoomNameInput() {
|
2019-06-26 14:59:20 +00:00
|
|
|
const roomnameAccLabel = 'welcomepage.accessibilityLabel.roomname';
|
2021-11-17 12:54:00 +00:00
|
|
|
const { t } = this.props;
|
2022-07-28 07:28:29 +00:00
|
|
|
const { isSettingsScreenFocused } = this.state;
|
2019-06-26 14:59:20 +00:00
|
|
|
|
2022-07-28 07:28:29 +00:00
|
|
|
return (
|
|
|
|
<Animated.View
|
|
|
|
style = { [
|
|
|
|
isSettingsScreenFocused && styles.roomNameInputContainer,
|
|
|
|
{ opacity: this.state.roomNameInputAnimation }
|
|
|
|
] }>
|
|
|
|
<SafeAreaView style = { styles.roomContainer }>
|
|
|
|
<View style = { styles.joinControls } >
|
|
|
|
<Text style = { styles.enterRoomText }>
|
|
|
|
{ t('welcomepage.roomname') }
|
|
|
|
</Text>
|
2022-11-08 15:46:46 +00:00
|
|
|
<Input
|
2022-07-28 07:28:29 +00:00
|
|
|
accessibilityLabel = { t(roomnameAccLabel) }
|
|
|
|
autoCapitalize = { 'none' }
|
|
|
|
autoComplete = { 'off' }
|
|
|
|
autoCorrect = { false }
|
|
|
|
autoFocus = { false }
|
2022-11-08 15:46:46 +00:00
|
|
|
customStyles = {{ input: styles.customInput }}
|
2022-07-28 07:28:29 +00:00
|
|
|
onBlur = { this._onFieldBlur }
|
2022-11-08 15:46:46 +00:00
|
|
|
onChange = { this._onRoomChange }
|
2022-07-28 07:28:29 +00:00
|
|
|
onFocus = { this._onFieldFocus }
|
|
|
|
onSubmitEditing = { this._onJoin }
|
|
|
|
placeholder = { this.state.roomPlaceholder }
|
|
|
|
returnKeyType = { 'go' }
|
|
|
|
value = { this.state.room } />
|
|
|
|
{
|
|
|
|
this._renderInsecureRoomNameWarning()
|
|
|
|
}
|
|
|
|
{
|
|
|
|
this._renderHintBox()
|
|
|
|
}
|
|
|
|
</View>
|
|
|
|
</SafeAreaView>
|
|
|
|
</Animated.View>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Renders the full welcome page.
|
|
|
|
*
|
|
|
|
* @returns {ReactElement}
|
|
|
|
*/
|
|
|
|
_renderFullUI() {
|
2019-06-26 14:59:20 +00:00
|
|
|
return (
|
2021-11-11 14:32:56 +00:00
|
|
|
<>
|
2022-07-28 07:28:29 +00:00
|
|
|
{ this._renderRoomNameInput() }
|
2021-11-17 12:54:00 +00:00
|
|
|
<View style = { styles.welcomePage }>
|
2022-01-27 10:46:49 +00:00
|
|
|
<WelcomePageTabs
|
|
|
|
disabled = { this.state._fieldFocused }
|
2022-07-28 07:28:29 +00:00
|
|
|
onListContainerPress = { this._onFieldBlur }
|
|
|
|
onSettingsScreenFocused = { this._onSettingsScreenFocused } />
|
2021-11-17 12:54:00 +00:00
|
|
|
</View>
|
2021-11-11 14:32:56 +00:00
|
|
|
</>
|
2019-06-26 14:59:20 +00:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Renders a "reduced" version of the welcome page.
|
|
|
|
*
|
|
|
|
* @returns {ReactElement}
|
|
|
|
*/
|
|
|
|
_renderReducedUI() {
|
|
|
|
const { t } = this.props;
|
|
|
|
|
|
|
|
return (
|
|
|
|
<View style = { styles.reducedUIContainer }>
|
|
|
|
<Text style = { styles.reducedUIText }>
|
|
|
|
{ t('welcomepage.reducedUIText', { app: getName() }) }
|
|
|
|
</Text>
|
|
|
|
</View>
|
|
|
|
);
|
|
|
|
}
|
2016-10-05 14:36:59 +00:00
|
|
|
}
|
|
|
|
|
2019-03-05 17:41:39 +00:00
|
|
|
/**
|
|
|
|
* Maps part of the Redux state to the props of this component.
|
|
|
|
*
|
|
|
|
* @param {Object} state - The Redux state.
|
2019-06-26 14:59:20 +00:00
|
|
|
* @returns {Object}
|
2019-03-05 17:41:39 +00:00
|
|
|
*/
|
|
|
|
function _mapStateToProps(state) {
|
|
|
|
return {
|
2022-10-06 11:55:44 +00:00
|
|
|
..._abstractMapStateToProps(state)
|
2019-07-23 14:07:55 +00:00
|
|
|
|
|
|
|
// _reducedUI: state['features/base/responsive-ui'].reducedUI
|
2019-03-05 17:41:39 +00:00
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2017-02-23 16:56:25 +00:00
|
|
|
export default translate(connect(_mapStateToProps)(WelcomePage));
|