Skip to content

Commit

Permalink
Add navigation transactions in message queue
Browse files Browse the repository at this point in the history
  • Loading branch information
VitalyPeryatin committed Apr 8, 2021
1 parent 4c674c2 commit f2de564
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ package com.github.terrakok.cicerone.androidx

import android.content.ActivityNotFoundException
import android.content.Intent
import android.os.Handler
import android.os.Looper
import androidx.fragment.app.*
import com.github.terrakok.cicerone.*
import com.github.terrakok.cicerone.androidx.TransactionInfo.Type.ADD
Expand All @@ -22,8 +24,15 @@ open class AppNavigator @JvmOverloads constructor(
) : Navigator {

protected val localStackCopy = mutableListOf<TransactionInfo>()
private val mainHandler = Handler(Looper.getMainLooper())

override fun applyCommands(commands: Array<out Command>) {
mainHandler.post {
applyCommandsSync(commands)
}
}

protected open fun applyCommandsSync(commands: Array<out Command>) {
fragmentManager.executePendingTransactions()

//copy stack before apply commands
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,8 @@ class MainActivity : MvpAppCompatActivity(), ChainHolder {

private val navigator: Navigator = object : AppNavigator(this, R.id.main_container) {

override fun applyCommands(commands: Array<out Command>) {
super.applyCommands(commands)
override fun applyCommandsSync(commands: Array<out Command>) {
super.applyCommandsSync(commands)
supportFragmentManager.executePendingTransactions()
printScreensScheme()
}
Expand Down

0 comments on commit f2de564

Please sign in to comment.