accept Settings.Global.TRANSITION_ANIMATION_SCALE with a comma decimal separator (#50864)

Summary:
Pull Request resolved: https://github.com/facebook/react-native/pull/50864

Changelog:
[Android][Fixed] Settings.Global.TRANSITION_ANIMATION_SCALE accepts comma as decimal separator

Reviewed By: javache

Differential Revision: D73501445

fbshipit-source-id: f7f54dbbcbc4cea1e746222febf8ec63638a73ac
This commit is contained in:
Vitali Zaidman
2025-04-23 04:45:01 -07:00
committed by Facebook GitHub Bot
parent 5ed486cc8f
commit 8b11970adb
@@ -105,9 +105,19 @@ internal class AccessibilityInfoModule(context: ReactApplicationContext) :
val rawValue =
Settings.Global.getString(contentResolver, Settings.Global.TRANSITION_ANIMATION_SCALE)
// Parse the value as a float so we can check for a single value.
val parsedValue = rawValue?.toFloat() ?: 1f
return parsedValue == 0f
if (rawValue == null) {
return false
}
try {
// In some locales, the decimal separator is a comma instead of a dot,
// but "toFloat" would crash failing to conver these.
val parsedValue = rawValue.replace(',', '.').toFloat()
return parsedValue == 0f
} catch (e: NumberFormatException) {
// If the value is not a valid number, we assume reduced motion is not enabled
return false
}
}
private val isInvertColorsEnabledValue: Boolean