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 3.0KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  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';
  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. label = { t('dialog.close') }
  26. onPress = { goBack } />
  27. );
  28. }
  29. return (
  30. <HeaderNavigationButton
  31. onPress = { goBack }
  32. src = { IconCloseLarge } />
  33. );
  34. }
  35. /**
  36. * Determines whether the {@code Prejoin page} is enabled by the app itself
  37. * (e.g. Programmatically via the Jitsi Meet SDK for Android and iOS).
  38. *
  39. * @param {Function|Object} stateful - The redux state or {@link getState}
  40. * function.
  41. * @returns {boolean} If the {@code Prejoin} is enabled by the app, then
  42. * {@code true}; otherwise, {@code false}.
  43. */
  44. export function isPrejoinPageEnabled(stateful: IStateful) {
  45. const state = toState(stateful);
  46. return getFeatureFlag(state, PREJOIN_PAGE_ENABLED, isPrejoinEnabledInConfig(state));
  47. }
  48. /**
  49. * Close icon/text button for lobby screen based on platform.
  50. *
  51. * @returns {React.Component}
  52. */
  53. export function lobbyScreenHeaderCloseButton() {
  54. const dispatch = useDispatch();
  55. const { t } = useTranslation();
  56. const goBack = useCallback(() => {
  57. dispatch(cancelKnocking());
  58. dispatch(appNavigate(undefined));
  59. }, [ dispatch ]);
  60. if (Platform.OS === 'ios') {
  61. return (
  62. <HeaderNavigationButton
  63. label = { t('dialog.close') }
  64. onPress = { goBack } />
  65. );
  66. }
  67. return (
  68. <HeaderNavigationButton
  69. onPress = { goBack }
  70. src = { IconCloseLarge } />
  71. );
  72. }
  73. /**
  74. * Returns true if we should auto-knock in case prejoin is enabled for the room.
  75. *
  76. * @param {Function|Object} stateful - The redux state or {@link getState}
  77. * function.
  78. * @returns {boolean}
  79. */
  80. export function shouldEnableAutoKnock(stateful: IStateful) {
  81. const state = toState(stateful);
  82. const { displayName } = state['features/base/settings'];
  83. if (isPrejoinPageEnabled(state)) {
  84. if (displayName) {
  85. return true;
  86. }
  87. } else {
  88. return false;
  89. }
  90. }