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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332
  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, IconMenu } from '../../base/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. this._updateRoomname();
  69. const { dispatch } = this.props;
  70. if (this.props._settings.startAudioOnly) {
  71. dispatch(destroyLocalTracks());
  72. } else {
  73. // Make sure we don't request the permission for the camera from
  74. // the start. We will, however, create a video track iff the user
  75. // already granted the permission.
  76. navigator.permissions.query({ name: 'camera' }).then(response => {
  77. response === 'granted'
  78. && dispatch(createDesiredLocalTracks(MEDIA_TYPE.VIDEO));
  79. });
  80. }
  81. }
  82. /**
  83. * Implements React's {@link Component#render()}. Renders a prompt for
  84. * entering a room name.
  85. *
  86. * @inheritdoc
  87. * @returns {ReactElement}
  88. */
  89. render() {
  90. // We want to have the welcome page support the reduced UI layout,
  91. // but we ran into serious issues enabling it so we disable it
  92. // until we have a proper fix in place. We leave the code here though, because
  93. // this part should be fine when the bug is fixed.
  94. //
  95. // NOTE: when re-enabling, don't forget to uncomment the respective _mapStateToProps line too
  96. /*
  97. const { _reducedUI } = this.props;
  98. if (_reducedUI) {
  99. return this._renderReducedUI();
  100. }
  101. */
  102. return this._renderFullUI();
  103. }
  104. /**
  105. * Constructs a style array to handle the hint box animation.
  106. *
  107. * @private
  108. * @returns {Array<Object>}
  109. */
  110. _getHintBoxStyle() {
  111. return [
  112. styles.hintContainer,
  113. {
  114. opacity: this.state.hintBoxAnimation
  115. }
  116. ];
  117. }
  118. /**
  119. * Callback for when the room field's focus changes so the hint box
  120. * must be rendered or removed.
  121. *
  122. * @private
  123. * @param {boolean} focused - The focused state of the field.
  124. * @returns {void}
  125. */
  126. _onFieldFocusChange(focused) {
  127. focused
  128. && this.setState({
  129. _fieldFocused: true
  130. });
  131. Animated.timing(
  132. this.state.hintBoxAnimation,
  133. {
  134. duration: 300,
  135. toValue: focused ? 1 : 0
  136. })
  137. .start(animationState =>
  138. animationState.finished
  139. && !focused
  140. && this.setState({
  141. _fieldFocused: false
  142. }));
  143. }
  144. /**
  145. * Toggles the side bar.
  146. *
  147. * @private
  148. * @returns {void}
  149. */
  150. _onShowSideBar() {
  151. Keyboard.dismiss();
  152. this.props.dispatch(setSideBarVisible(true));
  153. }
  154. /**
  155. * Renders the hint box if necessary.
  156. *
  157. * @private
  158. * @returns {React$Node}
  159. */
  160. _renderHintBox() {
  161. if (this.state._fieldFocused) {
  162. const { t } = this.props;
  163. return (
  164. <Animated.View style = { this._getHintBoxStyle() }>
  165. <View style = { styles.hintTextContainer } >
  166. <Text style = { styles.hintText }>
  167. { t('welcomepage.roomnameHint') }
  168. </Text>
  169. </View>
  170. <View style = { styles.hintButtonContainer } >
  171. { this._renderJoinButton() }
  172. </View>
  173. </Animated.View>
  174. );
  175. }
  176. return null;
  177. }
  178. /**
  179. * Renders the join button.
  180. *
  181. * @private
  182. * @returns {ReactElement}
  183. */
  184. _renderJoinButton() {
  185. const { t } = this.props;
  186. let children;
  187. if (this.state.joining) {
  188. // TouchableHighlight is picky about what its children can be, so
  189. // wrap it in a native component, i.e. View to avoid having to
  190. // modify non-native children.
  191. children = (
  192. <View>
  193. <LoadingIndicator
  194. color = { styles.buttonText.color }
  195. size = 'small' />
  196. </View>
  197. );
  198. } else {
  199. children = (
  200. <Text style = { styles.buttonText }>
  201. { this.props.t('welcomepage.join') }
  202. </Text>
  203. );
  204. }
  205. return (
  206. <TouchableHighlight
  207. accessibilityLabel =
  208. { t('welcomepage.accessibilityLabel.join') }
  209. onPress = { this._onJoin }
  210. style = { styles.button }
  211. underlayColor = { ColorPalette.white }>
  212. { children }
  213. </TouchableHighlight>
  214. );
  215. }
  216. /**
  217. * Renders the full welcome page.
  218. *
  219. * @returns {ReactElement}
  220. */
  221. _renderFullUI() {
  222. const roomnameAccLabel = 'welcomepage.accessibilityLabel.roomname';
  223. const { _headerStyles, t } = this.props;
  224. return (
  225. <LocalVideoTrackUnderlay style = { styles.welcomePage }>
  226. <View style = { _headerStyles.page }>
  227. <Header style = { styles.header }>
  228. <TouchableOpacity onPress = { this._onShowSideBar } >
  229. <Icon
  230. src = { IconMenu }
  231. style = { _headerStyles.headerButtonIcon } />
  232. </TouchableOpacity>
  233. <VideoSwitch />
  234. </Header>
  235. <SafeAreaView style = { styles.roomContainer } >
  236. <View style = { styles.joinControls } >
  237. <Text style = { styles.enterRoomText }>
  238. { t('welcomepage.roomname') }
  239. </Text>
  240. <TextInput
  241. accessibilityLabel = { t(roomnameAccLabel) }
  242. autoCapitalize = 'none'
  243. autoComplete = 'off'
  244. autoCorrect = { false }
  245. autoFocus = { false }
  246. onBlur = { this._onFieldBlur }
  247. onChangeText = { this._onRoomChange }
  248. onFocus = { this._onFieldFocus }
  249. onSubmitEditing = { this._onJoin }
  250. placeholder = { this.state.roomPlaceholder }
  251. placeholderTextColor = { PLACEHOLDER_TEXT_COLOR }
  252. returnKeyType = { 'go' }
  253. style = { styles.textInput }
  254. underlineColorAndroid = 'transparent'
  255. value = { this.state.room } />
  256. {
  257. this._renderHintBox()
  258. }
  259. </View>
  260. </SafeAreaView>
  261. <WelcomePageLists disabled = { this.state._fieldFocused } />
  262. <SettingsView />
  263. <DialInSummary />
  264. </View>
  265. <WelcomePageSideBar />
  266. </LocalVideoTrackUnderlay>
  267. );
  268. }
  269. /**
  270. * Renders a "reduced" version of the welcome page.
  271. *
  272. * @returns {ReactElement}
  273. */
  274. _renderReducedUI() {
  275. const { t } = this.props;
  276. return (
  277. <View style = { styles.reducedUIContainer }>
  278. <Text style = { styles.reducedUIText }>
  279. { t('welcomepage.reducedUIText', { app: getName() }) }
  280. </Text>
  281. </View>
  282. );
  283. }
  284. }
  285. /**
  286. * Maps part of the Redux state to the props of this component.
  287. *
  288. * @param {Object} state - The Redux state.
  289. * @returns {Object}
  290. */
  291. function _mapStateToProps(state) {
  292. return {
  293. ..._abstractMapStateToProps(state),
  294. _headerStyles: ColorSchemeRegistry.get(state, 'Header')
  295. // _reducedUI: state['features/base/responsive-ui'].reducedUI
  296. };
  297. }
  298. export default translate(connect(_mapStateToProps)(WelcomePage));