tidev / titanium-sdk

🚀 Native iOS and Android Apps with JavaScript
https://titaniumsdk.com/
Other
2.75k stars 1.21k forks source link

iOS: Be able to specify animation parameters to "scrollToTop" and "scrollToBottom" #13203

Open hansemannn opened 2 years ago

hansemannn commented 2 years ago

I have searched and made sure there are no existing issues for the issue I am filing

Description

There is currently no way to disable the animation when using scrollToTop and scrollToBottom.

Solution

It can be changed while keeping backwards compatibility 👍 Not sure if Android also allows this, so it could be added parity. To move fast, I would like to add iOS first and then add Android later if anyone needs it as well.

Alternatives

No response

Platforms

iOS

m1ga commented 2 years ago

About Android:

https://github.com/appcelerator/titanium_mobile/pull/9601

Animated vertical scrolling bugs mentioned above were solved by disabling the smooth scrolling animation. It now immediately jumps to the given position. This appears to be a Google bug in their Java NestedScrollView class.

That said: It works for me like this but it should be default false of course and we might need to add that note to the README. Just in case:

https://github.com/appcelerator/titanium_mobile/blob/c706bea567d683d318fe179c97ba33cb20809ab4/android/modules/ui/src/java/ti/modules/titanium/ui/widget/TiUIScrollView.java#L997-L1005

    public void scrollToBottom(boolean animated)
    {
        View view = this.scrollView;
        if (view instanceof TiHorizontalScrollView) {
            ((TiHorizontalScrollView) view).fullScroll(View.FOCUS_RIGHT);
        } else if (view instanceof TiVerticalScrollView) {
            if (animated == false) {
                ((TiVerticalScrollView) view).fullScroll(View.FOCUS_DOWN);
            } else {
                NestedScrollView nestedScrollView = ((TiVerticalScrollView) view);
                nestedScrollView.smoothScrollBy(0, nestedScrollView.getChildAt(0).getHeight());
            }
        }
    }

https://github.com/appcelerator/titanium_mobile/blob/fe3deddcea07ecb3555673cf2dba8d676fd79611/android/modules/ui/src/java/ti/modules/titanium/ui/ScrollViewProxy.java#L80-L85

    @Kroll.method
    public void scrollToBottom(@Kroll.argument(optional = true) HashMap args)
    {
        boolean animated = false;
        if (args != null) {
            animated = TiConvert.toBoolean(args.get("animated"), false);
        }
        handleScrollToBottom(animated);
    }

https://github.com/appcelerator/titanium_mobile/blob/fe3deddcea07ecb3555673cf2dba8d676fd79611/android/modules/ui/src/java/ti/modules/titanium/ui/ScrollViewProxy.java#L97-L100

    public void handleScrollToBottom(boolean animated)
    {
        getScrollView().scrollToBottom(animated);
    }