Skip to content

Commit 5b8995a

Browse files
committed
initialSelectedIndex bug fixed, scrollToInitialPosition function added
1 parent 289b75d commit 5b8995a

File tree

3 files changed

+12
-1
lines changed

3 files changed

+12
-1
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ export default class Example extends React.Component {
9090
| onScrollBeginDrag | - | `func` | Returns selected item object and selected index |
9191
| onScrollEndDrag | - | `func` | Returns selected item object and selected index |
9292
| initialSelectedIndex | 0 | `number` | Set index number of initial item. |
93-
| transparentItemRows | 2 | `number` | Set number of items at top and bottom of selected index. |
93+
| transparentItemRows | 3 | `number` | Set number of items at top and bottom of selected index. |
9494
| width | 300 | `number` | - |
9595
| height | 300 | `number` | - |
9696
| allItemsColor | #000 | `string` | - |

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
"license": "MIT",
3333
"dependencies": {
3434
"prop-types": "^15.7.2",
35+
"react-native-dynamically-selected-picker": "^2.0.0",
3536
"react-native-linear-gradient": "^2.5.6"
3637
}
3738
}

src/DynamicallySelectedPicker.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,12 @@ export default class DynamicallySelectedPicker extends React.Component {
2020
};
2121
}
2222

23+
scrollToInitialPosition = () => {
24+
this.scrollViewRef.scrollTo({
25+
y: this.state.itemHeight * this.props.initialSelectedIndex,
26+
});
27+
};
28+
2329
fakeItems(n = 3) {
2430
const itemsArr = [];
2531
for (let i = 0; i < n; i++) {
@@ -125,6 +131,10 @@ export default class DynamicallySelectedPicker extends React.Component {
125131
return (
126132
<View style={{height: height, width: width}}>
127133
<ScrollView
134+
ref={(ref) => {
135+
this.scrollViewRef = ref;
136+
}}
137+
onLayout={this.scrollToInitialPosition}
128138
showsVerticalScrollIndicator={false}
129139
showsHorizontalScrollIndicator={false}
130140
onMomentumScrollBegin={(event) => {

0 commit comments

Comments
 (0)