Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ object KeyboardDimensions {
// 按键尺寸
val KeyHeight = 44.dp

val BubbleHeightDown = 36.dp // 下滑气泡主体高度
val BubbleHeightDown = 40.dp // 下滑气泡主体高度
val BubbleCornerRadius = 8.dp

// 气泡底部pointer(覆盖按键的部分�?
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -884,14 +884,25 @@ class XimeInputMethodService : InputMethodService(), LifecycleOwner, SavedStateR
* 实测关闭面板后 insets 残留数秒(仅在下一次输入会话/窗口事件时才恢复)。
* 这里通过容器做一次真实尺寸变化(+1dp)再立即还原(同帧内完成,视觉不可见),
* 强制系统按 keyboardContentTopPx 重算并下发,消除残留。
*
* [insetsRecomputePending] 防重入:+1dp 到 resetHeight 还原之间为"飞行中",
* 期间再次调用会读到 +1dp 后的当前高度再叠加 +1——某些 ROM 上 onApplyWindowInsets
* 回调时机不同导致 reset 滞后,+1dp 反复叠加/循环 → 键盘底部被持续垫高(2.7.0 用户反馈)。
*/
private var insetsRecomputePending = false

internal fun forceInsetsRecompute() {
if (!::keyboardContainer.isInitialized) return
if (insetsRecomputePending) return
val density = resources.displayMetrics.density
val h = keyboardContainer.height
if (h > 0) {
insetsRecomputePending = true
keyboardContainer.updateHeight((h / density).toInt() + 1)
keyboardContainer.post { keyboardContainer.resetHeight() }
keyboardContainer.post {
keyboardContainer.resetHeight()
insetsRecomputePending = false
}
} else {
keyboardContainer.post { keyboardContainer.requestLayout() }
}
Expand Down Expand Up @@ -1252,7 +1263,10 @@ class XimeInputMethodService : InputMethodService(), LifecycleOwner, SavedStateR
.align(androidx.compose.ui.Alignment.BottomCenter)
.then(if (state.isFloatingMode) Modifier else Modifier.offset(y = (-activeBottomDp).dp))
.onGloballyPositioned {
if (!state.isFloatingMode && !state.isCompact) {
// insetsRecomputePending 期间的高度摆动是 +1dp hack
// 自身引起的,忽略之:否则 y 在 h/h+1 间交替变化,
// 每次都 != keyboardContentTopPx → 无限循环触发重算。
if (!state.isFloatingMode && !state.isCompact && !insetsRecomputePending) {
val y = it.positionInWindow().y.toInt()
if (y != keyboardContentTopPx) {
keyboardContentTopPx = y
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,27 +87,28 @@ fun CommonSymbolKeyboardLayout(
val isLandscape = !isFloatingMode && configuration.screenWidthDp > configuration.screenHeightDp
val isDarkTheme = keyTextColor == Color(0xFFE8EAED)
val suppressCursorMove = LocalSuppressCursorMove.current
var swipeState by remember { mutableStateOf(SwipeState()) }
val swipeBubble = rememberSwipeBubbleController()
var keyboardBounds by remember { mutableStateOf(Rect(0f, 0f, 0f, 0f)) }
var lastKeyBounds by remember { mutableStateOf(Rect(0f, 0f, 0f, 0f)) }

fun processSwipeState(state: SwipeState, bounds: Rect) {
swipeState = state
lastKeyBounds = Rect(
left = bounds.left - keyboardBounds.left,
top = bounds.top - keyboardBounds.top,
right = bounds.right - keyboardBounds.left,
bottom = bounds.bottom - keyboardBounds.top,
swipeBubble.update(
state,
Rect(
left = bounds.left - keyboardBounds.left,
top = bounds.top - keyboardBounds.top,
right = bounds.right - keyboardBounds.left,
bottom = bounds.bottom - keyboardBounds.top,
)
)
}

val bubbleData = rememberSwipeBubbleDrawData(
swipeState = swipeState,
keyBounds = lastKeyBounds,
swipeState = swipeBubble.state,
keyBounds = swipeBubble.keyBounds,
keyBackgroundColor = bubbleBackgroundColor,
keyTextColor = keyTextColor,
accentColor = specialKeyTextColor,
keyWidth = if (swipeState.isSwiping || swipeState.isPressed) lastKeyBounds.width else 0f,
keyWidth = if (swipeBubble.state.isSwiping || swipeBubble.state.isPressed) swipeBubble.keyBounds.width else 0f,
keyboardWidth = keyboardBounds.width,
)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -213,9 +213,8 @@ fun KeyboardLayout(
SubcharHelper.init(context)
}

var swipeState by remember { mutableStateOf(SwipeState()) }
val swipeBubble = rememberSwipeBubbleController()
var keyboardBounds by remember { mutableStateOf(Rect(0f, 0f, 0f, 0f)) }
var lastKeyBounds by remember { mutableStateOf(Rect(0f, 0f, 0f, 0f)) }

// 监听手势配置版本号,部署后强制刷新键帽显示
val cfgVer by KeysConfigHelper.configVersion.collectAsState()
Expand All @@ -226,23 +225,24 @@ fun KeyboardLayout(
} else {
state
}
swipeState = newState

lastKeyBounds = Rect(
left = bounds.left - keyboardBounds.left,
top = bounds.top - keyboardBounds.top,
right = bounds.right - keyboardBounds.left,
bottom = bounds.bottom - keyboardBounds.top
swipeBubble.update(
newState,
Rect(
left = bounds.left - keyboardBounds.left,
top = bounds.top - keyboardBounds.top,
right = bounds.right - keyboardBounds.left,
bottom = bounds.bottom - keyboardBounds.top
)
)
}

val bubbleData = rememberSwipeBubbleDrawData(
swipeState = swipeState,
keyBounds = lastKeyBounds,
swipeState = swipeBubble.state,
keyBounds = swipeBubble.keyBounds,
keyBackgroundColor = bubbleBgColor,
keyTextColor = keyTextColor,
accentColor = specialKeyTextColor,
keyWidth = if (swipeState.isSwiping || swipeState.isPressed) lastKeyBounds.width else 0f,
keyWidth = if (swipeBubble.state.isSwiping || swipeBubble.state.isPressed) swipeBubble.keyBounds.width else 0f,
keyboardWidth = keyboardBounds.width
)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,22 +79,36 @@ fun NumberKeyboardLayout(
"\\", "|", ";", ":", "'", "\"", "<", ">"
)

var swipeState by remember { mutableStateOf(SwipeState()) }
val swipeBubble = rememberSwipeBubbleController()
var keyboardBounds by remember { mutableStateOf(Rect(0f, 0f, 0f, 0f)) }
var lastKeyBounds by remember { mutableStateOf(Rect(0f, 0f, 0f, 0f)) }

val isDarkTheme = keyTextColor == Color(0xFFE8EAED)

val bubbleData = rememberSwipeBubbleDrawData(
swipeState = swipeState,
keyBounds = lastKeyBounds,
swipeState = swipeBubble.state,
keyBounds = swipeBubble.keyBounds,
keyBackgroundColor = bubbleBackgroundColor,
keyTextColor = keyTextColor,
accentColor = specialKeyTextColor,
keyWidth = if (swipeState.isSwiping || swipeState.isPressed) lastKeyBounds.width else 0f,
keyWidth = if (swipeBubble.state.isSwiping || swipeBubble.state.isPressed) swipeBubble.keyBounds.width else 0f,
keyboardWidth = keyboardBounds.width
)

fun processSwipeState(state: SwipeState, bounds: Rect) {
val newState = if (state.isSwipeDown && state.swipeText != null) {
state.copy(charInfos = SubcharHelper.parseSwipeDownText(state.swipeText))
} else state
swipeBubble.update(
newState,
Rect(
left = bounds.left - keyboardBounds.left,
top = bounds.top - keyboardBounds.top,
right = bounds.right - keyboardBounds.left,
bottom = bounds.bottom - keyboardBounds.top
)
)
}

CompositionLocalProvider(LocalKeyCornerRadius provides keyCornerRadius) {
Box(
modifier = modifier
Expand Down Expand Up @@ -171,18 +185,7 @@ fun NumberKeyboardLayout(
onKeyPressDown = onKeyPressDown,
compactMode = true,
specialKeyTextColor = specialKeyTextColor,
onSwipeStateChange = { state, bounds ->
val newState = if (state.isSwipeDown && state.swipeText != null) {
state.copy(charInfos = SubcharHelper.parseSwipeDownText(state.swipeText))
} else state
swipeState = newState
lastKeyBounds = Rect(
left = bounds.left - keyboardBounds.left,
top = bounds.top - keyboardBounds.top,
right = bounds.right - keyboardBounds.left,
bottom = bounds.bottom - keyboardBounds.top
)
}
onSwipeStateChange = ::processSwipeState
)
}
}
Expand All @@ -208,18 +211,8 @@ fun NumberKeyboardLayout(
shadowShapeRadius = shadowShapeRadius,
onKeyPressDown = onKeyPressDown,
specialKeyTextColor = specialKeyTextColor,
onSwipeStateChange = { state, bounds ->
val newState = if (state.isSwipeDown && state.swipeText != null) {
state.copy(charInfos = SubcharHelper.parseSwipeDownText(state.swipeText))
} else state
swipeState = newState
lastKeyBounds = Rect(
left = bounds.left - keyboardBounds.left,
top = bounds.top - keyboardBounds.top,
right = bounds.right - keyboardBounds.left,
bottom = bounds.bottom - keyboardBounds.top
)
})
onSwipeStateChange = ::processSwipeState
)
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -128,19 +128,18 @@ private fun StrokeKeyboardSwipeOverlay(
val configuration = LocalConfiguration.current
val isLandscape = !isFloatingMode && configuration.orientation == android.content.res.Configuration.ORIENTATION_LANDSCAPE

var swipeState by remember { mutableStateOf(SwipeState()) }
val swipeBubble = rememberSwipeBubbleController()
var keyboardBounds by remember { mutableStateOf(Rect(0f, 0f, 0f, 0f)) }
var lastKeyBounds by remember { mutableStateOf(Rect(0f, 0f, 0f, 0f)) }

val isDarkTheme = keyTextColor == Color(0xFFE8EAED)

val bubbleData = rememberSwipeBubbleDrawData(
swipeState = swipeState,
keyBounds = lastKeyBounds,
swipeState = swipeBubble.state,
keyBounds = swipeBubble.keyBounds,
keyBackgroundColor = bubbleBackgroundColor,
keyTextColor = keyTextColor,
accentColor = specialKeyTextColor,
keyWidth = if (swipeState.isSwiping || swipeState.isPressed) lastKeyBounds.width else 0f,
keyWidth = if (swipeBubble.state.isSwiping || swipeBubble.state.isPressed) swipeBubble.keyBounds.width else 0f,
keyboardWidth = keyboardBounds.width
)

Expand All @@ -150,12 +149,14 @@ private fun StrokeKeyboardSwipeOverlay(
} else {
state
}
swipeState = newState
lastKeyBounds = Rect(
left = bounds.left - keyboardBounds.left,
top = bounds.top - keyboardBounds.top,
right = bounds.right - keyboardBounds.left,
bottom = bounds.bottom - keyboardBounds.top
swipeBubble.update(
newState,
Rect(
left = bounds.left - keyboardBounds.left,
top = bounds.top - keyboardBounds.top,
right = bounds.right - keyboardBounds.left,
bottom = bounds.bottom - keyboardBounds.top
)
)
}

Expand Down
Loading
Loading