Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[AdvancedStateAndSideEffectsCodelab] injected Modifier in CraneTabBar not used #204

Open
pitoszud opened this issue Oct 7, 2021 · 3 comments

Comments

@pitoszud
Copy link

pitoszud commented Oct 7, 2021

You are injecting modifier - Row(modifier), and then you call Modifier.width(8.dp), Modifier.padding(8.dp) etc... instead of modifier.width(8.dp), modifier.padding(8.dp) etc.
Is it a typo, or it was intentional? If so, what's the benefit and why injecting Modifier at all (in this case)?

@Composable
fun CraneTabBar(
    modifier: Modifier = Modifier,
    onMenuClicked: () -> Unit,
    children: @Composable (Modifier) -> Unit
) {
    Row(modifier) {
        // Separate Row as the children shouldn't have the padding
        Row(Modifier.padding(top = 8.dp)) {
            Image(
                modifier = Modifier
                    .padding(top = 8.dp)
                    .clickable(onClick = onMenuClicked),
                painter = painterResource(id = R.drawable.ic_menu),
                contentDescription = stringResource(id = R.string.cd_menu)
            )
            Spacer(Modifier.width(8.dp))
            Image(
                painter = painterResource(id = R.drawable.ic_crane_logo),
                contentDescription = null
            )
        }
        children(
            Modifier
                .weight(1f)
                .align(Alignment.CenterVertically)
        )
    }
}
@TheRealDarkEagle
Copy link

The modifier is used in the outer Row
Row(modifier) { ...

Benefit is that u can modify the Row itself without translating this modification to the element itself.
As an example: u could set a fillMaxSize() to the outer Row without modifying the Elements inside it.

@pitoszud
Copy link
Author

In which part of the outer row it is being used?

@TheRealDarkEagle
Copy link

@composable
fun CraneTabBar(
modifier: Modifier = Modifier,
onMenuClicked: () -> Unit,
children: @composable (Modifier) -> Unit
) {
Row(modifier) { <- here
// Separate Row as the children shouldn't have the padding

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants
@pitoszud @TheRealDarkEagle and others