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

fix: check canUseTouchScreen on each render #24356

Merged
Merged
Changes from 1 commit
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
6 changes: 3 additions & 3 deletions src/components/Attachments/AttachmentCarousel/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ import compose from '../../../libs/compose';
import useCarouselArrows from './useCarouselArrows';
import useWindowDimensions from '../../../hooks/useWindowDimensions';

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 @@ -27,6 +26,7 @@ function AttachmentCarousel({report, reportActions, source, onNavigate}) {
const scrollRef = useRef(null);

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

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One minor concern is that we currently can't trigger a re-render when the value from DeviceCapabilities.canUseTouchScreen() changes. This means we're dependent on external factors to trigger a re-render of AttachmentCarousel before it acknowledges any change in the canUseTouchScreen() value.

However, given the context of this specific use-case, this behavior seems acceptable.


const {attachments, initialPage, initialActiveSource, initialItem} = useMemo(() => extractAttachmentsFromReport(report, reportActions, source), [report, reportActions, source]);

Expand Down Expand Up @@ -82,7 +82,7 @@ function AttachmentCarousel({report, reportActions, source, onNavigate}) {

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

/**
Expand Down Expand Up @@ -143,7 +143,7 @@ function AttachmentCarousel({report, reportActions, source, onNavigate}) {
isUsedInCarousel
/>
),
[activeSource, setShouldShowArrows, shouldShowArrows],
[activeSource, canUseTouchScreen, setShouldShowArrows, shouldShowArrows],
);

return (
Expand Down
Loading