@@ -57,7 +57,7 @@ export type ScrollToItemResultProps<T extends ScrollToSupportedViews> = Pick<Scr
57
57
*/
58
58
itemsWidths : number [ ] ;
59
59
/**
60
- * Use in order to focus the item with the specified index
60
+ * Use in order to focus the item with the specified index (use when the selectedIndex is not changed)
61
61
*/
62
62
focusIndex : ( index : number , animated ?: boolean ) => void ;
63
63
} ;
@@ -95,22 +95,22 @@ const useScrollToItem = <T extends ScrollToSupportedViews>(props: ScrollToItemPr
95
95
const centeredOffsets = [ ] ;
96
96
let currentCenterOffset = outerSpacing ;
97
97
const leftOffsets = [ ] ;
98
- leftOffsets . push ( 0 ) ;
98
+ leftOffsets . push ( outerSpacing - innerSpacing ) ;
99
99
const rightOffsets = [ ] ;
100
- rightOffsets . push ( - Constants . screenWidth + itemsWidths [ 0 ] ) ;
100
+ rightOffsets . push ( - Constants . screenWidth + itemsWidths [ 0 ] + outerSpacing + innerSpacing ) ;
101
101
while ( index < itemsCount ) {
102
102
centeredOffsets [ index ] = currentCenterOffset - screenCenter + itemsWidths [ index ] / 2 ;
103
103
++ index ;
104
104
currentCenterOffset += itemsWidths [ index - 1 ] + innerSpacing ;
105
- leftOffsets [ index ] = leftOffsets [ index - 1 ] + itemsWidths [ index - 1 ] ;
106
- rightOffsets [ index ] = rightOffsets [ index - 1 ] + itemsWidths [ index ] ;
105
+ leftOffsets [ index ] = leftOffsets [ index - 1 ] + itemsWidths [ index - 1 ] + innerSpacing ;
106
+ rightOffsets [ index ] = rightOffsets [ index - 1 ] + itemsWidths [ index ] + innerSpacing ;
107
107
}
108
108
109
109
if ( addOffsetMargin ) {
110
- index = 1 ;
110
+ index = 1 ;
111
111
while ( index < itemsCount - 1 ) {
112
112
leftOffsets [ index ] -= itemsWidths [ index - 1 ] ;
113
- rightOffsets [ index ] += itemsWidths [ index + 1 ] ;
113
+ rightOffsets [ index ] += itemsWidths [ index + 1 ] + innerSpacing ;
114
114
++ index ;
115
115
}
116
116
}
@@ -155,4 +155,6 @@ const useScrollToItem = <T extends ScrollToSupportedViews>(props: ScrollToItemPr
155
155
} ;
156
156
} ;
157
157
158
+ useScrollToItem . offsetType = OffsetType ;
159
+
158
160
export default useScrollToItem ;
0 commit comments