Du kannst nicht mehr als 25 Themen auswählen Themen müssen mit entweder einem Buchstaben oder einer Ziffer beginnen. Sie können Bindestriche („-“) enthalten und bis zu 35 Zeichen lang sein.

WelcomePage.native.js 9.2KB

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