Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use debounce for onDimensionChange in withWindowDimensions HOC #2799

Merged
merged 2 commits into from
May 13, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion src/components/withWindowDimensions.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import React, {Component} from 'react';
import _ from 'underscore';
import PropTypes from 'prop-types';
import {Dimensions} from 'react-native';
import getComponentDisplayName from '../libs/getComponentDisplayName';
Expand Down Expand Up @@ -28,7 +29,14 @@ export default function (WrappedComponent) {
constructor(props) {
super(props);

this.onDimensionChange = this.onDimensionChange.bind(this);
// Using debounce here as a temporary fix for a bug in react-native
// https://github.com/facebook/react-native/issues/29290
// When the app is sent to background on iPads, onDimensionChange callback is called with
// swapped window dimensions before it was called with correct dimensions within miliseconds, then
// drawer is being positioned incorrectly due to animation issues in react-navigation.
// Adding debounce here slows down window dimension changes to let
// react-navigation to complete the positioning of elements properly.
this.onDimensionChange = _.debounce(this.onDimensionChange.bind(this), 100);

const initialDimensions = Dimensions.get('window');
const isSmallScreenWidth = initialDimensions.width <= variables.mobileResponsiveWidthBreakpoint;
Expand Down