您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

WelcomePage.native.js 11KB

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