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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328
  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 { getName } from '../../app';
  12. import { ColorSchemeRegistry } from '../../base/color-scheme';
  13. import { translate } from '../../base/i18n';
  14. import { Icon } from '../../base/font-icons';
  15. import { MEDIA_TYPE } from '../../base/media';
  16. import { Header, LoadingIndicator, Text } from '../../base/react';
  17. import { connect } from '../../base/redux';
  18. import { ColorPalette } from '../../base/styles';
  19. import {
  20. createDesiredLocalTracks,
  21. destroyLocalTracks
  22. } from '../../base/tracks';
  23. import { DialInSummary } from '../../invite';
  24. import { SettingsView } from '../../settings';
  25. import { setSideBarVisible } from '../actions';
  26. import {
  27. AbstractWelcomePage,
  28. _mapStateToProps as _abstractMapStateToProps
  29. } from './AbstractWelcomePage';
  30. import LocalVideoTrackUnderlay from './LocalVideoTrackUnderlay';
  31. import styles, { PLACEHOLDER_TEXT_COLOR } from './styles';
  32. import VideoSwitch from './VideoSwitch';
  33. import WelcomePageLists from './WelcomePageLists';
  34. import WelcomePageSideBar from './WelcomePageSideBar';
  35. /**
  36. * The native container rendering the welcome page.
  37. *
  38. * @extends AbstractWelcomePage
  39. */
  40. class WelcomePage extends AbstractWelcomePage {
  41. /**
  42. * Constructor of the Component.
  43. *
  44. * @inheritdoc
  45. */
  46. constructor(props) {
  47. super(props);
  48. this.state._fieldFocused = false;
  49. this.state.hintBoxAnimation = new Animated.Value(0);
  50. // Bind event handlers so they are only bound once per instance.
  51. this._onFieldFocusChange = this._onFieldFocusChange.bind(this);
  52. this._onShowSideBar = this._onShowSideBar.bind(this);
  53. this._renderHintBox = this._renderHintBox.bind(this);
  54. // Specially bind functions to avoid function definition on render.
  55. this._onFieldBlur = this._onFieldFocusChange.bind(this, false);
  56. this._onFieldFocus = this._onFieldFocusChange.bind(this, true);
  57. }
  58. /**
  59. * Implements React's {@link Component#componentDidMount()}. Invoked
  60. * immediately after mounting occurs. Creates a local video track if none
  61. * is available and the camera permission was already granted.
  62. *
  63. * @inheritdoc
  64. * @returns {void}
  65. */
  66. componentDidMount() {
  67. super.componentDidMount();
  68. const { dispatch } = this.props;
  69. if (this.props._settings.startAudioOnly) {
  70. dispatch(destroyLocalTracks());
  71. } else {
  72. // Make sure we don't request the permission for the camera from
  73. // the start. We will, however, create a video track iff the user
  74. // already granted the permission.
  75. navigator.permissions.query({ name: 'camera' }).then(response => {
  76. response === 'granted'
  77. && dispatch(createDesiredLocalTracks(MEDIA_TYPE.VIDEO));
  78. });
  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 { _reducedUI } = this.props;
  90. if (_reducedUI) {
  91. return this._renderReducedUI();
  92. }
  93. return this._renderFullUI();
  94. }
  95. /**
  96. * Constructs a style array to handle the hint box animation.
  97. *
  98. * @private
  99. * @returns {Array<Object>}
  100. */
  101. _getHintBoxStyle() {
  102. return [
  103. styles.hintContainer,
  104. {
  105. opacity: this.state.hintBoxAnimation
  106. }
  107. ];
  108. }
  109. /**
  110. * Callback for when the room field's focus changes so the hint box
  111. * must be rendered or removed.
  112. *
  113. * @private
  114. * @param {boolean} focused - The focused state of the field.
  115. * @returns {void}
  116. */
  117. _onFieldFocusChange(focused) {
  118. focused
  119. && this.setState({
  120. _fieldFocused: true
  121. });
  122. Animated.timing(
  123. this.state.hintBoxAnimation,
  124. {
  125. duration: 300,
  126. toValue: focused ? 1 : 0
  127. })
  128. .start(animationState =>
  129. animationState.finished
  130. && !focused
  131. && this.setState({
  132. _fieldFocused: false
  133. }));
  134. }
  135. /**
  136. * Toggles the side bar.
  137. *
  138. * @private
  139. * @returns {void}
  140. */
  141. _onShowSideBar() {
  142. Keyboard.dismiss();
  143. this.props.dispatch(setSideBarVisible(true));
  144. }
  145. /**
  146. * Renders the hint box if necessary.
  147. *
  148. * @private
  149. * @returns {React$Node}
  150. */
  151. _renderHintBox() {
  152. if (this.state._fieldFocused) {
  153. const { t } = this.props;
  154. return (
  155. <Animated.View style = { this._getHintBoxStyle() }>
  156. <View style = { styles.hintTextContainer } >
  157. <Text style = { styles.hintText }>
  158. { t('welcomepage.roomnameHint') }
  159. </Text>
  160. </View>
  161. <View style = { styles.hintButtonContainer } >
  162. { this._renderJoinButton() }
  163. </View>
  164. </Animated.View>
  165. );
  166. }
  167. return null;
  168. }
  169. /**
  170. * Renders the join button.
  171. *
  172. * @private
  173. * @returns {ReactElement}
  174. */
  175. _renderJoinButton() {
  176. const { t } = this.props;
  177. let children;
  178. if (this.state.joining) {
  179. // TouchableHighlight is picky about what its children can be, so
  180. // wrap it in a native component, i.e. View to avoid having to
  181. // modify non-native children.
  182. children = (
  183. <View>
  184. <LoadingIndicator
  185. color = { styles.buttonText.color }
  186. size = 'small' />
  187. </View>
  188. );
  189. } else {
  190. children = (
  191. <Text style = { styles.buttonText }>
  192. { this.props.t('welcomepage.join') }
  193. </Text>
  194. );
  195. }
  196. const buttonDisabled = this._isJoinDisabled();
  197. return (
  198. <TouchableHighlight
  199. accessibilityLabel =
  200. { t('welcomepage.accessibilityLabel.join') }
  201. disabled = { buttonDisabled }
  202. onPress = { this._onJoin }
  203. style = { [
  204. styles.button,
  205. buttonDisabled ? styles.buttonDisabled : null
  206. ] }
  207. underlayColor = { ColorPalette.white }>
  208. { children }
  209. </TouchableHighlight>
  210. );
  211. }
  212. /**
  213. * Renders the full welcome page.
  214. *
  215. * @returns {ReactElement}
  216. */
  217. _renderFullUI() {
  218. const roomnameAccLabel = 'welcomepage.accessibilityLabel.roomname';
  219. const { _headerStyles, t } = this.props;
  220. return (
  221. <LocalVideoTrackUnderlay style = { styles.welcomePage }>
  222. <View style = { _headerStyles.page }>
  223. <Header style = { styles.header }>
  224. <TouchableOpacity onPress = { this._onShowSideBar } >
  225. <Icon
  226. name = 'menu'
  227. style = { _headerStyles.headerButtonIcon } />
  228. </TouchableOpacity>
  229. <VideoSwitch />
  230. </Header>
  231. <SafeAreaView style = { styles.roomContainer } >
  232. <View style = { styles.joinControls } >
  233. <TextInput
  234. accessibilityLabel = { t(roomnameAccLabel) }
  235. autoCapitalize = 'none'
  236. autoComplete = 'off'
  237. autoCorrect = { false }
  238. autoFocus = { false }
  239. onBlur = { this._onFieldBlur }
  240. onChangeText = { this._onRoomChange }
  241. onFocus = { this._onFieldFocus }
  242. onSubmitEditing = { this._onJoin }
  243. placeholder = { t('welcomepage.roomname') }
  244. placeholderTextColor = {
  245. PLACEHOLDER_TEXT_COLOR
  246. }
  247. returnKeyType = { 'go' }
  248. style = { styles.textInput }
  249. underlineColorAndroid = 'transparent'
  250. value = { this.state.room } />
  251. {
  252. this._renderHintBox()
  253. }
  254. </View>
  255. </SafeAreaView>
  256. <WelcomePageLists disabled = { this.state._fieldFocused } />
  257. <SettingsView />
  258. <DialInSummary />
  259. </View>
  260. <WelcomePageSideBar />
  261. </LocalVideoTrackUnderlay>
  262. );
  263. }
  264. /**
  265. * Renders a "reduced" version of the welcome page.
  266. *
  267. * @returns {ReactElement}
  268. */
  269. _renderReducedUI() {
  270. const { t } = this.props;
  271. return (
  272. <View style = { styles.reducedUIContainer }>
  273. <Text style = { styles.reducedUIText }>
  274. { t('welcomepage.reducedUIText', { app: getName() }) }
  275. </Text>
  276. </View>
  277. );
  278. }
  279. }
  280. /**
  281. * Maps part of the Redux state to the props of this component.
  282. *
  283. * @param {Object} state - The Redux state.
  284. * @returns {Object}
  285. */
  286. function _mapStateToProps(state) {
  287. const { reducedUI } = state['features/base/responsive-ui'];
  288. return {
  289. ..._abstractMapStateToProps(state),
  290. _headerStyles: ColorSchemeRegistry.get(state, 'Header'),
  291. _reducedUI: reducedUI
  292. };
  293. }
  294. export default translate(connect(_mapStateToProps)(WelcomePage));