Add Support for Emojis in Fabric for Text and TextInput components
Summary: This diff refactors Text and Text input components in Fabric to support customizable emojis changelog: [internal] Reviewed By: JoshuaGross Differential Revision: D19679391 fbshipit-source-id: 358aa97064209d28d317ba4ca5fff84245c9b1bb
This commit is contained in:
Родитель
d1e2c9435e
Коммит
9312313c3c
|
@ -90,7 +90,8 @@ public class ReactTextViewManager
|
|||
ReadableMap paragraphAttributes = state.getMap("paragraphAttributes");
|
||||
|
||||
Spannable spanned =
|
||||
TextLayoutManager.getOrCreateSpannableForText(view.getContext(), attributedString);
|
||||
TextLayoutManager.getOrCreateSpannableForText(
|
||||
view.getContext(), attributedString, mReactTextViewManagerCallback);
|
||||
view.setSpanned(spanned);
|
||||
|
||||
TextAttributeProps textViewProps = new TextAttributeProps(props);
|
||||
|
@ -147,7 +148,14 @@ public class ReactTextViewManager
|
|||
YogaMeasureMode heightMode) {
|
||||
|
||||
return TextLayoutManager.measureText(
|
||||
context, localData, props, width, widthMode, height, heightMode);
|
||||
context,
|
||||
localData,
|
||||
props,
|
||||
width,
|
||||
widthMode,
|
||||
height,
|
||||
heightMode,
|
||||
mReactTextViewManagerCallback);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -19,6 +19,7 @@ import android.text.Spanned;
|
|||
import android.text.StaticLayout;
|
||||
import android.text.TextPaint;
|
||||
import android.util.LruCache;
|
||||
import androidx.annotation.Nullable;
|
||||
import com.facebook.react.bridge.ReadableArray;
|
||||
import com.facebook.react.bridge.ReadableMap;
|
||||
import com.facebook.react.uimanager.PixelUtil;
|
||||
|
@ -127,7 +128,9 @@ public class TextLayoutManager {
|
|||
|
||||
// public because both ReactTextViewManager and ReactTextInputManager need to use this
|
||||
public static Spannable getOrCreateSpannableForText(
|
||||
Context context, ReadableMap attributedString) {
|
||||
Context context,
|
||||
ReadableMap attributedString,
|
||||
@Nullable ReactTextViewManagerCallback reactTextViewManagerCallback) {
|
||||
|
||||
Spannable preparedSpannableText;
|
||||
String attributedStringPayload = attributedString.toString();
|
||||
|
@ -139,7 +142,9 @@ public class TextLayoutManager {
|
|||
}
|
||||
}
|
||||
|
||||
preparedSpannableText = createSpannableFromAttributedString(context, attributedString);
|
||||
preparedSpannableText =
|
||||
createSpannableFromAttributedString(
|
||||
context, attributedString, reactTextViewManagerCallback);
|
||||
synchronized (sSpannableCacheLock) {
|
||||
sSpannableCache.put(attributedStringPayload, preparedSpannableText);
|
||||
}
|
||||
|
@ -147,7 +152,9 @@ public class TextLayoutManager {
|
|||
}
|
||||
|
||||
private static Spannable createSpannableFromAttributedString(
|
||||
Context context, ReadableMap attributedString) {
|
||||
Context context,
|
||||
ReadableMap attributedString,
|
||||
@Nullable ReactTextViewManagerCallback reactTextViewManagerCallback) {
|
||||
|
||||
SpannableStringBuilder sb = new SpannableStringBuilder();
|
||||
|
||||
|
@ -168,6 +175,9 @@ public class TextLayoutManager {
|
|||
priority++;
|
||||
}
|
||||
|
||||
if (reactTextViewManagerCallback != null) {
|
||||
reactTextViewManagerCallback.onPostProcessSpannable(sb);
|
||||
}
|
||||
return sb;
|
||||
}
|
||||
|
||||
|
@ -178,11 +188,13 @@ public class TextLayoutManager {
|
|||
float width,
|
||||
YogaMeasureMode widthYogaMeasureMode,
|
||||
float height,
|
||||
YogaMeasureMode heightYogaMeasureMode) {
|
||||
YogaMeasureMode heightYogaMeasureMode,
|
||||
ReactTextViewManagerCallback reactTextViewManagerCallback) {
|
||||
|
||||
// TODO(5578671): Handle text direction (see View#getTextDirectionHeuristic)
|
||||
TextPaint textPaint = sTextPaintInstance;
|
||||
Spannable preparedSpannableText = getOrCreateSpannableForText(context, attributedString);
|
||||
Spannable preparedSpannableText =
|
||||
getOrCreateSpannableForText(context, attributedString, reactTextViewManagerCallback);
|
||||
|
||||
// TODO add these props to paragraph attributes
|
||||
int textBreakStrategy = Layout.BREAK_STRATEGY_HIGH_QUALITY;
|
||||
|
|
|
@ -1238,7 +1238,8 @@ public class ReactTextInputManager extends BaseViewManager<ReactEditText, Layout
|
|||
ReadableMap paragraphAttributes = state.getMap("paragraphAttributes");
|
||||
|
||||
Spannable spanned =
|
||||
TextLayoutManager.getOrCreateSpannableForText(view.getContext(), attributedString);
|
||||
TextLayoutManager.getOrCreateSpannableForText(
|
||||
view.getContext(), attributedString, mReactTextViewManagerCallback);
|
||||
|
||||
TextAttributeProps textViewProps = new TextAttributeProps(props);
|
||||
|
||||
|
|
Загрузка…
Ссылка в новой задаче