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

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