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

LobbyScreen.js 9.5KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297
  1. // @flow
  2. import React from 'react';
  3. import { Text, View, TouchableOpacity, TextInput } from 'react-native';
  4. import { SafeAreaView } from 'react-native-safe-area-context';
  5. import { Avatar } from '../../../base/avatar';
  6. import { translate } from '../../../base/i18n';
  7. import { Icon, IconClose, IconEdit } from '../../../base/icons';
  8. import JitsiScreen from '../../../base/modal/components/JitsiScreen';
  9. import { LoadingIndicator } from '../../../base/react';
  10. import { connect } from '../../../base/redux';
  11. import ChatInputBar from '../../../chat/components/native/ChatInputBar';
  12. import MessageContainer from '../../../chat/components/native/MessageContainer';
  13. import AbstractLobbyScreen, { _mapStateToProps } from '../AbstractLobbyScreen';
  14. import styles from './styles';
  15. /**
  16. * Implements a waiting screen that represents the participant being in the lobby.
  17. */
  18. class LobbyScreen extends AbstractLobbyScreen {
  19. /**
  20. * Implements {@code PureComponent#render}.
  21. *
  22. * @inheritdoc
  23. */
  24. render() {
  25. const { _meetingName, t } = this.props;
  26. return (
  27. <JitsiScreen
  28. style = { this.props._isLobbyChatActive && this.state.isChatOpen
  29. ? styles.lobbyChatWrapper
  30. : styles.contentWrapper }>
  31. {this.props._isLobbyChatActive && this.state.isChatOpen
  32. ? this._renderLobbyChat()
  33. : <SafeAreaView>
  34. <Text style = { styles.dialogTitle }>
  35. { t(this._getScreenTitleKey(), { moderator: this.props._lobbyMessageRecipient }) }
  36. </Text>
  37. <Text style = { styles.secondaryText }>
  38. { _meetingName }
  39. </Text>
  40. { this._renderContent()}
  41. </SafeAreaView> }
  42. </JitsiScreen>
  43. );
  44. }
  45. _getScreenTitleKey: () => string;
  46. _onAskToJoin: () => void;
  47. _onCancel: () => boolean;
  48. _onChangeDisplayName: Object => void;
  49. _onChangeEmail: Object => void;
  50. _onChangePassword: Object => void;
  51. _onEnableEdit: () => void;
  52. _onJoinWithPassword: () => void;
  53. _onSwitchToKnockMode: () => void;
  54. _onSwitchToPasswordMode: () => void;
  55. _onSendMessage: () => void;
  56. _onToggleChat: () => void;
  57. _renderContent: () => React$Element<*>;
  58. /**
  59. * Renders the lobby chat.
  60. *
  61. * @inheritdoc
  62. */
  63. _renderLobbyChat() {
  64. const { t } = this.props;
  65. return (
  66. <>
  67. <View style = { styles.lobbyChatHeader }>
  68. <Text style = { styles.lobbyChatTitle }>
  69. { t(this._getScreenTitleKey(), { moderator: this.props._lobbyMessageRecipient }) }
  70. </Text>
  71. <TouchableOpacity onPress = { this._onToggleChat }>
  72. <Icon
  73. src = { IconClose }
  74. style = { styles.lobbyChatCloseButton } />
  75. </TouchableOpacity>
  76. </View>
  77. <MessageContainer messages = { this.props._lobbyChatMessages } />
  78. <ChatInputBar onSend = { this._onSendMessage } />
  79. </>
  80. );
  81. }
  82. /**
  83. * Renders the joining (waiting) fragment of the screen.
  84. *
  85. * @inheritdoc
  86. */
  87. _renderJoining() {
  88. return (
  89. <>
  90. <LoadingIndicator
  91. color = 'black'
  92. style = { styles.loadingIndicator } />
  93. <Text style = { styles.joiningMessage }>
  94. { this.props.t('lobby.joiningMessage') }
  95. </Text>
  96. { this._renderStandardButtons() }
  97. </>
  98. );
  99. }
  100. /**
  101. * Renders the participant form to let the knocking participant enter its details.
  102. *
  103. * @inheritdoc
  104. */
  105. _renderParticipantForm() {
  106. const { t } = this.props;
  107. const { displayName, email } = this.state;
  108. return (
  109. <View style = { styles.formWrapper }>
  110. <Text style = { styles.fieldLabel }>
  111. { t('lobby.nameField') }
  112. </Text>
  113. <TextInput
  114. onChangeText = { this._onChangeDisplayName }
  115. style = { styles.field }
  116. value = { displayName } />
  117. <Text style = { styles.fieldLabel }>
  118. { t('lobby.emailField') }
  119. </Text>
  120. <TextInput
  121. onChangeText = { this._onChangeEmail }
  122. style = { styles.field }
  123. value = { email } />
  124. </View>
  125. );
  126. }
  127. /**
  128. * Renders the participant info fragment when we have all the required details of the user.
  129. *
  130. * @inheritdoc
  131. */
  132. _renderParticipantInfo() {
  133. const { displayName, email } = this.state;
  134. return (
  135. <View style = { styles.participantBox }>
  136. <TouchableOpacity
  137. onPress = { this._onEnableEdit }
  138. style = { styles.editButton }>
  139. <Icon
  140. src = { IconEdit }
  141. style = { styles.editIcon } />
  142. </TouchableOpacity>
  143. <Avatar
  144. participantId = { this.props._participantId }
  145. size = { 64 } />
  146. <Text style = { styles.displayNameText }>
  147. { displayName }
  148. </Text>
  149. { Boolean(email) && <Text style = { styles.secondaryText }>
  150. { email }
  151. </Text> }
  152. </View>
  153. );
  154. }
  155. /**
  156. * Renders the password form to let the participant join by using a password instead of knocking.
  157. *
  158. * @inheritdoc
  159. */
  160. _renderPasswordForm() {
  161. const { _passwordJoinFailed, t } = this.props;
  162. return (
  163. <View style = { styles.formWrapper }>
  164. <Text style = { styles.fieldLabel }>
  165. { this.props.t('lobby.passwordField') }
  166. </Text>
  167. <TextInput
  168. autoCapitalize = 'none'
  169. autoCompleteType = 'off'
  170. onChangeText = { this._onChangePassword }
  171. secureTextEntry = { true }
  172. style = { styles.field }
  173. value = { this.state.password } />
  174. { _passwordJoinFailed && <Text style = { styles.fieldError }>
  175. { t('lobby.invalidPassword') }
  176. </Text> }
  177. </View>
  178. );
  179. }
  180. /**
  181. * Renders the password join button (set).
  182. *
  183. * @inheritdoc
  184. */
  185. _renderPasswordJoinButtons() {
  186. const { t } = this.props;
  187. return (
  188. <>
  189. <TouchableOpacity
  190. disabled = { !this.state.password }
  191. onPress = { this._onJoinWithPassword }
  192. style = { [
  193. styles.button,
  194. styles.primaryButton
  195. ] }>
  196. <Text style = { styles.primaryButtonText }>
  197. { t('lobby.passwordJoinButton') }
  198. </Text>
  199. </TouchableOpacity>
  200. <TouchableOpacity
  201. onPress = { this._onSwitchToKnockMode }
  202. style = { [
  203. styles.button,
  204. styles.secondaryButton
  205. ] }>
  206. <Text>
  207. { t('lobby.backToKnockModeButton') }
  208. </Text>
  209. </TouchableOpacity>
  210. </>
  211. );
  212. }
  213. /**
  214. * Renders the standard button set.
  215. *
  216. * @inheritdoc
  217. */
  218. _renderStandardButtons() {
  219. const { _knocking, _renderPassword, _isLobbyChatActive, t } = this.props;
  220. return (
  221. <>
  222. { _knocking || <TouchableOpacity
  223. disabled = { !this.state.displayName }
  224. onPress = { this._onAskToJoin }
  225. style = { [
  226. styles.button,
  227. styles.primaryButton
  228. ] }>
  229. <Text style = { styles.primaryButtonText }>
  230. { t('lobby.knockButton') }
  231. </Text>
  232. </TouchableOpacity> }
  233. { _knocking && _isLobbyChatActive && <TouchableOpacity
  234. onPress = { this._onToggleChat }
  235. style = { [
  236. styles.button,
  237. styles.secondaryButton
  238. ] }>
  239. <Text>
  240. { t('toolbar.openChat') }
  241. </Text>
  242. </TouchableOpacity>}
  243. { _renderPassword && <TouchableOpacity
  244. onPress = { this._onSwitchToPasswordMode }
  245. style = { [
  246. styles.button,
  247. styles.secondaryButton
  248. ] }>
  249. <Text>
  250. { t('lobby.enterPasswordButton') }
  251. </Text>
  252. </TouchableOpacity> }
  253. <TouchableOpacity
  254. onPress = { this._onCancel }
  255. style = { styles.cancelButton }>
  256. <Text>
  257. { t('dialog.Cancel') }
  258. </Text>
  259. </TouchableOpacity>
  260. </>
  261. );
  262. }
  263. }
  264. export default translate(connect(_mapStateToProps)(LobbyScreen));