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

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