Skip to content

Instantly share code, notes, and snippets.

View PHELAT's full-sized avatar

Mahdi Nouri PHELAT

View GitHub Profile
@PHELAT
PHELAT / MainActivity.kt
Created May 11, 2019 19:45
navigateUp with Bundle!
class MainActivity : FragmentResultActivity() {
// You can use updateNavHostFragmentId function to update
// nav host fragment's id at runtime.
override fun getNavHostFragmentId(): Int = R.id.nav_host_fragment
}
@PHELAT
PHELAT / FragmentB.kt
Last active May 11, 2019 19:31
navigateUp with Bundle!
// This is an extension function on Fragment
import com.phelat.navigationresult.navigateUp
class FragmentB : Fragment() {
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState)
anotherButton.setOnClickListener {
val bundle = Bundle().apply {
putBoolean(IS_LOG_IN_SUCCESSFUL, true)
}
@PHELAT
PHELAT / FragmentA.kt
Last active May 11, 2019 19:34
navigateUp with Bundle!
class FragmentA : BundleFragment() {
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState)
myButton.setOnClickListener {
navigate(FragmentADirections.fragmentAToFragmentB(), REQUEST_CODE)
// If you aren't using SafeArgs plugin, you can navigate with direction id
navigate(R.id.fragmentAToFragmentB, REQUEST_CODE)
}
}
override fun onFragmentResult(requestCode: Int, bundle: Bundle) {
@PHELAT
PHELAT / FragmentA.kt
Last active May 10, 2019 21:31
navigateUp with Bundle!
class FragmentA : BundleFragment() {
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState)
myButton.setOnClickListener {
navigate(FragmentADirections.fragmentAToFragmentB(), REQUEST_CODE)
// If you aren't using SafeArgs plugin, you can navigate with direction id
navigate(R.id.fragmentAToFragmentB, REQUEST_CODE)
}
}
companion object {
@PHELAT
PHELAT / FragmentA.kt
Last active May 10, 2019 19:20
navigateUp with Bundle!
class FragmentA : BundleFragment() {
...
}