2023-04-12 16:58:42 +03:00
|
|
|
import React, { ComponentType } from 'react';
|
2022-08-01 17:15:59 +02:00
|
|
|
import { NativeModules, Platform, StyleSheet, View } from 'react-native';
|
2023-07-24 12:22:51 +02:00
|
|
|
import DeviceInfo from 'react-native-device-info';
|
2022-05-06 05:18:57 -05:00
|
|
|
import { SafeAreaProvider } from 'react-native-safe-area-context';
|
2025-07-10 14:56:43 +03:00
|
|
|
// @ts-ignore
|
|
|
|
|
import { hideSplash } from 'react-native-splash-view';
|
2016-10-05 09:36:59 -05:00
|
|
|
|
2022-06-20 16:53:19 +02:00
|
|
|
import BottomSheetContainer from '../../base/dialog/components/native/BottomSheetContainer';
|
2023-03-31 14:04:33 +03:00
|
|
|
import DialogContainer from '../../base/dialog/components/native/DialogContainer';
|
2020-07-22 12:50:10 +02:00
|
|
|
import { updateFlags } from '../../base/flags/actions';
|
2023-10-30 09:52:45 +01:00
|
|
|
import { CALL_INTEGRATION_ENABLED } from '../../base/flags/constants';
|
2023-04-03 13:49:19 +03:00
|
|
|
import { clientResized, setSafeAreaInsets } from '../../base/responsive-ui/actions';
|
|
|
|
|
import DimensionsDetector from '../../base/responsive-ui/components/DimensionsDetector.native';
|
|
|
|
|
import { updateSettings } from '../../base/settings/actions';
|
2023-07-31 15:39:08 +02:00
|
|
|
import JitsiThemePaperProvider from '../../base/ui/components/JitsiThemeProvider.native';
|
2025-03-07 13:48:16 +01:00
|
|
|
import { isEmbedded } from '../../base/util/embedUtils.native';
|
2022-02-01 13:29:54 +02:00
|
|
|
import { _getRouteToRender } from '../getRouteToRender.native';
|
2019-08-21 16:50:00 +02:00
|
|
|
import logger from '../logger';
|
2020-05-20 12:57:03 +02:00
|
|
|
|
2023-04-12 16:58:42 +03:00
|
|
|
import { AbstractApp, IProps as AbstractAppProps } from './AbstractApp';
|
2018-07-11 11:42:43 +02:00
|
|
|
|
2020-06-04 16:09:13 +02:00
|
|
|
// Register middlewares and reducers.
|
2023-04-12 16:58:42 +03:00
|
|
|
import '../middlewares.native';
|
|
|
|
|
import '../reducers.native';
|
2020-06-04 16:09:13 +02:00
|
|
|
|
2023-11-22 17:13:02 +02:00
|
|
|
|
2023-04-12 16:58:42 +03:00
|
|
|
declare let __DEV__: any;
|
2016-10-05 09:36:59 -05:00
|
|
|
|
2022-08-01 17:15:59 +02:00
|
|
|
const { AppInfo } = NativeModules;
|
|
|
|
|
|
2022-06-20 11:50:40 +02:00
|
|
|
const DialogContainerWrapper = Platform.select({
|
|
|
|
|
default: View
|
|
|
|
|
});
|
|
|
|
|
|
2016-10-05 09:36:59 -05:00
|
|
|
/**
|
2018-07-12 11:16:57 -05:00
|
|
|
* The type of React {@code Component} props of {@link App}.
|
2016-10-05 09:36:59 -05:00
|
|
|
*/
|
2023-04-12 16:58:42 +03:00
|
|
|
interface IProps extends AbstractAppProps {
|
2018-07-11 11:42:43 +02:00
|
|
|
|
|
|
|
|
/**
|
2019-05-24 13:06:05 +02:00
|
|
|
* An object with the feature flags.
|
2018-07-11 11:42:43 +02:00
|
|
|
*/
|
2023-07-24 12:22:51 +02:00
|
|
|
flags: any;
|
2019-06-11 15:38:33 +02:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* An object with user information (display name, email, avatar URL).
|
|
|
|
|
*/
|
2023-04-12 16:58:42 +03:00
|
|
|
userInfo?: Object;
|
|
|
|
|
}
|
2016-11-30 19:52:39 -06:00
|
|
|
|
2018-07-11 11:42:43 +02:00
|
|
|
/**
|
2018-07-12 11:16:57 -05:00
|
|
|
* Root app {@code Component} on mobile/React Native.
|
2018-07-11 11:42:43 +02:00
|
|
|
*
|
2021-11-04 22:10:43 +01:00
|
|
|
* @augments AbstractApp
|
2018-07-11 11:42:43 +02:00
|
|
|
*/
|
2023-04-12 16:58:42 +03:00
|
|
|
export class App extends AbstractApp<IProps> {
|
2019-01-22 11:32:18 +01:00
|
|
|
|
2016-10-05 09:36:59 -05:00
|
|
|
/**
|
2018-07-12 11:16:57 -05:00
|
|
|
* Initializes a new {@code App} instance.
|
2016-10-05 09:36:59 -05:00
|
|
|
*
|
2023-04-12 16:58:42 +03:00
|
|
|
* @param {IProps} props - The read-only React {@code Component} props with
|
2018-07-12 11:16:57 -05:00
|
|
|
* which the new instance is to be initialized.
|
2016-10-05 09:36:59 -05:00
|
|
|
*/
|
2023-04-12 16:58:42 +03:00
|
|
|
constructor(props: IProps) {
|
2016-10-05 09:36:59 -05:00
|
|
|
super(props);
|
|
|
|
|
|
2017-01-05 15:06:41 -06:00
|
|
|
// In the Release configuration, React Native will (intentionally) throw
|
|
|
|
|
// an unhandled JavascriptException for an unhandled JavaScript error.
|
2018-07-12 11:16:57 -05:00
|
|
|
// This will effectively kill the app. In accord with the Web, do not
|
|
|
|
|
// kill the app.
|
2017-01-05 15:06:41 -06:00
|
|
|
this._maybeDisableExceptionsManager();
|
2020-06-02 11:03:17 +02:00
|
|
|
|
|
|
|
|
// Bind event handler so it is only bound once per instance.
|
|
|
|
|
this._onDimensionsChanged = this._onDimensionsChanged.bind(this);
|
2022-05-06 05:18:57 -05:00
|
|
|
this._onSafeAreaInsetsChanged = this._onSafeAreaInsetsChanged.bind(this);
|
2016-10-05 09:36:59 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
2019-01-24 16:53:28 +01:00
|
|
|
* Initializes the color scheme.
|
2016-10-05 09:36:59 -05:00
|
|
|
*
|
|
|
|
|
* @inheritdoc
|
2019-01-24 16:53:28 +01:00
|
|
|
*
|
2016-10-05 09:36:59 -05:00
|
|
|
* @returns {void}
|
|
|
|
|
*/
|
2025-03-12 10:19:11 -05:00
|
|
|
override async componentDidMount() {
|
2022-01-07 15:18:24 +02:00
|
|
|
await super.componentDidMount();
|
2016-10-05 09:36:59 -05:00
|
|
|
|
2025-07-10 14:56:43 +03:00
|
|
|
hideSplash();
|
2022-08-01 17:15:59 +02:00
|
|
|
|
|
|
|
|
const liteTxt = AppInfo.isLiteSDK ? ' (lite)' : '';
|
|
|
|
|
|
2025-03-07 13:48:16 +01:00
|
|
|
logger.info(`Loaded SDK ${AppInfo.sdkVersion}${liteTxt} isEmbedded=${isEmbedded()}`);
|
2022-01-07 15:18:24 +02:00
|
|
|
}
|
2020-10-14 12:26:47 +03:00
|
|
|
|
2023-07-31 15:39:08 +02:00
|
|
|
/**
|
|
|
|
|
* Implements React's {@link Component#render()}.
|
|
|
|
|
*
|
|
|
|
|
* @inheritdoc
|
|
|
|
|
* @returns {ReactElement}
|
|
|
|
|
*/
|
2025-03-12 10:19:11 -05:00
|
|
|
override render() {
|
2023-07-31 15:39:08 +02:00
|
|
|
return (
|
|
|
|
|
<JitsiThemePaperProvider>
|
|
|
|
|
{ super.render() }
|
|
|
|
|
</JitsiThemePaperProvider>
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
2022-01-07 15:18:24 +02:00
|
|
|
/**
|
|
|
|
|
* Initializes feature flags and updates settings.
|
|
|
|
|
*
|
|
|
|
|
* @returns {void}
|
|
|
|
|
*/
|
2022-02-01 13:29:54 +02:00
|
|
|
async _extraInit() {
|
2023-04-12 16:58:42 +03:00
|
|
|
const { dispatch, getState } = this.state.store ?? {};
|
2023-11-22 17:13:02 +02:00
|
|
|
const { flags = {}, url, userInfo } = this.props;
|
2023-09-22 21:33:15 +02:00
|
|
|
let callIntegrationEnabled = flags[CALL_INTEGRATION_ENABLED as keyof typeof flags];
|
2023-07-24 12:22:51 +02:00
|
|
|
|
|
|
|
|
// CallKit does not work on the simulator, make sure we disable it.
|
|
|
|
|
if (Platform.OS === 'ios' && DeviceInfo.isEmulatorSync()) {
|
2023-09-22 21:33:15 +02:00
|
|
|
flags[CALL_INTEGRATION_ENABLED] = false;
|
|
|
|
|
callIntegrationEnabled = false;
|
2023-07-24 12:22:51 +02:00
|
|
|
logger.info('Disabling CallKit because this is a simulator');
|
|
|
|
|
}
|
2022-05-06 11:20:22 +02:00
|
|
|
|
2023-09-22 21:33:15 +02:00
|
|
|
// Disable Android ConnectionService by default.
|
|
|
|
|
if (Platform.OS === 'android' && typeof callIntegrationEnabled === 'undefined') {
|
|
|
|
|
flags[CALL_INTEGRATION_ENABLED] = false;
|
|
|
|
|
callIntegrationEnabled = false;
|
|
|
|
|
}
|
|
|
|
|
|
2022-05-06 11:20:22 +02:00
|
|
|
// We set these early enough so then we avoid any unnecessary re-renders.
|
2023-04-12 16:58:42 +03:00
|
|
|
dispatch?.(updateFlags(flags));
|
2022-05-06 11:20:22 +02:00
|
|
|
|
2022-02-01 13:29:54 +02:00
|
|
|
const route = await _getRouteToRender();
|
|
|
|
|
|
|
|
|
|
// We need the root navigator to be set early.
|
|
|
|
|
await this._navigate(route);
|
2020-07-22 12:50:10 +02:00
|
|
|
|
2022-05-06 11:20:22 +02:00
|
|
|
// HACK ALERT!
|
|
|
|
|
// Wait until the root navigator is ready.
|
|
|
|
|
// We really need to break the inheritance relationship between App,
|
|
|
|
|
// AbstractApp and BaseApp, it's very inflexible and cumbersome right now.
|
2023-04-12 16:58:42 +03:00
|
|
|
const rootNavigationReady = new Promise<void>(resolve => {
|
2022-05-06 11:20:22 +02:00
|
|
|
const i = setInterval(() => {
|
2023-04-12 16:58:42 +03:00
|
|
|
// @ts-ignore
|
2022-05-06 11:20:22 +02:00
|
|
|
const { ready } = getState()['features/app'] || {};
|
|
|
|
|
|
|
|
|
|
if (ready) {
|
|
|
|
|
clearInterval(i);
|
|
|
|
|
resolve();
|
|
|
|
|
}
|
|
|
|
|
}, 50);
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
await rootNavigationReady;
|
2020-06-26 12:47:48 +03:00
|
|
|
|
2023-10-30 09:52:45 +01:00
|
|
|
// Update specified server URL.
|
2023-11-22 17:13:02 +02:00
|
|
|
if (typeof url !== 'undefined') {
|
|
|
|
|
|
2023-10-30 09:52:45 +01:00
|
|
|
// @ts-ignore
|
2023-11-22 17:13:02 +02:00
|
|
|
const { serverURL } = url;
|
2020-06-26 12:47:48 +03:00
|
|
|
|
2023-10-30 09:52:45 +01:00
|
|
|
if (typeof serverURL !== 'undefined') {
|
|
|
|
|
dispatch?.(updateSettings({ serverURL }));
|
2020-06-26 12:47:48 +03:00
|
|
|
}
|
2022-01-07 15:18:24 +02:00
|
|
|
}
|
2019-05-24 13:06:05 +02:00
|
|
|
|
2023-11-22 17:13:02 +02:00
|
|
|
// @ts-ignore
|
|
|
|
|
dispatch?.(updateSettings(userInfo || {}));
|
2019-10-18 16:30:59 +02:00
|
|
|
|
2022-01-07 15:18:24 +02:00
|
|
|
// Update settings with feature-flag.
|
|
|
|
|
if (typeof callIntegrationEnabled !== 'undefined') {
|
2023-04-12 16:58:42 +03:00
|
|
|
dispatch?.(updateSettings({ disableCallIntegration: !callIntegrationEnabled }));
|
2022-01-07 15:18:24 +02:00
|
|
|
}
|
2016-10-05 09:36:59 -05:00
|
|
|
}
|
|
|
|
|
|
2020-06-02 11:03:17 +02:00
|
|
|
/**
|
|
|
|
|
* Overrides the parent method to inject {@link DimensionsDetector} as
|
|
|
|
|
* the top most component.
|
|
|
|
|
*
|
|
|
|
|
* @override
|
|
|
|
|
*/
|
2023-04-12 16:58:42 +03:00
|
|
|
_createMainElement(component: ComponentType<any>, props: Object) {
|
2020-06-02 11:03:17 +02:00
|
|
|
return (
|
2022-05-06 05:18:57 -05:00
|
|
|
<SafeAreaProvider>
|
|
|
|
|
<DimensionsDetector
|
|
|
|
|
onDimensionsChanged = { this._onDimensionsChanged }
|
|
|
|
|
onSafeAreaInsetsChanged = { this._onSafeAreaInsetsChanged }>
|
|
|
|
|
{ super._createMainElement(component, props) }
|
|
|
|
|
</DimensionsDetector>
|
|
|
|
|
</SafeAreaProvider>
|
2020-06-02 11:03:17 +02:00
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
2017-01-05 15:06:41 -06:00
|
|
|
/**
|
|
|
|
|
* Attempts to disable the use of React Native
|
|
|
|
|
* {@link ExceptionsManager#handleException} on platforms and in
|
|
|
|
|
* configurations on/in which the use of the method in questions has been
|
|
|
|
|
* determined to be undesirable. For example, React Native will
|
2018-07-12 11:16:57 -05:00
|
|
|
* (intentionally) throw an unhandled {@code JavascriptException} for an
|
2017-01-05 15:06:41 -06:00
|
|
|
* unhandled JavaScript error in the Release configuration. This will
|
2018-07-12 11:16:57 -05:00
|
|
|
* effectively kill the app. In accord with the Web, do not kill the app.
|
2017-01-05 15:06:41 -06:00
|
|
|
*
|
|
|
|
|
* @private
|
|
|
|
|
* @returns {void}
|
|
|
|
|
*/
|
|
|
|
|
_maybeDisableExceptionsManager() {
|
|
|
|
|
if (__DEV__) {
|
|
|
|
|
// As mentioned above, only the Release configuration was observed
|
|
|
|
|
// to suffer.
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
if (Platform.OS !== 'android') {
|
|
|
|
|
// A solution based on RTCSetFatalHandler was implemented on iOS and
|
|
|
|
|
// it is preferred because it is at a later step of the
|
|
|
|
|
// error/exception handling and it is specific to fatal
|
2018-07-12 11:16:57 -05:00
|
|
|
// errors/exceptions which were observed to kill the app. The
|
2021-03-16 11:59:33 -04:00
|
|
|
// solution implemented below was tested on Android only so it is
|
2018-07-12 11:16:57 -05:00
|
|
|
// considered safest to use it there only.
|
2017-01-05 15:06:41 -06:00
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2023-04-12 16:58:42 +03:00
|
|
|
// @ts-ignore
|
2017-01-05 15:06:41 -06:00
|
|
|
const oldHandler = global.ErrorUtils.getGlobalHandler();
|
|
|
|
|
const newHandler = _handleException;
|
|
|
|
|
|
|
|
|
|
if (!oldHandler || oldHandler !== newHandler) {
|
2023-04-12 16:58:42 +03:00
|
|
|
// @ts-ignore
|
2017-01-05 15:06:41 -06:00
|
|
|
newHandler.next = oldHandler;
|
2023-04-12 16:58:42 +03:00
|
|
|
|
|
|
|
|
// @ts-ignore
|
2017-01-05 15:06:41 -06:00
|
|
|
global.ErrorUtils.setGlobalHandler(newHandler);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2020-06-02 11:03:17 +02:00
|
|
|
/**
|
|
|
|
|
* Updates the known available size for the app to occupy.
|
|
|
|
|
*
|
|
|
|
|
* @param {number} width - The component's current width.
|
|
|
|
|
* @param {number} height - The component's current height.
|
|
|
|
|
* @private
|
|
|
|
|
* @returns {void}
|
|
|
|
|
*/
|
|
|
|
|
_onDimensionsChanged(width: number, height: number) {
|
2023-04-12 16:58:42 +03:00
|
|
|
const { dispatch } = this.state.store ?? {};
|
2020-06-02 11:03:17 +02:00
|
|
|
|
2023-04-12 16:58:42 +03:00
|
|
|
dispatch?.(clientResized(width, height));
|
2020-06-02 11:03:17 +02:00
|
|
|
}
|
|
|
|
|
|
2022-05-06 05:18:57 -05:00
|
|
|
/**
|
|
|
|
|
* Updates the safe are insets values.
|
|
|
|
|
*
|
|
|
|
|
* @param {Object} insets - The insets.
|
|
|
|
|
* @param {number} insets.top - The top inset.
|
|
|
|
|
* @param {number} insets.right - The right inset.
|
|
|
|
|
* @param {number} insets.bottom - The bottom inset.
|
|
|
|
|
* @param {number} insets.left - The left inset.
|
|
|
|
|
* @private
|
|
|
|
|
* @returns {void}
|
|
|
|
|
*/
|
2023-04-12 16:58:42 +03:00
|
|
|
_onSafeAreaInsetsChanged(insets: Object) {
|
|
|
|
|
const { dispatch } = this.state.store ?? {};
|
2022-05-06 05:18:57 -05:00
|
|
|
|
2023-04-12 16:58:42 +03:00
|
|
|
dispatch?.(setSafeAreaInsets(insets));
|
2022-05-06 05:18:57 -05:00
|
|
|
}
|
|
|
|
|
|
2018-09-03 15:53:24 +02:00
|
|
|
/**
|
|
|
|
|
* Renders the platform specific dialog container.
|
|
|
|
|
*
|
|
|
|
|
* @returns {React$Element}
|
|
|
|
|
*/
|
|
|
|
|
_renderDialogContainer() {
|
|
|
|
|
return (
|
2022-06-20 11:50:40 +02:00
|
|
|
<DialogContainerWrapper
|
|
|
|
|
pointerEvents = 'box-none'
|
|
|
|
|
style = { StyleSheet.absoluteFill }>
|
2022-06-20 16:53:19 +02:00
|
|
|
<BottomSheetContainer />
|
2022-06-20 11:50:40 +02:00
|
|
|
<DialogContainer />
|
|
|
|
|
</DialogContainerWrapper>
|
2018-09-03 15:53:24 +02:00
|
|
|
);
|
|
|
|
|
}
|
2016-10-05 09:36:59 -05:00
|
|
|
}
|
2017-01-05 15:06:41 -06:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Handles a (possibly unhandled) JavaScript error by preventing React Native
|
|
|
|
|
* from converting a fatal error into an unhandled native exception which will
|
2018-07-12 11:16:57 -05:00
|
|
|
* kill the app.
|
2017-01-05 15:06:41 -06:00
|
|
|
*
|
|
|
|
|
* @param {Error} error - The (possibly unhandled) JavaScript error to handle.
|
2018-07-12 11:16:57 -05:00
|
|
|
* @param {boolean} fatal - If the specified error is fatal, {@code true};
|
|
|
|
|
* otherwise, {@code false}.
|
2017-01-05 15:06:41 -06:00
|
|
|
* @private
|
|
|
|
|
* @returns {void}
|
|
|
|
|
*/
|
2023-04-12 16:58:42 +03:00
|
|
|
function _handleException(error: Error, fatal: boolean) {
|
2017-01-05 15:06:41 -06:00
|
|
|
if (fatal) {
|
|
|
|
|
// In the Release configuration, React Native will (intentionally) throw
|
|
|
|
|
// an unhandled JavascriptException for an unhandled JavaScript error.
|
2018-07-12 11:16:57 -05:00
|
|
|
// This will effectively kill the app. In accord with the Web, do not
|
|
|
|
|
// kill the app.
|
2018-07-30 16:38:25 +02:00
|
|
|
logger.error(error);
|
2017-01-05 15:06:41 -06:00
|
|
|
} else {
|
|
|
|
|
// Forward to the next globalHandler of ErrorUtils.
|
2023-04-12 16:58:42 +03:00
|
|
|
// @ts-ignore
|
2018-07-12 11:16:57 -05:00
|
|
|
const { next } = _handleException;
|
2017-01-05 15:06:41 -06:00
|
|
|
|
|
|
|
|
typeof next === 'function' && next(error, fatal);
|
|
|
|
|
}
|
|
|
|
|
}
|