r0adkll / Slidr

Easily add slide to dismiss functionality to an Activity
Apache License 2.0
2.68k stars 389 forks source link

Can I use it to start new activity? #69

Closed MarcHe124 closed 5 years ago

MarcHe124 commented 6 years ago

Wonder if it supports start a new activity when swiping with minimum code modification.

happyho3ein commented 6 years ago

can anyone answer how to do this?

Kolyall commented 5 years ago

@MarcHe124 , @happyho3ein

Intent intent = new Intent(context, AnyActivity.class);
ActivityOptions options =
                    ActivityOptions.makeCustomAnimation(activity, R.anim.slide_in_down, R.anim.none);
            ActivityCompat.startActivity(activity, intent, options.toBundle());

slide_in_down.xml

<?xml version="1.0" encoding="utf-8"?>
<translate xmlns:android="http://schemas.android.com/apk/res/android"
           android:duration="300"
           android:fromYDelta="100%p"
           android:toYDelta="0"/>

AnyActivity.class


    @Override
    protected void onPause() {
        super.onPause();
        overridePendingTransition(R.anim.none, R.anim.slide_out_down);

    }

slide_out_down.xml

<?xml version="1.0" encoding="utf-8"?>
<translate xmlns:android="http://schemas.android.com/apk/res/android"
           android:duration="300"
           android:fromYDelta="0%p"
           android:toYDelta="100%p"/>
bhargavms commented 5 years ago

Basically you want to horizontally scroll between activities like you do with a viewpager and fragments?

r0adkll commented 5 years ago

You could hook into the SlidrListener that you can configure when attaching to an activity and override it's boolean onSlideClosed() method and do what you want when the slide is completed:

e.g.

@Override
public boolean onSlideClosed() {
    startActivity(Intent(...));
    finish();
    return true; // Important so as to override the default behaviour 
}

However, the library isn't currently capable of launching different activities based on the direction of the slide.