OBKN-658 OrderDetails returns to first picklist item on every pick #264
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
The ticket describes something else than Justin's videos, but that's okay and I'll describe why:
Carousel
andFlatList
: a nice discussion about this topic is here: linkTo fix that (it seemed like for all people reporting that issue, the problem happened when their data was > 6 length) I just had to add
useScrollview={true}
.BUT it was when using old, before refactor OrderDetails component. On new one it's true, that it always returned to first item, because
initialPicklistItemIndex
was passed to props wrongly and it was always 0 when console.loged inside Carousel (it was setting the intialPicklsitItemIndex state as the previous one, so in general it was setting that as the initial value, so 0).Then another problem saw the light of the day - when I fixed
initialPicklistItemIndex
it turned out, that theCarousel
'doesn't see' that the state (initialPiclistItemIndex) updated, so in the beginning it was rendered a few times with 0 passed as props (before thegetOrderDetails()
function ended its work) and then it was passing the correct value, for example: 8 (but those renders were just a characteristic of React and there is nothing wrong about that - the wrong part was that theCarousel
didn't react thatfirstItem
was updated from 0 to 8 etc.).I was wondering why and thought that maybe
Carousel
just doesn't re-render after thefirstItem
changes and yeah, thekey
was set (don't know why) as3
. I think it madeCarousel
not re-rendering when thefirstItem
changed from props.After changing
key
to actual value ofinitialPicklistItemIndex
the problem doesn't happen anymore - theCarousel
updates thefirstItem
propely (it just re-renders)