Last active
February 12, 2016 02:25
-
-
Save zo0m/a5b11f1ddb9ed41b250f to your computer and use it in GitHub Desktop.
TableView scroll event offset on Android , Appcelerator Titanium
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# NOT FINISHED | |
# It works, but not good, for such transformation waiting hyperloop | |
topOffset = 30 | |
previousOffset = 0 | |
previousFirstVisibleItem = 0 | |
previousOffsetY = 30 | |
previousMoveDirection = "down" | |
upCounter = 0 | |
downCounter = 0 | |
$.eventTable.addEventListener 'scroll', (event) -> | |
# Ti.API.info "scroll:" | |
firstVisibleView = $.eventList?.data?[0].rows[event.firstVisibleItem].children[0] | |
moveDirection = "down" | |
pointOnWindow = firstVisibleView.convertPointToView firstVisibleView.rect, $.eventList | |
if event.firstVisibleItem < 3 | |
Alloy.Globals.topPane.opacity = 1 | |
Alloy.Globals.calendarPane.opacity = 1 | |
Alloy.Globals.eventsContainer.top = 120 | |
else if pointOnWindow | |
currentFirstVisibleItem = event.firstVisibleItem | |
currentOffsetY = pointOnWindow.y | |
currentOffset = 0 | |
currentOffset = Math.abs(currentOffsetY) + topOffset if currentOffsetY < 0 | |
currentOffset = topOffset - Math.abs(currentOffsetY) if currentOffsetY > 0 | |
# not true, just for comparation, for better acurase sum all (rect.heights + top) | |
currentTotalOffset = 5000*currentFirstVisibleItem + currentOffset | |
previousTotalOffset = 5000*previousFirstVisibleItem + previousOffset | |
if currentTotalOffset < previousTotalOffset | |
moveDirection = "up" | |
else if currentTotalOffset > previousTotalOffset | |
moveDirection = "down" | |
else | |
moveDirection = previousMoveDirection | |
offsetDiff = Math.abs(currentOffset - previousOffset) | |
# Ti.API.debug "#{if skipCalc then "[SKIPPED]" else ""}#{moveDirection.toUpperCase()} | #{previousOffsetY} -> #{currentOffsetY} ]===[#{currentOffset} -- #{offsetDiff} --- [#{currentTotalOffset } || #{previousTotalOffset}]" if Alloy.Globals.isDebug | |
savePreviousMoveDirection = previousMoveDirection | |
previousOffsetY = currentOffsetY | |
previousOffset = currentOffset | |
previousMoveDirection = moveDirection | |
previousFirstVisibleItem = currentFirstVisibleItem | |
currentTop = parseInt Alloy.Globals.eventsContainer.top | |
currentTopPaneOpacity = Alloy.Globals.topPane.opacity | |
# Ti.API.debug "#{currentTop} - #{currentTopPaneOpacity} " if Alloy.Globals.isDebug | |
if (moveDirection is "up") | |
upCounter++ | |
downCounter = 0 if upCounter > 2 # filter 'bad' events | |
Ti.API.debug ":::::::::::::::#{moveDirection.toUpperCase()} #{downCounter < upCounter} : #{currentTopPaneOpacity} : #{currentTotalOffset}" if Alloy.Globals.isDebug | |
if downCounter < upCounter | |
if currentTopPaneOpacity < 1 | |
opacity = Math.min((currentTopPaneOpacity + 0.12), 1) | |
Alloy.Globals.topPane.opacity = opacity | |
Alloy.Globals.calendarPane.opacity = opacity | |
if currentTopPaneOpacity > 0.8 | |
Alloy.Globals.eventsContainer.top = 120 if currentTop isnt 120 | |
# Alloy.Globals.eventsContainer.top = Math.min((currentTop + 20), 120) if currentTop < 120 | |
else | |
previousMoveDirection = savePreviousMoveDirection | |
else if (moveDirection is "down") | |
downCounter++ | |
upCounter = 0 if downCounter > 2 # filter 'bad' events | |
Ti.API.debug ":::::::::::::::#{moveDirection.toUpperCase()} #{upCounter < downCounter} : #{currentTopPaneOpacity} : #{currentTotalOffset}" if Alloy.Globals.isDebug | |
if upCounter < downCounter | |
if currentTopPaneOpacity <= 1 | |
opacity = Math.max((currentTopPaneOpacity - 0.12), 0) | |
Alloy.Globals.topPane.opacity = opacity | |
Alloy.Globals.calendarPane.opacity = opacity | |
if currentTopPaneOpacity < 0.3 | |
Alloy.Globals.eventsContainer.top = 0 if currentTop isnt 0 | |
# Alloy.Globals.eventsContainer.top = Math.max((currentTop - 20), 0) if currentTop <= 120 | |
else | |
previousMoveDirection = savePreviousMoveDirection | |
else | |
moveDirection = previousMoveDirection | |
Ti.API.debug "#{moveDirection} : #{previousOffsetY} -> #{currentOffsetY}" if Alloy.Globals.isDebug | |
null |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment