Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bug when want to change current position without smooth #68

Open
anonym24 opened this issue Oct 1, 2017 · 2 comments
Open

Bug when want to change current position without smooth #68

anonym24 opened this issue Oct 1, 2017 · 2 comments

Comments

@anonym24
Copy link

anonym24 commented Oct 1, 2017

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
Copy link
Author

anonym24 commented Oct 1, 2017

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
Copy link
Author

anonym24 commented Oct 1, 2017

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


Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant