From 1a831aac66e69cb5ec4e240c61449c9056069af6 Mon Sep 17 00:00:00 2001 From: Mattermost Build Date: Thu, 19 Mar 2020 17:57:16 +0100 Subject: [PATCH] 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. --- app/init/global_event_handler.js | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/app/init/global_event_handler.js b/app/init/global_event_handler.js index 46482a1cd..cc1f6e7c2 100644 --- a/app/init/global_event_handler.js +++ b/app/init/global_event_handler.js @@ -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)); + } } };