Fragmentor
is a fragment-based navigation manager for Android. It solves common issues related to navigation between fragments.
Add jitpack.io
repository to your project:
allprojects {
repositories {
jcenter()
maven { url "https://jitpack.io" }
}
}
Then add Fragmentor
to dependencies list:
dependencies {
implementation 'com.github.igormatyushkin014:Fragmentor:1.2'
}
- Android SDK 15 and later
- Android Studio 3.3 and later
- Kotlin 1.3 or later
First of all, you need a container for your fragments. Simply put FrameLayout
component with fragmentorContainer
ID into your activity's layout just like in the example below:
...
<FrameLayout
...
id="@+id/fragmentorContainer"
/>
...
You're all set!
Navigation starts with NavigationManager
instance. It handles everything related to navigation between fragments. All fragments exist inside of stack. When you push new fragment to the stack, it will be shown on the top. When you pop the latest fragment, the top underlying fragment will be shown. So, push
and pop
will be the main operations used for navigation.
You can access the NavigationManager
instance related to your current activity by using fragmentor
. For example, this is how you push a fragment from your activity:
fragmentor.push(MyFragment())
Also, it's possible to push an array of fragments:
fragmentor.push(
arrayOf(
MyFragment(),
AnotherFragment(),
OneMoreFragment()
)
)
Navigate back:
fragmentor.pop()
Navigate back to the first fragment:
fragmentor.popToBottom()
You can use fragmentor
directly from your fragment class. The method will return nullable NavigationManager
instance:
fragmentor?.push(AnotherFragment())
By default, fragment is not clickable and focusable. Also, it has transparent background. Fragmentor
solves these issues automatically so you don't need to write anything! All fragments that are pushed using NavigationManager
are clickable, focusable and include white background. That's how the library saves developer's time.
Fragmentor
is available under the Apache 2.0 license. See the LICENSE file for more info.