Skip to content

Commit

Permalink
1.Make headers banners to be replaced now. (Unitl implement better al…
Browse files Browse the repository at this point in the history
…gorithms to make the collision more 'sticky' 2.Add in longer data in the array.
  • Loading branch information
cht8687 committed Jun 29, 2016
1 parent ebb0e14 commit f6f45ee
Show file tree
Hide file tree
Showing 2 changed files with 214 additions and 4 deletions.
8 changes: 4 additions & 4 deletions src/ReactListView.js
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ export default class ReactListView extends Component {

onScroll () {
// update current header positions and apply fixed positions to the top one
let currentWindowScrollTop = 2 * this.state._headerFixedPosition - this.state._firstChildWrapper.getBoundingClientRect().top
let currentWindowScrollTop = this.state._headerFixedPosition - this.state._firstChildWrapper.getBoundingClientRect().top
this.state._instances._originalPositions.forEach((c, index) => {
let currentNode = c.headerObj.refs.header
const currentHeaderHeight = parseInt(currentNode.style.height, 10)
Expand All @@ -84,19 +84,19 @@ export default class ReactListView extends Component {
nextNode = this.state._instances._originalPositions[index + 1]
}
if (nextNode) {
topPos = -(currentWindowScrollTop + (index + 2) * currentHeaderHeight - nextNode.originalPosition - this.state._headerFixedPosition)
// temporily disable the clapsed effect
}
if (index === 0) {
if (currentWindowScrollTop === c.originalPosition) {
currentNode.style.position = ''
ignoreCheck = true
}
}
if (!ignoreCheck && (c.originalPosition) < (currentWindowScrollTop + this.state._headerFixedPosition + currentHeaderHeight * 1)) {
if (!ignoreCheck && (c.originalPosition) < (currentWindowScrollTop + this.state._headerFixedPosition + currentHeaderHeight)) {
Object.assign(currentNode.style, this.props.styles.fixedPosition)
// apply top value
currentNode.style.top = `${this.state._headerFixedPosition}px`
if (currentWindowScrollTop + (index + 2) * currentHeaderHeight > nextNode.originalPosition) {
if (currentWindowScrollTop + index * currentHeaderHeight > nextNode.originalPosition) {
currentNode.style.position = 'absolute'
currentNode.style.top = `${topPos}px`
}
Expand Down
210 changes: 210 additions & 0 deletions src/example/data.js
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,216 @@ export const DATA = [
title: 'items6'
}]
},
{
headerName: 'ListE',
items: [{
title: 'items1'
},
{
title: 'items2'
},
{
title: 'items3'
},
{
title: 'items4'
},
{
title: 'items5'
},
{
title: 'items6'
}]
},
{
headerName: 'ListF',
items: [{
title: 'items1'
},
{
title: 'items2'
},
{
title: 'items3'
},
{
title: 'items4'
},
{
title: 'items5'
},
{
title: 'items6'
}]
},
{
headerName: 'ListG',
items: [{
title: 'items1'
},
{
title: 'items2'
},
{
title: 'items3'
},
{
title: 'items4'
},
{
title: 'items5'
},
{
title: 'items6'
}]
},
{
headerName: 'ListH',
items: [{
title: 'items1'
},
{
title: 'items2'
},
{
title: 'items3'
},
{
title: 'items4'
},
{
title: 'items5'
},
{
title: 'items6'
}]
},
{
headerName: 'ListI',
items: [{
title: 'items1'
},
{
title: 'items2'
},
{
title: 'items3'
},
{
title: 'items4'
},
{
title: 'items5'
},
{
title: 'items6'
}]
},
{
headerName: 'ListJ',
items: [{
title: 'items1'
},
{
title: 'items2'
},
{
title: 'items3'
},
{
title: 'items4'
},
{
title: 'items5'
},
{
title: 'items6'
}]
},
{
headerName: 'ListK',
items: [{
title: 'items1'
},
{
title: 'items2'
},
{
title: 'items3'
},
{
title: 'items4'
},
{
title: 'items5'
},
{
title: 'items6'
}]
},
{
headerName: 'ListL',
items: [{
title: 'items1'
},
{
title: 'items2'
},
{
title: 'items3'
},
{
title: 'items4'
},
{
title: 'items5'
},
{
title: 'items6'
}]
},
{
headerName: 'ListE',
items: [{
title: 'items1'
},
{
title: 'items2'
},
{
title: 'items3'
},
{
title: 'items4'
},
{
title: 'items5'
},
{
title: 'items6'
}]
},
{
headerName: 'ListE',
items: [{
title: 'items1'
},
{
title: 'items2'
},
{
title: 'items3'
},
{
title: 'items4'
},
{
title: 'items5'
},
{
title: 'items6'
}]
},
{
headerName: 'ListE',
items: [{
Expand Down

0 comments on commit f6f45ee

Please sign in to comment.