選択できるのは25トピックまでです。 トピックは、先頭が英数字で、英数字とダッシュ('-')を使用した35文字以内のものにしてください。

WelcomePage.native.js 11KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345
  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';
  12. import { ColorSchemeRegistry } from '../../base/color-scheme';
  13. import { translate } from '../../base/i18n';
  14. import { Icon, IconMenu } 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 styles, { PLACEHOLDER_TEXT_COLOR } from './styles';
  33. import VideoSwitch from './VideoSwitch';
  34. import WelcomePageLists from './WelcomePageLists';
  35. import WelcomePageSideBar from './WelcomePageSideBar';
  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. * Constructs a style array to handle the hint box animation.
  107. *
  108. * @private
  109. * @returns {Array<Object>}
  110. */
  111. _getHintBoxStyle() {
  112. return [
  113. styles.hintContainer,
  114. {
  115. opacity: this.state.hintBoxAnimation
  116. }
  117. ];
  118. }
  119. /**
  120. * Callback for when the room field's focus changes so the hint box
  121. * must be rendered or removed.
  122. *
  123. * @private
  124. * @param {boolean} focused - The focused state of the field.
  125. * @returns {void}
  126. */
  127. _onFieldFocusChange(focused) {
  128. focused
  129. && this.setState({
  130. _fieldFocused: true
  131. });
  132. Animated.timing(
  133. this.state.hintBoxAnimation,
  134. {
  135. duration: 300,
  136. toValue: focused ? 1 : 0
  137. })
  138. .start(animationState =>
  139. animationState.finished
  140. && !focused
  141. && this.setState({
  142. _fieldFocused: false
  143. }));
  144. }
  145. /**
  146. * Toggles the side bar.
  147. *
  148. * @private
  149. * @returns {void}
  150. */
  151. _onShowSideBar() {
  152. Keyboard.dismiss();
  153. this.props.dispatch(setSideBarVisible(true));
  154. }
  155. /**
  156. * Renders the hint box if necessary.
  157. *
  158. * @private
  159. * @returns {React$Node}
  160. */
  161. _renderHintBox() {
  162. if (this.state._fieldFocused) {
  163. const { t } = this.props;
  164. return (
  165. <Animated.View style = { this._getHintBoxStyle() }>
  166. <View style = { styles.hintTextContainer } >
  167. <Text style = { styles.hintText }>
  168. { t('welcomepage.roomnameHint') }
  169. </Text>
  170. </View>
  171. <View style = { styles.hintButtonContainer } >
  172. { this._renderJoinButton() }
  173. </View>
  174. </Animated.View>
  175. );
  176. }
  177. return null;
  178. }
  179. /**
  180. * Renders the join button.
  181. *
  182. * @private
  183. * @returns {ReactElement}
  184. */
  185. _renderJoinButton() {
  186. const { t } = this.props;
  187. let children;
  188. if (this.state.joining) {
  189. // TouchableHighlight is picky about what its children can be, so
  190. // wrap it in a native component, i.e. View to avoid having to
  191. // modify non-native children.
  192. children = (
  193. <View>
  194. <LoadingIndicator
  195. color = { styles.buttonText.color }
  196. size = 'small' />
  197. </View>
  198. );
  199. } else {
  200. children = (
  201. <Text style = { styles.buttonText }>
  202. { this.props.t('welcomepage.join') }
  203. </Text>
  204. );
  205. }
  206. return (
  207. <TouchableHighlight
  208. accessibilityLabel =
  209. { t('welcomepage.accessibilityLabel.join') }
  210. onPress = { this._onJoin }
  211. style = { styles.button }
  212. underlayColor = { ColorPalette.white }>
  213. { children }
  214. </TouchableHighlight>
  215. );
  216. }
  217. /**
  218. * Renders the full welcome page.
  219. *
  220. * @returns {ReactElement}
  221. */
  222. _renderFullUI() {
  223. const roomnameAccLabel = 'welcomepage.accessibilityLabel.roomname';
  224. const { _headerStyles, t } = this.props;
  225. return (
  226. <LocalVideoTrackUnderlay style = { styles.welcomePage }>
  227. <View style = { _headerStyles.page }>
  228. <Header style = { styles.header }>
  229. <TouchableOpacity onPress = { this._onShowSideBar } >
  230. <Icon
  231. src = { IconMenu }
  232. style = { _headerStyles.headerButtonIcon } />
  233. </TouchableOpacity>
  234. <VideoSwitch />
  235. </Header>
  236. <SafeAreaView style = { styles.roomContainer } >
  237. <View style = { styles.joinControls } >
  238. <Text style = { styles.enterRoomText }>
  239. { t('welcomepage.roomname') }
  240. </Text>
  241. <TextInput
  242. accessibilityLabel = { t(roomnameAccLabel) }
  243. autoCapitalize = 'none'
  244. autoComplete = 'off'
  245. autoCorrect = { false }
  246. autoFocus = { false }
  247. onBlur = { this._onFieldBlur }
  248. onChangeText = { this._onRoomChange }
  249. onFocus = { this._onFieldFocus }
  250. onSubmitEditing = { this._onJoin }
  251. placeholder = { this.state.roomPlaceholder }
  252. placeholderTextColor = { PLACEHOLDER_TEXT_COLOR }
  253. returnKeyType = { 'go' }
  254. style = { styles.textInput }
  255. underlineColorAndroid = 'transparent'
  256. value = { this.state.room } />
  257. {
  258. this._renderHintBox()
  259. }
  260. </View>
  261. </SafeAreaView>
  262. <WelcomePageLists disabled = { this.state._fieldFocused } />
  263. </View>
  264. <WelcomePageSideBar />
  265. { this._renderWelcomePageModals() }
  266. </LocalVideoTrackUnderlay>
  267. );
  268. }
  269. /**
  270. * Renders a "reduced" version of the welcome page.
  271. *
  272. * @returns {ReactElement}
  273. */
  274. _renderReducedUI() {
  275. const { t } = this.props;
  276. return (
  277. <View style = { styles.reducedUIContainer }>
  278. <Text style = { styles.reducedUIText }>
  279. { t('welcomepage.reducedUIText', { app: getName() }) }
  280. </Text>
  281. </View>
  282. );
  283. }
  284. /**
  285. * Renders JitsiModals that are supposed to be on the welcome page.
  286. *
  287. * @returns {Array<ReactElement>}
  288. */
  289. _renderWelcomePageModals() {
  290. return [
  291. <HelpView key = 'helpView' />,
  292. <DialInSummary key = 'dialInSummary' />,
  293. <SettingsView key = 'settings' />
  294. ];
  295. }
  296. }
  297. /**
  298. * Maps part of the Redux state to the props of this component.
  299. *
  300. * @param {Object} state - The Redux state.
  301. * @returns {Object}
  302. */
  303. function _mapStateToProps(state) {
  304. return {
  305. ..._abstractMapStateToProps(state),
  306. _headerStyles: ColorSchemeRegistry.get(state, 'Header')
  307. // _reducedUI: state['features/base/responsive-ui'].reducedUI
  308. };
  309. }
  310. export default translate(connect(_mapStateToProps)(WelcomePage));