File tree Expand file tree Collapse file tree 3 files changed +12
-1
lines changed Expand file tree Collapse file tree 3 files changed +12
-1
lines changed Original file line number Diff line number Diff 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 ` | - |
Original file line number Diff line number Diff line change 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}
Original file line number Diff line number Diff 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 ) => {
You can’t perform that action at this time.
0 commit comments