@@ -26,21 +26,27 @@ import androidx.compose.material3.TextField
2626import androidx.compose.material3.TextFieldDefaults
2727import androidx.compose.material3.TopAppBar
2828import androidx.compose.runtime.Composable
29+ import androidx.compose.runtime.LaunchedEffect
2930import androidx.compose.runtime.getValue
3031import androidx.compose.runtime.mutableStateOf
3132import androidx.compose.runtime.remember
3233import androidx.compose.runtime.setValue
3334import androidx.compose.ui.Alignment
3435import androidx.compose.ui.Modifier
3536import androidx.compose.ui.draw.clip
37+ import androidx.compose.ui.focus.FocusRequester
38+ import androidx.compose.ui.focus.focusRequester
39+ import androidx.compose.ui.focus.onFocusChanged
3640import androidx.compose.ui.graphics.Color
3741import androidx.compose.ui.platform.LocalFocusManager
42+ import androidx.compose.ui.platform.LocalSoftwareKeyboardController
3843import androidx.compose.ui.text.font.FontWeight
3944import androidx.compose.ui.text.style.TextOverflow
4045import androidx.compose.ui.unit.dp
4146import androidx.compose.ui.unit.sp
4247import androidx.lifecycle.compose.collectAsStateWithLifecycle
4348import com.russhwolf.settings.ExperimentalSettingsApi
49+ import kotlinx.coroutines.delay
4450import org.jetbrains.compose.resources.painterResource
4551import org.jetbrains.compose.resources.stringResource
4652import site.remlit.snowdrop.api.statuses.createStatus
@@ -80,6 +86,7 @@ import snowdrop.shared.generated.resources.visibility_public_description
8086import snowdrop.shared.generated.resources.visibility_unlisted
8187import snowdrop.shared.generated.resources.visibility_unlisted_description
8288import snowdrop.shared.generated.resources.write_your_post_here
89+ import kotlin.time.Duration.Companion.milliseconds
8390
8491@Composable
8592@OptIn(ExperimentalSettingsApi ::class )
@@ -92,6 +99,8 @@ fun ComposeView(
9299 val navHandler = LocalNavController .current
93100 val snackbarHandler = SnackbarController .current
94101 val focusManager = LocalFocusManager .current
102+ val focusRequester = remember { FocusRequester () }
103+ val keyboardController = LocalSoftwareKeyboardController .current
95104
96105 val currentAccount by getCurrentAccountObjectFlow()
97106 .collectAsStateWithLifecycle(null )
@@ -135,6 +144,12 @@ fun ComposeView(
135144 }
136145 }
137146
147+ LaunchedEffect (Unit ) {
148+ // kinda jank but there's no good way around this
149+ delay(50 .milliseconds)
150+ focusRequester.requestFocus()
151+ }
152+
138153 TopAppBar (
139154 navigationIcon = {
140155 IconButton (onClick = { navHandler.popBackStack() }) {
@@ -320,7 +335,15 @@ fun ComposeView(
320335 value = content,
321336 placeholder = { Text (stringResource(Res .string.write_your_post_here)) },
322337 onValueChange = { content = it },
323- modifier = Modifier .fillMaxWidth().fillMaxHeight(),
338+ modifier = Modifier
339+ .focusRequester(focusRequester)
340+ .onFocusChanged {
341+ if (it.hasFocus) {
342+ keyboardController?.show()
343+ }
344+ }
345+ .fillMaxWidth()
346+ .fillMaxHeight(),
324347 colors = TextFieldDefaults .colors(
325348 unfocusedContainerColor = Color (0x00000000 ),
326349 unfocusedIndicatorColor = Color (0x00000000 ),
0 commit comments