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

`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:
Amit Uttam 2020-03-19 13:50:51 -03:00 committed by GitHub
parent 4a1c35489d
commit 956b65556c
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

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));
}
}
};