-
Notifications
You must be signed in to change notification settings - Fork 0
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
Add delete button to Lightbox #41
Changes from 14 commits
e422833
be35706
6b3163d
e522d82
168c9b4
c343b9a
6d94164
119bd46
0eb9ab4
357c071
83e699c
768ce68
0ff2a3e
a57afda
a3713a6
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
{ | ||
"name": "@observation.org/react-native-components", | ||
"version": "1.31.0", | ||
"version": "1.32.0", | ||
"main": "src/index.ts", | ||
"repository": "[email protected]:observation/react-native-components.git", | ||
"author": "Observation.org", | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
import React from 'react' | ||
import React, { useState } from 'react' | ||
import { SafeAreaView, StyleSheet, Text, TextStyle, TouchableOpacity, View } from 'react-native' | ||
|
||
import ImageView from '@observation.org/react-native-image-viewing' | ||
|
@@ -10,34 +10,40 @@ import font from '../styles/font' | |
import textStyle from '../styles/text' | ||
import theme from '../styles/theme' | ||
|
||
const hitSlop = { top: 16, left: 16, bottom: 16, right: 16 } | ||
|
||
const getLightboxHeaderComponent = | ||
(numberOfPages: number, onClose: () => void) => | ||
({ imageIndex }: { imageIndex: number }) => { | ||
const hitSlop = { top: 16, left: 16, bottom: 16, right: 16 } | ||
return ( | ||
<SafeAreaView style={styles.lightboxHeaderContainer}> | ||
<View style={styles.lightboxHeader}> | ||
<View style={{ flex: 1 }} /> | ||
<View style={styles.pageIndicator}> | ||
<PageIndicator currentPage={imageIndex + 1} numberOfPages={numberOfPages} /> | ||
</View> | ||
<View style={{ flex: 1 }}> | ||
<TouchableOpacity style={styles.closeButton} onPress={() => onClose()} hitSlop={hitSlop}> | ||
<Icon | ||
name="times" | ||
color={Color(theme.color.white).alpha(0.5).string()} | ||
size={theme.icon.size.extraExtraLarge} | ||
testID="close-lightbox" | ||
/> | ||
</TouchableOpacity> | ||
</View> | ||
({ imageIndex }: { imageIndex: number }) => ( | ||
<SafeAreaView style={styles.lightboxHeaderContainer}> | ||
<View style={styles.lightboxHeader}> | ||
<View style={{ flex: 1 }} /> | ||
<View style={styles.pageIndicator}> | ||
<PageIndicator currentPage={imageIndex + 1} numberOfPages={numberOfPages} /> | ||
</View> | ||
</SafeAreaView> | ||
) | ||
} | ||
<View style={{ flex: 1 }}> | ||
<TouchableOpacity style={styles.closeButton} onPress={() => onClose()} hitSlop={hitSlop}> | ||
<Icon | ||
name="times" | ||
color={Color(theme.color.white).alpha(0.5).string()} | ||
size={theme.icon.size.extraExtraLarge} | ||
testID="close-lightbox" | ||
/> | ||
</TouchableOpacity> | ||
</View> | ||
</View> | ||
</SafeAreaView> | ||
) | ||
|
||
const getLightboxFooterComponent = | ||
(title?: string, description?: string, content?: React.ReactNode, style?: LightboxStyle) => () => ( | ||
( | ||
title?: string, | ||
description?: string, | ||
content?: React.ReactNode, | ||
style?: LightboxStyle, | ||
onPressDelete?: () => void, | ||
) => | ||
() => ( | ||
<SafeAreaView style={styles.lightboxFooterContainer}> | ||
<View style={styles.lightboxFooter}> | ||
{title && ( | ||
|
@@ -51,6 +57,15 @@ const getLightboxFooterComponent = | |
</View> | ||
)} | ||
{content && <View style={styles.footerItem}>{content}</View>} | ||
{onPressDelete && ( | ||
<View style={styles.buttonsContainer}> | ||
<View style={styles.buttonContainer}> | ||
<TouchableOpacity onPress={onPressDelete} hitSlop={hitSlop}> | ||
<Icon name="trash-alt" color={theme.color.white} size={20} testID="delete-photo" /> | ||
</TouchableOpacity> | ||
</View> | ||
</View> | ||
)} | ||
</View> | ||
</SafeAreaView> | ||
) | ||
|
@@ -62,24 +77,33 @@ type LightboxStyle = { | |
type Props = { | ||
index?: number | ||
onClose: () => void | ||
onDelete?: (imageIndex: number) => void | ||
photos: string[] | ||
title?: string | ||
description?: string | ||
content?: JSX.Element | ||
style?: LightboxStyle | ||
} | ||
|
||
const Lightbox = ({ index, onClose, photos, title, description, content, style }: Props) => ( | ||
<ImageView | ||
images={photos.map((photo) => ({ uri: photo }))} | ||
imageIndex={index ?? 0} | ||
visible={index !== undefined} | ||
swipeToCloseEnabled={false} | ||
onRequestClose={onClose} | ||
HeaderComponent={getLightboxHeaderComponent(photos.length, onClose)} | ||
FooterComponent={getLightboxFooterComponent(title, description, content, style)} | ||
/> | ||
) | ||
const Lightbox = ({ index, onClose, onDelete, photos, title, description, content, style }: Props) => { | ||
const initialIndex = index ?? 0 | ||
const [currentImageIndex, setCurrentImageIndex] = useState<number>() | ||
|
||
const onPressDelete = onDelete ? () => onDelete(currentImageIndex ?? initialIndex) : undefined | ||
|
||
return ( | ||
<ImageView | ||
images={photos.map((photo) => ({ uri: photo }))} | ||
imageIndex={initialIndex} | ||
visible={index !== undefined} | ||
swipeToCloseEnabled={false} | ||
onImageIndexChange={setCurrentImageIndex} | ||
onRequestClose={onClose} | ||
HeaderComponent={getLightboxHeaderComponent(photos.length, onClose)} | ||
FooterComponent={getLightboxFooterComponent(title, description, content, style, onPressDelete)} | ||
/> | ||
) | ||
} | ||
|
||
export default Lightbox | ||
|
||
|
@@ -123,4 +147,13 @@ const styles = StyleSheet.create({ | |
...textStyle.body, | ||
color: theme.color.white, | ||
}, | ||
buttonsContainer: { | ||
flexDirection: 'row', | ||
marginVertical: theme.margin.large, | ||
marginHorizontal: theme.margin.common, | ||
}, | ||
buttonContainer: { | ||
width: '50%', | ||
alignItems: 'center', | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Dit gaat mis als we drie buttons hebben. Ik denk dat het beter is om dit te vervangen door |
||
}, | ||
}) |
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Zoals ook gezegd in de andere PR voor dit issue: ik weet niet hoe ik deze test moet implementeren: Dit omdat ik niet goed inzie hoe het swipen kan gesimuleerd worden. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Een swipe doen kan zo te zien niet via testing library, maar second best is om een There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Je kunt zo'n |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Of dit om consistent te blijven?