-
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
Conversation
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.
Zoals ook gezegd in de andere PR voor dit issue: ik weet niet hoe ik deze test moet implementeren:
"Swiping to the left and pressing the delete button, will delete the second photo".
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 comment
The 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 onImageIndexChange
call te triggeren vanuit ImageView
. Zou dat kunnen?
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.
Je kunt zo'n onImageIndexChange
triggeren als je met een testID erbij kan, maar dat was nu niet 't geval.
Wat ik nu heb gedaan is een mock met requireActual, die de mock inject. Dus 't is uiteindelijk gelukt.
src/components/Lightbox.tsx
Outdated
@@ -52,6 +60,15 @@ const getLightboxFooterComponent = | |||
)} | |||
{content && <View style={styles.footerItem}>{content}</View>} | |||
</View> | |||
{onPressDelete && ( |
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.
@SjaakSchilperoort we hadden het eerst over om de button(s) om de mogelijk aanwezige content te plaatsen, maar ik zag dat de buttons in het design een redelijk grote margin hebben en dus heb ik dit maar onderaan gezet.
Een voordeel is wel dat er geen snapshot changes zijn voor componenten die de onPressDelete
niet meegeven.
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.
Paar opmerkingen.
Terzijde: ik zie drie commits met de beschrijving "WIP". Kun je de commits waar een PR uit bestaat begrijpelijk maken door altijd te beschrijven wat het doel van een commit is? Ik doe het zelf ook altijd. Het is dan tijdens een code review gemakkelijker om te achterhalen waar een bepaalde code-wijziging voor nodig is. Als je enkel wat vergeten bent in een vorige commit kun je natuurlijk ook commits samenvoegen. Of als dat voor de begrijpelijkheid beter is, kun je ook de volgorde van commits aanpassen. Kost weinig moeite, maar is voor een reviewer erg fijn.
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.
Een swipe doen kan zo te zien niet via testing library, maar second best is om een onImageIndexChange
call te triggeren vanuit ImageView
. Zou dat kunnen?
src/components/Lightbox.tsx
Outdated
const [imageIndexAfterSwipe, setImageIndexAfterSwipe] = useState<number>() | ||
|
||
const imageIndex = index ?? 0 |
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.
Ik zou swipe
niet in de naam van deze velden gebruiken. Dit is te specifiek en swipe-support is ook niet de verantwoordelijkheid van deze component maar van ImageView
. Hier een suggestie:
const [imageIndexAfterSwipe, setImageIndexAfterSwipe] = useState<number>() | |
const imageIndex = index ?? 0 | |
const [currentImageIndex, setCurrentImageIndex] = useState<number>() | |
const initialImageIndex = index ?? 0 |
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.
Ja, die is wel elegant
src/components/Lightbox.tsx
Outdated
|
||
const imageIndex = index ?? 0 | ||
|
||
const onPressDelete = onDelete ? () => onDelete(imageIndexAfterSwipe ?? imageIndex) : undefined |
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.
Zou de default imageIndex
naar de state kunnen? Dus:
const initialImageIndex = index ?? 0
const [currentImageIndex, setCurrentImageIndex] = useState<number>(initialImageIndex)
Dan wordt het hier simpeler:
const onPressDelete = onDelete ? () => onDelete(currentImageIndex) : undefined
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.
Nee.
Het component is altijd aanwezig. Dus de state die je aanmaakt met useState
is altijd hetzelfde object.
Als je 3 foto's hebt en je opent de eerste en slide naar de laatste, is de waarde van currentImageIndex
2.
Je sluit de Lightbox en opent weer de eerste. Op dit moment is de waarde currentImageIndex
nog steeds 2 (ipv 0).
Ik dacht dat mijn methode dit afving, maar ik zie dat ik hetzelfde probleem heb...
Wat wel zou kunnen werken is alleen de Lightbox tonen als er een foto is geselecteerd. Dan kunnen we jouw methode gebruiken en is 't wat makkelijker. Dus in de Observation app:
{photoIndex &&
<Lightbox
index={photoIndex}
onClose={() => setPhotoIndex(undefined)}
photos={uris}
onDelete={onDelete} />
}
Wat vind je hiervan?
Ik begrijp 't doel, maar nieuwe code in de RN components is niet bepaald fijn om te maken. Je moet een commit maken, pushen, ophalen in de andere repo, en dan kom je erachter dat 't niet klopt. Dus na een tijdje ben je 't wel zat. Dus als er "WIP" staat (wat ik volgens mij zelden doe in andere branches) moet je lezen als "Weer fout, nu dan?". |
Die werkwijze levert dus rommel op in de commits, maar dat kun je toch opruimen voordat je een review opent? Ik dacht dat je in |
Ik dacht niet dat dit erg was, maar zal er voortaan aan denken.
Dit zal 't leven veel gemakkelijker maken, zal eens kijken |
eba0817
to
83e699c
Compare
src/components/Lightbox.tsx
Outdated
/> | ||
) | ||
const Lightbox = ({ index, onClose, onDelete, photos, title, description, content, style }: Props) => { | ||
const initialIndex = index ?? 0 |
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?
const initialIndex = index ?? 0 | |
const initialImageIndex = index ?? 0 |
src/components/Lightbox.tsx
Outdated
marginHorizontal: theme.margin.common, | ||
}, | ||
buttonContainer: { | ||
width: '50%', |
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.
Dit gaat mis als we drie buttons hebben. Ik denk dat het beter is om dit te vervangen door flex: 0.5
, dat gaat wel goed bij >2 buttons.
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.
👌🏻
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.
Wat mij betreft prima zo 👍
Displays a delete button in Lightbox. If there is also content, the button is displayed below this content.
Part of: https://github.com/observation/app/issues/349