kodecocodes / jet-materials

The projects and the materials that accompany the Jetpack Compose book
Other
167 stars 93 forks source link

Divider issue in Chapter 09 #31

Open chinalwb opened 2 years ago

chinalwb commented 2 years ago

The design / screenshot in chapter 9 was:

image

But with the code in the final directory, it is:


/**
 * Represents app drawer header with the icon and the app name
 */
@Composable
private fun AppDrawerHeader() {
  Column(
    modifier = Modifier.fillMaxWidth(),
    horizontalAlignment = Alignment.CenterHorizontally
  ) {
    Image(
      imageVector = Icons.Filled.AccountCircle,
      colorFilter = ColorFilter.tint(Color.LightGray),
      modifier = Modifier
        .padding(16.dp)
        .size(50.dp),
      contentScale = ContentScale.Fit,
      alignment = Alignment.Center,
      contentDescription = stringResource(id = R.string.account)
    )

    Text(
      text = stringResource(R.string.default_username),
      color = MaterialTheme.colors.primaryVariant
    )

    ProfileInfo()
  }

  Divider( // Here
    color = MaterialTheme.colors.onSurface.copy(alpha = .2f),
    modifier = Modifier.padding(
      start = 16.dp,
      end = 16.dp,
      top = 16.dp
    )
  )
}

Look at the Divider.

The code snippet in the book is:

@Composable
private fun AppDrawerHeader() {
  Column(
     modifier = Modifier.fillMaxWidth(),
     horizontalAlignment = Alignment.CenterHorizontally
  ) {
    Image(
       ...
    )

    Text(
       ...
    )
    ProfileInfo() // Add this
  }

  Divider( // Here
      ...
  )
}

Look at the Divider again, with the sample code the divider would be above the Column rather than below it. Screen Shot 2022-04-20 at 9 30 40 AM

This is something you guys could do better, it confused me when reading this, sample codes before chapter 8 never runs into such issues.