diff --git a/package.json b/package.json index 081f48a..2a046dc 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@observation.org/react-native-components", - "version": "1.38.0", + "version": "1.39.0", "main": "src/index.ts", "repository": "git@github.com:observation/react-native-components.git", "author": "Observation.org", diff --git a/src/components/Lightbox.tsx b/src/components/Lightbox.tsx index d0db34d..ddd3311 100644 --- a/src/components/Lightbox.tsx +++ b/src/components/Lightbox.tsx @@ -42,6 +42,7 @@ const getLightboxFooterComponent = content?: React.ReactNode, style?: LightboxStyle, onPressDelete?: () => void, + onPressCrop?: () => void, ) => () => ( @@ -57,13 +58,22 @@ const getLightboxFooterComponent = )} {content && {content}} - {onPressDelete && ( + {(onPressDelete || onPressCrop) && ( - - - - - + {onPressDelete && ( + + + + + + )} + {onPressCrop && ( + + + + + + )} )} @@ -78,6 +88,7 @@ type Props = { index?: number onClose: () => void onDelete?: (imageIndex: number) => void + onCrop?: (imageIndex: number) => void photos: string[] title?: string description?: string @@ -85,11 +96,12 @@ type Props = { style?: LightboxStyle } -const Lightbox = ({ index, onClose, onDelete, photos, title, description, content, style }: Props) => { +const Lightbox = ({ index, onClose, onDelete, onCrop, photos, title, description, content, style }: Props) => { const initialImageIndex = index ?? 0 const [currentImageIndex, setCurrentImageIndex] = useState() const onPressDelete = onDelete ? () => onDelete(currentImageIndex ?? initialImageIndex) : undefined + const onPressCrop = onCrop ? () => onCrop(currentImageIndex ?? initialImageIndex) : undefined return ( ) } diff --git a/src/components/__tests__/Lightbox.test.tsx b/src/components/__tests__/Lightbox.test.tsx index 1d58f26..e9b4875 100644 --- a/src/components/__tests__/Lightbox.test.tsx +++ b/src/components/__tests__/Lightbox.test.tsx @@ -77,6 +77,15 @@ describe('Lightbox', () => { expect(queryByTestId('delete-photo')).not.toBeNull() expect(toJSON()).toMatchSnapshot() }) + + test('With a crop button', () => { + const { toJSON, queryByTestId } = render( + {}} />, + ) + + expect(queryByTestId('crop-photo')).not.toBeNull() + expect(toJSON()).toMatchSnapshot() + }) }) describe('Interaction', () => { @@ -103,6 +112,18 @@ describe('Lightbox', () => { expect(onDelete).toHaveBeenCalledWith(0) }) + test('Press crop button calls onCrop', async () => { + // GIVEN + const onCrop = jest.fn() + const { getByTestId } = render() + + // WHEN + await fireEvent.press(getByTestId('crop-photo')) + + // THEN + expect(onCrop).toHaveBeenCalledWith(0) + }) + test('When swiping to the second photo and pressing the delete button, onDelete is called with the second photo', async () => { // GIVEN jest.mock('@observation.org/react-native-image-viewing', () => 'ImageCarousel') diff --git a/src/components/__tests__/__snapshots__/Lightbox.test.tsx.snap b/src/components/__tests__/__snapshots__/Lightbox.test.tsx.snap index e9939df..8a78956 100644 --- a/src/components/__tests__/__snapshots__/Lightbox.test.tsx.snap +++ b/src/components/__tests__/__snapshots__/Lightbox.test.tsx.snap @@ -1599,6 +1599,437 @@ exports[`Lightbox Rendering Second photo 1`] = ` `; +exports[`Lightbox Rendering With a crop button 1`] = ` + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +`; + exports[`Lightbox Rendering With a delete button 1`] = `