Uploaded image for project: 'Titanium SDK/CLI'
  1. Titanium SDK/CLI
  2. TIMOB-25514

Android: Vertical ScrollView.scrollTo() goes to wrong position when animated as of 6.2.2

    Details

      Description

      Summary:
      The ScrollView.scrollTo() method, when "animated" is set to true, will not always scroll to the given position for "vertical" scroll views as of Titanium 6.2.2.

      Steps to reproduce:

      1. Build and run the below code on Android via Titanium 6.2.2 or higher.
      2. Scroll down to the bottom of the ScrollView.
      3. Tap the "Scroll to Top" button.

      var window = Ti.UI.createWindow();
      var scrollView = Ti.UI.createScrollView(
      {
      	layout: "vertical",
      	scrollType: "vertical",
      	showHorizontalScrollIndicator: false,
      	shorVerticalScrollIndicator: true,
      	width: Ti.UI.FILL,
      	height: Ti.UI.FILL,
      });
      scrollView.add(Ti.UI.createLabel(
      {
      	text: "First View",
      	textAlign: Ti.UI.TEXT_ALIGNMENT_CENTER,
      	color: "white",
      	backgroundColor: "blue",
      	borderColor: "white",
      	borderWidth: "1dp",
      	width: "100%",
      	height: "75%",
      }));
      scrollView.add(Ti.UI.createLabel(
      {
      	text: "Middle View",
      	textAlign: Ti.UI.TEXT_ALIGNMENT_CENTER,
      	color: "white",
      	backgroundColor: "#008800",
      	borderColor: "white",
      	borderWidth: "1dp",
      	width: "100%",
      	height: "75%",
      }));
      scrollView.add(Ti.UI.createLabel(
      {
      	text: "Last View",
      	textAlign: Ti.UI.TEXT_ALIGNMENT_CENTER,
      	color: "white",
      	backgroundColor: "purple",
      	borderColor: "white",
      	borderWidth: "1dp",
      	width: "100%",
      	height: "75%",
      }));
      window.add(scrollView);
      var button = Ti.UI.createButton(
      {
      	title: "Scroll To Top",
      	bottom: "10dp",
      	right: "10dp",
      });
      button.addEventListener("click", function(e) {
      	scrollView.scrollTo(0, 0, { animated: true });
      });
      window.add(button);
      window.open();
      

      Result:
      The ScrollView does not scroll to the top.

      Expected Result:
      The scrollTo() method should go to the given position.

      Notes:

      • The scrollTo() function will work if not set up to be animated.
      • The scrollTo() function will work when starting from the top of the ScrollView to scroll down, but is unreliable when called from any other scroll position.
      • This is not an issue with horizontal ScrollViews.
      • This appears to be a bug in Google's "NestedScrollView" Java class. It's smoothScrollTo() and fullScroll() methods are now unreliable, but its non-smooth scrolling methods work fine.

      Work-Around:
      The scrollTo() method will work when not set up to be animated, like this...

      // Don't do this.
      //scrollView.scrollTo(x, y, { animated: true });
       
      // Do this. It works-around the issue.
      scrollView.scrollTo(x, y);
      

        Attachments

          Activity

            People

            • Assignee:
              jquick Joshua Quick
              Reporter:
              jquick Joshua Quick
              Reviewer:
              Gary Mathews
              Tester:
              Abir Mukherjee
            • Watchers:
              3 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved:

                Backbone Issue Sync

                • Titanium SDK/CLI <> Titanium Mobile
                  Synced with:
                  TIMOB-5976
                  Sync status:
                  ERROR
                  Last received:
                  Last sent:

                  Git Source Code