Skip to content

Commit eff587c

Browse files
committed
[#13]:First item have height issue when scroll back
1 parent d4d6290 commit eff587c

File tree

4 files changed

+63
-63
lines changed

4 files changed

+63
-63
lines changed

README.md

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -116,35 +116,35 @@ In above example, it's `items`.
116116
```js
117117
let styles = {
118118
outerDiv: {
119-
height: '400px',
119+
height: '420px',
120120
overflowY: 'auto',
121-
outline: '1px dashed blue',
122-
width: '400px',
121+
outline: '#b9ceb6 dashed 1px',
122+
width: '383px'
123123
},
124124

125125
ul: {
126126
margin: '0px',
127127
listStyleType: 'none',
128-
padding: '0'
128+
padding: '0px'
129129
},
130130

131131
fixedPosition: {
132-
position : 'fixed',
133-
width : '383px',
132+
position: 'fixed',
133+
width: '383px',
134134
top: '0px'
135135
},
136136

137137
listHeader: {
138138
width: '383px',
139-
height: '20px',
140-
background: 'green',
139+
height: '27px',
140+
background: '#94D6CF',
141141
color: 'white'
142142
},
143143

144144
listItems: {
145-
color: 'blue'
146-
},
147-
};
145+
color: '#a9adab'
146+
}
147+
}
148148
```
149149

150150
`outerDiv`, `ul`, `fixedPosition`, `listHeader`, `listItems` are required, you can modify the CSS to meet your needs.

src/ReactListView.js

Lines changed: 24 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ export default class ReactListView extends Component {
2828
}
2929

3030
componentWillUnmount () {
31-
// unRegister events listeners with the listview div
31+
// unRegister events listeners with the listview div
3232
this.state.events.forEach((type) => {
3333
if (window.addEventListener) {
3434
findDOMNode(this.refs.listview).removeEventListener(type, this.onScroll.bind(this), false)
@@ -40,7 +40,7 @@ export default class ReactListView extends Component {
4040

4141
refsToArray (ctx, prefix) {
4242
let results = []
43-
for (let i = 0; ;i++) {
43+
for (let i = 0; ; i++) {
4444
let ref = ctx.refs[prefix + '-' + String(i)]
4545
if (ref) results.push(ref)
4646
else return results
@@ -57,7 +57,7 @@ export default class ReactListView extends Component {
5757
return headerAndPosInfo
5858
})
5959
this.setState({
60-
_instances: Object.assign(this.state._instances, {_originalPositions}),
60+
_instances: Object.assign(this.state._instances, { _originalPositions }),
6161
_firstChildWrapper: listHeaders[0].refs.followWrap,
6262
_headerFixedPosition: listHeaders[0].refs.header.getBoundingClientRect().top
6363
})
@@ -85,15 +85,14 @@ export default class ReactListView extends Component {
8585
nextNode = this.state._instances._originalPositions[index + 1]
8686
}
8787
if (nextNode) {
88-
// temporily disable the clapsed effect
8988
}
9089
if (index === 0) {
9190
if (currentWindowScrollTop === c.originalPosition) {
9291
currentNode.style.position = ''
9392
ignoreCheck = true
9493
}
9594
}
96-
if (!ignoreCheck && (c.originalPosition) < (currentWindowScrollTop + this.state._headerFixedPosition + currentHeaderHeight)) {
95+
if (!ignoreCheck && (c.originalPosition) < (currentWindowScrollTop + this.state._headerFixedPosition + index * currentHeaderHeight)) {
9796
Object.assign(currentNode.style, this.props.styles.fixedPosition)
9897
// apply top value
9998
currentNode.style.top = `${this.state._headerFixedPosition}px`
@@ -109,7 +108,7 @@ export default class ReactListView extends Component {
109108

110109
render () {
111110
const { data, headerAttName, itemsAttName } = this.props
112-
const { styles: {outerDiv, ul, listHeader, listItems, li} } = this.props
111+
const { styles: { outerDiv, ul, listHeader, listItems, li } } = this.props
113112
let _refi = 0
114113
let makeRef = () => {
115114
return `ListHeader-${_refi++}`
@@ -118,25 +117,25 @@ export default class ReactListView extends Component {
118117
return (
119118
<div ref='listview' style={outerDiv}>
120119
<ul style={ul}>
121-
{
122-
Object.keys(data).map((k) => {
123-
const header = data[k][headerAttName]
124-
const items = data[k][itemsAttName]
125-
return (
126-
<li key={k}>
127-
<ListHeader
128-
ref={makeRef()}
129-
header={header}
130-
styles={listHeader}
131-
/>
132-
<ListItems
133-
items={items}
134-
styles={listItems}
135-
/>
136-
</li>
137-
)
138-
})
139-
}
120+
{
121+
Object.keys(data).map((k) => {
122+
const header = data[k][headerAttName]
123+
const items = data[k][itemsAttName]
124+
return (
125+
<li key={k}>
126+
<ListHeader
127+
ref={makeRef()}
128+
header={header}
129+
styles={listHeader}
130+
/>
131+
<ListItems
132+
items={items}
133+
styles={listItems}
134+
/>
135+
</li>
136+
)
137+
})
138+
}
140139
</ul>
141140
</div>
142141
)

src/example/Example.js

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,11 @@ import { DATA } from './data'
55

66
let styles = {
77
outerDiv: {
8-
height: '400px',
8+
height: '420px',
99
overflowY: 'auto',
10-
outline: '1px dashed blue',
11-
width: '400px'
10+
outline: '#b9ceb6 dashed 1px',
11+
width: '383px',
12+
margin: '0 auto'
1213
},
1314

1415
ul: {
@@ -26,12 +27,12 @@ let styles = {
2627
listHeader: {
2728
width: '383px',
2829
height: '27px',
29-
background: 'green',
30+
background: '#94D6CF',
3031
color: 'white'
3132
},
3233

3334
listItems: {
34-
color: 'blue'
35+
color: '#a9adab'
3536
}
3637
}
3738

src/example/data.js

Lines changed: 22 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,69 +1,69 @@
11
export const DATA = [
22
{
3-
headerName: 'ListA',
3+
headerName: 'Electronics',
44
items: [{
5-
title: 'items1'
5+
title: 'Macbook'
66
},
77
{
8-
title: 'items2'
8+
title: 'Dell'
99
},
1010
{
11-
title: 'items3'
11+
title: 'HP'
1212
},
1313
{
14-
title: 'items4'
14+
title: 'Asus'
1515
},
1616
{
17-
title: 'items5'
17+
title: 'SAMSUNG'
1818
},
1919
{
20-
title: 'items6'
20+
title: 'Office Works'
2121
}]
2222
},
2323
{
24-
headerName: 'ListB is bravo',
24+
headerName: 'Home Appliances',
2525
items: [{
26-
title: 'items1'
26+
title: 'LG'
2727
},
2828
{
29-
title: 'items2'
29+
title: 'Philips'
3030
},
3131
{
32-
title: 'items3'
32+
title: 'BEKO'
3333
},
3434
{
35-
title: 'items4'
35+
title: 'Breville'
3636
},
3737
{
38-
title: 'items5'
38+
title: 'Fisher & Paykel'
3939
},
4040
{
41-
title: 'items6'
41+
title: 'Hisense'
4242
}]
4343
},
4444
{
45-
headerName: 'ListC is Charlie',
45+
headerName: 'Headphones & DJ',
4646
items: [{
47-
title: 'items1'
47+
title: 'BOSE'
4848
},
4949
{
50-
title: 'items2'
50+
title: 'Beats'
5151
},
5252
{
53-
title: 'items3'
53+
title: 'Sony'
5454
},
5555
{
56-
title: 'items4'
56+
title: 'JBL'
5757
},
5858
{
59-
title: 'items5'
59+
title: 'Marley'
6060
},
6161
{
62-
title: 'items6'
62+
title: 'Pioneer DJ'
6363
}]
6464
},
6565
{
66-
headerName: 'ListD is Dynamic',
66+
headerName: 'Kitchen',
6767
items: [{
6868
title: 'items1'
6969
},

0 commit comments

Comments
 (0)