Skip to content

Commit

Permalink
Merge pull request #22 from tsdmrfth/develop
Browse files Browse the repository at this point in the history
v4
  • Loading branch information
tsdmrfth authored Apr 14, 2021
2 parents 5442025 + fb0eccb commit a627a1d
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 8 deletions.
1 change: 0 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,6 @@ export default function App() {
<Steve
isRTL={false}
data={topics}
itemSpacing={10}
renderItem={renderTopic}
itemStyle={{ margin: 5 }}
containerStyle={steveContainer}
Expand Down
22 changes: 15 additions & 7 deletions src/Steve.js
Original file line number Diff line number Diff line change
Expand Up @@ -160,13 +160,7 @@ export const Steve = ({ data, renderItem, keyExtractor, containerStyle, isRTL, i
.values(itemLayoutsCache.current)
.reduce((accumulator, current, index) => {
if (index === 0) {
const firstIndex = isRTL ? 1 : 0
const secondIndex = isRTL ? 0 : 1
const firstKey = keyExtractor(data[firstIndex], firstIndex)
const secondKey = keyExtractor(data[secondIndex], secondIndex)
const firstItem = itemLayoutsCache.current[firstKey]
const secondItem = itemLayoutsCache.current[secondKey]
spacingBetweenItems = secondItem.layout.x - firstItem.layout.width - firstItem.layout.x
spacingBetweenItems = getSpacingBetweenItems()
}

if (!accumulator.sumWidthOfLayer) {
Expand All @@ -183,6 +177,20 @@ export const Steve = ({ data, renderItem, keyExtractor, containerStyle, isRTL, i
setItemLayouts(itemLayoutsCache.current)
}

const getSpacingBetweenItems = () => {
if (data.length < 2) {
return 0
}

const firstIndex = isRTL ? 1 : 0
const secondIndex = isRTL ? 0 : 1
const firstKey = keyExtractor(data[firstIndex], firstIndex)
const secondKey = keyExtractor(data[secondIndex], secondIndex)
const firstItem = itemLayoutsCache.current[firstKey]
const secondItem = itemLayoutsCache.current[secondKey]
return secondItem.layout.x - firstItem.layout.width - firstItem.layout.x
}

return (
<PanGestureHandler
activeOffsetX={[-10, 10]}
Expand Down

0 comments on commit a627a1d

Please sign in to comment.