You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

functions.tsx 2.7KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. import React, { useCallback } from 'react';
  2. import { useTranslation } from 'react-i18next';
  3. import { GestureResponderEvent, Platform } from 'react-native';
  4. import { useDispatch } from 'react-redux';
  5. import { appNavigate } from '../../app/actions.native';
  6. import { IStateful } from '../../base/app/types';
  7. import { PREJOIN_PAGE_ENABLED } from '../../base/flags/constants';
  8. import { getFeatureFlag } from '../../base/flags/functions';
  9. import { IconCloseLarge } from '../../base/icons/svg';
  10. import { toState } from '../../base/redux/functions';
  11. import { cancelKnocking } from '../../lobby/actions.native';
  12. import { isPrejoinEnabledInConfig } from '../../prejoin/functions.native';
  13. import HeaderNavigationButton from './components/HeaderNavigationButton';
  14. /**
  15. * Close icon/text button based on platform.
  16. *
  17. * @param {Function} goBack - Goes back to the previous screen function.
  18. * @returns {React.Component}
  19. */
  20. export function screenHeaderCloseButton(goBack: (e?: GestureResponderEvent | React.MouseEvent) => void) {
  21. const { t } = useTranslation();
  22. if (Platform.OS === 'ios') {
  23. return (
  24. <HeaderNavigationButton
  25. id = { 'close-screen-button' }
  26. label = { t('dialog.close') }
  27. onPress = { goBack } />
  28. );
  29. }
  30. return (
  31. <HeaderNavigationButton
  32. id = { 'close-screen-button' }
  33. onPress = { goBack }
  34. src = { IconCloseLarge } />
  35. );
  36. }
  37. /**
  38. * Determines whether the {@code Prejoin page} is enabled by the app itself
  39. * (e.g. Programmatically via the Jitsi Meet SDK for Android and iOS).
  40. *
  41. * @param {Function|Object} stateful - The redux state or {@link getState}
  42. * function.
  43. * @returns {boolean} If the {@code Prejoin} is enabled by the app, then
  44. * {@code true}; otherwise, {@code false}.
  45. */
  46. export function isPrejoinPageEnabled(stateful: IStateful) {
  47. const state = toState(stateful);
  48. return getFeatureFlag(state, PREJOIN_PAGE_ENABLED, isPrejoinEnabledInConfig(state));
  49. }
  50. /**
  51. * Close icon/text button for lobby screen based on platform.
  52. *
  53. * @returns {React.Component}
  54. */
  55. export function lobbyScreenHeaderCloseButton() {
  56. const dispatch = useDispatch();
  57. const { t } = useTranslation();
  58. const goBack = useCallback(() => {
  59. dispatch(cancelKnocking());
  60. dispatch(appNavigate(undefined));
  61. }, [ dispatch ]);
  62. if (Platform.OS === 'ios') {
  63. return (
  64. <HeaderNavigationButton
  65. id = { 'close-screen-button' }
  66. label = { t('dialog.close') }
  67. onPress = { goBack } />
  68. );
  69. }
  70. return (
  71. <HeaderNavigationButton
  72. id = { 'close-screen-button' }
  73. onPress = { goBack }
  74. src = { IconCloseLarge } />
  75. );
  76. }