/Fragmentor

Easy fragment-based navigation for Android apps

Primary LanguageKotlinApache License 2.0Apache-2.0

At a Glance

Fragmentor is a fragment-based navigation manager for Android. It solves common issues related to navigation between fragments.

How to Get Started

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'
}

Requirements

  • Android SDK 15 and later
  • Android Studio 3.3 and later
  • Kotlin 1.3 or later

Usage

Preparations

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 from activity

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()

Navigation from fragment

You can use fragmentor directly from your fragment class. The method will return nullable NavigationManager instance:

fragmentor?.push(AnotherFragment())

Solving Android issues

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.

License

Fragmentor is available under the Apache 2.0 license. See the LICENSE file for more info.