Skip to content

Commit

Permalink
🧪 Type inference cannot resolve nullable @composable lambda
Browse files Browse the repository at this point in the history
  • Loading branch information
SimonMarquis committed Jan 25, 2024
1 parent ef77975 commit f492f84
Show file tree
Hide file tree
Showing 9 changed files with 39 additions and 35 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -101,8 +101,8 @@ private fun TextFieldSample() {
label = labelText,
placeholder = placeHolderText,
helper = helperText,
leadingContent = addonText?.let { { Text(it) } },
trailingContent = icon?.let { { Icon(it, contentDescription = null) } },
leadingContent = addonText?.let { { Text(it) } } ?: {},
trailingContent = icon?.let { { Icon(it, contentDescription = null) } } ?: {},
state = state,
stateMessage = stateMessageText,
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,11 @@ public fun ThemePicker(
text = {
Text(text = brand.name)
},
trailingIcon = if (brand == theme.brandMode) selectedIcon else null,
trailingIcon = if (brand == theme.brandMode) {
selectedIcon
} else {
{}
},
onClick = {
onThemeChange(theme.copy(brandMode = brand))
expanded = false
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,16 +81,16 @@ internal class TextFieldScreenshot {
"_enabled".takeIf { enabled }.orEmpty() +
helper?.let { "_helper.${helper.count()}" }.orEmpty(),
) {
val leadingContent: (@Composable AddonScope.() -> Unit)? = leadingIcon?.let {
val leadingContent: (@Composable AddonScope.() -> Unit) = leadingIcon?.let {
@Composable {
Icon(it, contentDescription = null)
}
}
val trailingContent: (@Composable AddonScope.() -> Unit)? = trailingIcon?.let {
} ?: {}
val trailingContent: (@Composable AddonScope.() -> Unit) = trailingIcon?.let {
@Composable {
Icon(it, contentDescription = null)
}
}
} ?: {}
Column(
verticalArrangement = Arrangement.spacedBy(8.dp),
) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -145,8 +145,8 @@ public fun DropdownMenuItem(
text: @Composable () -> Unit,
onClick: () -> Unit,
modifier: Modifier = Modifier,
leadingIcon: @Composable (() -> Unit)? = null,
trailingIcon: @Composable (() -> Unit)? = null,
leadingIcon: @Composable (() -> Unit) = {},
trailingIcon: @Composable (() -> Unit) = {},
enabled: Boolean = true,
colors: MenuItemColors = MenuDefaults.itemColors(),
contentPadding: PaddingValues = MenuDefaults.DropdownMenuItemContentPadding,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ public fun MultilineTextField(
placeholder: String? = null,
helper: String? = null,
counter: TextFieldCharacterCounter? = null,
leadingContent: @Composable (AddonScope.() -> Unit)? = null,
leadingContent: @Composable (AddonScope.() -> Unit) = {},
state: TextFieldState? = null,
stateMessage: String? = null,
visualTransformation: VisualTransformation = VisualTransformation.None,
Expand All @@ -133,7 +133,7 @@ public fun MultilineTextField(
minLines: Int = 1,
interactionSource: MutableInteractionSource = remember { MutableInteractionSource() },
) {
val trailingIconComposable: (@Composable AddonScope.() -> Unit)? = getTrailingContent(
val trailingIconComposable: (@Composable AddonScope.() -> Unit) = getTrailingContent(
state = state,
trailingIcon = if (value.text.isNotBlank()) {
{
Expand All @@ -150,7 +150,7 @@ public fun MultilineTextField(
)
}
} else {
null
{}
},
)

Expand Down Expand Up @@ -244,7 +244,7 @@ public fun MultilineTextField(
placeholder: String? = null,
helper: String? = null,
counter: TextFieldCharacterCounter? = null,
leadingContent: @Composable (AddonScope.() -> Unit)? = null,
leadingContent: @Composable (AddonScope.() -> Unit) = {},
state: TextFieldState? = null,
stateMessage: String? = null,
visualTransformation: VisualTransformation = VisualTransformation.None,
Expand All @@ -254,7 +254,7 @@ public fun MultilineTextField(
minLines: Int = 1,
interactionSource: MutableInteractionSource = remember { MutableInteractionSource() },
) {
val trailingIconComposable: (@Composable AddonScope.() -> Unit)? = getTrailingContent(
val trailingIconComposable: (@Composable AddonScope.() -> Unit) = getTrailingContent(
state = state,
trailingIcon = if (value.isNotBlank()) {
{
Expand All @@ -271,7 +271,7 @@ public fun MultilineTextField(
)
}
} else {
null
{}
},
)
SparkTextField(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ public fun SelectTextField(
label: String? = null,
placeholder: String? = null,
helper: String? = null,
leadingContent: @Composable (AddonScope.() -> Unit)? = null,
leadingContent: @Composable (AddonScope.() -> Unit) = {},
state: TextFieldState? = null,
stateMessage: String? = null,
visualTransformation: VisualTransformation = VisualTransformation.None,
Expand Down Expand Up @@ -232,7 +232,7 @@ public fun SelectTextField(
label: String? = null,
placeholder: String? = null,
helper: String? = null,
leadingContent: @Composable (AddonScope.() -> Unit)? = null,
leadingContent: @Composable (AddonScope.() -> Unit) = {},
state: TextFieldState? = null,
stateMessage: String? = null,
visualTransformation: VisualTransformation = VisualTransformation.None,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,8 +94,8 @@ internal fun SparkTextField(
placeholder: String?,
helper: String?,
counter: TextFieldCharacterCounter?,
leadingContent: @Composable (AddonScope.() -> Unit)?,
trailingContent: @Composable (AddonScope.() -> Unit)?,
leadingContent: @Composable (AddonScope.() -> Unit),
trailingContent: @Composable (AddonScope.() -> Unit),
state: TextFieldState?,
stateMessage: String?,
visualTransformation: VisualTransformation,
Expand Down Expand Up @@ -193,8 +193,8 @@ internal fun SparkTextField(
placeholder: String?,
helper: String?,
counter: TextFieldCharacterCounter?,
leadingIcon: @Composable (AddonScope.() -> Unit)?, // Should we rename it to leadingContent?
trailingIcon: @Composable (AddonScope.() -> Unit)?, // Should we rename it to trailingContent?
leadingIcon: @Composable (AddonScope.() -> Unit), // Should we rename it to leadingContent?
trailingIcon: @Composable (AddonScope.() -> Unit), // Should we rename it to trailingContent?
state: TextFieldState?,
stateMessage: String?,
visualTransformation: VisualTransformation,
Expand Down Expand Up @@ -383,8 +383,8 @@ internal object TextFieldDefault {
@Composable
internal fun getTrailingContent(
state: TextFieldState?,
trailingIcon: (@Composable AddonScope.() -> Unit)?,
): (@Composable AddonScope.() -> Unit)? = when {
trailingIcon: (@Composable AddonScope.() -> Unit),
): (@Composable AddonScope.() -> Unit) = when {
state != null -> {
{
val icon = when (state) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,15 +78,15 @@ internal fun SparkDecorationBox(
value: String,
innerTextField: @Composable () -> Unit,
visualTransformation: VisualTransformation,
label: @Composable (() -> Unit)?,
label: @Composable (() -> Unit),
interactionSource: InteractionSource,
colors: DefaultSparkTextFieldColors,
readOnly: Boolean,
placeholder: @Composable (() -> Unit)? = null,
supportingText: @Composable (() -> Unit)? = null,
counter: @Composable (() -> Unit)? = null,
leadingIcon: @Composable (AddonScope.() -> Unit)? = null,
trailingIcon: @Composable (AddonScope.() -> Unit)? = null,
leadingIcon: @Composable (AddonScope.() -> Unit) = {},
trailingIcon: @Composable (AddonScope.() -> Unit) = {},
singleLine: Boolean = false,
enabled: Boolean = true,
state: TextFieldState? = null,
Expand All @@ -99,8 +99,8 @@ internal fun SparkDecorationBox(
val contentPadding = OutlinedTextFieldDefaults.contentPadding(
top = VerticalContentPadding,
bottom = VerticalContentPadding,
start = if (leadingIcon != null) 8.dp else 16.dp,
end = if (trailingIcon != null) 8.dp else 16.dp,
start = 8.dp,
end = 8.dp,
)

val isFocused = interactionSource.collectIsFocusedAsState().value
Expand Down Expand Up @@ -130,10 +130,10 @@ internal fun SparkDecorationBox(
if (shouldOverrideTextStyleColor) this.takeOrElse { labelColor(inputState) } else this
},
contentColor = labelColor,
showLabel = label != null,
showLabel = true,
) { labelProgress, labelTextStyleColor, labelContentColor, placeholderAlphaProgress ->

val decoratedLabel: @Composable (() -> Unit)? = label?.let {
val decoratedLabel: @Composable (() -> Unit)? = label.let {
@Composable {
val labelTextStyle = lerp(
SparkTheme.typography.body1,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -106,16 +106,16 @@ public fun TextField(
label: String? = null,
placeholder: String? = null,
helper: String? = null,
leadingContent: @Composable (AddonScope.() -> Unit)? = null,
trailingContent: @Composable (AddonScope.() -> Unit)? = null,
leadingContent: @Composable (AddonScope.() -> Unit) = {},
trailingContent: @Composable (AddonScope.() -> Unit) = {},
state: TextFieldState? = null,
stateMessage: String? = null,
visualTransformation: VisualTransformation = VisualTransformation.None,
keyboardOptions: KeyboardOptions = KeyboardOptions.Default.copy(capitalization = KeyboardCapitalization.Sentences),
keyboardActions: KeyboardActions = KeyboardActions.Default,
interactionSource: MutableInteractionSource = remember { MutableInteractionSource() },
) {
val trailingContentBasedOnState: (@Composable AddonScope.() -> Unit)? = TextFieldDefault.getTrailingContent(
val trailingContentBasedOnState: (@Composable AddonScope.() -> Unit) = TextFieldDefault.getTrailingContent(
state = state,
trailingIcon = trailingContent,
)
Expand Down Expand Up @@ -201,8 +201,8 @@ public fun TextField(
label: String? = null,
placeholder: String? = null,
helper: String? = null,
leadingContent: @Composable (AddonScope.() -> Unit)? = null,
trailingContent: @Composable (AddonScope.() -> Unit)? = null,
leadingContent: @Composable (AddonScope.() -> Unit) = {},
trailingContent: @Composable (AddonScope.() -> Unit) = {},
state: TextFieldState? = null,
stateMessage: String? = null,
visualTransformation: VisualTransformation = VisualTransformation.None,
Expand Down

0 comments on commit f492f84

Please sign in to comment.