Skip to content

Commit 5026dd2

Browse files
authored
fix: remove extra space under the input window (#1930)
1 parent 3dc322a commit 5026dd2

File tree

2 files changed

+13
-7
lines changed

2 files changed

+13
-7
lines changed

app/src/main/java/com/osfans/trime/ime/core/BaseInputView.kt

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -70,15 +70,16 @@ abstract class BaseInputView(
7070
return 0
7171
}
7272
val insets = WindowInsetsCompat.toWindowInsetsCompat(windowInsets)
73-
// use navigation bar insets when available
7473
val navBars = insets.getInsets(WindowInsetsCompat.Type.navigationBars())
75-
// in case navigation bar insets goes wrong (eg. on LineageOS 21+ with gesture navigation)
76-
// use mandatory system gesture insets
7774
val mandatory = insets.getInsets(WindowInsetsCompat.Type.mandatorySystemGestures())
75+
// If navBars is 0 but mandatory is non-zero, likely gesture nav - don't add inset
76+
if (navBars.bottom == 0 && mandatory.bottom > 0) {
77+
return 0
78+
}
7879
var insetsBottom = max(navBars.bottom, mandatory.bottom)
7980
if (insetsBottom <= 0) {
80-
// check system gesture insets and fallback to navigation_bar_frame_height just in case
81-
val gesturesBottom = insets.getInsets(WindowInsetsCompat.Type.systemGestures()).bottom
81+
val gestures = insets.getInsets(WindowInsetsCompat.Type.systemGestures())
82+
val gesturesBottom = gestures.bottom
8283
if (gesturesBottom > 0) {
8384
insetsBottom = max(gesturesBottom, navBarFrameHeight)
8485
}

app/src/main/java/com/osfans/trime/ime/core/TrimeInputMethodService.kt

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ import android.widget.FrameLayout
3232
import androidx.annotation.Keep
3333
import androidx.annotation.RequiresApi
3434
import androidx.core.content.ContextCompat
35+
import androidx.core.view.WindowInsetsCompat
3536
import androidx.core.view.updateLayoutParams
3637
import androidx.lifecycle.lifecycleScope
3738
import com.osfans.trime.core.KeyModifiers
@@ -449,8 +450,12 @@ open class TrimeInputMethodService : LifecycleInputMethodService() {
449450
touchableInsets = Insets.TOUCHABLE_INSETS_VISIBLE
450451
}
451452
} else {
452-
val n = decorView.findViewById<View>(android.R.id.navigationBarBackground)?.height ?: 0
453-
val h = decorView.height - n
453+
val insets = WindowInsetsCompat.toWindowInsetsCompat(decorView.rootWindowInsets)
454+
val navBarHeight = insets?.getInsets(WindowInsetsCompat.Type.navigationBars())?.bottom ?: 0
455+
val mandatoryHeight = insets?.getInsets(WindowInsetsCompat.Type.mandatorySystemGestures())?.bottom ?: 0
456+
// If navBarHeight is 0 but mandatory is non-zero, likely gesture nav - don't add inset
457+
val finalNavHeight = if (navBarHeight == 0 && mandatoryHeight > 0) 0 else maxOf(navBarHeight, mandatoryHeight)
458+
val h = decorView.height - finalNavHeight
454459
outInsets.apply {
455460
contentTopInsets = h
456461
visibleTopInsets = h

0 commit comments

Comments
 (0)