Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Android. ScrollView. Inconsistent units in contentOffset #12608

Closed
drauggres opened this issue Mar 17, 2021 · 2 comments · Fixed by #12615
Closed

Android. ScrollView. Inconsistent units in contentOffset #12608

drauggres opened this issue Mar 17, 2021 · 2 comments · Fixed by #12615
Assignees

Comments

@drauggres
Copy link
Contributor

Ti.UI.ScrollView on Android returns value for contentOffset in pixels and dp.

To Reproduce

Sample app
const win = Ti.UI.createWindow({
  backgroundColor: 'white',
  layout: 'vertical',
});

const scroll = Ti.UI.createScrollView({
  scrollType: 'horizontal',
  backgroundColor: 'black',
  width: Ti.UI.FILL,
  height: '50%',
  center: {
    y: '50%'
  }
});

const longView = Ti.UI.createView({
  width: 2000,
  height: Ti.UI.FILL,
  backgroundGradient: {
    type: 'linear',
    startPoint: {
      x: '0%',
      y: '50%'
    },
    endPoint: {
      x: '100%',
      y: '50%'
    },
    colors: [
      {color: 'red', offset: 0},
      {color: 'green', offset: 0.5},
      {color: 'blue', offset: 1}
    ]
  }
});

setInterval(() => {
  console.log('contentOffset.x:', scroll.contentOffset.x);
}, 300);

const inc = Ti.UI.createButton({
  title: '+100'
});
const dec = Ti.UI.createButton({
  title: '-100'
});

inc.addEventListener('click', function() {
  let { x, y } = scroll.contentOffset;
  x += 100;
  // I know it's possible to overscroll here
  // It doesn't matter for this case
  scroll.contentOffset = {x, y };
})
dec.addEventListener('click', function() {
  let { x, y } = scroll.contentOffset;
  x -= 100;
  if (x < 0) {
    x = 0;
  }
  scroll.contentOffset = {x, y };
})

win.add(inc);
win.add(dec);

scroll.add(longView);
win.add(scroll);
win.open();
  1. Put code above in the app.js, build the app, observe console output
  2. Click +100 button five times
  3. Notice contentOffset.x: 500 in the output (value in dp)
  4. Drag scroll view slightly to the right, so the offset should decrease
  5. Notice contentOffset.x: <VALUE> in the output increased (value in pixels)

P.S. Default app template has <property name="ti.ui.defaultunit" type="string">dp</property> in it.

Expected behavior

contentOffset property of Ti.UI.ScrollView must contain values in consistent units

Environment

Titanium SDK version: 9.3.2.GA, 10.1.0 (master)

@jquick-axway
Copy link
Contributor

@drauggres , thanks for reporting this. A ticket has been written for it here:
https://jira.appcelerator.org/browse/TIMOB-28397

@jquick-axway
Copy link
Contributor

I see another issue too. When calling convertPointToView() where the destination view is the ScrollView, then the contentOffset should be applied to the return point as well. This is an issue on both Android and iOS. Supporting this would make it easier to scroll to a child view within a scroll view.

I wrote up a ticket for this here...
https://jira.appcelerator.org/browse/TIMOB-28398

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants