You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

WelcomePage.native.js 8.2KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264
  1. import React from 'react';
  2. import {
  3. Animated,
  4. Keyboard,
  5. SafeAreaView,
  6. TextInput,
  7. TouchableHighlight,
  8. TouchableOpacity,
  9. View
  10. } from 'react-native';
  11. import { connect } from 'react-redux';
  12. import { translate } from '../../base/i18n';
  13. import { Icon } from '../../base/font-icons';
  14. import { MEDIA_TYPE } from '../../base/media';
  15. import { Header, LoadingIndicator, Text } from '../../base/react';
  16. import { ColorPalette } from '../../base/styles';
  17. import {
  18. createDesiredLocalTracks,
  19. destroyLocalTracks
  20. } from '../../base/tracks';
  21. import { SettingsView } from '../../settings';
  22. import { AbstractWelcomePage, _mapStateToProps } from './AbstractWelcomePage';
  23. import { setSideBarVisible } from '../actions';
  24. import LocalVideoTrackUnderlay from './LocalVideoTrackUnderlay';
  25. import styles, { PLACEHOLDER_TEXT_COLOR } from './styles';
  26. import VideoSwitch from './VideoSwitch';
  27. import WelcomePageLists from './WelcomePageLists';
  28. import WelcomePageSideBar from './WelcomePageSideBar';
  29. /**
  30. * The native container rendering the welcome page.
  31. *
  32. * @extends AbstractWelcomePage
  33. */
  34. class WelcomePage extends AbstractWelcomePage {
  35. /**
  36. * Constructor of the Component.
  37. *
  38. * @inheritdoc
  39. */
  40. constructor(props) {
  41. super(props);
  42. this.state._fieldFocused = false;
  43. this.state.hintBoxAnimation = new Animated.Value(0);
  44. // Bind event handlers so they are only bound once per instance.
  45. this._getHintBoxStyle = this._getHintBoxStyle.bind(this);
  46. this._onFieldFocusChange = this._onFieldFocusChange.bind(this);
  47. this._onShowSideBar = this._onShowSideBar.bind(this);
  48. this._renderHintBox = this._renderHintBox.bind(this);
  49. }
  50. /**
  51. * Implements React's {@link Component#componentWillMount()}. Invoked
  52. * immediately before mounting occurs. Creates a local video track if none
  53. * is available.
  54. *
  55. * @inheritdoc
  56. * @returns {void}
  57. */
  58. componentWillMount() {
  59. super.componentWillMount();
  60. const { dispatch } = this.props;
  61. if (this.props._settings.startAudioOnly) {
  62. dispatch(destroyLocalTracks());
  63. } else {
  64. dispatch(createDesiredLocalTracks(MEDIA_TYPE.VIDEO));
  65. }
  66. }
  67. /**
  68. * Implements React's {@link Component#render()}. Renders a prompt for
  69. * entering a room name.
  70. *
  71. * @inheritdoc
  72. * @returns {ReactElement}
  73. */
  74. render() {
  75. const { buttonStyle, pageStyle } = Header;
  76. const { t } = this.props;
  77. return (
  78. <LocalVideoTrackUnderlay style = { styles.welcomePage }>
  79. <View style = { pageStyle }>
  80. <Header style = { styles.header }>
  81. <TouchableOpacity onPress = { this._onShowSideBar } >
  82. <Icon
  83. name = 'menu'
  84. style = { buttonStyle } />
  85. </TouchableOpacity>
  86. <VideoSwitch />
  87. </Header>
  88. <SafeAreaView style = { styles.roomContainer } >
  89. <View style = { styles.joinControls } >
  90. <TextInput
  91. accessibilityLabel = { 'Input room name.' }
  92. autoCapitalize = 'none'
  93. autoComplete = { false }
  94. autoCorrect = { false }
  95. autoFocus = { false }
  96. onBlur = { this._onFieldFocusChange(false) }
  97. onChangeText = { this._onRoomChange }
  98. onFocus = { this._onFieldFocusChange(true) }
  99. onSubmitEditing = { this._onJoin }
  100. placeholder = { t('welcomepage.roomname') }
  101. placeholderTextColor = {
  102. PLACEHOLDER_TEXT_COLOR
  103. }
  104. returnKeyType = { 'go' }
  105. style = { styles.textInput }
  106. underlineColorAndroid = 'transparent'
  107. value = { this.state.room } />
  108. {
  109. this._renderHintBox()
  110. }
  111. </View>
  112. </SafeAreaView>
  113. <WelcomePageLists disabled = { this.state._fieldFocused } />
  114. <SettingsView />
  115. </View>
  116. <WelcomePageSideBar />
  117. </LocalVideoTrackUnderlay>
  118. );
  119. }
  120. /**
  121. * Constructs a style array to handle the hint box animation.
  122. *
  123. * @private
  124. * @returns {Array<Object>}
  125. */
  126. _getHintBoxStyle() {
  127. return [
  128. styles.hintContainer,
  129. {
  130. opacity: this.state.hintBoxAnimation
  131. }
  132. ];
  133. }
  134. /**
  135. * Callback for when the room field's focus changes so the hint box
  136. * must be rendered or removed.
  137. *
  138. * @private
  139. * @param {boolean} focused - The focused state of the field.
  140. * @returns {Function}
  141. */
  142. _onFieldFocusChange(focused) {
  143. return () => {
  144. focused
  145. && this.setState({
  146. _fieldFocused: true
  147. });
  148. Animated.timing(
  149. this.state.hintBoxAnimation,
  150. {
  151. duration: 300,
  152. toValue: focused ? 1 : 0
  153. })
  154. .start(animationState =>
  155. animationState.finished
  156. && !focused
  157. && this.setState({
  158. _fieldFocused: false
  159. }));
  160. };
  161. }
  162. /**
  163. * Toggles the side bar.
  164. *
  165. * @private
  166. * @returns {void}
  167. */
  168. _onShowSideBar() {
  169. Keyboard.dismiss();
  170. this.props.dispatch(setSideBarVisible(true));
  171. }
  172. /**
  173. * Renders the hint box if necessary.
  174. *
  175. * @private
  176. * @returns {React$Node}
  177. */
  178. _renderHintBox() {
  179. if (this.state._fieldFocused) {
  180. const { t } = this.props;
  181. return (
  182. <Animated.View style = { this._getHintBoxStyle() }>
  183. <View style = { styles.hintTextContainer } >
  184. <Text style = { styles.hintText }>
  185. { t('welcomepage.roomnameHint') }
  186. </Text>
  187. </View>
  188. <View style = { styles.hintButtonContainer } >
  189. { this._renderJoinButton() }
  190. </View>
  191. </Animated.View>
  192. );
  193. }
  194. return null;
  195. }
  196. /**
  197. * Renders the join button.
  198. *
  199. * @private
  200. * @returns {ReactElement}
  201. */
  202. _renderJoinButton() {
  203. let children;
  204. /* eslint-disable no-extra-parens */
  205. if (this.state.joining) {
  206. // TouchableHighlight is picky about what its children can be, so
  207. // wrap it in a native component, i.e. View to avoid having to
  208. // modify non-native children.
  209. children = (
  210. <View>
  211. <LoadingIndicator
  212. color = { styles.buttonText.color }
  213. size = 'small' />
  214. </View>
  215. );
  216. } else {
  217. children = (
  218. <Text style = { styles.buttonText }>
  219. { this.props.t('welcomepage.join') }
  220. </Text>
  221. );
  222. }
  223. /* eslint-enable no-extra-parens */
  224. const buttonDisabled = this._isJoinDisabled();
  225. return (
  226. <TouchableHighlight
  227. accessibilityLabel = { 'Tap to Join.' }
  228. disabled = { buttonDisabled }
  229. onPress = { this._onJoin }
  230. style = { [
  231. styles.button,
  232. buttonDisabled ? styles.buttonDisabled : null
  233. ] }
  234. underlayColor = { ColorPalette.white }>
  235. { children }
  236. </TouchableHighlight>
  237. );
  238. }
  239. }
  240. export default translate(connect(_mapStateToProps)(WelcomePage));