/* eslint-disable lines-around-comment */ import _ from 'lodash'; import React, { Component } from 'react'; import { WithTranslation } from 'react-i18next'; import { Alert, Linking, NativeModules, Platform, ScrollView, Text, View } from 'react-native'; import { Divider } from 'react-native-paper'; import { getDefaultURL } from '../../../app/functions.native'; import { IReduxState } from '../../../app/types'; // @ts-ignore import { Avatar } from '../../../base/avatar'; import { translate } from '../../../base/i18n/functions'; // @ts-ignore import JitsiScreen from '../../../base/modal/components/JitsiScreen'; import { getLocalParticipant } from '../../../base/participants/functions'; import { connect } from '../../../base/redux/functions'; import { updateSettings } from '../../../base/settings/actions'; import Button from '../../../base/ui/components/native/Button'; import Input from '../../../base/ui/components/native/Input'; import Switch from '../../../base/ui/components/native/Switch'; // @ts-ignore import { BUTTON_TYPES } from '../../../base/ui/constants.any'; // @ts-ignore import { AVATAR_SIZE } from '../../../welcome/components/styles'; import { isServerURLChangeEnabled, normalizeUserInputURL } from '../../functions.native'; // @ts-ignore import FormRow from './FormRow'; // @ts-ignore import FormSection from './FormSection'; // @ts-ignore import styles from './styles'; /** * Application information module. */ const { AppInfo } = NativeModules; /** * The URL at which the terms (of service/use) are available to the user. */ const TERMS_URL = 'https://jitsi.org/meet/terms'; /** * The URL at which the privacy policy is available to the user. */ const PRIVACY_URL = 'https://jitsi.org/meet/privacy'; const DEFAULT_HELP_CENTRE_URL = 'https://web-cdn.jitsi.net/faq/meet-faq.html'; interface IState { /** * State variable for the disable call integration switch. */ disableCallIntegration: boolean; /** * State variable for the disable crash reporting switch. */ disableCrashReporting: boolean; /** * State variable for the disable p2p switch. */ disableP2P: boolean; /** * Whether the self view is disabled or not. */ disableSelfView: boolean; /** * State variable for the display name field. */ displayName: string; /** * State variable for the email field. */ email: string; /** * State variable for the server URL field. */ serverURL: string; /** * State variable for start car mode. */ startCarMode: boolean; /** * State variable for the start with audio muted switch. */ startWithAudioMuted: boolean; /** * State variable for the start with video muted switch. */ startWithVideoMuted: boolean; } /** * The type of the React {@code Component} props of * {@link SettingsView}. */ interface IProps extends WithTranslation { /** * The URL for when the help link. * * @protected */ _helpCentreUrl: string; /** * The ID of the local participant. */ _localParticipantId: string; /** * The default URL for when there is no custom URL set in the settings. * * @protected */ _serverURL: string; /** * Flag indicating if URL can be changed by user. * * @protected */ _serverURLChangeEnabled: boolean; /** * The current settings object. */ _settings: { disableCallIntegration: boolean; disableCrashReporting: boolean; disableP2P: boolean; disableSelfView: boolean; displayName: string; email: string; serverURL: string; startCarMode: boolean; startWithAudioMuted: boolean; startWithVideoMuted: boolean; }; /** * Whether {@link SettingsView} is visible. * * @protected */ _visible: boolean; /** * Add bottom padding to the screen. */ addBottomInset?: boolean; /** * Redux store dispatch function. */ dispatch: Function; /** * Default prop for navigating between screen components(React Navigation). */ navigation: Object; /** * Bounce when scrolling. */ scrollBounces?: boolean; } /** * The native container rendering the app settings page. */ class SettingsView extends Component { _urlField: Object; /** * * Initializes a new {@code SettingsView} instance. * * @inheritdoc */ constructor(props: IProps) { super(props); const { disableCallIntegration, disableCrashReporting, disableP2P, disableSelfView, displayName, email, serverURL, startCarMode, startWithAudioMuted, startWithVideoMuted } = props._settings || {}; this.state = { disableCallIntegration, disableCrashReporting, disableP2P, disableSelfView, displayName: displayName || '', email: email || '', serverURL: serverURL || '', startCarMode, startWithAudioMuted, startWithVideoMuted }; // Bind event handlers so they are only bound once per instance. this._onBlurServerURL = this._onBlurServerURL.bind(this); this._onChangeDisplayName = this._onChangeDisplayName.bind(this); this._onChangeEmail = this._onChangeEmail.bind(this); this._onChangeServerURL = this._onChangeServerURL.bind(this); this._onClose = this._onClose.bind(this); this._onDisableCallIntegration = this._onDisableCallIntegration.bind(this); this._onDisableCrashReporting = this._onDisableCrashReporting.bind(this); this._onDisableP2P = this._onDisableP2P.bind(this); this._onDisableSelfView = this._onDisableSelfView.bind(this); this._onStartAudioMutedChange = this._onStartAudioMutedChange.bind(this); this._onStartCarmodeInLowBandwidthMode = this._onStartCarmodeInLowBandwidthMode.bind(this); this._onStartVideoMutedChange = this._onStartVideoMutedChange.bind(this); this._setURLFieldReference = this._setURLFieldReference.bind(this); this._onShowHelpPressed = this._onShowHelpPressed.bind(this); this._onShowPrivacyPressed = this._onShowPrivacyPressed.bind(this); this._onShowTermsPressed = this._onShowTermsPressed.bind(this); this._showURLAlert = this._showURLAlert.bind(this); } /** * Updates and syncs settings. * * @inheritdoc * @returns {void} */ componentDidUpdate(prevProps: IProps) { const { _settings } = this.props; if (!_.isEqual(prevProps._settings, _settings)) { // @ts-ignore // eslint-disable-next-line react/no-did-update-set-state this.setState(_settings); } } /** * Implements React's {@link Component#render()}, renders the settings page. * * @inheritdoc * @returns {ReactElement} */ render() { const { disableCallIntegration, disableCrashReporting, disableP2P, disableSelfView, displayName, email, serverURL, startCarMode, startWithAudioMuted, startWithVideoMuted } = this.state; const { addBottomInset = false, scrollBounces = false, t } = this.props; return ( {/* @ts-ignore */} {/* @ts-ignore */} {/* @ts-ignore */} {/* @ts-ignore */} {/* @ts-ignore */} {/* @ts-ignore */} {/* @ts-ignore */} {/* @ts-ignore */}