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

Android: ScrollView.scrollTo() ignores "ti.ui.defaultunit" when animated

    Details

    • Story Points:
      1

      Description

      Summary:
      The Android ScrollView.scrollTo() method always operates in pixels when set up to be animated. Meaning that it ignores the "ti.ui.defaultunit" property's configured units (such as "dp") in the "tiapp.xml" file.

      Note that ScrollView.scrollTo() when not set up to animated does respect the "ti.ui.defaultunit" property.

      Steps to reproduce:

      1. Open your project's "tiapp.xml" file.
      2. Add a "ti.ui.defaultunit" property set to "dp" as shown below.
      3. Create an "app.js" file using the below code.
      4. Build and run the app on Android.
      5. Tap the "Scroll to Middle" button.

      <?xml version="1.0" encoding="UTF-8"?>
      <ti:app xmlns:ti="http://ti.appcelerator.org">
      	<property name="ti.ui.defaultunit" type="string">dp</property>
      </ti:app>
      

      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,
      });
      var firstView = 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(firstView);
      var middleView = 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(middleView);
      var lastView = Ti.UI.createLabel(
      {
      	text: "Last View",
      	textAlign: Ti.UI.TEXT_ALIGNMENT_CENTER,
      	color: "white",
      	backgroundColor: "purple",
      	borderColor: "white",
      	borderWidth: "1dp",
      	width: "100%",
      	height: "75%",
      });
      scrollView.add(lastView);
      window.add(scrollView);
      var button = Ti.UI.createButton(
      {
      	title: "Scroll to Middle",
      	bottom: "10dp",
      	right: "10dp",
      });
      button.addEventListener("click", function(e) {
      	scrollView.scrollTo(0, firstView.size.height, { animated: true });
      });
      window.add(button);
      window.open();
      

      Result:
      The top of the "middle" view fails to be scrolled to the top of the scroll view.

      This is because the view's height was returned in "dp" units but the scrollTo() method interpretted it as "pixels" instead.

      Expected Result:
      The scrollTo() method must respect the project's "ti.ui.defaultunit" setting.

      Work-Around:
      This issue can be worked-around by doing 1 of the following...

      • Do not use animated scrolling.
      • Set "ti.ui.defaultunit" to pixels.

        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-5977
                  Sync status:
                  ERROR
                  Last received:
                  Last sent:

                  Git Source Code