From 963f86f1eba6d9dbf7fb2fb1e3623d7c11fe7b68 Mon Sep 17 00:00:00 2001 From: ibrahimtuna Date: Wed, 31 Jan 2024 17:37:42 +0300 Subject: [PATCH] fix landscape flickering bug --- src/Date/AutoSizer.tsx | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/src/Date/AutoSizer.tsx b/src/Date/AutoSizer.tsx index 07396aef..4f31666f 100644 --- a/src/Date/AutoSizer.tsx +++ b/src/Date/AutoSizer.tsx @@ -1,5 +1,5 @@ import * as React from 'react' -import { LayoutChangeEvent, StyleSheet, View } from 'react-native' +import { Dimensions, LayoutChangeEvent, StyleSheet, View } from 'react-native' type WidthAndHeight = { width: number @@ -15,9 +15,17 @@ export default function AutoSizer({ const onLayout = React.useCallback( (event: LayoutChangeEvent) => { const nl = event.nativeEvent.layout + const windowDimensions = Dimensions.get('window') + const isLandscapeScreen = windowDimensions.width > windowDimensions.height // https://github.com/necolas/react-native-web/issues/1704 - if (!layout || layout.width !== nl.width || layout.height !== nl.height) { + if (!layout) { + setLayout({ width: nl.width, height: nl.height }) + return + } + if (isLandscapeScreen && nl.width < layout.width) { + return + } else if (layout.width !== nl.width || layout.height !== nl.height) { setLayout({ width: nl.width, height: nl.height }) } },