Files
jitsi-meet/react/features/welcome/components/WelcomePage.native.tsx

418 lines
12 KiB
TypeScript
Raw Normal View History

import React from 'react';
import {
Animated,
NativeSyntheticEvent,
StyleProp,
TextInputFocusEventData,
TextStyle,
TouchableHighlight,
View,
ViewStyle
} from 'react-native';
import { SafeAreaView } from 'react-native-safe-area-context';
import { connect } from 'react-redux';
import { getName } from '../../app/functions.native';
import { IReduxState } from '../../app/types';
import { translate } from '../../base/i18n/functions';
import Icon from '../../base/icons/components/Icon';
import { IconWarning } from '../../base/icons/svg';
import LoadingIndicator from '../../base/react/components/native/LoadingIndicator';
import Text from '../../base/react/components/native/Text';
import BaseTheme from '../../base/ui/components/BaseTheme.native';
2022-11-09 12:59:17 +02:00
import Button from '../../base/ui/components/native/Button';
import Input from '../../base/ui/components/native/Input';
2022-11-09 12:59:17 +02:00
import { BUTTON_TYPES } from '../../base/ui/constants.native';
import getUnsafeRoomText from '../../base/util/getUnsafeRoomText.native';
2022-01-25 14:55:57 +02:00
import WelcomePageTabs
from '../../mobile/navigation/components/welcome/components/WelcomePageTabs';
import {
IProps as AbstractProps,
AbstractWelcomePage,
_mapStateToProps as _abstractMapStateToProps
} from './AbstractWelcomePage';
import styles from './styles.native';
interface IProps extends AbstractProps {
/**
* Function for getting the unsafe room text.
*/
getUnsafeRoomTextFn: Function;
/**
* Default prop for navigating between screen components(React Navigation).
*/
navigation: any;
}
/**
* The native container rendering the welcome page.
*
2021-11-04 22:10:43 +01:00
* @augments AbstractWelcomePage
*/
class WelcomePage extends AbstractWelcomePage<IProps> {
_onFieldBlur: (e: NativeSyntheticEvent<TextInputFocusEventData>) => void;
_onFieldFocus: (e: NativeSyntheticEvent<TextInputFocusEventData>) => void;
2018-02-02 15:50:16 +01:00
/**
* Constructor of the Component.
*
* @inheritdoc
*/
constructor(props: IProps) {
2018-02-02 15:50:16 +01:00
super(props);
this.state._fieldFocused = false;
this.state.isSettingsScreenFocused = false;
this.state.roomNameInputAnimation = new Animated.Value(1);
2018-02-16 10:06:03 -06:00
this.state.hintBoxAnimation = new Animated.Value(0);
// Bind event handlers so they are only bound once per instance.
2018-02-16 10:06:03 -06:00
this._onFieldFocusChange = this._onFieldFocusChange.bind(this);
this._renderHintBox = this._renderHintBox.bind(this);
2018-05-29 14:51:55 +02:00
// Specially bind functions to avoid function definition on render.
this._onFieldBlur = this._onFieldFocusChange.bind(this, false);
this._onFieldFocus = this._onFieldFocusChange.bind(this, true);
this._onSettingsScreenFocused = this._onSettingsScreenFocused.bind(this);
2018-02-02 15:50:16 +01:00
}
/**
* Implements React's {@link Component#componentDidMount()}. Invoked
* immediately after mounting occurs. Creates a local video track if none
* is available and the camera permission was already granted.
*
* @inheritdoc
* @returns {void}
*/
override componentDidMount() {
super.componentDidMount();
const {
navigation,
t
} = this.props;
navigation.setOptions({
headerTitle: t('welcomepage.headerTitle')
});
2022-01-25 14:55:57 +02:00
navigation.addListener('focus', () => {
this._updateRoomName();
2022-01-25 14:55:57 +02:00
});
navigation.addListener('blur', () => {
this._clearTimeouts();
this.setState({
generatedRoomName: '',
2022-01-25 14:55:57 +02:00
insecureRoomName: false,
room: ''
});
});
}
/**
* Implements React's {@link Component#render()}. Renders a prompt for
* entering a room name.
*
* @inheritdoc
* @returns {ReactElement}
*/
override render() {
// 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
/*
const { _reducedUI } = this.props;
if (_reducedUI) {
return this._renderReducedUI();
}
*/
return this._renderFullUI();
}
2020-05-18 14:07:09 +02:00
/**
* Renders the insecure room name warning.
*
* @inheritdoc
*/
_doRenderInsecureRoomNameWarning() {
return (
<View
style = { [
styles.messageContainer,
styles.insecureRoomNameWarningContainer as ViewStyle
2020-05-18 14:07:09 +02:00
] }>
<Icon
src = { IconWarning }
style = { styles.insecureRoomNameWarningIcon } />
<Text style = { styles.insecureRoomNameWarningText }>
{ this.props.getUnsafeRoomTextFn(this.props.t) }
2020-05-18 14:07:09 +02:00
</Text>
</View>
);
}
2018-02-16 10:06:03 -06:00
/**
* Constructs a style array to handle the hint box animation.
*
* @private
* @returns {Array<Object>}
*/
_getHintBoxStyle() {
return [
2020-05-18 14:07:09 +02:00
styles.messageContainer,
2018-02-16 10:06:03 -06:00
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.
2018-05-29 14:51:55 +02:00
* @returns {void}
2018-02-16 10:06:03 -06:00
*/
_onFieldFocusChange(focused: boolean) {
if (focused) {
// Stop placeholder animation.
this._clearTimeouts();
this.setState({
_fieldFocused: true,
roomPlaceholder: ''
2018-05-29 14:51:55 +02:00
});
} else {
// Restart room placeholder animation.
this._updateRoomName();
}
2018-05-29 14:51:55 +02:00
Animated.timing(
2018-05-29 14:51:55 +02:00
this.state.hintBoxAnimation,
2018-05-29 14:51:55 +02:00
{
duration: 300,
toValue: focused ? 1 : 0,
useNativeDriver: true
2018-05-29 14:51:55 +02:00
})
.start(animationState =>
2018-05-29 14:51:55 +02:00
animationState.finished
&& !focused
2018-05-29 14:51:55 +02:00
&& this.setState({
_fieldFocused: false
}));
2018-02-16 10:06:03 -06:00
}
/**
* Callback for when the settings screen is focused.
*
* @private
* @param {boolean} focused - The focused state of the screen.
* @returns {void}
*/
_onSettingsScreenFocused(focused: boolean) {
this.setState({
isSettingsScreenFocused: focused
});
this.props.navigation.setOptions({
headerShown: !focused
});
Animated.timing(
this.state.roomNameInputAnimation,
{
toValue: focused ? 0 : 1,
duration: 500,
useNativeDriver: true
})
.start();
}
2018-02-16 10:06:03 -06:00
/**
* Renders the hint box if necessary.
*
* @private
* @returns {React$Node}
*/
_renderHintBox() {
const { t } = this.props;
2018-02-16 10:06:03 -06:00
if (this.state._fieldFocused) {
2018-02-16 10:06:03 -06:00
return (
<Animated.View style = { this._getHintBoxStyle() as ViewStyle[] }>
<View style = { styles.hintTextContainer as ViewStyle } >
<Text style = { styles.hintText as TextStyle }>
{ t('welcomepage.roomnameHint') }
2018-02-16 10:06:03 -06:00
</Text>
</View>
<View style = { styles.hintButtonContainer as ViewStyle } >
{ this._renderJoinButton() }
2018-02-16 10:06:03 -06:00
</View>
</Animated.View>
);
}
return null;
}
/**
* Renders the join button.
*
* @private
* @returns {ReactElement}
*/
_renderJoinButton() {
fix(i18n) Accessiblity labels translations (#3071) * fix(toolbar): accessibilityLabel should be translatable. This commit adds a helper property to get the accessibilityLabel of an item, providing a translation if one is available. This mimics the behavior of label and tooltip. * fix(toolbar) 'hangup' button accessibilityLabel i18n * fix(toolbar) 'mute' button accessibilityLabel i18n * fix(toolbar) 'videomute' button accessibilityLabel i18n * fix(toolbar) 'moreActions' button accessibilityLabel i18n * fix(toolbar) 'shareRoom' button accessibilityLabel i18n * fix(toolbar) 'audioRoute' button accessibilityLabel i18n * fix(toolbar) 'toggleCamera' button accessibilityLabel i18n * fix(toolbar) 'audioOnly' button accessibilityLabel i18n * fix(toolbar) 'roomLock' button accessibilityLabel i18n * fix(toolbar) 'pip' button accessibilityLabel i18n * fix(toolbar) 'invite' button accessibilityLabel i18n * fix(toolbar) 'raiseHand' button accessibilityLabel i18n * fix(toolbar) 'chat' button accessibilityLabel i18n * fix(toolbar) 'shareYourScreen' button accessibilityLabel i18n * fix(toolbar) 'fullScreen' button accessibilityLabel i18n * fix(toolbar) 'sharedvideo' button accessibilityLabel i18n * fix(toolbar) 'document' button accessibilityLabel i18n * fix(toolbar) 'speakerStats' button accessibilityLabel i18n * fix(toolbar) 'feedback' button accessibilityLabel i18n * fix(toolbar) 'shortcuts' button accessibilityLabel i18n * fix(toolbar) 'recording' button accessibilityLabel i18n * fix(toolbar) 'settings' button accessibilityLabel i18n * fix(welcomepage) accessibilityLabels i18n * fix(toolbar) 'info' button accessibilityLabel i18n * fix(i18n): Add translation to various aria-label property values. * fix(i18n): Differentiate between overflow menu and button.
2018-06-07 22:32:18 +02:00
const { t } = this.props;
2022-11-09 12:59:17 +02:00
let joinButton;
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 12:59:17 +02:00
joinButton = (
<TouchableHighlight
accessibilityLabel =
{ t('welcomepage.accessibilityLabel.join') }
onPress = { this._onJoin }
style = { styles.button as ViewStyle }>
2022-11-09 12:59:17 +02:00
<View>
<LoadingIndicator
color = { BaseTheme.palette.icon01 }
size = 'small' />
</View>
</TouchableHighlight>
);
} else {
2022-11-09 12:59:17 +02:00
joinButton = (
<Button
accessibilityLabel = { 'welcomepage.accessibilityLabel.join' }
labelKey = { 'welcomepage.join' }
labelStyle = { styles.joinButtonLabel }
onClick = { this._onJoin }
type = { BUTTON_TYPES.PRIMARY } />
);
}
2022-11-09 12:59:17 +02:00
return joinButton;
}
/**
* Renders the room name input.
*
* @private
* @returns {ReactElement}
*/
_renderRoomNameInput() {
const roomnameAccLabel = 'welcomepage.accessibilityLabel.roomname';
const { t } = this.props;
const { isSettingsScreenFocused } = this.state;
return (
<Animated.View
style = { [
isSettingsScreenFocused && styles.roomNameInputContainer,
{ opacity: this.state.roomNameInputAnimation }
] as StyleProp<ViewStyle> }>
<SafeAreaView
edges = { [ 'left', 'right' ] }
style = { styles.roomContainer as StyleProp<ViewStyle> }>
<Text style = { styles.enterRoomText as StyleProp<TextStyle> }>
{ t('welcomepage.roomname') }
</Text>
<Input
accessibilityLabel = { t(roomnameAccLabel) }
autoCapitalize = { 'none' }
autoFocus = { false }
customStyles = {{ input: styles.customInput }}
onBlur = { this._onFieldBlur }
onChange = { this._onRoomChange }
onFocus = { this._onFieldFocus }
onSubmitEditing = { this._onJoin }
placeholder = { this.state.roomPlaceholder }
returnKeyType = { 'go' }
value = { this.state.room } />
{
this._renderInsecureRoomNameWarning()
}
{
this._renderHintBox()
}
</SafeAreaView>
</Animated.View>
);
}
/**
* Renders the full welcome page.
*
* @returns {ReactElement}
*/
_renderFullUI() {
return (
<>
{ this._renderRoomNameInput() }
<View style = { styles.welcomePage as ViewStyle }>
<WelcomePageTabs
disabled = { Boolean(this.state._fieldFocused) } // @ts-ignore
onListContainerPress = { this._onFieldBlur }
onSettingsScreenFocused = { this._onSettingsScreenFocused } />
</View>
</>
);
}
/**
* Renders a "reduced" version of the welcome page.
*
* @returns {ReactElement}
*/
_renderReducedUI() {
const { t } = this.props;
return (
<View style = { styles.reducedUIContainer as ViewStyle }>
<Text style = { styles.reducedUIText }>
{ t('welcomepage.reducedUIText', { app: getName() }) }
</Text>
</View>
);
}
}
/**
* Maps part of the Redux state to the props of this component.
*
* @param {Object} state - The Redux state.
* @returns {Object}
*/
function _mapStateToProps(state: IReduxState) {
return {
..._abstractMapStateToProps(state),
// _reducedUI: state['features/base/responsive-ui'].reducedUI
getUnsafeRoomTextFn: (t: Function) => getUnsafeRoomText(state, t, 'welcome')
};
}
export default translate(connect(_mapStateToProps)(WelcomePage));