Skip to content

Commit a31b3b7

Browse files
Replace Modifier.composed with Composable Modifier (#1959)
Co-authored-by: AntsyLich <[email protected]>
1 parent fea8524 commit a31b3b7

File tree

3 files changed

+31
-32
lines changed

3 files changed

+31
-32
lines changed

app/src/main/java/eu/kanade/presentation/more/settings/widget/BasePreferenceWidget.kt

+3-3
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@ import androidx.compose.runtime.remember
2525
import androidx.compose.runtime.setValue
2626
import androidx.compose.ui.Alignment
2727
import androidx.compose.ui.Modifier
28-
import androidx.compose.ui.composed
2928
import androidx.compose.ui.graphics.Color
3029
import androidx.compose.ui.text.style.TextOverflow
3130
import androidx.compose.ui.unit.dp
@@ -86,7 +85,8 @@ internal fun BasePreferenceWidget(
8685
}
8786
}
8887

89-
internal fun Modifier.highlightBackground(highlighted: Boolean): Modifier = composed {
88+
@Composable
89+
internal fun Modifier.highlightBackground(highlighted: Boolean): Modifier {
9090
var highlightFlag by remember { mutableStateOf(false) }
9191
LaunchedEffect(Unit) {
9292
if (highlighted) {
@@ -116,7 +116,7 @@ internal fun Modifier.highlightBackground(highlighted: Boolean): Modifier = comp
116116
},
117117
label = "highlight",
118118
)
119-
Modifier.background(color = highlight)
119+
return this.background(color = highlight)
120120
}
121121

122122
internal val TrailingWidgetBuffer = 16.dp

presentation-core/src/main/java/tachiyomi/presentation/core/util/Modifier.kt

+21-26
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,14 @@ import androidx.compose.foundation.isSystemInDarkTheme
55
import androidx.compose.foundation.layout.WindowInsets
66
import androidx.compose.foundation.layout.isImeVisible
77
import androidx.compose.material3.MaterialTheme
8+
import androidx.compose.runtime.Composable
89
import androidx.compose.runtime.LaunchedEffect
910
import androidx.compose.runtime.getValue
1011
import androidx.compose.runtime.mutableStateOf
1112
import androidx.compose.runtime.remember
1213
import androidx.compose.runtime.saveable.rememberSaveable
1314
import androidx.compose.runtime.setValue
1415
import androidx.compose.ui.Modifier
15-
import androidx.compose.ui.composed
1616
import androidx.compose.ui.draw.alpha
1717
import androidx.compose.ui.draw.drawBehind
1818
import androidx.compose.ui.focus.FocusRequester
@@ -24,16 +24,12 @@ import androidx.compose.ui.input.key.onPreviewKeyEvent
2424
import androidx.compose.ui.platform.LocalFocusManager
2525
import tachiyomi.presentation.core.components.material.SECONDARY_ALPHA
2626

27-
fun Modifier.selectedBackground(isSelected: Boolean): Modifier = if (isSelected) {
28-
composed {
29-
val alpha = if (isSystemInDarkTheme()) 0.16f else 0.22f
30-
val color = MaterialTheme.colorScheme.secondary.copy(alpha = alpha)
31-
Modifier.drawBehind {
32-
drawRect(color)
33-
}
34-
}
35-
} else {
36-
this
27+
@Composable
28+
fun Modifier.selectedBackground(isSelected: Boolean): Modifier {
29+
if (!isSelected) return this
30+
val alpha = if (isSystemInDarkTheme()) 0.16f else 0.22f
31+
val color = MaterialTheme.colorScheme.secondary.copy(alpha = alpha)
32+
return this.drawBehind { drawRect(color) }
3733
}
3834

3935
fun Modifier.secondaryItemAlpha(): Modifier = this.alpha(SECONDARY_ALPHA)
@@ -60,6 +56,7 @@ fun Modifier.runOnEnterKeyPressed(action: () -> Unit): Modifier = this.onPreview
6056
action()
6157
true
6258
}
59+
6360
else -> false
6461
}
6562
}
@@ -68,30 +65,28 @@ fun Modifier.runOnEnterKeyPressed(action: () -> Unit): Modifier = this.onPreview
6865
* For TextField on AppBar, this modifier will request focus
6966
* to the element the first time it's composed.
7067
*/
71-
fun Modifier.showSoftKeyboard(show: Boolean): Modifier = if (show) {
72-
composed {
73-
val focusRequester = remember { FocusRequester() }
74-
var openKeyboard by rememberSaveable { mutableStateOf(show) }
75-
LaunchedEffect(focusRequester) {
76-
if (openKeyboard) {
77-
focusRequester.requestFocus()
78-
openKeyboard = false
79-
}
68+
@Composable
69+
fun Modifier.showSoftKeyboard(show: Boolean): Modifier {
70+
if (!show) return this
71+
val focusRequester = remember { FocusRequester() }
72+
var openKeyboard by rememberSaveable { mutableStateOf(show) }
73+
LaunchedEffect(focusRequester) {
74+
if (openKeyboard) {
75+
focusRequester.requestFocus()
76+
openKeyboard = false
8077
}
81-
82-
Modifier.focusRequester(focusRequester)
8378
}
84-
} else {
85-
this
79+
return this.focusRequester(focusRequester)
8680
}
8781

8882
/**
8983
* For TextField, this modifier will clear focus when soft
9084
* keyboard is hidden.
9185
*/
86+
@Composable
9287
fun Modifier.clearFocusOnSoftKeyboardHide(
9388
onFocusCleared: (() -> Unit)? = null,
94-
): Modifier = composed {
89+
): Modifier {
9590
var isFocused by remember { mutableStateOf(false) }
9691
var keyboardShowedSinceFocused by remember { mutableStateOf(false) }
9792
if (isFocused) {
@@ -107,7 +102,7 @@ fun Modifier.clearFocusOnSoftKeyboardHide(
107102
}
108103
}
109104

110-
Modifier.onFocusChanged {
105+
return this.onFocusChanged {
111106
if (isFocused != it.isFocused) {
112107
if (isFocused) {
113108
keyboardShowedSinceFocused = false

presentation-core/src/main/java/tachiyomi/presentation/core/util/Scrollbar.kt

+7-3
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,6 @@ import androidx.compose.runtime.Composable
4747
import androidx.compose.runtime.LaunchedEffect
4848
import androidx.compose.runtime.remember
4949
import androidx.compose.ui.Modifier
50-
import androidx.compose.ui.composed
5150
import androidx.compose.ui.draw.drawWithContent
5251
import androidx.compose.ui.geometry.Offset
5352
import androidx.compose.ui.geometry.Size
@@ -75,6 +74,7 @@ import tachiyomi.presentation.core.components.Scroller.STICKY_HEADER_KEY_PREFIX
7574
*
7675
* Set key with [STICKY_HEADER_KEY_PREFIX] prefix to any sticky header item in the list.
7776
*/
77+
@Composable
7878
fun Modifier.drawHorizontalScrollbar(
7979
state: LazyListState,
8080
reverseScrolling: Boolean = false,
@@ -87,13 +87,15 @@ fun Modifier.drawHorizontalScrollbar(
8787
*
8888
* Set key with [STICKY_HEADER_KEY_PREFIX] prefix to any sticky header item in the list.
8989
*/
90+
@Composable
9091
fun Modifier.drawVerticalScrollbar(
9192
state: LazyListState,
9293
reverseScrolling: Boolean = false,
9394
// The amount of offset the scrollbar position towards the start of the layout
9495
positionOffsetPx: Float = 0f,
9596
): Modifier = drawScrollbar(state, Orientation.Vertical, reverseScrolling, positionOffsetPx)
9697

98+
@Composable
9799
private fun Modifier.drawScrollbar(
98100
state: LazyListState,
99101
orientation: Orientation,
@@ -178,6 +180,7 @@ private fun ContentDrawScope.onDrawScrollbar(
178180
}
179181
}
180182

183+
@Composable
181184
private fun Modifier.drawScrollbar(
182185
orientation: Orientation,
183186
reverseScrolling: Boolean,
@@ -188,7 +191,7 @@ private fun Modifier.drawScrollbar(
188191
color: Color,
189192
alpha: () -> Float,
190193
) -> Unit,
191-
): Modifier = composed {
194+
): Modifier {
192195
val scrolled = remember {
193196
MutableSharedFlow<Unit>(
194197
extraBufferCapacity = 1,
@@ -230,7 +233,8 @@ private fun Modifier.drawScrollbar(
230233
val context = LocalContext.current
231234
val thickness = remember { ViewConfiguration.get(context).scaledScrollBarSize.toFloat() }
232235
val color = MaterialTheme.colorScheme.onSurface.copy(alpha = 0.364f)
233-
Modifier
236+
237+
return this
234238
.nestedScroll(nestedScrollConnection)
235239
.drawWithContent {
236240
onDraw(reverseDirection, atEnd, thickness, color, alpha::value)

0 commit comments

Comments
 (0)