this post was submitted on 06 Feb 2025
1 points (100.0% liked)

Developing Android Apps

46 readers
1 users here now

News for Android developers with the who, what, where, when and how of the Android community. News / Articles / Talks / Tools / Open source!.

founded 2 years ago
MODERATORS
 
This is an automated archive made by the Lemmit Bot.

The original was posted on /r/androiddev by /u/DroidRamon on 2025-02-05 09:24:05+00:00.


I know one should not pass down the navController. However people just do it. (People including devs generally do stupid shit.)

I pretty much inherited an app that passes through a navController deep into each composable. To make it even worse, it also uses hiltViewModels and there isn't a single preview in the entire app. I repeat, not a single preview. I do not know how they worked on it. Most probably they used LiveEdit as some kind of hot reload. That works if you're on the dashboard and you make a quick reload after a change.

However, being 5 clicks deep in a detail graph, it becomes extremely inefficient. Each time you have to click your way through, in addition to programming the UI blindly. In any case, my job isn't just to change the colors, so I need previews. To generate previews, there is a lot of refactoring to do.

After that however, one looks at a function and thinks what am I doing here. The sheer verbosity makes me uneasy. Down there is an example of what I mean. There are 2 questions here: 1. Am I doing the right thing here? 2. What do I do with this many function parameters? (given that I will have even more)

@Composable
fun SomeScreen(
    navController: NavController,
    isMocked: Boolean = false,
    @DrawableRes placeholderImageId: Int = -1,
    viewModel: ViewModel = hiltViewModel(),
    designArgs: DesignArgs = viewModel.defaultDesignArgs,
    behaviorArgs: ListBehaviorArgs = BehaviorArgs()
) {

    SomeScreenContent(
        isMocked = isMocked,
        data = viewModel.displayedData,
        designArgs = masterDesignArgs,
        designArgs = someViewModel.designArgs,
        behaviorArgs = behaviorArgs,
        doSth = viewModel::init,
        getMockedData =  vm::doSth,
        placeholderImageId = placeholderImageId,
        onSearch = { pressReleaseViewModel.search(it) },
        wrapperState = vm.wrapperState,
        previousBackStackEntry = navController.previousBackStackEntry,
        popBackstack = navController::popBackStack,
        navigateToDetail = {
            navController.navigate(NavItems.getGetRoute(it))
        })
}

no comments (yet)
sorted by: hot top controversial new old
there doesn't seem to be anything here