1
1
package org.futo.inputmethod.latin.uix.settings.pages
2
2
3
+ import android.app.Activity
4
+ import android.os.Build
3
5
import androidx.compose.foundation.layout.Column
4
6
import androidx.compose.foundation.layout.fillMaxSize
7
+ import androidx.compose.foundation.layout.padding
8
+ import androidx.compose.material3.FabPosition
9
+ import androidx.compose.material3.Scaffold
10
+ import androidx.compose.material3.SmallFloatingActionButton
5
11
import androidx.compose.runtime.Composable
12
+ import androidx.compose.runtime.DisposableEffect
13
+ import androidx.compose.runtime.getValue
14
+ import androidx.compose.runtime.mutableStateOf
15
+ import androidx.compose.runtime.remember
16
+ import androidx.compose.runtime.setValue
6
17
import androidx.compose.ui.Modifier
7
18
import androidx.compose.ui.platform.LocalContext
19
+ import androidx.compose.ui.platform.LocalTextInputService
8
20
import androidx.compose.ui.res.stringResource
21
+ import androidx.compose.ui.text.input.ImeOptions
22
+ import androidx.compose.ui.text.input.PlatformImeOptions
23
+ import androidx.compose.ui.text.input.TextFieldValue
24
+ import androidx.compose.ui.text.input.TextInputSession
9
25
import androidx.compose.ui.tooling.preview.Preview
26
+ import androidx.core.view.ViewCompat
27
+ import androidx.core.view.WindowInsetsCompat
10
28
import androidx.navigation.NavHostController
11
29
import androidx.navigation.compose.rememberNavController
12
30
import org.futo.inputmethod.latin.uix.THEME_KEY
13
31
import org.futo.inputmethod.latin.uix.settings.ScreenTitle
14
32
import org.futo.inputmethod.latin.uix.settings.useDataStore
15
33
import org.futo.inputmethod.latin.uix.theme.selector.ThemePicker
16
34
import org.futo.inputmethod.latin.R
35
+ import org.futo.inputmethod.latin.uix.settings.RotatingChevronIcon
17
36
18
37
@Preview
19
38
@Composable
20
39
fun ThemeScreen (navController : NavHostController = rememberNavController()) {
21
40
val (theme, setTheme) = useDataStore(THEME_KEY .key, THEME_KEY .default)
22
41
23
42
val context = LocalContext .current
24
- Column (modifier = Modifier .fillMaxSize()) {
25
- ScreenTitle (stringResource(R .string.theme_settings_title), showBack = true , navController)
26
- ThemePicker {
27
- setTheme(it.key)
43
+ val enableKeyboardPreview = Build .VERSION .SDK_INT >= Build .VERSION_CODES .R
44
+ var showKeyboard by remember { mutableStateOf(false ) }
45
+
46
+ if (enableKeyboardPreview) {
47
+ val textInputService = LocalTextInputService .current
48
+ val rootView = (context as ? Activity )?.window?.decorView?.rootView
49
+ val session = remember { mutableStateOf<TextInputSession ?>(null ) }
50
+
51
+ DisposableEffect (showKeyboard, theme) {
52
+ val service = textInputService ? : return @DisposableEffect onDispose { }
53
+
54
+ if (showKeyboard) {
55
+ session.value = service.startInput(
56
+ TextFieldValue (" " ),
57
+ imeOptions = ImeOptions .Default .copy(
58
+ platformImeOptions = PlatformImeOptions (
59
+ privateImeOptions = " org.futo.inputmethod.latin.NoSuggestions=1"
60
+ )
61
+ ),
62
+ onEditCommand = { },
63
+ onImeActionPerformed = { }
64
+ )
65
+ }
66
+
67
+ onDispose {
68
+ service.stopInput(session.value ? : return @onDispose)
69
+ }
70
+ }
71
+
72
+ // Detect manual keyboard dismissal (e.g., back button press)
73
+ rootView?.let { view ->
74
+ DisposableEffect (view) {
75
+ ViewCompat .setOnApplyWindowInsetsListener(view) { _, insets ->
76
+ val isKeyboardVisible = insets.isVisible(WindowInsetsCompat .Type .ime())
77
+ if (! isKeyboardVisible && showKeyboard) {
78
+ showKeyboard = false
79
+ }
80
+ insets
81
+ }
82
+
83
+ onDispose {
84
+ ViewCompat .setOnApplyWindowInsetsListener(view, null )
85
+ }
86
+ }
87
+ }
88
+ }
89
+
90
+ Scaffold (
91
+ floatingActionButton = {
92
+ if (enableKeyboardPreview) {
93
+ SmallFloatingActionButton (
94
+ onClick = {
95
+ showKeyboard = ! showKeyboard
96
+ }
97
+ ) {
98
+ RotatingChevronIcon (! showKeyboard)
99
+ }
100
+ }
101
+ },
102
+ floatingActionButtonPosition = FabPosition .Start
103
+ ) { innerPadding ->
104
+ Column (modifier = Modifier .fillMaxSize().padding(innerPadding)) {
105
+ ScreenTitle (stringResource(R .string.theme_settings_title), showBack = true , navController)
106
+ ThemePicker {
107
+ setTheme(it.key)
108
+ }
28
109
}
29
110
}
30
111
}
0 commit comments