Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 18 additions & 13 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ export const HighLightView = styled.View`
border-bottom-color: ${props => props.highlightColor};
border-top-width: ${props => props.highlightBorderWidth}px;
border-bottom-width: ${props => props.highlightBorderWidth}px;
background-color: ${props => props.highlightBackground};
`;
export const SelectedItem = styled.View`
height: 30px;
Expand Down Expand Up @@ -59,15 +60,17 @@ export default class ScrollPicker extends React.Component {
}

render() {
const {header, footer} = this.renderPlaceHolder();
const { header, footer } = this.renderPlaceHolder();
return (
<Container wrapperHeight={this.props.wrapperHeight} wrapperWidth={this.props.wrapperWidth}
wrapperBackground={this.props.wrapperBackground}>
wrapperBackground={this.props.wrapperBackground}>
<HighLightView highlightColor={this.props.highlightColor}
highlightWidth={this.props.highlightWidth}
wrapperHeight={this.props.wrapperHeight}
itemHeight={this.props.itemHeight}
highlightBorderWidth={this.props.highlightBorderWidth}/>
highlightWidth={this.props.highlightWidth}
wrapperHeight={this.props.wrapperHeight}
itemHeight={this.props.itemHeight}
highlightBorderWidth={this.props.highlightBorderWidth}
highlightBackground={this.props.highlightBackground}
/>
<ScrollView
ref={(sview) => {
this.sview = sview;
Expand All @@ -90,9 +93,9 @@ export default class ScrollPicker extends React.Component {

renderPlaceHolder() {
const height = (this.props.wrapperHeight - this.props.itemHeight) / 2;
const header = <View style={{height, flex: 1}}></View>;
const footer = <View style={{height, flex: 1}}></View>;
return {header, footer};
const header = <View style={{ height, flex: 1 }}></View>;
const footer = <View style={{ height, flex: 1 }}></View>;
return { header, footer };
}

renderItem(data, index) {
Expand Down Expand Up @@ -120,7 +123,7 @@ export default class ScrollPicker extends React.Component {
this.isScrollTo = true;
}
if (this.sview) {
this.sview.scrollTo({y: verticalElem});
this.sview.scrollTo({ y: verticalElem });
}
}
if (this.state.selectedIndex === selectedIndex) {
Expand Down Expand Up @@ -192,7 +195,7 @@ export default class ScrollPicker extends React.Component {
const y = this.props.itemHeight * ind;
setTimeout(() => {
if (this.sview) {
this.sview.scrollTo({y});
this.sview.scrollTo({ y });
}
}, 0);
}
Expand All @@ -206,6 +209,7 @@ ScrollPicker.propTypes = {
highlightColor: PropTypes.string,
itemHeight: PropTypes.number,
wrapperBackground: PropTypes.string,
highlightBackground: PropTypes.string,
wrapperWidth: PropTypes.number,
wrapperHeight: PropTypes.number,
highlightWidth: PropTypes.number,
Expand All @@ -222,12 +226,13 @@ ScrollPicker.defaultProps = {
wrapperHeight: 180,
wrapperWidth: 150,
highlightWidth: deviceWidth,
highlightBackground: '#FFFFFF',
highlightBorderWidth: 2,
highlightColor: '#333',
onMomentumScrollEnd: () => {
},
onScrollEndDrag: () => {
},
itemTextStyle: {fontSize: 20, lineHeight: 26, textAlign: 'center', color: '#B4B4B4'},
activeItemTextStyle: {fontSize: 20, lineHeight: 26, textAlign: 'center', color: '#222121'}
itemTextStyle: { fontSize: 20, lineHeight: 26, textAlign: 'center', color: '#B4B4B4' },
activeItemTextStyle: { fontSize: 20, lineHeight: 26, textAlign: 'center', color: '#222121' }
};