Du kan inte välja fler än 25 ämnen Ämnen måste starta med en bokstav eller siffra, kan innehålla bindestreck ('-') och vara max 35 tecken långa.

functions.tsx 2.9KB

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