[TIMOB-25515] Android: ScrollView.scrollTo() ignores "ti.ui.defaultunit" when animated
GitHub Issue | n/a |
---|---|
Type | Bug |
Priority | Medium |
Status | Closed |
Resolution | Fixed |
Resolution Date | 2017-11-16T00:50:27.000+0000 |
Affected Version/s | Release 6.1.0 |
Fix Version/s | Release 7.0.0 |
Components | Android |
Labels | android, scrollview |
Reporter | Joshua Quick |
Assignee | Joshua Quick |
Created | 2017-11-15T04:25:23.000+0000 |
Updated | 2017-11-16T01:56:21.000+0000 |
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:*
Open your project's "tiapp.xml" file.
Add a "ti.ui.defaultunit" property set to "dp" as shown below.
Create an "app.js" file using the below code.
Build and run the app on Android.
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.
PR (master): https://github.com/appcelerator/titanium_mobile/pull/9601
FR passed; waiting for CR before merging.
PR merged.
Verified the fix in SDK 7.0.0.v20171115153702. Closing.