ToxicBakery / ViewPagerTransforms

Library containing common animations needed for transforming ViewPager scrolling for Android v13+.
https://toxicbakery.github.io/ViewPagerTransforms/
Apache License 2.0
2.57k stars 489 forks source link

Bug when want to change current position without smooth #68

Open anonym24 opened 6 years ago

anonym24 commented 6 years ago

How to test bug: add next code in onCreate, run app, choose some transformation and wait for 6 seconds, it will change something but slider won't appear or animation would be frozen (paused at its start)

        // test bug
        Handler handler = new Handler();
        handler.postDelayed(new Runnable() {
            @Override
            public void run() {
                mPager.setCurrentItem(4, false);
            }
        }, 6000);
protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        int selectedPage = 0;
        if (savedInstanceState != null) {
            mSelectedItem = savedInstanceState.getInt(KEY_SELECTED_CLASS);
            selectedPage = savedInstanceState.getInt(KEY_SELECTED_PAGE);
        }

        final ArrayAdapter<TransformerItem> actionBarAdapter = new ArrayAdapter<>(
                getApplicationContext(), android.R.layout.simple_list_item_1, android.R.id.text1, TRANSFORM_CLASSES);

        setContentView(R.layout.activity_main);

        mAdapter = new PageAdapter(getFragmentManager());

        mPager = (ViewPager) findViewById(R.id.container);
        mPager.setAdapter(mAdapter);
        mPager.setCurrentItem(selectedPage);

        // test bug
        Handler handler = new Handler();
        handler.postDelayed(new Runnable() {
            @Override
            public void run() {
                mPager.setCurrentItem(4, false);
            }
        }, 6000);

        final ActionBar actionBar = getActionBar();
        if (actionBar != null) {
            actionBar.setListNavigationCallbacks(actionBarAdapter, this);
            actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_LIST);

            //noinspection ResourceType
            actionBar.setDisplayOptions(actionBar.getDisplayOptions() ^ ActionBar.DISPLAY_SHOW_TITLE);

            actionBar.setSelectedNavigationItem(mSelectedItem);
        }

    }

for example with ZoomOutSliderTransformer slider won't be fully 100% taking all space of layout (you can see white paddings or margin at right and bottom)

screenshot_2017-10-01-18-40-51-795_com toxicbakery viewpager transforms

anonym24 commented 6 years ago

it only works with smooth parameter set to true, but it could result in bad user exepirence if someone changes position form 3 to 125, so in this case I need to change current fragment without any smooth and transformation, fastly, it should be done only if we change from 2 to 3 or from 3 to 2 (next, previous fragments), in this case transformation is ok

anonym24 commented 6 years ago

solved this by setting temporarily page transformer to null before setCurrentItem for big distances between position and then again set needed page transformer:

        try {
            mPager.setPageTransformer(true, new TransformerItem(ZoomOutSlideTransformer.class).clazz.newInstance());
        } catch (Exception e) {
            throw new RuntimeException(e);
        }

        // test bug
        Handler handler = new Handler();
        handler.postDelayed(new Runnable() {
            @Override
            public void run() {
                mPager.setPageTransformer(true, null);
                mPager.setCurrentItem(4, false);
                try {
                    mPager.setPageTransformer(true, new TransformerItem(ZoomOutSlideTransformer.class).clazz.newInstance());
                } catch (Exception e) {
                    throw new RuntimeException(e);
                }
            }
        }, 3000);