@onekeyfe/react-native-tab-view 3.0.139 → 3.0.141

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -20,6 +20,8 @@ import android.view.ViewGroup
20
20
  import android.widget.FrameLayout
21
21
  import android.widget.LinearLayout
22
22
  import android.widget.TextView
23
+ import androidx.core.view.ViewCompat
24
+ import androidx.core.view.WindowInsetsCompat
23
25
  import androidx.core.view.forEachIndexed
24
26
  import coil3.ImageLoader
25
27
  import coil3.asDrawable
@@ -45,15 +47,54 @@ private fun getMaterialContext(context: Context): Context {
45
47
  }
46
48
 
47
49
  class ExtendedBottomNavigationView(context: Context) : BottomNavigationView(getMaterialContext(context)) {
50
+ private val basePaddingStart = paddingStart
51
+ private val basePaddingTop = paddingTop
52
+ private val basePaddingEnd = paddingEnd
53
+ private val basePaddingBottom = paddingBottom
54
+ private var ignoreBottomInsets = false
55
+ private var ignoreKeyboardInsets = true
56
+
57
+ init {
58
+ // OneKey patch: Material pads the bar with getSystemWindowInsetBottom(), which
59
+ // includes the IME height only while the window uses adjustResize (switched on by
60
+ // react-native-keyboard-controller hooks), so whether the bar rose above the
61
+ // keyboard depended on the screen. Pad for system bars, and add the IME only when
62
+ // ignoreKeyboardInsets is turned off.
63
+ ViewCompat.setOnApplyWindowInsetsListener(this) { view, insets ->
64
+ val barInsets = insets.getInsets(
65
+ WindowInsetsCompat.Type.systemBars() or WindowInsetsCompat.Type.displayCutout()
66
+ )
67
+ val navigationBarBottom = if (ignoreBottomInsets) 0 else barInsets.bottom
68
+ val keyboardBottom = if (ignoreKeyboardInsets) {
69
+ 0
70
+ } else {
71
+ insets.getInsets(WindowInsetsCompat.Type.ime()).bottom
72
+ }
73
+ val isRtl = view.layoutDirection == View.LAYOUT_DIRECTION_RTL
74
+ view.setPaddingRelative(
75
+ basePaddingStart + if (isRtl) barInsets.right else barInsets.left,
76
+ basePaddingTop,
77
+ basePaddingEnd + if (isRtl) barInsets.left else barInsets.right,
78
+ basePaddingBottom + maxOf(navigationBarBottom, keyboardBottom),
79
+ )
80
+ insets
81
+ }
82
+ }
48
83
 
49
84
  fun setIgnoreBottomInsets(ignore: Boolean) {
50
- if (ignore) {
51
- setOnApplyWindowInsetsListener { v, insets -> insets }
52
- setPadding(paddingLeft, paddingTop, paddingRight, 0)
53
- } else {
54
- setOnApplyWindowInsetsListener(null)
55
- requestApplyInsets()
85
+ if (ignoreBottomInsets == ignore) {
86
+ return
87
+ }
88
+ ignoreBottomInsets = ignore
89
+ requestApplyInsets()
90
+ }
91
+
92
+ fun setIgnoreKeyboardInsets(ignore: Boolean) {
93
+ if (ignoreKeyboardInsets == ignore) {
94
+ return
56
95
  }
96
+ ignoreKeyboardInsets = ignore
97
+ requestApplyInsets()
57
98
  }
58
99
 
59
100
  override fun getMaxItemCount(): Int {
@@ -106,6 +147,8 @@ class ReactBottomNavigationView(context: Context) : LinearLayout(context) {
106
147
  private var lastReportedSize: Size? = null
107
148
  private var hasCustomAppearance = false
108
149
  private var uiModeConfiguration: Int = Configuration.UI_MODE_NIGHT_UNDEFINED
150
+ private var ignoreBottomInsets = false
151
+ private var ignoreKeyboardInsets = true
109
152
 
110
153
  private val imageLoader = ImageLoader.Builder(context)
111
154
  .components {
@@ -289,9 +332,15 @@ class ReactBottomNavigationView(context: Context) : LinearLayout(context) {
289
332
  }
290
333
 
291
334
  fun setIgnoreBottomInsets(ignore: Boolean) {
335
+ ignoreBottomInsets = ignore
292
336
  bottomNavigation.setIgnoreBottomInsets(ignore)
293
337
  }
294
338
 
339
+ fun setIgnoreKeyboardInsets(ignore: Boolean) {
340
+ ignoreKeyboardInsets = ignore
341
+ bottomNavigation.setIgnoreKeyboardInsets(ignore)
342
+ }
343
+
295
344
  fun setTabBarHidden(isHidden: Boolean) {
296
345
  if (isHidden) {
297
346
  bottomNavigation.visibility = GONE
@@ -576,6 +625,8 @@ class ReactBottomNavigationView(context: Context) : LinearLayout(context) {
576
625
  // We also opt-out of this recreation when custom styles are used.
577
626
  removeView(bottomNavigation)
578
627
  bottomNavigation = ExtendedBottomNavigationView(context)
628
+ bottomNavigation.setIgnoreBottomInsets(ignoreBottomInsets)
629
+ bottomNavigation.setIgnoreKeyboardInsets(ignoreKeyboardInsets)
579
630
  addView(bottomNavigation)
580
631
  updateItems(items)
581
632
  setLabeled(this.labeled)
@@ -193,6 +193,10 @@ class RCTTabViewManager(context: ReactApplicationContext) :
193
193
  view?.setIgnoreBottomInsets(value)
194
194
  }
195
195
 
196
+ override fun setIgnoreKeyboardInsets(view: ReactBottomNavigationView?, value: Boolean) {
197
+ view?.setIgnoreKeyboardInsets(value)
198
+ }
199
+
196
200
  // iOS-only props (no-ops on Android)
197
201
  // selectedIcons feeds UITabBarItem.selectedImage on iOS; Android keeps
198
202
  // swapping the icon in JS via the focusedKey-driven `icons` array.
@@ -62,6 +62,7 @@ export interface TabViewProps extends ViewProps {
62
62
  fontWeight?: string;
63
63
  fontSize?: Int32;
64
64
  ignoreBottomInsets?: boolean;
65
+ ignoreKeyboardInsets?: WithDefault<boolean, true>;
65
66
  }
66
67
 
67
68
  export default codegenNativeComponent<TabViewProps>('RNCTabView');
@@ -178,6 +178,12 @@ interface Props<Route extends BaseRoute> {
178
178
  * Whether to ignore bottom system insets (navigation bar). Android only.
179
179
  */
180
180
  ignoreBottomInsets?: boolean;
181
+ /**
182
+ * Whether the tab bar ignores the soft keyboard. Defaults to true, so the
183
+ * keyboard covers the tab bar as on iOS. Set to false to pad the tab bar by
184
+ * the keyboard height so it rises above the keyboard. Android only.
185
+ */
186
+ ignoreKeyboardInsets?: boolean;
181
187
  /**
182
188
  * Whether to delay freeze/unfreeze by 200ms on tab switch.
183
189
  * Defaults to false (immediate freeze). Set to true to restore the
@@ -50,6 +50,7 @@ export interface TabViewProps extends ViewProps {
50
50
  fontWeight?: string;
51
51
  fontSize?: Int32;
52
52
  ignoreBottomInsets?: boolean;
53
+ ignoreKeyboardInsets?: WithDefault<boolean, true>;
53
54
  }
54
55
  declare const _default: import("react-native").HostComponent<TabViewProps>;
55
56
  export default _default;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@onekeyfe/react-native-tab-view",
3
- "version": "3.0.139",
3
+ "version": "3.0.141",
4
4
  "description": "Native Bottom Tabs for React Native (UIKit implementation)",
5
5
  "source": "./src/index.tsx",
6
6
  "main": "./lib/module/index.js",
package/src/TabView.tsx CHANGED
@@ -190,6 +190,12 @@ interface Props<Route extends BaseRoute> {
190
190
  * Whether to ignore bottom system insets (navigation bar). Android only.
191
191
  */
192
192
  ignoreBottomInsets?: boolean;
193
+ /**
194
+ * Whether the tab bar ignores the soft keyboard. Defaults to true, so the
195
+ * keyboard covers the tab bar as on iOS. Set to false to pad the tab bar by
196
+ * the keyboard height so it rises above the keyboard. Android only.
197
+ */
198
+ ignoreKeyboardInsets?: boolean;
193
199
  /**
194
200
  * Whether to delay freeze/unfreeze by 200ms on tab switch.
195
201
  * Defaults to false (immediate freeze). Set to true to restore the
@@ -62,6 +62,7 @@ export interface TabViewProps extends ViewProps {
62
62
  fontWeight?: string;
63
63
  fontSize?: Int32;
64
64
  ignoreBottomInsets?: boolean;
65
+ ignoreKeyboardInsets?: WithDefault<boolean, true>;
65
66
  }
66
67
 
67
68
  export default codegenNativeComponent<TabViewProps>('RNCTabView');