MM-23162 Remove unnecessary dimension and orientation dispatches (#4050)

`setDeviceOrientation` and `setDeviceDimensions` used to get called on any navigation change (e.g. modal launches) and triggered multiple needless dispatches.
This commit is contained in:
Mattermost Build
2020-03-19 17:57:16 +01:00
committed by GitHub
parent e7e972b211
commit 1a831aac66

View File

@@ -189,16 +189,26 @@ class GlobalEventHandler {
onOrientationChange = (dimensions) => {
if (this.store) {
const {dispatch} = this.store;
const {dispatch, getState} = this.store;
const deviceState = getState().device;
if (DeviceInfo.isTablet()) {
dispatch(setDeviceAsTablet());
}
const {height, width} = dimensions.window;
const orientation = height > width ? 'PORTRAIT' : 'LANDSCAPE';
const savedOrientation = deviceState?.orientation;
const savedDimension = deviceState?.dimension;
dispatch(setDeviceOrientation(orientation));
dispatch(setDeviceDimensions(height, width));
if (orientation !== savedOrientation) {
dispatch(setDeviceOrientation(orientation));
}
if (height !== savedDimension?.deviceHeight ||
width !== savedDimension?.deviceWidth) {
dispatch(setDeviceDimensions(height, width));
}
}
};