Skip to content

Commit fb68bbf

Browse files
authored
Merge branch 'master' into master
2 parents dfa500e + 86692f1 commit fb68bbf

File tree

3 files changed

+41
-15
lines changed

3 files changed

+41
-15
lines changed

CHANGELOG.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,13 @@
1+
- [1.5.12]
2+
+ Update core packages
3+
+ Optionally disable the 'next' control button (thanks [@SSTPIERRE2](https://github.com/SSTPIERRE2))
4+
+ Fix `Uncaught TypeError: _this.refs.scrollView.scrollTo is not a function` (thanks [@flyskywhy](https://github.com/flyskywhy))
5+
+ Allow dotStyle and activeDotStyle PropTypes to accept Stylesheet (thanks [@knopt](https://github.com/knopt))
6+
+ Calculate the offset in the initial state instead of `onLayout` (thanks [@kjkta](https://github.com/kjkta))
7+
8+
- [1.5.11]
9+
+ Typescript Definition
10+
111
- [1.5.1]
212
+ Allow scroll without animate, ref: [scrollBy(index, animated)](#scrollbyindex-animated)
313
+ Remove [#254](https://github.com/leecade/react-native-swiper/pull/254) which break the scroll direction in loop mode

package.json

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
"react-native",
66
"ios"
77
],
8-
"version": "1.5.10",
8+
"version": "1.5.12",
99
"description": "Swiper component for React Native.",
1010
"main": "index.js",
1111
"scripts": {
@@ -54,9 +54,9 @@
5454
"devDependencies": {
5555
"babel-eslint": "^7.1.1",
5656
"rimraf": "^2.5.4",
57-
"snazzy": "^5.0.0",
58-
"standard": "^8.5.0",
59-
"updtr": "^0.2.3"
57+
"snazzy": "^6.0.0",
58+
"standard": "^10.0.3",
59+
"updtr": "^2.0.0"
6060
},
6161
"dependencies": {
6262
"prop-types": "^15.5.10"

src/index.js

Lines changed: 27 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,7 @@ export default class extends Component {
129129
automaticallyAdjustContentInsets: PropTypes.bool,
130130
showsPagination: PropTypes.bool,
131131
showsButtons: PropTypes.bool,
132+
disableNextButton: PropTypes.bool,
132133
loadMinimal: PropTypes.bool,
133134
loadMinimalSize: PropTypes.number,
134135
loadMinimalLoader: PropTypes.element,
@@ -138,8 +139,8 @@ export default class extends Component {
138139
autoplayDirection: PropTypes.bool,
139140
index: PropTypes.number,
140141
renderPagination: PropTypes.func,
141-
dotStyle: PropTypes.object,
142-
activeDotStyle: PropTypes.object,
142+
dotStyle: PropTypes.oneOfType([PropTypes.object, PropTypes.number]),
143+
activeDotStyle: PropTypes.oneOfType([PropTypes.object, PropTypes.number]),
143144
dotColor: PropTypes.string,
144145
activeDotColor: PropTypes.string,
145146
/**
@@ -164,6 +165,7 @@ export default class extends Component {
164165
automaticallyAdjustContentInsets: false,
165166
showsPagination: true,
166167
showsButtons: false,
168+
disableNextButton: false,
167169
loop: true,
168170
loadMinimal: false,
169171
loadMinimalSize: 1,
@@ -212,7 +214,8 @@ export default class extends Component {
212214

213215
const initState = {
214216
autoplayEnd: false,
215-
loopJump: false
217+
loopJump: false,
218+
offset: {}
216219
}
217220

218221
initState.total = props.children ? props.children.length || 1 : 0
@@ -226,6 +229,7 @@ export default class extends Component {
226229

227230
// Default: horizontal
228231
initState.dir = props.horizontal === false ? 'y' : 'x'
232+
229233
if (props.width) {
230234
initState.width = props.width
231235
} else if (this.state && this.state.width){
@@ -242,6 +246,11 @@ export default class extends Component {
242246
initState.height = height;
243247
}
244248

249+
initState.offset[initState.dir] = initState.dir === 'y'
250+
? height * props.index
251+
: width * props.index
252+
253+
245254
this.internals = {
246255
...this.internals,
247256
isScrolling: false
@@ -280,7 +289,7 @@ export default class extends Component {
280289
loopJump = () => {
281290
if (!this.state.loopJump) return
282291
const i = this.state.index + (this.props.loop ? 1 : 0)
283-
const scrollView = this.refs.scrollView
292+
const scrollView = this.scrollView
284293
this.loopJumpTimer = setTimeout(() => scrollView.setPageWithoutAnimation &&
285294
scrollView.setPageWithoutAnimation(i), 50)
286295
}
@@ -436,10 +445,10 @@ export default class extends Component {
436445
if (state.dir === 'x') x = diff * state.width
437446
if (state.dir === 'y') y = diff * state.height
438447

439-
if (Platform.OS === 'android') {
440-
this.refs.scrollView && this.refs.scrollView[animated ? 'setPage' : 'setPageWithoutAnimation'](diff)
448+
if (Platform.OS !== 'ios') {
449+
this.scrollView && this.scrollView[animated ? 'setPage' : 'setPageWithoutAnimation'](diff)
441450
} else {
442-
this.refs.scrollView && this.refs.scrollView.scrollTo({ x, y, animated })
451+
this.scrollView && this.scrollView.scrollTo({ x, y, animated })
443452
}
444453

445454
// update scroll state
@@ -449,7 +458,7 @@ export default class extends Component {
449458
})
450459

451460
// trigger onScrollEnd manually in android
452-
if (!animated || Platform.OS === 'android') {
461+
if (!animated || Platform.OS !== 'ios') {
453462
setImmediate(() => {
454463
this.onScrollEnd({
455464
nativeEvent: {
@@ -551,7 +560,10 @@ export default class extends Component {
551560
}
552561

553562
return (
554-
<TouchableOpacity onPress={() => button !== null && this.scrollBy(1)}>
563+
<TouchableOpacity
564+
onPress={() => button !== null && this.scrollBy(1)}
565+
disabled={this.props.disableNextButton}
566+
>
555567
<View>
556568
{button}
557569
</View>
@@ -587,10 +599,14 @@ export default class extends Component {
587599
)
588600
}
589601

602+
refScrollView = view => {
603+
this.scrollView = view;
604+
}
605+
590606
renderScrollView = pages => {
591607
if (Platform.OS === 'ios') {
592608
return (
593-
<ScrollView ref='scrollView'
609+
<ScrollView ref={this.refScrollView}
594610
{...this.props}
595611
{...this.scrollViewPropOverrides()}
596612
contentContainerStyle={[styles.wrapperIOS, this.props.style]}
@@ -604,7 +620,7 @@ export default class extends Component {
604620
)
605621
}
606622
return (
607-
<ViewPagerAndroid ref='scrollView'
623+
<ViewPagerAndroid ref={this.refScrollView}
608624
{...this.props}
609625
initialPage={this.props.loop ? this.state.index + 1 : this.state.index}
610626
onPageSelected={this.onScrollEnd}

0 commit comments

Comments
 (0)