Skip to content

Commit

Permalink
Merge pull request #24356 from margelo/fix/attachment-caruousel-canus…
Browse files Browse the repository at this point in the history
…etouchscreen

fix: check canUseTouchScreen on each render
  • Loading branch information
MariaHCD authored Sep 14, 2023
2 parents 39d0f01 + 15fc3a7 commit 3e2723c
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 7 deletions.
8 changes: 4 additions & 4 deletions src/components/Attachments/AttachmentCarousel/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import React, {useRef, useCallback, useState, useEffect} from 'react';
import {View, FlatList, PixelRatio, Keyboard} from 'react-native';
import {withOnyx} from 'react-native-onyx';
import _ from 'underscore';
import * as DeviceCapabilities from '../../../libs/DeviceCapabilities';
import styles from '../../../styles/styles';
import CarouselActions from './CarouselActions';
import withWindowDimensions from '../../withWindowDimensions';
Expand All @@ -19,8 +18,8 @@ import Navigation from '../../../libs/Navigation/Navigation';
import BlockingView from '../../BlockingViews/BlockingView';
import * as Illustrations from '../../Icon/Illustrations';
import variables from '../../../styles/variables';
import * as DeviceCapabilities from '../../../libs/DeviceCapabilities';

const canUseTouchScreen = DeviceCapabilities.canUseTouchScreen();
const viewabilityConfig = {
// To facilitate paging through the attachments, we want to consider an item "viewable" when it is
// more than 95% visible. When that happens we update the page index in the state.
Expand All @@ -31,6 +30,7 @@ function AttachmentCarousel({report, reportActions, source, onNavigate, setDownl
const scrollRef = useRef(null);

const {windowWidth, isSmallScreenWidth} = useWindowDimensions();
const canUseTouchScreen = DeviceCapabilities.canUseTouchScreen();

const [containerWidth, setContainerWidth] = useState(0);
const [page, setPage] = useState(0);
Expand Down Expand Up @@ -99,7 +99,7 @@ function AttachmentCarousel({report, reportActions, source, onNavigate, setDownl

scrollRef.current.scrollToIndex({index: nextIndex, animated: canUseTouchScreen});
},
[attachments, page],
[attachments, canUseTouchScreen, page],
);

/**
Expand Down Expand Up @@ -159,7 +159,7 @@ function AttachmentCarousel({report, reportActions, source, onNavigate, setDownl
onPress={canUseTouchScreen ? () => setShouldShowArrows(!shouldShowArrows) : undefined}
/>
),
[activeSource, setShouldShowArrows, shouldShowArrows],
[activeSource, canUseTouchScreen, setShouldShowArrows, shouldShowArrows],
);

return (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,8 @@ import {useCallback, useEffect, useRef, useState} from 'react';
import CONST from '../../../CONST';
import * as DeviceCapabilities from '../../../libs/DeviceCapabilities';

const canUseTouchScreen = DeviceCapabilities.canUseTouchScreen();

function useCarouselArrows() {
const canUseTouchScreen = DeviceCapabilities.canUseTouchScreen();
const [shouldShowArrows, setShouldShowArrowsInternal] = useState(canUseTouchScreen);
const autoHideArrowTimeout = useRef(null);

Expand All @@ -25,7 +24,7 @@ function useCarouselArrows() {
autoHideArrowTimeout.current = setTimeout(() => {
setShouldShowArrowsInternal(false);
}, CONST.ARROW_HIDE_DELAY);
}, [cancelAutoHideArrows]);
}, [canUseTouchScreen, cancelAutoHideArrows]);

const setShouldShowArrows = useCallback(
(show = true) => {
Expand Down

0 comments on commit 3e2723c

Please sign in to comment.