Skip to content

Commit

Permalink
Merge pull request #548 from germanst/master
Browse files Browse the repository at this point in the history
Calculated width & height on layout, used later on re-rendering. Possibility to change ScrollView styles
  • Loading branch information
Bart Arribe authored Sep 28, 2017
2 parents 0dbe73b + fb68bbf commit b3c6264
Showing 1 changed file with 24 additions and 3 deletions.
27 changes: 24 additions & 3 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,10 @@ export default class extends Component {
PropTypes.object,
PropTypes.number,
]),
scrollViewStyle: PropTypes.oneOfType([
PropTypes.object,
PropTypes.number,
]),
pagingEnabled: PropTypes.bool,
showsHorizontalScrollIndicator: PropTypes.bool,
showsVerticalScrollIndicator: PropTypes.bool,
Expand Down Expand Up @@ -231,12 +235,28 @@ export default class extends Component {
const { width, height } = Dimensions.get('window')

initState.dir = props.horizontal === false ? 'y' : 'x'
initState.width = props.width || width
initState.height = props.height || height

if (props.width) {
initState.width = props.width
} else if (this.state && this.state.width){
initState.width = this.state.width
} else {
initState.width = width;
}

if (props.height) {
initState.height = props.height
} else if (this.state && this.state.height){
initState.height = this.state.height
} else {
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 @@ -610,7 +630,8 @@ export default class extends Component {
contentOffset={this.state.offset}
onScrollBeginDrag={this.onScrollBegin}
onMomentumScrollEnd={this.onScrollEnd}
onScrollEndDrag={this.onScrollEndDrag}>
onScrollEndDrag={this.onScrollEndDrag}
style={this.props.scrollViewStyle}>
{pages}
</ScrollView>
)
Expand Down

0 comments on commit b3c6264

Please sign in to comment.