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.

AdvancedSection.tsx 3.8KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  1. import React, { useCallback, useMemo } from 'react';
  2. import { useTranslation } from 'react-i18next';
  3. import { Alert, NativeModules, Platform, Text } from 'react-native';
  4. import { Divider } from 'react-native-paper';
  5. import { useDispatch, useSelector } from 'react-redux';
  6. import { IReduxState } from '../../../app/types';
  7. import { updateSettings } from '../../../base/settings/actions';
  8. import Switch from '../../../base/ui/components/native/Switch';
  9. import FormRow from './FormRow';
  10. import FormSection from './FormSection';
  11. import styles from './styles';
  12. const { AppInfo } = NativeModules;
  13. const AdvancedSection = () => {
  14. const { t } = useTranslation();
  15. const dispatch = useDispatch();
  16. const {
  17. disableCrashReporting,
  18. disableCallIntegration,
  19. disableP2P
  20. } = useSelector((state: IReduxState) => state['features/base/settings']);
  21. const onSwitchToggled = useCallback((name: string) => (enabled?: boolean) => {
  22. if (name === 'disableCrashReporting' && enabled === true) {
  23. Alert.alert(
  24. t('settingsView.alertTitle'),
  25. t('settingsView.disableCrashReportingWarning'),
  26. [
  27. {
  28. onPress: () => dispatch(updateSettings({ disableCrashReporting: true })),
  29. text: t('settingsView.alertOk')
  30. },
  31. {
  32. text: t('settingsView.alertCancel')
  33. }
  34. ]
  35. );
  36. } else {
  37. dispatch(updateSettings({ [name]: enabled }));
  38. }
  39. }, [ dispatch, updateSettings ]);
  40. const switches = useMemo(() => {
  41. const partialSwitches = [
  42. {
  43. label: 'settingsView.disableCallIntegration',
  44. state: disableCallIntegration,
  45. name: 'disableCallIntegration'
  46. },
  47. {
  48. label: 'settingsView.disableP2P',
  49. state: disableP2P,
  50. name: 'disableP2P'
  51. },
  52. {
  53. label: 'settingsView.disableCrashReporting',
  54. state: disableCrashReporting,
  55. name: 'disableCrashReporting'
  56. }
  57. ];
  58. if (Platform.OS !== 'android') {
  59. partialSwitches.shift();
  60. }
  61. if (!AppInfo.GOOGLE_SERVICES_ENABLED) {
  62. partialSwitches.pop();
  63. }
  64. return partialSwitches;
  65. }, [ disableCallIntegration, disableP2P, disableCrashReporting ]);
  66. return (
  67. <>
  68. <FormSection
  69. label = 'settingsView.advanced'>
  70. {
  71. switches.map(({ label, state, name }) => (
  72. <FormRow
  73. key = { label }
  74. label = { label }>
  75. <Switch
  76. checked = { Boolean(state) }
  77. onChange = { onSwitchToggled(name) } />
  78. </FormRow>
  79. ))
  80. }
  81. </FormSection>
  82. {/* @ts-ignore */}
  83. <Divider style = { styles.fieldSeparator } />
  84. <FormSection
  85. label = 'settingsView.buildInfoSection'>
  86. <FormRow
  87. label = 'settingsView.version'>
  88. <Text style = { styles.text }>
  89. {`${AppInfo.version} build ${AppInfo.buildNumber}`}
  90. </Text>
  91. </FormRow>
  92. <FormRow
  93. label = 'settingsView.sdkVersion'>
  94. <Text style = { styles.text }>
  95. {AppInfo.sdkVersion}
  96. </Text>
  97. </FormRow>
  98. </FormSection>
  99. </>
  100. );
  101. };
  102. export default AdvancedSection;