wellingtoncabral / android-compose-mvi-navigation

GithubCompose is a sample project that uses Compose + MVI + Navigation Component to presents a modern approach to Android app development.
99 stars 17 forks source link

Navigation screens composed multiple times #1

Open ewaldc opened 1 year ago

ewaldc commented 1 year ago

First of all: thanks for this fine application architecture!

I have copied the architectural approach for my project (a Virtual Run App similar to Zwift) and everything runs fine, except for one thing: I noticed that when navigating to a different screen the start screen is recomposed even though it is not visible. Since I'm an absolute newbie in Kotlin/Koin/Compose/Navigation (but experienced Linux kernel programmer), I checked to see if this issue also is present in the "master" code.

If I add 'Log.d' calls to 'AppNavigation.kt`, and start the app, then the logs show:

D/VRUN: AppNavigation: navigateToRepos - wycats
D/VRUN: AppNavigation: NavHost - Users
D/VRUN: AppNavigation: NavHost - Repos
D/VRUN: AppNavigation: NavHost - Repos
D/MIUIInput: [KeyEvent] ViewRootImpl KeyEvent { action=ACTION_DOWN, keyCode=KEYCODE_BACK, scanCode=0, metaState=0, flags=0x48, repeatCount=0, eventTime=1659049858, downTime=1659049858, deviceId=-1, source=0x101, displayId=0 }
D/MIUIInput: [KeyEvent] ViewRootImpl KeyEvent { action=ACTION_UP, keyCode=KEYCODE_BACK, scanCode=0, metaState=0, flags=0x48, repeatCount=0, eventTime=1659049952, downTime=1659049858, deviceId=-1, source=0x101, displayId=0 }
D/VRUN: AppNavigation: NavHost - Repos
D/VRUN: AppNavigation: NavHost - Users
D/VRUN: AppNavigation: NavHost - Users
D/VRUN: AppNavigation: navigateToRepos - ivey
D/VRUN: AppNavigation: NavHost - Users
D/VRUN: AppNavigation: NavHost - Repos
D/VRUN: AppNavigation: NavHost - Repos

So navigation to user wycats is invoking the USERS screen again before calling REPOS twice. Also when going back, the sequence also seems strange: REPOS again and then USERS twice. And of course, as the screen is recomposed, all composables down the tree are also recomposed.

This does not seem right... Thanks in advance, Ewald