[TIMOB-24411] TiAPI: Enable ScrollView.smoothScrollTo(x,y) method
GitHub Issue | n/a |
---|---|
Type | Improvement |
Priority | Critical |
Status | Closed |
Resolution | Fixed |
Resolution Date | 2017-04-20T17:47:44.000+0000 |
Affected Version/s | n/a |
Fix Version/s | Release 6.1.0 |
Components | Android, iOS |
Labels | android, animated, merge-6.1.0, scrollTo, scrollview, smoothScrollTo |
Reporter | Carlos Henrique Zinato |
Assignee | Hans Knöchel |
Created | 2017-02-17T13:23:06.000+0000 |
Updated | 2017-05-15T18:09:51.000+0000 |
Description
Add support for smoothScrollTo() method on ScrollView component:
https://developer.android.com/reference/android/widget/ScrollView.html#smoothScrollTo(int,%20int)
It should use *{animated:true}* option for a better cross-platform implementation
Don't know how to implement the options this is what I have so far on ScrollViewProxy.java:
@Kroll.method
public void scrollTo(int x, int y, @Kroll.argument(optional=true) KrollDict options) {
if (!TiApplication.isUIThread()) {
TiMessenger.sendBlockingMainMessage(getMainHandler().obtainMessage(MSG_SCROLL_TO, x, y), getActivity());
//TiApplication.getInstance().getMessageQueue().sendBlockingMessage(getMainHandler().obtainMessage(MSG_SCROLL_TO, x, y), getActivity());
//sendBlockingUiMessage(MSG_SCROLL_TO, getActivity(), x, y);
} else {
handleScrollTo(x,y,options);
}
}
//...
@Override
public boolean handleMessage(Message msg) {
if (msg.what == MSG_SCROLL_TO) {
//I think the problem is here, since we're creating an empty KrollDict, ignoring the options. But I'm not sure =/
KrollDict options = new KrollDict();
handleScrollTo(msg.arg1, msg.arg2, options);
AsyncResult result = (AsyncResult) msg.obj;
result.setResult(null); // signal scrolled
return true;
} else if (msg.what == MSG_SCROLL_TO_BOTTOM) {
handleScrollToBottom();
AsyncResult result = (AsyncResult) msg.obj;
result.setResult(null); // signal scrolled
return true;
}
return super.handleMessage(msg);
}
public void handleScrollTo(int x, int y, KrollDict options) {
if (TiConvert.toBoolean(options, TiC.PROPERTY_ANIMATED, false)) {
getScrollView().smoothScrollTo(x, y);
}else{
getScrollView().scrollTo(x, y);
}
}
I think that every time I call scroll.scrollTo()
on JS it calls the handleMessage
on scrollViewProxy.java and I don't know of a good way to propagate the options
to scrollTo
method.
Of course, in the TiUIScrollView.java file I have the implementation of the smoothScrollTo() method:
public void smoothScrollTo(int x, int y)
{
View view = getNativeView();
if (view instanceof TiHorizontalScrollView) {
TiHorizontalScrollView scrollView = (TiHorizontalScrollView) view;
scrollView.smoothScrollTo(x, y);
} else if (view instanceof TiVerticalScrollView) {
TiVerticalScrollView scrollView = (TiVerticalScrollView) view;
scrollView.smoothScrollTo(x, y);
}
getNativeView().computeScroll();
}
And it does work and scrolls smoothly =)
Thanks for submitting the ticket. Our engineering team will look into it.
We should do the same for iOS. Couldn't we just add the
animated
parameter to the existingscrollTo
method, like this:iOS would be easy to implement as well.
https://github.com/appcelerator/titanium_mobile/pull/8841 Changing parameter to an object and adding animated parameter. Also keeping the normal scrollTo(x,y) for legacy support! Example:
Making a TiAPI ticket so we can have both iOS and Android together (or even Windows if it supports it). iOS PR will come later today.
About the documentation: Since it is possible to have two parameters for scrollTo now: * scrollTo(x,y) * scrollTo(dict) what do I need to add? Just a second method with the new parameters?
Shit, so when it has 2 params, we would probably need to expose it as a third one for now.
or
?
is better I guess. Just like the listview animation options.
Changed the properties and updated the example. Will do some more testing tomorrow but the example is working already
You can use 6.1.0 as the version. iOS is done, but i realized that iOS animates per default, which is different to Android I guess. We should leave a note for that in the docs. I will commit by changes to your branch on Monday, so we have a unified PR.
Thank you guys for your effort on that! ScrollView implementation on Android was a bit tricky for me. Glad you guys found a solution and a nice implementation on iOS as well!
FR Passed for master branch, waiting for backport to 6.1.0.
Backport: https://github.com/appcelerator/titanium_mobile/pull/9034
FR passed for both master & backport PR's.
Guys, I'm bit confused now, what SDK version should had this smoothScrollTo implemented? 6.1 and ? Thanks
It's in 6.1.0. The backport was missing, because it was merged after 6_1_X was branched. Always rely on the
Fix-Version
of a ticket.Verified the fix in 6.1.0.v20170514022959.
animated
inscrollView
works as expected in Android & IOS. Closing. Studio Ver: 4.9.0.201705110256 SDK Ver: 6.1.0.v20170514022959 OS Ver: 10.12.3 Xcode Ver: Xcode 8.3.2 Appc NPM: 4.2.9 Appc CLI: 6.2.1 Ti CLI Ver: 5.0.13 Alloy Ver: 1.9.11 Node Ver: 6.10.1 Java Ver: 1.8.0_101 Devices: ⇨ google Nexus 6 --- Android 6.0.1 ⇨ google Nexus 6P --- Android 7.1.1 IOS Simulator: Iphone 6S IOS 10.3