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

TiAPI: Enable ScrollView.smoothScrollTo(x,y) method

    Details

      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 =)

        Attachments

          Activity

            People

            • Assignee:
              hknoechel Hans Knöchel
              Reporter:
              chmiiller Carlos Henrique Zinato
              Reviewer:
              Gary Mathews
            • Watchers:
              7 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved:

                Backbone Issue Sync

                • Backbone Issue Sync is enabled for your project, but we do not have any synchronization info for this issue.

                  Git Integration