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 6.8KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217
  1. import React from 'react';
  2. import {
  3. SafeAreaView,
  4. Switch,
  5. TextInput,
  6. TouchableHighlight,
  7. TouchableOpacity,
  8. View
  9. } from 'react-native';
  10. import { connect } from 'react-redux';
  11. import { AppSettings } from '../../app-settings';
  12. import { translate } from '../../base/i18n';
  13. import { Icon } from '../../base/font-icons';
  14. import { MEDIA_TYPE } from '../../base/media';
  15. import { updateProfile } from '../../base/profile';
  16. import {
  17. LoadingIndicator,
  18. Header,
  19. Text
  20. } from '../../base/react';
  21. import { ColorPalette, PlatformElements } from '../../base/styles';
  22. import {
  23. createDesiredLocalTracks,
  24. destroyLocalTracks
  25. } from '../../base/tracks';
  26. import { RecentList } from '../../recent-list';
  27. import { setSideBarVisibility } from '../actions';
  28. import { AbstractWelcomePage, _mapStateToProps } from './AbstractWelcomePage';
  29. import LocalVideoTrackUnderlay from './LocalVideoTrackUnderlay';
  30. import styles, {
  31. PLACEHOLDER_TEXT_COLOR,
  32. SWITCH_THUMB_COLOR,
  33. SWITCH_UNDER_COLOR
  34. } from './styles';
  35. import WelcomePageSideBar from './WelcomePageSideBar';
  36. /**
  37. * The native container rendering the welcome page.
  38. *
  39. * @extends AbstractWelcomePage
  40. */
  41. class WelcomePage extends AbstractWelcomePage {
  42. /**
  43. * WelcomePage component's property types.
  44. *
  45. * @static
  46. */
  47. static propTypes = AbstractWelcomePage.propTypes;
  48. /**
  49. * Constructor of the Component.
  50. *
  51. * @inheritdoc
  52. */
  53. constructor(props) {
  54. super(props);
  55. this._onShowSideBar = this._onShowSideBar.bind(this);
  56. this._onStartAudioOnlyChange = this._onStartAudioOnlyChange.bind(this);
  57. }
  58. /**
  59. * Implements React's {@link Component#componentWillMount()}. Invoked
  60. * immediately before mounting occurs. Creates a local video track if none
  61. * is available.
  62. *
  63. * @inheritdoc
  64. * @returns {void}
  65. */
  66. componentWillMount() {
  67. super.componentWillMount();
  68. const { dispatch } = this.props;
  69. if (this.props._profile.startAudioOnly) {
  70. dispatch(destroyLocalTracks());
  71. } else {
  72. dispatch(createDesiredLocalTracks(MEDIA_TYPE.VIDEO));
  73. }
  74. }
  75. /**
  76. * Implements React's {@link Component#render()}. Renders a prompt for
  77. * entering a room name.
  78. *
  79. * @inheritdoc
  80. * @returns {ReactElement}
  81. */
  82. render() {
  83. const { t, _profile } = this.props;
  84. return (
  85. <LocalVideoTrackUnderlay style = { styles.welcomePage }>
  86. <View style = { PlatformElements.page }>
  87. <Header style = { styles.header }>
  88. <TouchableOpacity onPress = { this._onShowSideBar } >
  89. <Icon
  90. name = 'menu'
  91. style = { PlatformElements.headerButton } />
  92. </TouchableOpacity>
  93. <View style = { styles.audioVideoSwitchContainer }>
  94. <Text style = { PlatformElements.headerText } >
  95. { t('welcomepage.videoEnabledLabel') }
  96. </Text>
  97. <Switch
  98. onTintColor = { SWITCH_UNDER_COLOR }
  99. onValueChange = { this._onStartAudioOnlyChange }
  100. style = { styles.audioVideoSwitch }
  101. thumbTintColor = { SWITCH_THUMB_COLOR }
  102. value = { _profile.startAudioOnly } />
  103. <Text style = { PlatformElements.headerText } >
  104. { t('welcomepage.audioOnlyLabel') }
  105. </Text>
  106. </View>
  107. </Header>
  108. <SafeAreaView style = { styles.roomContainer } >
  109. <TextInput
  110. accessibilityLabel = { 'Input room name.' }
  111. autoCapitalize = 'none'
  112. autoComplete = { false }
  113. autoCorrect = { false }
  114. autoFocus = { false }
  115. onChangeText = { this._onRoomChange }
  116. onSubmitEditing = { this._onJoin }
  117. placeholder = { t('welcomepage.roomname') }
  118. placeholderTextColor = { PLACEHOLDER_TEXT_COLOR }
  119. returnKeyType = { 'go' }
  120. style = { styles.textInput }
  121. underlineColorAndroid = 'transparent'
  122. value = { this.state.room } />
  123. {
  124. this._renderJoinButton()
  125. }
  126. <RecentList />
  127. </SafeAreaView>
  128. <AppSettings />
  129. </View>
  130. <WelcomePageSideBar />
  131. </LocalVideoTrackUnderlay>
  132. );
  133. }
  134. /**
  135. * Toggles the side bar.
  136. *
  137. * @private
  138. * @returns {void}
  139. */
  140. _onShowSideBar() {
  141. this.props.dispatch(setSideBarVisibility(true));
  142. }
  143. /**
  144. * Handles the audio-video switch changes.
  145. *
  146. * @private
  147. * @param {boolean} startAudioOnly - The new startAudioOnly value.
  148. * @returns {void}
  149. */
  150. _onStartAudioOnlyChange(startAudioOnly) {
  151. const { dispatch } = this.props;
  152. dispatch(updateProfile({
  153. ...this.props._profile,
  154. startAudioOnly
  155. }));
  156. }
  157. /**
  158. * Renders the join button.
  159. *
  160. * @private
  161. * @returns {ReactElement}
  162. */
  163. _renderJoinButton() {
  164. let children;
  165. /* eslint-disable no-extra-parens */
  166. if (this.state.joining) {
  167. // TouchableHighlight is picky about what its children can be, so
  168. // wrap it in a native component, i.e. View to avoid having to
  169. // modify non-native children.
  170. children = (
  171. <View>
  172. <LoadingIndicator color = { styles.buttonText.color } />
  173. </View>
  174. );
  175. } else {
  176. children = (
  177. <Text style = { styles.buttonText }>
  178. { this.props.t('welcomepage.join') }
  179. </Text>
  180. );
  181. }
  182. /* eslint-enable no-extra-parens */
  183. return (
  184. <TouchableHighlight
  185. accessibilityLabel = { 'Tap to Join.' }
  186. disabled = { this._isJoinDisabled() }
  187. onPress = { this._onJoin }
  188. style = { styles.button }
  189. underlayColor = { ColorPalette.white }>
  190. {
  191. children
  192. }
  193. </TouchableHighlight>
  194. );
  195. }
  196. }
  197. export default translate(connect(_mapStateToProps)(WelcomePage));