Krupen / FabulousFilter

Android library to animate Floating Action Button to Bottom Sheet Dialog and vice-versa
Apache License 2.0
2.67k stars 324 forks source link

Null Pointer Exception on Screen Rotation #2

Closed ProgrammationAndroid closed 7 years ago

ProgrammationAndroid commented 7 years ago

Hi ;). I notice an error while playing with your library. Nice work by the way !

To Reproduce, Just Launch "Top Fab Demo" and while the Filters Fragment is open, rotate your phone. The app Crash with a Null Pointer Exception due to the Floating Action Button

Caused by: java.lang.NullPointerException: Attempt to invoke virtual method 'void android.support.design.widget.FloatingActionButton.getLocationInWindow(int[])' on a null object reference at com.allattentionhere.fabulousfilter.AAH_FabulousFragment.setupDialog(AAH_FabulousFragment.java:129)

Bye ;)

Krupen commented 7 years ago

Thank you for reporting the crash. This crash can be handled in the app code as follows: Add this line to your activity tag in AndroidManifest.xml.

  android:configChanges="orientation|screenSize" 

Add below code in your Activity/Fragment which inflates the AAH_FabulousFragment

@Override
    public void onConfigurationChanged(Configuration newConfig) {
        super.onConfigurationChanged(newConfig);
        if (dialogFrag.isAdded()) {
            dialogFrag.dismiss();
            dialogFrag.show(getActivity().getSupportFragmentManager(), dialogFrag.getTag()); //remove this line if you want to just hide the dialog on config change
        }
    }

Check the updated example to see it working.

ProgrammationAndroid commented 7 years ago

Actually, i handled that directly in onSaveInstanceState method where i check if the Dialog is displaying.

Also, what do you think of adding a listener when the fab's animations end ? I tested quickly and it seems pretty "logical" to wait the end of the fab animation before launch a new request with the filters.

Anyway, nice work ;).

Krupen commented 7 years ago

I just added callbacks for animations, update to version 0.0.3 and check MainActivity/MyFabFragment for example. Also adding it to README file.

ProgrammationAndroid commented 7 years ago

Nice ;). Gonna try this ;)

Krupen commented 7 years ago

Okay, Closing this issue. Feel free to re-open if necessary.