https://github.com/evant/fragstack
A better android fragment backstack
https://github.com/evant/fragstack
Last synced: about 1 year ago
JSON representation
A better android fragment backstack
- Host: GitHub
- URL: https://github.com/evant/fragstack
- Owner: evant
- License: apache-2.0
- Created: 2018-06-24T01:04:45.000Z (almost 8 years ago)
- Default Branch: main
- Last Pushed: 2020-06-14T22:47:21.000Z (about 6 years ago)
- Last Synced: 2025-04-01T14:46:02.734Z (about 1 year ago)
- Language: Kotlin
- Size: 138 KB
- Stars: 9
- Watchers: 1
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# fragstack
A better fragment back-stack™
The major difference from the built-in fragment back-stack is that
fragments in the back-stack on completely destroyed, not just their views. This removes the weird
extra `onViewCreated(View, Bundle)`/`Fragment#onDestroyView()` lifecycle
that fragments have.
## Usage
Specify the intial fragment, then use `push()` and `pop` to manipulate the back-stack.
```kotlin
import android.support.v7.app.AppCompatActivity
import android.os.Bundle
import me.tatarka.fragstack.ktx.backStack
class MainActivity : AppCompatActivity {
override fun onCreate(savedInstanceState: Bundle?) {
backStack.startWith(R.id.content, DashboardFragment.newInstance())
}
override fun onBackPressed() {
if (!backStack.popImmediate()) {
super.onBackPressed()
}
}
}
...
backStack.push(DetailFragment.newInstance())
backStack.pop()
```
Transactions will automatically be optimised, so you are free to edit the
back-stack with multiple operations. For example, to go from [A, B, C] to [A, B, D] you can do
```kotlin
backStack.pop().push(fragmentD)
```
### From Java
Get an instance of the backstack with `FragmentBackstack.of(activity.getSupportFragmentManager())` or
`FragmentBackstack.of(fragment.getChildFragmentManager())`.
## Differences with Fragment Transitions
Unfortunatly the fragment transitions api is tied deeply with the built-in back-stack. It will see a pop from
this lib the same way as a push. This means pop animations will run in the new fragment instead of the old one.
Methods like `setSharedElementReturnTransition()`, `setReenterTransition()` and `setReturnTransition()` will
be ignored.