Skip to content

Commit 4983a43

Browse files
committed
tests: added unit tests for new state stores
1 parent ca6b990 commit 4983a43

18 files changed

+2090
-705
lines changed

package/src/components/Attachment/Gallery.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -284,7 +284,7 @@ const GalleryThumbnail = ({
284284
if (!message) {
285285
return;
286286
}
287-
imageGalleryStateStore.openImageGallery(message, thumbnail.url);
287+
imageGalleryStateStore.openImageGallery({ message, selectedAttachmentUrl: thumbnail.url });
288288
setOverlay('gallery');
289289
};
290290

package/src/components/Attachment/Giphy.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -208,7 +208,7 @@ const GiphyWithContext = (props: GiphyPropsWithContext) => {
208208
if (!uri) {
209209
return;
210210
}
211-
imageGalleryStateStore.openImageGallery(message, uri);
211+
imageGalleryStateStore.openImageGallery({ message, selectedAttachmentUrl: uri });
212212
setOverlay('gallery');
213213
};
214214

package/src/components/ImageGallery/ImageGallery.tsx

Lines changed: 47 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ import { Gesture, GestureDetector } from 'react-native-gesture-handler';
55

66
import Animated, {
77
Easing,
8-
SharedValue,
98
useAnimatedReaction,
109
useAnimatedStyle,
1110
useDerivedValue,
@@ -35,7 +34,14 @@ import {
3534

3635
import { useImageGalleryGestures } from './hooks/useImageGalleryGestures';
3736

38-
import { useImageGalleryContext } from '../../contexts/imageGalleryContext/ImageGalleryContext';
37+
import {
38+
ImageGalleryProviderProps,
39+
useImageGalleryContext,
40+
} from '../../contexts/imageGalleryContext/ImageGalleryContext';
41+
import {
42+
OverlayContextValue,
43+
useOverlayContext,
44+
} from '../../contexts/overlayContext/OverlayContext';
3945
import { useTheme } from '../../contexts/themeContext/ThemeContext';
4046
import { useStateStore } from '../../hooks';
4147
import { useViewport } from '../../hooks/useViewport';
@@ -99,25 +105,30 @@ const imageGallerySelector = (state: ImageGalleryState) => ({
99105
currentIndex: state.currentIndex,
100106
});
101107

102-
type Props = {
103-
overlayOpacity: SharedValue<number>;
104-
};
108+
type ImageGalleryWithContextProps = Pick<
109+
ImageGalleryProviderProps,
110+
| 'imageGalleryCustomComponents'
111+
| 'imageGalleryGridSnapPoints'
112+
| 'imageGalleryGridHandleHeight'
113+
| 'numberOfImageGalleryGridColumns'
114+
> &
115+
Pick<OverlayContextValue, 'overlayOpacity'>;
105116

106-
export const ImageGallery = (props: Props) => {
107-
const { overlayOpacity } = props;
117+
export const ImageGalleryWithContext = (props: ImageGalleryWithContextProps) => {
118+
const {
119+
imageGalleryGridHandleHeight,
120+
imageGalleryGridSnapPoints,
121+
imageGalleryCustomComponents,
122+
numberOfImageGalleryGridColumns,
123+
overlayOpacity,
124+
} = props;
108125
const {
109126
theme: {
110127
colors: { white_snow },
111128
imageGallery: { backgroundColor, pager, slide },
112129
},
113130
} = useTheme();
114-
const {
115-
imageGalleryStateStore,
116-
imageGalleryCustomComponents,
117-
imageGalleryGridHandleHeight,
118-
imageGalleryGridSnapPoints,
119-
numberOfImageGalleryGridColumns,
120-
} = useImageGalleryContext();
131+
const { imageGalleryStateStore } = useImageGalleryContext();
121132
const { currentIndex } = useStateStore(imageGalleryStateStore.state, imageGallerySelector);
122133
const { assets, videoPlayerPool } = imageGalleryStateStore;
123134

@@ -436,6 +447,28 @@ export const ImageGallery = (props: Props) => {
436447
);
437448
};
438449

450+
export type ImageGalleryProps = Partial<ImageGalleryWithContextProps>;
451+
452+
export const ImageGallery = (props: ImageGalleryProps) => {
453+
const {
454+
imageGalleryCustomComponents,
455+
imageGalleryGridHandleHeight,
456+
imageGalleryGridSnapPoints,
457+
numberOfImageGalleryGridColumns,
458+
} = useImageGalleryContext();
459+
const { overlayOpacity } = useOverlayContext();
460+
return (
461+
<ImageGalleryWithContext
462+
imageGalleryCustomComponents={imageGalleryCustomComponents}
463+
imageGalleryGridHandleHeight={imageGalleryGridHandleHeight}
464+
imageGalleryGridSnapPoints={imageGalleryGridSnapPoints}
465+
numberOfImageGalleryGridColumns={numberOfImageGalleryGridColumns}
466+
overlayOpacity={overlayOpacity}
467+
{...props}
468+
/>
469+
);
470+
};
471+
439472
/**
440473
* Clamping worklet to clamp the scaling
441474
*/

package/src/components/ImageGallery/__tests__/AnimatedVideoGallery.test.tsx

Lines changed: 0 additions & 156 deletions
This file was deleted.

0 commit comments

Comments
 (0)