Skip to content

Commit 70f8986

Browse files
committed
Fixing dropdown @ mentions logic
1 parent 8696c0d commit 70f8986

File tree

1 file changed

+14
-12
lines changed

1 file changed

+14
-12
lines changed

sample/common/src/commonMain/kotlin/com/kjcommunities/KJRichTextEditorWithMentions.kt

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -166,17 +166,21 @@ fun KJRichTextEditorWithMentions(
166166

167167
// Mention dropdown popup
168168
if (showMentionDropdown && mentionSearchText.isNotEmpty()) {
169-
val screenHeight = with(density) { configuration.screenHeightDp.dp.toPx() }
170169
val dropdownHeight = 300.dp
171170
val dropdownHeightPx = with(density) { dropdownHeight.toPx() }
171+
val margin = with(density) { 8.dp.toPx() }
172+
173+
// Always position dropdown above the text input area
174+
// Anchor it directly above the editor with a small margin
175+
val dropdownOffset = -(dropdownHeightPx.toInt() + margin.toInt())
176+
177+
// Calculate available space above for the dropdown height
178+
// Allow it to extend up even if it overlaps the top panel
172179
val availableSpaceAbove = editorPosition.y
173-
val availableSpaceBelow = screenHeight - editorPosition.y - editorHeight
174-
175-
// Position dropdown above the editor if there's more space there
176-
val dropdownOffset = if (availableSpaceAbove > dropdownHeightPx && availableSpaceAbove > availableSpaceBelow) {
177-
-(dropdownHeightPx.toInt() + 8) // 8dp margin
178-
} else {
179-
editorHeight + with(density) { 8.dp.toPx().toInt() } // 8dp margin
180+
val maxDropdownHeight = with(density) {
181+
// Use all available space above, but ensure minimum of 150dp for usability
182+
val availableHeight = (availableSpaceAbove - margin * 2).toDp()
183+
maxOf(availableHeight, 150.dp).coerceAtMost(dropdownHeight)
180184
}
181185

182186
Popup(
@@ -187,7 +191,7 @@ fun KJRichTextEditorWithMentions(
187191
properties = PopupProperties(
188192
dismissOnBackPress = true,
189193
dismissOnClickOutside = true,
190-
clippingEnabled = false
194+
clippingEnabled = false // Allow overlapping with top panel
191195
),
192196
onDismissRequest = {
193197
showMentionDropdown = false
@@ -196,9 +200,7 @@ fun KJRichTextEditorWithMentions(
196200
KJMentionDropdown(
197201
users = users,
198202
searchText = mentionSearchText,
199-
maxHeight = with(density) {
200-
minOf(300.dp, availableSpaceAbove.toDp()).coerceAtLeast(100.dp)
201-
},
203+
maxHeight = maxDropdownHeight,
202204
enableDebugLogging = enableDebugLogging,
203205
onUserSelected = { user ->
204206
insertMention(state, user, mentionStartIndex, mentionStartIndex + mentionSearchText.length + 1, enableDebugLogging)

0 commit comments

Comments
 (0)