react-native-navigation-mode 1.2.3 → 1.2.5

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.
@@ -13,9 +13,9 @@ import com.facebook.react.bridge.WritableMap
13
13
  import com.facebook.react.module.annotations.ReactModule
14
14
 
15
15
  @ReactModule(name = NavigationModeModule.NAME)
16
- class NavigationModeModule(reactContext: ReactApplicationContext) :
16
+ class NavigationModeModule(reactContext: ReactApplicationContext) :
17
17
  NativeNavigationModeSpec(reactContext) {
18
-
18
+
19
19
  companion object {
20
20
  const val NAME = "NavigationMode"
21
21
  }
@@ -26,7 +26,7 @@ class NavigationModeModule(reactContext: ReactApplicationContext) :
26
26
  // Try to get Activity for WindowInsets
27
27
  val activity = if (context is Activity) context else reactApplicationContext.currentActivity
28
28
  val density = context.resources.displayMetrics.density // Get device density
29
-
29
+
30
30
  if (activity != null && Build.VERSION.SDK_INT >= Build.VERSION_CODES.R) {
31
31
  val insets = activity.window.decorView.rootWindowInsets
32
32
  if (insets != null) {
@@ -34,7 +34,7 @@ class NavigationModeModule(reactContext: ReactApplicationContext) :
34
34
  return (navBar.bottom / density).toInt() // Convert pixels to dp
35
35
  }
36
36
  }
37
-
37
+
38
38
  // Fallback to resource-based approach for API < 30
39
39
  val resources = context.resources
40
40
  val resourceId = resources.getIdentifier("navigation_bar_height", "dimen", "android")
@@ -60,20 +60,21 @@ class NavigationModeModule(reactContext: ReactApplicationContext) :
60
60
  try {
61
61
  val result = Arguments.createMap()
62
62
  val context = reactApplicationContext
63
-
63
+
64
64
  // Use reactApplicationContext for navigation bar height
65
65
  val navBarHeight = getNavigationBarHeight(context)
66
66
  result.putInt("navigationBarHeight", navBarHeight)
67
-
67
+
68
68
  if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) {
69
69
  val navBarInteractionMode = getNavBarInteractionMode(context)
70
70
  result.putInt("interactionMode", navBarInteractionMode)
71
71
  result.putString("type", getNavigationTypeFromInteractionMode(navBarInteractionMode))
72
+ result.putBoolean("isGestureNavigation", navBarInteractionMode == 2)
73
+ } else {
74
+ val gestureNavEnabled = isGestureNavigationEnabledLegacy(context)
75
+ result.putBoolean("isGestureNavigation", gestureNavEnabled)
72
76
  }
73
-
74
- val gestureNavEnabled = isGestureNavigationEnabled(context)
75
- result.putBoolean("isGestureNavigation", gestureNavEnabled)
76
-
77
+
77
78
  promise.resolve(result)
78
79
  } catch (e: Exception) {
79
80
  promise.reject("NAVIGATION_MODE_ERROR", "Failed to get navigation mode: ${e.message}", e)
@@ -83,12 +84,12 @@ class NavigationModeModule(reactContext: ReactApplicationContext) :
83
84
  override fun isGestureNavigation(promise: Promise) {
84
85
  try {
85
86
  val context = reactApplicationContext
86
-
87
+
87
88
  if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) {
88
89
  val navBarInteractionMode = getNavBarInteractionMode(context)
89
90
  promise.resolve(navBarInteractionMode == 2)
90
91
  } else {
91
- val gestureEnabled = isGestureNavigationEnabled(context)
92
+ val gestureEnabled = isGestureNavigationEnabledLegacy(context)
92
93
  promise.resolve(gestureEnabled)
93
94
  }
94
95
  } catch (e: Exception) {
@@ -119,17 +120,17 @@ class NavigationModeModule(reactContext: ReactApplicationContext) :
119
120
  }
120
121
  }
121
122
 
122
- private fun isGestureNavigationEnabled(context: Context): Boolean {
123
- return if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) {
124
- try {
125
- val navBarMode = Settings.Secure.getString(
126
- context.contentResolver,
127
- "navigation_mode"
128
- )
129
- "2" == navBarMode
130
- } catch (e: Exception) {
131
- false
132
- }
133
- } else false
123
+ private fun isGestureNavigationEnabledLegacy(context: Context): Boolean {
124
+ // Legacy fallback using Settings.Secure (for pre-Android Q devices)
125
+ // or as a backup when config_navBarInteractionMode is not available
126
+ return try {
127
+ val navBarMode = Settings.Secure.getString(
128
+ context.contentResolver,
129
+ "navigation_mode"
130
+ )
131
+ "2" == navBarMode
132
+ } catch (e: Exception) {
133
+ false
134
134
  }
135
- }
135
+ }
136
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "react-native-navigation-mode",
3
- "version": "1.2.3",
3
+ "version": "1.2.5",
4
4
  "description": "Detect Android navigation mode (3-button, 2-button, or gesture)",
5
5
  "main": "./lib/module/index.js",
6
6
  "react-native": "./lib/module/index.js",
@@ -71,7 +71,6 @@
71
71
  "@eslint/js": "^9.22.0",
72
72
  "@evilmartians/lefthook": "^1.5.0",
73
73
  "@expo/config-plugins": "^10.1.2",
74
- "@react-native-community/cli": "15.0.0-alpha.2",
75
74
  "@react-native/babel-preset": "0.79.5",
76
75
  "@react-native/eslint-config": "0.79.5",
77
76
  "@release-it/conventional-changelog": "^9.0.2",