Skip to content

Commit 785f1a9

Browse files
committed
feat: 允许禁用手势导航栏偏移
1 parent 958e01b commit 785f1a9

File tree

2 files changed

+39
-22
lines changed

2 files changed

+39
-22
lines changed

inputview/src/main/kotlin/com/xiaocydx/inputview/BuiltInImpl.kt

Lines changed: 34 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -21,29 +21,20 @@ import android.view.ViewGroup
2121
import android.view.animation.Interpolator
2222
import androidx.annotation.FloatRange
2323
import androidx.annotation.IntRange
24+
import androidx.core.view.WindowInsetsCompat.Type.navigationBars
25+
import com.xiaocydx.inputview.compat.onApplyWindowInsetsCompat
2426

2527
/**
26-
* [Editor]的IME默认实现
27-
*/
28-
object Ime : Editor
29-
30-
/**
31-
* 用于只需要IME的场景
32-
*
33-
* ```
34-
* val adapter = ImeAdapter()
35-
* inputView.editorAdapter = adapter
36-
*
37-
* // 显示IME
38-
* adapter.notifyShowIme()
28+
* 禁用手势导航栏偏移,在支持手势导航栏EdgeToEdge的情况下,
29+
* `contentView`和编辑区也不会有手势导航栏高度的初始偏移,
30+
* 当调用者需要自行处理手势导航栏时,可以调用该函数。
3931
*
40-
* // 隐藏IME
41-
* adapter.notifyHideIme()
42-
* ```
32+
* 关于手势导航栏偏移的描述,可以看[InputView.onApplyWindowInsets]的注释。
4333
*/
44-
class ImeAdapter : EditorAdapter<Ime>() {
45-
override val ime: Ime = Ime
46-
override fun onCreateView(parent: ViewGroup, editor: Ime): View? = null
34+
fun InputView.disableGestureNavBarOffset() = EdgeToEdgeHelper {
35+
doOnApplyWindowInsets { _, insets, _ ->
36+
onApplyWindowInsetsCompat(insets.consume(navigationBars()))
37+
}
4738
}
4839

4940
/**
@@ -80,6 +71,30 @@ inline fun EditorAnimator.addAnimationCallback(
8071
override fun onAnimationEnd(state: AnimationState) = onEnd(state)
8172
}.also(::addAnimationCallback)
8273

74+
/**
75+
* [Editor]的IME默认实现
76+
*/
77+
object Ime : Editor
78+
79+
/**
80+
* 用于只需要IME的场景
81+
*
82+
* ```
83+
* val adapter = ImeAdapter()
84+
* inputView.editorAdapter = adapter
85+
*
86+
* // 显示IME
87+
* adapter.notifyShowIme()
88+
*
89+
* // 隐藏IME
90+
* adapter.notifyHideIme()
91+
* ```
92+
*/
93+
class ImeAdapter : EditorAdapter<Ime>() {
94+
override val ime: Ime = Ime
95+
override fun onCreateView(parent: ViewGroup, editor: Ime): View? = null
96+
}
97+
8398
/**
8499
* [Editor]的淡入淡出动画
85100
*/

inputview/src/main/kotlin/com/xiaocydx/inputview/InputView.kt

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -185,9 +185,11 @@ class InputView @JvmOverloads constructor(
185185

186186
override fun shouldDelayChildPressedState(): Boolean = false
187187

188-
override fun generateLayoutParams(attrs: AttributeSet?): LayoutParams {
189-
return MarginLayoutParams(context, attrs)
190-
}
188+
override fun generateLayoutParams(attrs: AttributeSet) = MarginLayoutParams(context, attrs)
189+
190+
override fun generateDefaultLayoutParams() = MarginLayoutParams(WRAP_CONTENT, WRAP_CONTENT)
191+
192+
override fun generateLayoutParams(p: LayoutParams) = MarginLayoutParams(p)
191193

192194
override fun onAttachedToWindow() {
193195
super.onAttachedToWindow()

0 commit comments

Comments
 (0)