Titanium JIRA Archive
Titanium SDK/CLI (TIMOB)

[TIMOB-27349] Android scroll both directions

GitHub Issuen/a
TypeImprovement
Priorityn/a
StatusOpen
ResolutionUnresolved
Affected Version/sn/a
Fix Version/sn/a
Componentsn/a
Labelsandroid
ReporterNathan Martin
AssigneeEric Merriman
Created2019-05-22T16:27:57.000+0000
Updated2019-08-23T14:55:32.000+0000

Description

Currently implementing a spreadsheet viewer. In iOS, I am able to scroll the spreadsheet both vertically and horizontally:
<ScrollView id="main" onScroll="dataScroll" top="0" layout="vertical" height="100%" width="Ti.UI.SIZE" platform='ios'>
	<View id="rows" left="0" layout="vertical" height="Ti.UI.SIZE" onClick="dataClick" borderColor="Alloy.CFG.Colors.grayMedium" 
         borderWidth="1"></View>
</ScrollView>
For Android, I can only choose a single scroll direction. My current workaround is to wrap the scrollview in a "sensorView" so that I have touch sensor stacked on top of the scrollview.
<View id="sensorView">
   <ScrollView id="main" top="0" scrollingEnabled="false" layout="vertical" height="100%" width="Ti.UI.SIZE" platform='android'>
      <View id="rows" left="0" top="0" layout="vertical" height="Ti.UI.SIZE" onClick="dataClick" borderColor="Alloy.CFG.Colors.grayMedium" 
      borderWidth="1"></View>
   </ScrollView>
   <View id="sensor" borderColor="maroon" borderWidth="2" backgroundColor="transparent" onTouchstart="dataTouchstart" 
   onTouchmove="dataTouchmove" onTouchend="dataTouchend"></View>
</View>
function dataTouchstart(e) {
   e.x = Ti.UI.convertUnits(e.x + "px", "dip");
   e.y = Ti.UI.convertUnits(e.y + "px", "dip");
   startX = e.x;
   startY = e.y;
   initialLeft = $.rows.left;
   initialTop = $.rows.top;
}

function dataTouchmove(e) {
   e.x = Ti.UI.convertUnits(e.x + "px", "dip");
   e.y = Ti.UI.convertUnits(e.y + "px", "dip");
   deltaX = (e.x - startX);
   deltaY = (e.y - startY);
   newXPos = initialLeft + deltaX;
   newYPos = initialTop + deltaY;
   var widthDif = ($.main.rect.width - $.rows.width);
   var heightDif = ($.main.rect.height - $.rows.rect.height);
   $.rows.left = (newXPos > 0) ? 0 : (newXPos < widthDif) ? widthDif : newXPos;
   $.rows.top = (newYPos > 0) ? 0 : (newYPos < heightDif) ? heightDif : newYPos;
}
dataTouchstart/dataTouchmove will move rows view both horizontally and vertically. Is there possibly a better way to do this for Android? In iOS, I am able to perform touch events on the rows view. In Android, the "sensor" sibling view covers the rows view so that I can no longer perform touch events on rows view.

Comments

No comments

JSON Source