Replace Modifier.composed with Composable Modifier (#1959)
Co-authored-by: AntsyLich <59261191+AntsyLich@users.noreply.github.com> (cherry picked from commit a31b3b7bbf2c5164baf76ac4b36f1d27c5d43135)
This commit is contained in:
parent
b6409b05e7
commit
802b6508fa
@ -25,7 +25,6 @@ import androidx.compose.runtime.remember
|
||||
import androidx.compose.runtime.setValue
|
||||
import androidx.compose.ui.Alignment
|
||||
import androidx.compose.ui.Modifier
|
||||
import androidx.compose.ui.composed
|
||||
import androidx.compose.ui.graphics.Color
|
||||
import androidx.compose.ui.text.style.TextOverflow
|
||||
import androidx.compose.ui.unit.dp
|
||||
@ -86,7 +85,8 @@ internal fun BasePreferenceWidget(
|
||||
}
|
||||
}
|
||||
|
||||
internal fun Modifier.highlightBackground(highlighted: Boolean): Modifier = composed {
|
||||
@Composable
|
||||
internal fun Modifier.highlightBackground(highlighted: Boolean): Modifier {
|
||||
var highlightFlag by remember { mutableStateOf(false) }
|
||||
LaunchedEffect(Unit) {
|
||||
if (highlighted) {
|
||||
@ -116,7 +116,7 @@ internal fun Modifier.highlightBackground(highlighted: Boolean): Modifier = comp
|
||||
},
|
||||
label = "highlight",
|
||||
)
|
||||
Modifier.background(color = highlight)
|
||||
return this.background(color = highlight)
|
||||
}
|
||||
|
||||
internal val TrailingWidgetBuffer = 16.dp
|
||||
|
@ -5,6 +5,7 @@ import androidx.compose.foundation.isSystemInDarkTheme
|
||||
import androidx.compose.foundation.layout.WindowInsets
|
||||
import androidx.compose.foundation.layout.isImeVisible
|
||||
import androidx.compose.material3.MaterialTheme
|
||||
import androidx.compose.runtime.Composable
|
||||
import androidx.compose.runtime.LaunchedEffect
|
||||
import androidx.compose.runtime.getValue
|
||||
import androidx.compose.runtime.mutableStateOf
|
||||
@ -12,7 +13,6 @@ import androidx.compose.runtime.remember
|
||||
import androidx.compose.runtime.saveable.rememberSaveable
|
||||
import androidx.compose.runtime.setValue
|
||||
import androidx.compose.ui.Modifier
|
||||
import androidx.compose.ui.composed
|
||||
import androidx.compose.ui.draw.alpha
|
||||
import androidx.compose.ui.draw.drawBehind
|
||||
import androidx.compose.ui.focus.FocusRequester
|
||||
@ -24,16 +24,12 @@ import androidx.compose.ui.input.key.onPreviewKeyEvent
|
||||
import androidx.compose.ui.platform.LocalFocusManager
|
||||
import tachiyomi.presentation.core.components.material.SECONDARY_ALPHA
|
||||
|
||||
fun Modifier.selectedBackground(isSelected: Boolean): Modifier = if (isSelected) {
|
||||
composed {
|
||||
val alpha = if (isSystemInDarkTheme()) 0.16f else 0.22f
|
||||
val color = MaterialTheme.colorScheme.secondary.copy(alpha = alpha)
|
||||
Modifier.drawBehind {
|
||||
drawRect(color)
|
||||
}
|
||||
}
|
||||
} else {
|
||||
this
|
||||
@Composable
|
||||
fun Modifier.selectedBackground(isSelected: Boolean): Modifier {
|
||||
if (!isSelected) return this
|
||||
val alpha = if (isSystemInDarkTheme()) 0.16f else 0.22f
|
||||
val color = MaterialTheme.colorScheme.secondary.copy(alpha = alpha)
|
||||
return this.drawBehind { drawRect(color) }
|
||||
}
|
||||
|
||||
fun Modifier.secondaryItemAlpha(): Modifier = this.alpha(SECONDARY_ALPHA)
|
||||
@ -60,6 +56,7 @@ fun Modifier.runOnEnterKeyPressed(action: () -> Unit): Modifier = this.onPreview
|
||||
action()
|
||||
true
|
||||
}
|
||||
|
||||
else -> false
|
||||
}
|
||||
}
|
||||
@ -68,30 +65,28 @@ fun Modifier.runOnEnterKeyPressed(action: () -> Unit): Modifier = this.onPreview
|
||||
* For TextField on AppBar, this modifier will request focus
|
||||
* to the element the first time it's composed.
|
||||
*/
|
||||
fun Modifier.showSoftKeyboard(show: Boolean): Modifier = if (show) {
|
||||
composed {
|
||||
val focusRequester = remember { FocusRequester() }
|
||||
var openKeyboard by rememberSaveable { mutableStateOf(show) }
|
||||
LaunchedEffect(focusRequester) {
|
||||
if (openKeyboard) {
|
||||
focusRequester.requestFocus()
|
||||
openKeyboard = false
|
||||
}
|
||||
@Composable
|
||||
fun Modifier.showSoftKeyboard(show: Boolean): Modifier {
|
||||
if (!show) return this
|
||||
val focusRequester = remember { FocusRequester() }
|
||||
var openKeyboard by rememberSaveable { mutableStateOf(show) }
|
||||
LaunchedEffect(focusRequester) {
|
||||
if (openKeyboard) {
|
||||
focusRequester.requestFocus()
|
||||
openKeyboard = false
|
||||
}
|
||||
|
||||
Modifier.focusRequester(focusRequester)
|
||||
}
|
||||
} else {
|
||||
this
|
||||
return this.focusRequester(focusRequester)
|
||||
}
|
||||
|
||||
/**
|
||||
* For TextField, this modifier will clear focus when soft
|
||||
* keyboard is hidden.
|
||||
*/
|
||||
@Composable
|
||||
fun Modifier.clearFocusOnSoftKeyboardHide(
|
||||
onFocusCleared: (() -> Unit)? = null,
|
||||
): Modifier = composed {
|
||||
): Modifier {
|
||||
var isFocused by remember { mutableStateOf(false) }
|
||||
var keyboardShowedSinceFocused by remember { mutableStateOf(false) }
|
||||
if (isFocused) {
|
||||
@ -107,7 +102,7 @@ fun Modifier.clearFocusOnSoftKeyboardHide(
|
||||
}
|
||||
}
|
||||
|
||||
Modifier.onFocusChanged {
|
||||
return this.onFocusChanged {
|
||||
if (isFocused != it.isFocused) {
|
||||
if (isFocused) {
|
||||
keyboardShowedSinceFocused = false
|
||||
|
@ -47,7 +47,6 @@ import androidx.compose.runtime.Composable
|
||||
import androidx.compose.runtime.LaunchedEffect
|
||||
import androidx.compose.runtime.remember
|
||||
import androidx.compose.ui.Modifier
|
||||
import androidx.compose.ui.composed
|
||||
import androidx.compose.ui.draw.drawWithContent
|
||||
import androidx.compose.ui.geometry.Offset
|
||||
import androidx.compose.ui.geometry.Size
|
||||
@ -75,6 +74,7 @@ import tachiyomi.presentation.core.components.Scroller.STICKY_HEADER_KEY_PREFIX
|
||||
*
|
||||
* Set key with [STICKY_HEADER_KEY_PREFIX] prefix to any sticky header item in the list.
|
||||
*/
|
||||
@Composable
|
||||
fun Modifier.drawHorizontalScrollbar(
|
||||
state: LazyListState,
|
||||
reverseScrolling: Boolean = false,
|
||||
@ -87,6 +87,7 @@ fun Modifier.drawHorizontalScrollbar(
|
||||
*
|
||||
* Set key with [STICKY_HEADER_KEY_PREFIX] prefix to any sticky header item in the list.
|
||||
*/
|
||||
@Composable
|
||||
fun Modifier.drawVerticalScrollbar(
|
||||
state: LazyListState,
|
||||
reverseScrolling: Boolean = false,
|
||||
@ -94,6 +95,7 @@ fun Modifier.drawVerticalScrollbar(
|
||||
positionOffsetPx: Float = 0f,
|
||||
): Modifier = drawScrollbar(state, Orientation.Vertical, reverseScrolling, positionOffsetPx)
|
||||
|
||||
@Composable
|
||||
private fun Modifier.drawScrollbar(
|
||||
state: LazyListState,
|
||||
orientation: Orientation,
|
||||
@ -178,6 +180,7 @@ private fun ContentDrawScope.onDrawScrollbar(
|
||||
}
|
||||
}
|
||||
|
||||
@Composable
|
||||
private fun Modifier.drawScrollbar(
|
||||
orientation: Orientation,
|
||||
reverseScrolling: Boolean,
|
||||
@ -188,7 +191,7 @@ private fun Modifier.drawScrollbar(
|
||||
color: Color,
|
||||
alpha: () -> Float,
|
||||
) -> Unit,
|
||||
): Modifier = composed {
|
||||
): Modifier {
|
||||
val scrolled = remember {
|
||||
MutableSharedFlow<Unit>(
|
||||
extraBufferCapacity = 1,
|
||||
@ -230,7 +233,8 @@ private fun Modifier.drawScrollbar(
|
||||
val context = LocalContext.current
|
||||
val thickness = remember { ViewConfiguration.get(context).scaledScrollBarSize.toFloat() }
|
||||
val color = MaterialTheme.colorScheme.onSurface.copy(alpha = 0.364f)
|
||||
Modifier
|
||||
|
||||
return this
|
||||
.nestedScroll(nestedScrollConnection)
|
||||
.drawWithContent {
|
||||
onDraw(reverseDirection, atEnd, thickness, color, alpha::value)
|
||||
|
Loading…
x
Reference in New Issue
Block a user