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

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