Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.

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