1
0
Fork 0
mirror of https://github.com/anyproto/anytype-kotlin.git synced 2025-06-08 05:47:05 +09:00

DROID-78 Editor | Improve keyboard experience by taking advantage of the new WindowInsets API (#2524)

* DROID-78 remove focus on hide keyboard event

* DROID-78 add delay on navigation toolbar visibility

* DROID-78 add check

Co-authored-by: konstantiniiv <ki@anytype.io>
This commit is contained in:
Konstantin Ivanov 2022-08-17 18:07:11 +02:00 committed by GitHub
parent b051b4f0d9
commit 651a097caa
Signed by: github
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 65 additions and 9 deletions

View file

@ -1312,9 +1312,13 @@ open class EditorFragment : NavigationFragment<FragmentEditorBinding>(R.layout.f
val insets = ViewCompat.getRootWindowInsets(binding.root)
if (state.navigationToolbar.isVisible) {
binding.placeholder.requestFocus()
hideKeyboard()
binding.bottomToolbar.visible()
keyboardDelayJobs += lifecycleScope.launch {
if (binding.toolbar.isVisible) binding.toolbar.gone()
binding.placeholder.requestFocus()
hideKeyboard()
delayKeyboardHide(insets)
binding.bottomToolbar.visible()
}
} else {
binding.bottomToolbar.gone()
}

View file

@ -4056,6 +4056,7 @@ class EditorViewModel(
return controlPanelViewState.value?.let { state ->
val isVisible = state.mentionToolbar.isVisible
val isSlashWidgetVisible = state.slashWidget.isVisible
val isMainToolbarVisible = state.mainToolbar.isVisible
if (isVisible) {
onMentionEvent(MentionEvent.MentionSuggestStop)
return true
@ -4064,6 +4065,9 @@ class EditorViewModel(
controlPanelInteractor.onEvent(ControlPanelMachine.Event.Slash.OnStop)
return true
}
if (isMainToolbarVisible) {
onHideKeyboardClicked()
}
return false
} ?: run { false }
}

View file

@ -2,8 +2,12 @@ package com.anytypeio.anytype.presentation.editor.editor
import androidx.arch.core.executor.testing.InstantTaskExecutorRule
import com.anytypeio.anytype.core_models.Block
import com.anytypeio.anytype.core_models.StubHeader
import com.anytypeio.anytype.core_models.StubParagraph
import com.anytypeio.anytype.core_models.StubTitle
import com.anytypeio.anytype.core_models.ext.content
import com.anytypeio.anytype.presentation.editor.EditorViewModel
import com.anytypeio.anytype.presentation.editor.editor.control.ControlPanelState
import com.anytypeio.anytype.presentation.editor.editor.model.Focusable
import com.anytypeio.anytype.presentation.util.CoroutinesTestRule
import com.anytypeio.anytype.test_utils.MockDataFactory
@ -58,7 +62,8 @@ class EditorFocusTest : EditorPresentationTestSetup() {
content = Block.Content.Text(
text = MockDataFactory.randomString(),
marks = emptyList(),
style = Block.Content.Text.Style.values().filter { it != Block.Content.Text.Style.DESCRIPTION }.random()
style = Block.Content.Text.Style.values()
.filter { it != Block.Content.Text.Style.DESCRIPTION }.random()
),
children = emptyList()
)
@ -190,16 +195,16 @@ class EditorFocusTest : EditorPresentationTestSetup() {
testFocusObserver.assertValue(EditorViewModel.EMPTY_FOCUS_ID)
}
//@Test
@Test
fun `should update views on hide-keyboard event`() {
// SETUP
val style = Block.Content.Text.Style.values()
.filter { style ->
style != Block.Content.Text.Style.TITLE || style != Block.Content.Text.Style.DESCRIPTION
}
.random()
.filter { style ->
style != Block.Content.Text.Style.TITLE || style != Block.Content.Text.Style.DESCRIPTION
}
.random()
val block = Block(
id = MockDataFactory.randomUuid(),
@ -276,4 +281,47 @@ class EditorFocusTest : EditorPresentationTestSetup() {
verifyZeroInteractions(createBlock)
}
@Test
fun `should close keyboard and clear focus when system close keyboard happened`() {
// SETUP
val paragraph = StubParagraph()
val title = StubTitle()
val header = StubHeader(children = listOf(title.id))
val page = Block(
id = root,
fields = Block.Fields(emptyMap()),
content = Block.Content.Smart(),
children = listOf(header.id, paragraph.id)
)
val document = listOf(page, header, title, paragraph)
stubInterceptEvents()
stubInterceptThreadStatus()
stubOpenDocument(document)
val vm = buildViewModel()
// TESTING
vm.onStart(root)
vm.onSelectionChanged(
id = paragraph.id,
selection = IntRange(0, 0)
)
vm.onBlockFocusChanged(
id = paragraph.id,
hasFocus = true
)
vm.onBackPressedCallback()
vm.controlPanelViewState.test().assertValue(
ControlPanelState(
navigationToolbar = ControlPanelState.Toolbar.Navigation(isVisible = true)
)
)
}
}