@@ -5,14 +5,14 @@ import androidx.compose.foundation.isSystemInDarkTheme
5
5
import androidx.compose.foundation.layout.WindowInsets
6
6
import androidx.compose.foundation.layout.isImeVisible
7
7
import androidx.compose.material3.MaterialTheme
8
+ import androidx.compose.runtime.Composable
8
9
import androidx.compose.runtime.LaunchedEffect
9
10
import androidx.compose.runtime.getValue
10
11
import androidx.compose.runtime.mutableStateOf
11
12
import androidx.compose.runtime.remember
12
13
import androidx.compose.runtime.saveable.rememberSaveable
13
14
import androidx.compose.runtime.setValue
14
15
import androidx.compose.ui.Modifier
15
- import androidx.compose.ui.composed
16
16
import androidx.compose.ui.draw.alpha
17
17
import androidx.compose.ui.draw.drawBehind
18
18
import androidx.compose.ui.focus.FocusRequester
@@ -24,16 +24,12 @@ import androidx.compose.ui.input.key.onPreviewKeyEvent
24
24
import androidx.compose.ui.platform.LocalFocusManager
25
25
import tachiyomi.presentation.core.components.material.SECONDARY_ALPHA
26
26
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) }
37
33
}
38
34
39
35
fun Modifier.secondaryItemAlpha (): Modifier = this .alpha(SECONDARY_ALPHA )
@@ -60,6 +56,7 @@ fun Modifier.runOnEnterKeyPressed(action: () -> Unit): Modifier = this.onPreview
60
56
action()
61
57
true
62
58
}
59
+
63
60
else -> false
64
61
}
65
62
}
@@ -68,30 +65,28 @@ fun Modifier.runOnEnterKeyPressed(action: () -> Unit): Modifier = this.onPreview
68
65
* For TextField on AppBar, this modifier will request focus
69
66
* to the element the first time it's composed.
70
67
*/
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
80
77
}
81
-
82
- Modifier .focusRequester(focusRequester)
83
78
}
84
- } else {
85
- this
79
+ return this .focusRequester(focusRequester)
86
80
}
87
81
88
82
/* *
89
83
* For TextField, this modifier will clear focus when soft
90
84
* keyboard is hidden.
91
85
*/
86
+ @Composable
92
87
fun Modifier.clearFocusOnSoftKeyboardHide (
93
88
onFocusCleared : (() -> Unit )? = null,
94
- ): Modifier = composed {
89
+ ): Modifier {
95
90
var isFocused by remember { mutableStateOf(false ) }
96
91
var keyboardShowedSinceFocused by remember { mutableStateOf(false ) }
97
92
if (isFocused) {
@@ -107,7 +102,7 @@ fun Modifier.clearFocusOnSoftKeyboardHide(
107
102
}
108
103
}
109
104
110
- Modifier .onFocusChanged {
105
+ return this .onFocusChanged {
111
106
if (isFocused != it.isFocused) {
112
107
if (isFocused) {
113
108
keyboardShowedSinceFocused = false
0 commit comments