Android-MultiStacks

Additional

Language
Kotlin
Version
1.1 (Jan 22, 2020)
Created
Jan 21, 2020
Updated
Jan 27, 2020
Owner
DimaKron
Contributor
DimaKron
1
Activity
Badge
Generate
Download
Source code

Announcement

Android MultiStacks

Getting started

Dependency

Add following line to root build.gradle

allprojects {
    repositories {
        ...
        maven { url 'https://jitpack.io' }
    }
}

and line to modul level build.gradle

dependencies {
    implementation 'com.github.DimaKron:Android-MultiStacks:1.1'
}

Usage

Initialization

Initialize component with Builder in your main navigation activity

multiStacks = MultiStacks.Builder(supportFragmentManager, R.id.containerLayout)
            .setState(savedInstanceState)
            .setRootFragmentInitializers(fragmentInitializers)
            .setSelectedTabIndex(0)
            .setTabHistoryEnabled(true)
            .setTransactionListener(this)
            .build()

Saving state

Override method of navigation activity

override fun onSaveInstanceState(outState: Bundle) {
        multiStacks.saveInstanceState(outState)
        super.onSaveInstanceState(outState)
}

Back action

Call method to perform back action (close fragment or back to other tab)

...
 multiStacks.onBackPressed()
...

Manage

Use methods following methods for navigation managent

  • setSelectedTabIndex(Int) change tab
  • push(Fragment) add new fragment to current tab
  • replace(Fragment) replace current with new fragment
  • popFragments(Int) remove X last fragments of current stack
  • clearStack() remove all fragments of current stack (except first)

Other features

Unique fragment in stack

Your fragment should implements getIdentifierInStack() of IMultiStackFragmentinterface

Built-in tabs history

Enable tabs history with MultiStack.Builder.setTabHistoryEnabled(true)