Skip to content

Commit

Permalink
Merge pull request #151 from VitalyPeryatin/handle_transactions_by_ui…
Browse files Browse the repository at this point in the history
…_handler

Add navigation transactions in message queue
  • Loading branch information
terrakok authored Apr 8, 2021
2 parents 4c674c2 + f2de564 commit 7a862cb
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 7a862cb

Please sign in to comment.