do not call setHyphenationFrequency on AndroidSdk < 23 (#29258)

Summary:
JoshuaGross This issue fixes https://github.com/facebook/react-native/issues/28279 as discussed in https://github.com/facebook/react-native/pull/29157#issuecomment-649993571
Avoid calling [setHyphenationFrequency](https://developer.android.com/reference/android/widget/TextView#setHyphenationFrequency(int)) on Android Sdk < 23.

## Changelog

<!-- Help reviewers and the release process by writing your own changelog entry. For an example, see:
https://github.com/facebook/react-native/wiki/Changelog
-->

[Android] [Fixed] - do not call setHyphenationFrequency on AndroidSdk < 23
Pull Request resolved: https://github.com/facebook/react-native/pull/29258

Test Plan:
| **BEFORE** | **AFTER** |
|:-------------------------:|:-------------------------:|
|  <img src="https://user-images.githubusercontent.com/24992535/86214122-05bf0e00-bb7b-11ea-93b5-2174812bfec9.png"  width="300" height="" />| <img src="https://user-images.githubusercontent.com/24992535/86214130-08216800-bb7b-11ea-9fc0-68b28638bf57.png" width="300" height="" /> |

The warning displayed with `adb logcat | grep -P "ReactTextAnchorViewManager"`

![image](https://user-images.githubusercontent.com/24992535/86214242-34d57f80-bb7b-11ea-9945-30ae25332bfb.png)

I remain available to do improvements. Thanks a lot. Fabrizio.

Reviewed By: JoshuaGross

Differential Revision: D22337095

Pulled By: mdvacca

fbshipit-source-id: d0943397af180929c48044ccbc7a9388549021b8
This commit is contained in:
fabriziobertoglio1987
2020-07-01 17:43:25 -07:00
committed by Facebook GitHub Bot
parent c6b9cc36da
commit 7d8aeb4955
@@ -7,6 +7,7 @@
package com.facebook.react.views.text;
import android.os.Build;
import android.text.Layout;
import android.text.Spannable;
import android.text.TextUtils;
@@ -14,6 +15,7 @@ import android.text.util.Linkify;
import android.view.Gravity;
import android.view.View;
import androidx.annotation.Nullable;
import com.facebook.common.logging.FLog;
import com.facebook.react.bridge.JSApplicationIllegalArgumentException;
import com.facebook.react.uimanager.BaseViewManager;
import com.facebook.react.uimanager.PixelUtil;
@@ -39,6 +41,7 @@ public abstract class ReactTextAnchorViewManager<T extends View, C extends React
private static final int[] SPACING_TYPES = {
Spacing.ALL, Spacing.LEFT, Spacing.RIGHT, Spacing.TOP, Spacing.BOTTOM,
};
private static final String TAG = "ReactTextAnchorViewManager";
// maxLines can only be set in master view (block), doesn't really make sense to set in a span
@ReactProp(name = ViewProps.NUMBER_OF_LINES, defaultInt = ViewDefaults.NUMBER_OF_LINES)
@@ -99,6 +102,10 @@ public abstract class ReactTextAnchorViewManager<T extends View, C extends React
@ReactProp(name = "android_hyphenationFrequency")
public void setAndroidHyphenationFrequency(ReactTextView view, @Nullable String frequency) {
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.M) {
FLog.w(TAG, "android_hyphenationFrequency only available since android 23");
return;
}
if (frequency == null || frequency.equals("none")) {
view.setHyphenationFrequency(Layout.HYPHENATION_FREQUENCY_NONE);
} else if (frequency.equals("full")) {