Skip to content

Commit

Permalink
Merge branch 'master' into master
Browse files Browse the repository at this point in the history
  • Loading branch information
germanst authored Sep 22, 2017
2 parents dfa500e + 86692f1 commit fb68bbf
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 15 deletions.
10 changes: 10 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,13 @@
- [1.5.12]
+ Update core packages
+ Optionally disable the 'next' control button (thanks [@SSTPIERRE2](https://github.com/SSTPIERRE2))
+ Fix `Uncaught TypeError: _this.refs.scrollView.scrollTo is not a function` (thanks [@flyskywhy](https://github.com/flyskywhy))
+ Allow dotStyle and activeDotStyle PropTypes to accept Stylesheet (thanks [@knopt](https://github.com/knopt))
+ Calculate the offset in the initial state instead of `onLayout` (thanks [@kjkta](https://github.com/kjkta))

- [1.5.11]
+ Typescript Definition

- [1.5.1]
+ Allow scroll without animate, ref: [scrollBy(index, animated)](#scrollbyindex-animated)
+ Remove [#254](https://github.com/leecade/react-native-swiper/pull/254) which break the scroll direction in loop mode
Expand Down
8 changes: 4 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"react-native",
"ios"
],
"version": "1.5.10",
"version": "1.5.12",
"description": "Swiper component for React Native.",
"main": "index.js",
"scripts": {
Expand Down Expand Up @@ -54,9 +54,9 @@
"devDependencies": {
"babel-eslint": "^7.1.1",
"rimraf": "^2.5.4",
"snazzy": "^5.0.0",
"standard": "^8.5.0",
"updtr": "^0.2.3"
"snazzy": "^6.0.0",
"standard": "^10.0.3",
"updtr": "^2.0.0"
},
"dependencies": {
"prop-types": "^15.5.10"
Expand Down
38 changes: 27 additions & 11 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,7 @@ export default class extends Component {
automaticallyAdjustContentInsets: PropTypes.bool,
showsPagination: PropTypes.bool,
showsButtons: PropTypes.bool,
disableNextButton: PropTypes.bool,
loadMinimal: PropTypes.bool,
loadMinimalSize: PropTypes.number,
loadMinimalLoader: PropTypes.element,
Expand All @@ -138,8 +139,8 @@ export default class extends Component {
autoplayDirection: PropTypes.bool,
index: PropTypes.number,
renderPagination: PropTypes.func,
dotStyle: PropTypes.object,
activeDotStyle: PropTypes.object,
dotStyle: PropTypes.oneOfType([PropTypes.object, PropTypes.number]),
activeDotStyle: PropTypes.oneOfType([PropTypes.object, PropTypes.number]),
dotColor: PropTypes.string,
activeDotColor: PropTypes.string,
/**
Expand All @@ -164,6 +165,7 @@ export default class extends Component {
automaticallyAdjustContentInsets: false,
showsPagination: true,
showsButtons: false,
disableNextButton: false,
loop: true,
loadMinimal: false,
loadMinimalSize: 1,
Expand Down Expand Up @@ -212,7 +214,8 @@ export default class extends Component {

const initState = {
autoplayEnd: false,
loopJump: false
loopJump: false,
offset: {}
}

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

// Default: horizontal
initState.dir = props.horizontal === false ? 'y' : 'x'

if (props.width) {
initState.width = props.width
} else if (this.state && this.state.width){
Expand All @@ -242,6 +246,11 @@ export default class extends Component {
initState.height = height;
}

initState.offset[initState.dir] = initState.dir === 'y'
? height * props.index
: width * props.index


this.internals = {
...this.internals,
isScrolling: false
Expand Down Expand Up @@ -280,7 +289,7 @@ export default class extends Component {
loopJump = () => {
if (!this.state.loopJump) return
const i = this.state.index + (this.props.loop ? 1 : 0)
const scrollView = this.refs.scrollView
const scrollView = this.scrollView
this.loopJumpTimer = setTimeout(() => scrollView.setPageWithoutAnimation &&
scrollView.setPageWithoutAnimation(i), 50)
}
Expand Down Expand Up @@ -436,10 +445,10 @@ export default class extends Component {
if (state.dir === 'x') x = diff * state.width
if (state.dir === 'y') y = diff * state.height

if (Platform.OS === 'android') {
this.refs.scrollView && this.refs.scrollView[animated ? 'setPage' : 'setPageWithoutAnimation'](diff)
if (Platform.OS !== 'ios') {
this.scrollView && this.scrollView[animated ? 'setPage' : 'setPageWithoutAnimation'](diff)
} else {
this.refs.scrollView && this.refs.scrollView.scrollTo({ x, y, animated })
this.scrollView && this.scrollView.scrollTo({ x, y, animated })
}

// update scroll state
Expand All @@ -449,7 +458,7 @@ export default class extends Component {
})

// trigger onScrollEnd manually in android
if (!animated || Platform.OS === 'android') {
if (!animated || Platform.OS !== 'ios') {
setImmediate(() => {
this.onScrollEnd({
nativeEvent: {
Expand Down Expand Up @@ -551,7 +560,10 @@ export default class extends Component {
}

return (
<TouchableOpacity onPress={() => button !== null && this.scrollBy(1)}>
<TouchableOpacity
onPress={() => button !== null && this.scrollBy(1)}
disabled={this.props.disableNextButton}
>
<View>
{button}
</View>
Expand Down Expand Up @@ -587,10 +599,14 @@ export default class extends Component {
)
}

refScrollView = view => {
this.scrollView = view;
}

renderScrollView = pages => {
if (Platform.OS === 'ios') {
return (
<ScrollView ref='scrollView'
<ScrollView ref={this.refScrollView}
{...this.props}
{...this.scrollViewPropOverrides()}
contentContainerStyle={[styles.wrapperIOS, this.props.style]}
Expand All @@ -604,7 +620,7 @@ export default class extends Component {
)
}
return (
<ViewPagerAndroid ref='scrollView'
<ViewPagerAndroid ref={this.refScrollView}
{...this.props}
initialPage={this.props.loop ? this.state.index + 1 : this.state.index}
onPageSelected={this.onScrollEnd}
Expand Down

0 comments on commit fb68bbf

Please sign in to comment.