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

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