File tree Expand file tree Collapse file tree 2 files changed +13
-2
lines changed Expand file tree Collapse file tree 2 files changed +13
-2
lines changed Original file line number Diff line number Diff line change @@ -185,6 +185,7 @@ AppRegistry.registerComponent('myproject', () => swiper);
185185| index | 0 | ` number ` | Index number of initial slide. |
186186| showsButtons | false | ` bool ` | Set to ` true ` make control buttons visible. |
187187| autoplay | false | ` bool ` | Set to ` true ` enable auto play mode. |
188+ | onIndexChanged | (index) => null | ` func ` | Called with the new index when the user swiped |
188189
189190#### Custom basic style & content
190191
Original file line number Diff line number Diff line change @@ -125,7 +125,11 @@ export default class extends Component {
125125 dotStyle : PropTypes . object ,
126126 activeDotStyle : PropTypes . object ,
127127 dotColor : PropTypes . string ,
128- activeDotColor : PropTypes . string
128+ activeDotColor : PropTypes . string ,
129+ /**
130+ * Called when the index has changed because the user swiped.
131+ */
132+ onIndexChanged : PropTypes . func
129133 }
130134
131135 /**
@@ -150,7 +154,8 @@ export default class extends Component {
150154 autoplay : false ,
151155 autoplayTimeout : 2.5 ,
152156 autoplayDirection : true ,
153- index : 0
157+ index : 0 ,
158+ onIndexChanged : ( ) => null
154159 }
155160
156161 /**
@@ -180,6 +185,11 @@ export default class extends Component {
180185 this . loopJumpTimer && clearTimeout ( this . loopJumpTimer )
181186 }
182187
188+ componentWillUpdate ( nextProps , nextState ) {
189+ // If the index has changed, we notify the parent via the onIndexChanged callback
190+ if ( this . state . index !== nextState . index ) this . props . onIndexChanged ( nextState . index )
191+ }
192+
183193 initState ( props ) {
184194 // set the current state
185195 const state = this . state || { }
You can’t perform that action at this time.
0 commit comments