Skip to content
Merged
Prev Previous commit
Next Next commit
Fixes for alpha constants, content color checks, etc.
  • Loading branch information
IanGClifton committed Aug 22, 2022
commit 2894c4e5d7a7ea2193de133018b0464154c90582
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ import androidx.compose.ui.tooling.preview.Preview
import androidx.compose.ui.unit.dp
import com.example.compose.jetsurvey.R
import com.example.compose.jetsurvey.theme.JetsurveyTheme
import com.example.compose.jetsurvey.theme.stronglyDeemphasizedAlpha

@Composable
fun SignInSignUpScreen(
Expand Down Expand Up @@ -92,7 +93,7 @@ fun SignInSignUpScreen(
}
}

@OptIn(ExperimentalMaterial3Api::class) // SmallTopAppBar is experimental in m3
@OptIn(ExperimentalMaterial3Api::class) // CenterAlignedTopAppBar is experimental in m3
@Composable
fun SignInSignUpTopAppBar(topAppBarText: String, onBackPressed: () -> Unit) {
CenterAlignedTopAppBar(
Expand Down Expand Up @@ -136,7 +137,7 @@ fun Email(
Text(
text = stringResource(id = R.string.email),
style = MaterialTheme.typography.bodyMedium,
color = MaterialTheme.colorScheme.onSurface.copy(alpha = 0.6f)
color = MaterialTheme.colorScheme.onSurface.copy(alpha = stronglyDeemphasizedAlpha)
)
},
modifier = Modifier
Expand Down Expand Up @@ -192,7 +193,7 @@ fun Password(
Text(
text = label,
style = MaterialTheme.typography.bodyMedium,
color = MaterialTheme.colorScheme.onSurface.copy(alpha = 0.6f)
color = MaterialTheme.colorScheme.onSurface.copy(alpha = stronglyDeemphasizedAlpha)
)
},
trailingIcon = {
Expand Down Expand Up @@ -259,7 +260,7 @@ fun OrSignInAsGuest(
Text(
text = stringResource(id = R.string.or),
style = MaterialTheme.typography.titleSmall,
color = MaterialTheme.colorScheme.onSurface.copy(alpha = 0.6f),
color = MaterialTheme.colorScheme.onSurface.copy(alpha = stronglyDeemphasizedAlpha),
modifier = Modifier.paddingFromBaseline(top = 25.dp)
)
OutlinedButton(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ import androidx.compose.ui.tooling.preview.Preview
import androidx.compose.ui.unit.dp
import com.example.compose.jetsurvey.R
import com.example.compose.jetsurvey.theme.JetsurveyTheme
import com.example.compose.jetsurvey.theme.stronglyDeemphasizedAlpha
import com.example.compose.jetsurvey.util.supportWideScreen

sealed class SignUpEvent {
Expand Down Expand Up @@ -106,7 +107,7 @@ fun SignUpContent(
Text(
text = stringResource(id = R.string.terms_and_conditions),
style = MaterialTheme.typography.bodySmall,
color = MaterialTheme.colorScheme.onSurface.copy(alpha = 0.6f)
color = MaterialTheme.colorScheme.onSurface.copy(alpha = stronglyDeemphasizedAlpha)
)

Spacer(modifier = Modifier.height(16.dp))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ import androidx.compose.foundation.layout.wrapContentHeight
import androidx.compose.foundation.rememberScrollState
import androidx.compose.foundation.verticalScroll
import androidx.compose.material3.Button
import androidx.compose.material3.LocalContentColor
import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.Surface
import androidx.compose.material3.Text
Expand All @@ -40,6 +41,7 @@ import androidx.compose.runtime.saveable.rememberSaveable
import androidx.compose.runtime.setValue
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.luminance
import androidx.compose.ui.res.painterResource
import androidx.compose.ui.res.stringResource
import androidx.compose.ui.text.input.ImeAction
Expand All @@ -48,7 +50,7 @@ import androidx.compose.ui.tooling.preview.Preview
import androidx.compose.ui.unit.dp
import com.example.compose.jetsurvey.R
import com.example.compose.jetsurvey.theme.JetsurveyTheme
import com.example.compose.jetsurvey.theme.surfaceIsLight
import com.example.compose.jetsurvey.theme.stronglyDeemphasizedAlpha
import com.example.compose.jetsurvey.util.supportWideScreen

sealed class WelcomeEvent {
Expand Down Expand Up @@ -120,9 +122,8 @@ private fun Branding(modifier: Modifier = Modifier) {
@Composable
private fun Logo(
modifier: Modifier = Modifier,
lightTheme: Boolean = surfaceIsLight()
) {
val assetId = if (lightTheme) {
val assetId = if (LocalContentColor.current.luminance() > 0.5f) {
R.drawable.ic_logo_light
} else {
R.drawable.ic_logo_dark
Expand All @@ -147,7 +148,7 @@ private fun SignInCreateAccount(
Text(
text = stringResource(id = R.string.sign_in_create_account),
style = MaterialTheme.typography.titleSmall,
color = MaterialTheme.colorScheme.onSurface.copy(alpha = 0.6f),
color = MaterialTheme.colorScheme.onSurface.copy(alpha = stronglyDeemphasizedAlpha),
textAlign = TextAlign.Center,
modifier = Modifier.padding(top = 64.dp, bottom = 12.dp)
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ import androidx.compose.material3.ButtonDefaults
import androidx.compose.material3.Checkbox
import androidx.compose.material3.CheckboxDefaults
import androidx.compose.material3.Icon
import androidx.compose.material3.LocalContentColor
import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.OutlinedButton
import androidx.compose.material3.RadioButton
Expand All @@ -61,6 +62,7 @@ import androidx.compose.runtime.setValue
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.draw.clip
import androidx.compose.ui.graphics.luminance
import androidx.compose.ui.platform.LocalContext
import androidx.compose.ui.res.painterResource
import androidx.compose.ui.res.stringResource
Expand All @@ -71,7 +73,8 @@ import coil.compose.AsyncImage
import coil.request.ImageRequest
import com.example.compose.jetsurvey.R
import com.example.compose.jetsurvey.theme.JetsurveyTheme
import com.example.compose.jetsurvey.theme.surfaceIsLight
import com.example.compose.jetsurvey.theme.slightlyDeemphasizedAlpha
import com.example.compose.jetsurvey.theme.stronglyDeemphasizedAlpha
import com.google.accompanist.permissions.ExperimentalPermissionsApi
import com.google.accompanist.permissions.MultiplePermissionsState
import com.google.accompanist.permissions.rememberMultiplePermissionsState
Expand Down Expand Up @@ -165,7 +168,8 @@ private fun QuestionContent(
if (question.description != null) {
Text(
text = stringResource(id = question.description),
color = MaterialTheme.colorScheme.onSurface.copy(alpha = 0.6f),
color = MaterialTheme.colorScheme.onSurface
.copy(alpha = stronglyDeemphasizedAlpha),
style = MaterialTheme.typography.bodySmall,
modifier = Modifier
.fillParentMaxWidth()
Expand Down Expand Up @@ -244,7 +248,7 @@ private fun QuestionTitle(@StringRes title: Int) {
Text(
text = stringResource(id = title),
style = MaterialTheme.typography.titleMedium,
color = MaterialTheme.colorScheme.onSurface.copy(alpha = 0.87f),
color = MaterialTheme.colorScheme.onSurface.copy(alpha = slightlyDeemphasizedAlpha),
modifier = Modifier
.fillMaxWidth()
.padding(vertical = 24.dp, horizontal = 16.dp)
Expand Down Expand Up @@ -671,7 +675,8 @@ private fun DateQuestion(
onClick = { onAction(questionId, SurveyActionType.PICK_DATE) },
colors = ButtonDefaults.buttonColors(
containerColor = MaterialTheme.colorScheme.surface,
contentColor = MaterialTheme.colorScheme.onSurface.copy(alpha = 0.87f),
contentColor = MaterialTheme.colorScheme.onSurface
.copy(alpha = slightlyDeemphasizedAlpha),
),
shape = MaterialTheme.shapes.small,
modifier = modifier
Expand Down Expand Up @@ -699,9 +704,8 @@ private fun DateQuestion(
@Composable
private fun PhotoDefaultImage(
modifier: Modifier = Modifier,
lightTheme: Boolean = surfaceIsLight()
) {
val assetId = if (lightTheme) {
val assetId = if (LocalContentColor.current.luminance() > 0.5f) {
R.drawable.ic_selfie_light
} else {
R.drawable.ic_selfie_dark
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ import androidx.compose.ui.res.stringResource
import androidx.compose.ui.unit.IntOffset
import androidx.compose.ui.unit.dp
import com.example.compose.jetsurvey.R
import com.example.compose.jetsurvey.theme.stronglyDeemphasizedAlpha
import com.example.compose.jetsurvey.util.supportWideScreen

private const val CONTENT_ANIMATION_DURATION = 500
Expand Down Expand Up @@ -203,7 +204,7 @@ private fun TopAppBarTitle(
Text(
text = (questionIndex + 1).toString(),
style = MaterialTheme.typography.labelMedium,
color = MaterialTheme.colorScheme.onSurface.copy(alpha = 0.6f)
color = MaterialTheme.colorScheme.onSurface.copy(alpha = stronglyDeemphasizedAlpha)
)
Text(
text = stringResource(R.string.question_count, totalQuestionsCount),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,11 @@ import androidx.compose.material3.darkColorScheme
import androidx.compose.material3.lightColorScheme
import androidx.compose.runtime.Composable
import androidx.compose.runtime.DisposableEffect
import androidx.compose.ui.graphics.luminance
import com.google.accompanist.systemuicontroller.rememberSystemUiController

const val stronglyDeemphasizedAlpha = 0.6f
const val slightlyDeemphasizedAlpha = 0.87f

private val LightColors = lightColorScheme(
primary = md_theme_light_primary,
onPrimary = md_theme_light_onPrimary,
Expand Down Expand Up @@ -115,6 +117,3 @@ fun JetsurveyTheme(
content = content,
)
}

@Composable
fun surfaceIsLight(): Boolean = MaterialTheme.colorScheme.surface.luminance() > 0.5f