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

LobbyScreen.js 7.3KB

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