Skip to content

Commit 01a1004

Browse files
Emily Janzerfacebook-github-bot
Emily Janzer
authored andcommittedOct 10, 2018
Fix for InterpolatorType crash
Summary: We're currently getting a redbox in Turkish when we try to convert the string 'easeInEaseOut' to an InterpolatorType. This is because I use toLowerCase() to compare the string without setting a locale; in Turkish, the capital letter 'I' doesn't convert to 'i' when you lowercase it, but rather to 'ı' (http://www.i18nguy.com/unicode/turkish-i18n.html). Passing in a locale param to `toLowerCase()` fixes it. Also updating the test. Differential Revision: D10315474 fbshipit-source-id: 54be3ff1d3f91cb2ec765ff705ac364b976b8c6f
1 parent a82f6e1 commit 01a1004

File tree

2 files changed

+10
-1
lines changed

2 files changed

+10
-1
lines changed
 

‎ReactAndroid/src/main/java/com/facebook/react/uimanager/layoutanimation/InterpolatorType.java

+3-1
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55

66
package com.facebook.react.uimanager.layoutanimation;
77

8+
import java.util.Locale;
9+
810
/**
911
* Enum representing the different interpolators that can be used in layout animation configuration.
1012
*/
@@ -16,7 +18,7 @@
1618
SPRING;
1719

1820
public static InterpolatorType fromString(String name) {
19-
switch (name.toLowerCase()) {
21+
switch (name.toLowerCase(Locale.US)) {
2022
case "linear":
2123
return LINEAR;
2224
case "easein":

‎ReactAndroid/src/test/java/com/facebook/react/uimanager/layoutanimation/InterpolatorTypeTest.java

+7
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
package com.facebook.react.uimanager.layoutanimation;
99

1010
import com.facebook.react.uimanager.layoutanimation.InterpolatorType;
11+
import java.util.Locale;
1112
import org.junit.Test;
1213
import org.junit.runner.RunWith;
1314
import org.robolectric.RobolectricTestRunner;
@@ -32,6 +33,12 @@ public void testOtherCases() {
3233
assertThat(InterpolatorType.fromString("easeineaseout")).isEqualTo(InterpolatorType.EASE_IN_EASE_OUT);
3334
}
3435

36+
@Test
37+
public void testLocales() {
38+
Locale.setDefault(Locale.forLanguageTag("tr-TR"));
39+
assertThat(InterpolatorType.fromString("easeInEaseOut")).isEqualTo(InterpolatorType.EASE_IN_EASE_OUT);
40+
}
41+
3542
@Test(expected = IllegalArgumentException.class)
3643
public void testInvalidInterpolatorTypes() throws IllegalArgumentException {
3744
InterpolatorType.fromString("ease_in_ease_out");

0 commit comments

Comments
 (0)
Please sign in to comment.