Code Monkey home page Code Monkey logo

Comments (5)

phucnguyensna avatar phucnguyensna commented on August 16, 2024 5

class BottomSheet : BottomSheetDialogFragment() {

override fun onCreateDialog(savedInstanceState: Bundle?): Dialog {
    return object: BottomSheetDialog(requireContext(), theme) {
        override fun onBackPressed() {
            // Handle backpress in here
        }
    }
}

}

from bottomsheet.

ZacSweers avatar ZacSweers commented on August 16, 2024

Unfortunately there's no easy way to handle this since the sheet is part of the activity's view hierarchy. We handle this in a base activity class, and you can see an example in the sample code's MainActivity

It's not pretty, but unless Activity has a secret addOnBackPressListener() API that we're not aware of, I don't see any better solutions. It's mitigated by stuffing it down into a base class. Open to ideas though, any thoughts?

For the record, the system share sheet (and Google Drive I think) get away with this by showing the sheet in a transparent activity on top of the current activity

from bottomsheet.

evant avatar evant commented on August 16, 2024

Of course there is a way to do this, DrawerLayout does. You have to override onKeyDown() and onKeyUp() and listen for keyCode == KeyEvent.KEYCODE_BACK. See http://grepcode.com/file/repository.grepcode.com/java/ext/com.google.android/android/4.3_r1/android/support/v4/widget/DrawerLayout.java#DrawerLayout.onKeyDown%28int%2Candroid.view.KeyEvent%29

from bottomsheet.

ZacSweers avatar ZacSweers commented on August 16, 2024

Ah true, I always forget it shows up as a KeyEvent. We're going to look into that PR tomorrow, thanks for the suggestion!

from bottomsheet.

KishoreReddydhana avatar KishoreReddydhana commented on August 16, 2024

@OverRide
public void onBackPressed() {
if (mBottomSheetBehavior.isHideable()) {
super.onBackPressed();
}else {
mBottomSheetBehavior.setState(BottomSheetBehavior.STATE_COLLAPSED);
}
}

from bottomsheet.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.