Skip to content

Commit

Permalink
Prevent loop of switching between scrollable and paginated horizontal…
Browse files Browse the repository at this point in the history
… gallery (#3730)

* Prevent possible endless loop of switching between scrollable and paginated horizontal gallery in VideoGallery

* Change files

* Duplicate change files for beta release

* fix and memoize scrollable horizontal gallery container style

* lint fix

* fix scrollable horizontal gallery width for other video gallery layouts

* dependecy array lint fix
  • Loading branch information
mgamis-msft authored Nov 5, 2023
1 parent 84b4c01 commit 6798e07
Show file tree
Hide file tree
Showing 13 changed files with 81 additions and 34 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"type": "patch",
"area": "fix",
"workstream": "VideoGallery",
"comment": "Prevent possible endless loop of switching between scrollable and paginated horizontal gallery in VideoGallery",
"packageName": "@azure/communication-react",
"email": "[email protected]",
"dependentChangeType": "patch"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"type": "patch",
"area": "fix",
"workstream": "VideoGallery",
"comment": "Prevent possible endless loop of switching between scrollable and paginated horizontal gallery in VideoGallery",
"packageName": "@azure/communication-react",
"email": "[email protected]",
"dependentChangeType": "patch"
}
3 changes: 3 additions & 0 deletions packages/acs-ui-common/review/beta/acs-ui-common.api.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,9 @@ export type CommonProperties<A, B> = {
[P in keyof A & keyof B]: A[P] extends B[P] ? P : never;
}[keyof A & keyof B];

// @internal
export const _convertPxToRem: (px: number) => number;

// @internal
export const _convertRemToPx: (rem: number) => number;

Expand Down
3 changes: 3 additions & 0 deletions packages/acs-ui-common/review/stable/acs-ui-common.api.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,9 @@ export type CommonProperties<A, B> = {
[P in keyof A & keyof B]: A[P] extends B[P] ? P : never;
}[keyof A & keyof B];

// @internal
export const _convertPxToRem: (px: number) => number;

// @internal
export const _convertRemToPx: (rem: number) => number;

Expand Down
10 changes: 10 additions & 0 deletions packages/acs-ui-common/src/common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,16 @@ export const _convertRemToPx = (rem: number): number => {
return rem * parseFloat(getComputedStyle(document.documentElement).fontSize);
};

/**
* @internal
* Converts units of pixels to units of rem
* @param px - units of px
* @returns units of rem
*/
export const _convertPxToRem = (px: number): number => {
return px / parseFloat(getComputedStyle(document.documentElement).fontSize);
};

/**
* @internal
* Disable dismiss on resize to work around a couple Fluent UI bugs
Expand Down
2 changes: 1 addition & 1 deletion packages/acs-ui-common/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ export {
export { _getApplicationId } from './telemetry';
export { _formatString } from './localizationUtils';
export { _safeJSONStringify } from './safeStringify';
export { _convertRemToPx, _preventDismissOnEvent } from './common';
export { _convertPxToRem, _convertRemToPx, _preventDismissOnEvent } from './common';

export type { Common, CommonProperties } from './commonProperties';
export type { CallbackType, FunctionWithKey } from './memoizeFnAll';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,7 @@ export const DefaultLayout = (props: DefaultLayoutProps): JSX.Element => {
}}
/* @conditional-compile-remove(gallery-layouts) */
layout={'default'}
parentWidth={parentWidth}
/>
);
}, [
Expand All @@ -129,7 +130,8 @@ export const DefaultLayout = (props: DefaultLayoutProps): JSX.Element => {
styles?.horizontalGallery,
/* @conditional-compile-remove(vertical-gallery) */ overflowGalleryPosition,
setIndexesToRender,
/* @conditional-compile-remove(vertical-gallery) */ styles?.verticalGallery
/* @conditional-compile-remove(vertical-gallery) */ styles?.verticalGallery,
parentWidth
]);

return (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -218,6 +218,7 @@ export const FloatingLocalVideoLayout = (props: FloatingLocalVideoLayoutProps):
onChildrenPerPageChange={(n: number) => {
childrenPerPage.current = n;
}}
parentWidth={parentWidth}
/>
);
}, [
Expand All @@ -228,7 +229,8 @@ export const FloatingLocalVideoLayout = (props: FloatingLocalVideoLayoutProps):
styles?.horizontalGallery,
/* @conditional-compile-remove(vertical-gallery) */ overflowGalleryPosition,
setIndexesToRender,
/* @conditional-compile-remove(vertical-gallery) */ styles?.verticalGallery
/* @conditional-compile-remove(vertical-gallery) */ styles?.verticalGallery,
parentWidth
]);

return (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,7 @@ export const LargeGalleryLayout = (props: LargeGalleryProps): JSX.Element => {
onChildrenPerPageChange={(n: number) => {
childrenPerPage.current = n;
}}
parentWidth={parentWidth}
/>
);
}, [
Expand All @@ -140,7 +141,8 @@ export const LargeGalleryLayout = (props: LargeGalleryProps): JSX.Element => {
styles?.horizontalGallery,
/* @conditional-compile-remove(vertical-gallery) */ overflowGalleryPosition,
setIndexesToRender,
/* @conditional-compile-remove(vertical-gallery) */ styles?.verticalGallery
/* @conditional-compile-remove(vertical-gallery) */ styles?.verticalGallery,
parentWidth
]);

return (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,13 @@ import { OverflowGalleryPosition } from '../VideoGallery';
import { VideoGalleryLayout } from '../VideoGallery';
import { ScrollableHorizontalGallery } from './ScrollableHorizontalGallery';
import {
SMALL_HORIZONTAL_GALLERY_TILE_SIZE_REM,
horizontalGalleryContainerStyle,
horizontalGalleryStyle
} from './styles/VideoGalleryResponsiveHorizontalGallery.styles';
/* @conditional-compile-remove(vertical-gallery) */
import { _convertPxToRem } from '@internal/acs-ui-common';
import { SMALL_FLOATING_MODAL_SIZE_REM } from './styles/FloatingLocalVideo.styles';
import {
verticalGalleryContainerStyle,
verticalGalleryStyle
Expand All @@ -45,6 +48,7 @@ export const OverflowGallery = (props: {
onChildrenPerPageChange?: (childrenPerPage: number) => void;
/* @conditional-compile-remove(gallery-layouts) */
layout?: VideoGalleryLayout;
parentWidth?: number;
}): JSX.Element => {
const {
shouldFloatLocalVideo = false,
Expand All @@ -56,7 +60,8 @@ export const OverflowGallery = (props: {
horizontalGalleryStyles,
/* @conditional-compile-remove(vertical-gallery) */ overflowGalleryPosition = 'horizontalBottom',
/* @conditional-compile-remove(vertical-gallery) */ verticalGalleryStyles,
onChildrenPerPageChange
onChildrenPerPageChange,
parentWidth
} = props;

const containerStyles = useMemo(() => {
Expand Down Expand Up @@ -86,6 +91,18 @@ export const OverflowGallery = (props: {
/* @conditional-compile-remove(vertical-gallery) */ verticalGalleryStyles
]);

const scrollableHorizontalGalleryContainerStyles = useMemo(() => {
if (isNarrow && parentWidth) {
return {
width:
props.layout === 'default'
? `${_convertPxToRem(parentWidth) - 1}rem`
: `${_convertPxToRem(parentWidth) - SMALL_FLOATING_MODAL_SIZE_REM.width - 1}rem`
};
}
return undefined;
}, [isNarrow, parentWidth, props.layout]);

/* @conditional-compile-remove(vertical-gallery) */
if (overflowGalleryPosition === 'verticalRight') {
return (
Expand All @@ -104,18 +121,20 @@ export const OverflowGallery = (props: {
);
}

SMALL_HORIZONTAL_GALLERY_TILE_SIZE_REM;

/* @conditional-compile-remove(pinned-participants) */
if (isNarrow) {
// There are no pages for ScrollableHorizontalGallery so we will approximate the first 3 remote
// participant tiles are visible
onChildrenPerPageChange?.(3);

return (
<ScrollableHorizontalGallery
horizontalGalleryElements={overflowGalleryElements ? overflowGalleryElements : [<></>]}
onFetchTilesToRender={onFetchTilesToRender}
key="scrollable-horizontal-gallery"
/* @conditional-compile-remove(gallery-layouts) */
layout={props.layout}
containerStyles={scrollableHorizontalGalleryContainerStyles}
/>
);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,15 +1,13 @@
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT License.

import { Stack } from '@fluentui/react';
import { IStyle, Stack, mergeStyles } from '@fluentui/react';
import React, { useEffect, useRef } from 'react';
import { useDraggable } from 'react-use-draggable-scroll';
import {
scrollableHorizontalGalleryContainerStyles,
scrollableHorizontalGalleryStyles
} from './styles/ScrollableHorizontalGallery.style';
/* @conditional-compile-remove(gallery-layouts) */
import { VideoGalleryLayout } from '../VideoGallery';

/**
* Component to display elements horizontally in a scrollable container
Expand All @@ -18,17 +16,9 @@ import { VideoGalleryLayout } from '../VideoGallery';
export const ScrollableHorizontalGallery = (props: {
horizontalGalleryElements?: JSX.Element[];
onFetchTilesToRender?: (indexes: number[]) => void;
/* @conditional-compile-remove(gallery-layouts) */
layout?: VideoGalleryLayout;
containerStyles?: IStyle;
}): JSX.Element => {
const { horizontalGalleryElements, onFetchTilesToRender, /* @conditional-compile-remove(gallery-layouts) */ layout } =
props;

const useFullWidthTrampoline = (): boolean => {
/* @conditional-compile-remove(gallery-layouts) */
return layout === 'default' ? true : false;
return false;
};
const { horizontalGalleryElements, onFetchTilesToRender, containerStyles } = props;

useEffect(() => {
const indexesArray = [...Array(horizontalGalleryElements?.length).keys()];
Expand All @@ -44,7 +34,7 @@ export const ScrollableHorizontalGallery = (props: {
<div
ref={ref}
{...dragabbleEvents}
className={scrollableHorizontalGalleryContainerStyles(useFullWidthTrampoline())}
className={mergeStyles(scrollableHorizontalGalleryContainerStyles, containerStyles)}
>
<Stack
data-ui-id="scrollable-horizontal-gallery"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,7 @@ export const SpeakerVideoLayout = (props: SpeakerVideoLayoutProps): JSX.Element
onChildrenPerPageChange={(n: number) => {
childrenPerPage.current = n;
}}
parentWidth={parentWidth}
/>
);
}, [
Expand All @@ -203,7 +204,8 @@ export const SpeakerVideoLayout = (props: SpeakerVideoLayoutProps): JSX.Element
styles?.horizontalGallery,
/* @conditional-compile-remove(vertical-gallery) */ overflowGalleryPosition,
setIndexesToRender,
/* @conditional-compile-remove(vertical-gallery) */ styles?.verticalGallery
/* @conditional-compile-remove(vertical-gallery) */ styles?.verticalGallery,
parentWidth
]);

return (
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT License.

import { IStackStyles, mergeStyles } from '@fluentui/react';
import { SMALL_FLOATING_MODAL_SIZE_REM } from './FloatingLocalVideo.styles';
import { IStackStyles, IStyle } from '@fluentui/react';
import {
SMALL_HORIZONTAL_GALLERY_TILE_SIZE_REM,
SMALL_HORIZONTAL_GALLERY_TILE_STYLE
Expand All @@ -23,14 +22,11 @@ export const scrollableHorizontalGalleryStyles: IStackStyles = {
/**
* @private
*/
export const scrollableHorizontalGalleryContainerStyles = (fullWidth: boolean): string => {
return mergeStyles({
display: 'flex',
width: fullWidth ? '100%' : `calc(100% - ${SMALL_FLOATING_MODAL_SIZE_REM.width}rem)`,
minHeight: `${SMALL_HORIZONTAL_GALLERY_TILE_SIZE_REM.height}rem`,
overflow: 'scroll',
'-ms-overflow-style': 'none',
'scrollbar-width': 'none',
'::-webkit-scrollbar': { display: 'none' }
});
export const scrollableHorizontalGalleryContainerStyles: IStyle = {
display: 'flex',
minHeight: `${SMALL_HORIZONTAL_GALLERY_TILE_SIZE_REM.height}rem`,
overflow: 'scroll',
'-ms-overflow-style': 'none',
'scrollbar-width': 'none',
'::-webkit-scrollbar': { display: 'none' }
};

0 comments on commit 6798e07

Please sign in to comment.