fix compose field focus when replying to post with cw (#2634)

This commit is contained in:
Konrad Pozniak 2022-08-03 17:23:54 +02:00 committed by GitHub
parent 36901eb8d0
commit 2d2d7569e3
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 9 additions and 10 deletions

View file

@ -247,7 +247,10 @@ class ComposeActivity :
setupContentWarningField(composeOptions?.contentWarning)
setupPollView()
applyShareIntent(intent, savedInstanceState)
viewModel.setupComplete.value = true
binding.composeEditField.post {
binding.composeEditField.requestFocus()
}
}
private fun applyShareIntent(intent: Intent, savedInstanceState: Bundle?) {
@ -431,13 +434,6 @@ class ComposeActivity :
}
}
}
lifecycleScope.launch {
viewModel.setupComplete.collect {
// Focus may have changed during view model setup, ensure initial focus is on the edit field
binding.composeEditField.requestFocus()
}
}
}
private fun setupButtons() {

View file

@ -89,7 +89,6 @@ class ComposeViewModel @Inject constructor(
val statusVisibility: MutableStateFlow<Status.Visibility> = MutableStateFlow(Status.Visibility.UNKNOWN)
val showContentWarning: MutableStateFlow<Boolean> = MutableStateFlow(false)
val setupComplete: MutableStateFlow<Boolean> = MutableStateFlow(false)
val poll: MutableStateFlow<NewPoll?> = MutableStateFlow(null)
val scheduledAt: MutableStateFlow<String?> = MutableStateFlow(null)
@ -101,6 +100,8 @@ class ComposeViewModel @Inject constructor(
// Used in ComposeActivity to pass state to result function when cropImage contract inflight
var cropImageItemOld: QueuedMedia? = null
private var setupComplete = false
suspend fun pickMedia(mediaUri: Uri, description: String? = null): Result<QueuedMedia> = withContext(Dispatchers.IO) {
try {
val (type, uri, size) = mediaUploader.prepareMedia(mediaUri, instanceInfo.first())
@ -380,7 +381,7 @@ class ComposeViewModel @Inject constructor(
fun setup(composeOptions: ComposeActivity.ComposeOptions?) {
if (setupComplete.value) {
if (setupComplete) {
return
}
@ -452,6 +453,8 @@ class ComposeViewModel @Inject constructor(
}
replyingStatusContent = composeOptions?.replyingStatusContent
replyingStatusAuthor = composeOptions?.replyingStatusAuthor
setupComplete = true
}
fun updatePoll(newPoll: NewPoll) {