Skip to content

Commit 7c5e882

Browse files
fix(android): use ViewCompat.setStateDescription for API < 30 compat (#606)
* fix(android): use ViewCompat.setStateDescription for API < 30 compat `View.stateDescription` (added in API 30) is called directly in `TrueSheetGrabberView.updateAccessibilityValue()`, causing a fatal `NoSuchMethodError` on Android 10 and below on every sheet present. Replace with `ViewCompat.setStateDescription()` which is a no-op on API < 30 and works identically on API 30+. Introduced in #587 (v3.10.0-beta.0), still present in beta.2. * docs: add changelog entry for ViewCompat fix
1 parent a373125 commit 7c5e882

2 files changed

Lines changed: 4 additions & 1 deletion

File tree

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010

1111
### 🐛 Bug fixes
1212

13+
- **Android**: Fixed `NoSuchMethodError` crash on Android < 11 (API 30) when presenting a sheet with grabber accessibility. ([#606](https://github.com/lodev09/react-native-true-sheet/pull/606) by [@Mohamed-kassim](https://github.com/Mohamed-kassim))
1314
- **iOS**: Fixed keyboard scroll positioning when sheet auto-expands from a smaller detent. ([#592](https://github.com/lodev09/react-native-true-sheet/pull/592) by [@lodev09](https://github.com/lodev09))
1415
- **Android**: Fixed dead state after rapid present/dismiss cycles. ([#593](https://github.com/lodev09/react-native-true-sheet/pull/593) by [@lodev09](https://github.com/lodev09))
1516
- **iOS**: Fixed position change not emitting when detent or index changed. ([#584](https://github.com/lodev09/react-native-true-sheet/pull/584) by [@lodev09](https://github.com/lodev09))

android/src/main/java/com/lodev09/truesheet/core/TrueSheetGrabberView.kt

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import android.view.View
1111
import android.view.accessibility.AccessibilityNodeInfo
1212
import android.widget.FrameLayout
1313
import androidx.core.graphics.ColorUtils
14+
import androidx.core.view.ViewCompat
1415
import com.facebook.react.uimanager.PixelUtil.dpToPx
1516

1617
/**
@@ -131,12 +132,13 @@ class TrueSheetGrabberView(context: Context, private val options: GrabberOptions
131132
}
132133

133134
fun updateAccessibilityValue(index: Int, detentCount: Int) {
134-
stateDescription = when {
135+
val description: CharSequence? = when {
135136
index < 0 || detentCount <= 0 -> null
136137
index >= detentCount - 1 -> "Expanded"
137138
index == 0 -> "Collapsed"
138139
else -> "Detent ${index + 1} of $detentCount"
139140
}
141+
ViewCompat.setStateDescription(this, description)
140142
}
141143

142144
private fun getAdaptiveColor(baseColor: Int? = null): Int {

0 commit comments

Comments
 (0)