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

WelcomePage.native.js 12KB

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