In the navigation component version 2.1.0-alpha04
, Navigation Graph
can contain dialog
as one of the destinations.
<?xml version="1.0" encoding="utf-8"?>
<navigation xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/main_navigation"
app:startDestination="@id/startFragment">
<fragment
android:id="@+id/loginFragment"
android:name="com.awesomeproject.android.authentication.login.LoginFragment"
android:label="Login"
tools:layout="@layout/login_fragment" />
<dialog
android:id="@+id/bottomSheet"
android:name="com.awesomproject.android.BottomSheetFragment"
tools:layout="@layout/bottom_sheet_dialog_fragment" />
</navigation>
The BottomSheetFragment will look similar to other BottomSheet.
class BottomSheetFragment : BottomSheetDialogFragment() {
override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?,
savedInstanceState: Bundle?): View =
inflater.inflate(R.layout.bottom_sheet_dialog_fragment, container, false)
}
Then you can treat bottomSheet
the same way as other destinations. You can navigate to this destination or passing safeArgs
in.
Cheers!