Skip to content

Commit

Permalink
fix ScrollView
Browse files Browse the repository at this point in the history
  • Loading branch information
huangqi03 committed May 13, 2016
1 parent 8a66411 commit b364c3a
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 1 deletion.
18 changes: 17 additions & 1 deletion Libraries/ScrollView/ScrollView.web.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import autobind from 'autobind-decorator';

const SCROLLVIEW = 'ScrollView';
const INNERVIEW = 'InnerScrollView';
const CONTENT_EXT_STYLE = ['padding', 'paddingTop', 'paddingBottom', 'paddingLeft', 'paddingRight'];

/**
* Component that wraps platform ScrollView while providing
Expand Down Expand Up @@ -319,10 +320,24 @@ class ScrollView extends React.Component {
}

render() {
let {
style,
...otherProps
} = this.props;

let contentContainerExtStyle = {};

for (let i = 0; i < CONTENT_EXT_STYLE.length; i++) {
if (typeof style[CONTENT_EXT_STYLE[i]] === 'number') {
contentContainerExtStyle[CONTENT_EXT_STYLE[i]] = style[CONTENT_EXT_STYLE[i]];
}
}

let contentContainerStyle = [
styles.contentContainer,
this.props.horizontal && styles.contentContainerHorizontal,
this.props.contentContainerStyle,
contentContainerExtStyle,
];
// if (__DEV__ && this.props.style) {
// let style = flattenStyle(this.props.style);
Expand Down Expand Up @@ -360,7 +375,7 @@ class ScrollView extends React.Component {
}

let props = {
...this.props,
...otherProps,
alwaysBounceHorizontal,
alwaysBounceVertical,
style: ([styles.base, this.props.style]: ?Array<any>),
Expand Down Expand Up @@ -400,6 +415,7 @@ let styles = StyleSheet.create({
flex: 1,
},
contentContainer: {
position: 'absolute',
minWidth: '100%',
},
contentContainerHorizontal: {
Expand Down
3 changes: 3 additions & 0 deletions Libraries/StyleSheet/setDefaultStyle.web.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,9 @@ function appendSytle({
bottom: 0;
overflow: hidden;
}
.${rootClassName} > .${viewClassName} {
height: 100%;
}
.${rootClassName} .${viewClassName} {
position: relative;
${boxStyle}
Expand Down
6 changes: 6 additions & 0 deletions README-zh.md
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,12 @@ var Platform = require('ReactPlatform');
LayoutAnimation.configureNext(...)
}
```
5. ScrollView 需要指定高度
```js
<ScrollView style={{height: 235}} horizontal={true}> // 手动指定滚动区域高度、子元素不会自动撑起ScrollView
<View />
</ScrollView>
```

## 任务脚本

Expand Down
5 changes: 5 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,11 @@ As mentioned above, the HasteResolverPlugin plugin will help webpack to compile
}
```

5. Should manually specify the height of ScrollView
```js
<ScrollView style={{height: 235}} horizontal={true} />
```

### React Native compatible

#### Components
Expand Down

0 comments on commit b364c3a

Please sign in to comment.