Skip to content

Commit 7724a8e

Browse files
authored
ADFA-4171: (fix) close editor/bottom-sheet gap and prevent sheet from covering find-in-file (#1348)
1 parent e60a67f commit 7724a8e

5 files changed

Lines changed: 34 additions & 19 deletions

File tree

‎app/src/main/java/com/itsaky/androidide/activities/editor/BaseEditorActivity.kt‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1507,6 +1507,10 @@ abstract class BaseEditorActivity :
15071507
}
15081508
}
15091509

1510+
fun setEditorSearchModeActive(isActive: Boolean) {
1511+
contentOrNull?.bottomSheet?.setSearchModeActive(isActive)
1512+
}
1513+
15101514
private fun observeFileOperations() {
15111515
lifecycleScope.launch {
15121516
repeatOnLifecycle(Lifecycle.State.STARTED) {

‎app/src/main/java/com/itsaky/androidide/activities/editor/FullscreenManager.kt‎

Lines changed: 5 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -110,11 +110,6 @@ class FullscreenManager(
110110

111111
private var isFullscreenState = false
112112

113-
private val defaultEditorBottomMargin =
114-
(editorContainer.layoutParams as ViewGroup.MarginLayoutParams).bottomMargin
115-
116-
117-
118113
private val offsetListener = AppBarLayout.OnOffsetChangedListener { appBarLayout, verticalOffset ->
119114
val totalScrollRange = appBarLayout.totalScrollRange
120115
val effectiveScrollRange = if (totalScrollRange > 0) totalScrollRange else appBarLayout.height
@@ -124,18 +119,11 @@ class FullscreenManager(
124119
appBarContent.alpha = 1f - collapseFraction
125120
}
126121

127-
if (!isFullscreenState) {
128-
val visibleAppBarHeight = effectiveScrollRange + verticalOffset
129-
editorContainer.updateLayoutParams<ViewGroup.MarginLayoutParams> {
130-
bottomMargin = defaultEditorBottomMargin + visibleAppBarHeight
131-
}
132-
133-
if (verticalOffset == 0) {
134-
val params = appBarContent.layoutParams as AppBarLayout.LayoutParams
135-
if (params.scrollFlags != 0) {
136-
params.scrollFlags = 0
137-
appBarContent.layoutParams = params
138-
}
122+
if (!isFullscreenState && verticalOffset == 0) {
123+
val params = appBarContent.layoutParams as AppBarLayout.LayoutParams
124+
if (params.scrollFlags != 0) {
125+
params.scrollFlags = 0
126+
appBarContent.layoutParams = params
139127
}
140128
}
141129
}

‎app/src/main/java/com/itsaky/androidide/ui/CodeEditorView.kt‎

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -252,7 +252,12 @@ class CodeEditorView(
252252
true
253253
}
254254

255-
_searchLayout = EditorSearchLayout(context, binding.editor)
255+
_searchLayout = EditorSearchLayout(context, binding.editor).apply {
256+
onSearchModeChanged = { isActive ->
257+
(this@CodeEditorView.context as? BaseEditorActivity)
258+
?.setEditorSearchModeActive(isActive)
259+
}
260+
}
256261
orientation = VERTICAL
257262

258263
removeAllViews()

‎app/src/main/java/com/itsaky/androidide/ui/EditorBottomSheet.kt‎

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,7 @@ constructor(
112112

113113
private var anchorOffset = 0
114114
private var isImeVisible = false
115+
private var isSearchModeActive = false
115116
private var windowInsets: Insets? = null
116117

117118
private val insetBottom: Int
@@ -340,7 +341,20 @@ constructor(
340341
fun setImeVisible(isVisible: Boolean) {
341342
isImeVisible = isVisible
342343
behavior.isGestureInsetBottomIgnored = true
343-
behavior.peekHeight = if (isVisible) 0 else collapsedHeight.toInt()
344+
applyPeekHeight()
345+
}
346+
347+
348+
fun setSearchModeActive(isActive: Boolean) {
349+
isSearchModeActive = isActive
350+
if (isActive && behavior.state != BottomSheetBehavior.STATE_COLLAPSED) {
351+
behavior.state = BottomSheetBehavior.STATE_COLLAPSED
352+
}
353+
applyPeekHeight()
354+
}
355+
356+
private fun applyPeekHeight() {
357+
behavior.peekHeight = if (isImeVisible || isSearchModeActive) 0 else collapsedHeight.toInt()
344358
}
345359

346360
fun setOffsetAnchor(view: View) {

‎editor/src/main/java/com/itsaky/androidide/editor/ui/EditorSearchLayout.kt‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,8 @@ class EditorSearchLayout(context: Context, val editor: IDEEditor) : FrameLayout(
5353
private val collapsedSheetMargin =
5454
context.resources.getDimensionPixelSize(R.dimen.editor_sheet_peek_height)
5555

56+
var onSearchModeChanged: ((isActive: Boolean) -> Unit)? = null
57+
5658
private var searchInputTextWatcher: TextWatcher? = null
5759
private var searchOptions = SearchOptions(true, false)
5860
private val findInFileBinding: LayoutFindInFileBinding = LayoutFindInFileBinding.inflate(LayoutInflater.from(context))
@@ -216,6 +218,7 @@ class EditorSearchLayout(context: Context, val editor: IDEEditor) : FrameLayout(
216218
false
217219
}
218220
findInFileBinding.root.visibility = VISIBLE
221+
onSearchModeChanged?.invoke(true)
219222

220223
findInFileBinding.searchInput.requestFocus()
221224
findInFileBinding.searchInput.post {
@@ -233,6 +236,7 @@ class EditorSearchLayout(context: Context, val editor: IDEEditor) : FrameLayout(
233236
findInFileBinding.root.visibility = GONE
234237
this.searchInputTextWatcher = null
235238
searcher.onClose()
239+
onSearchModeChanged?.invoke(false)
236240
}
237241
if (!searcher.hasQuery()) {
238242
return

0 commit comments

Comments
 (0)