mirror of
https://github.com/zhigang1992/react-native.git
synced 2026-04-05 09:29:07 +08:00
Implement Local Data in Android Fabric C++
Summary: This diff introduces the concept of Local Data in Android Fabric C++ and as an example we uses it to implement Text View. Reviewed By: shergin Differential Revision: D9583970 fbshipit-source-id: ab7478b16ef4327ff574ca1467870ab9cb684ea0
This commit is contained in:
committed by
Facebook Github Bot
parent
5c0da011cb
commit
9ad193c35b
@@ -205,6 +205,13 @@ public abstract class ViewManager<T extends View, C extends ReactShadowNode>
|
||||
return ViewManagerPropertyUpdater.getNativeProps(getClass(), getShadowNodeClass());
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public @Nullable Object updateLocalData(T view, ReactStylesDiffMap props, ReactStylesDiffMap localData) {
|
||||
return null;
|
||||
}
|
||||
|
||||
public float[] measure(
|
||||
ReactContext context,
|
||||
T view,
|
||||
|
||||
@@ -7,12 +7,16 @@
|
||||
|
||||
package com.facebook.react.views.text;
|
||||
|
||||
import android.text.Layout;
|
||||
import android.text.Spannable;
|
||||
import com.facebook.react.common.MapBuilder;
|
||||
import com.facebook.react.bridge.ReactContext;
|
||||
import com.facebook.react.bridge.ReadableArray;
|
||||
import com.facebook.react.bridge.ReadableMap;
|
||||
import com.facebook.react.bridge.ReadableNativeMap;
|
||||
import com.facebook.react.common.annotations.VisibleForTesting;
|
||||
import com.facebook.react.module.annotations.ReactModule;
|
||||
import com.facebook.react.uimanager.ReactStylesDiffMap;
|
||||
import com.facebook.react.uimanager.ThemedReactContext;
|
||||
import java.util.Map;
|
||||
import javax.annotation.Nullable;
|
||||
@@ -65,6 +69,35 @@ public class ReactTextViewManager
|
||||
view.updateView();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object updateLocalData(ReactTextView view, ReactStylesDiffMap props, ReactStylesDiffMap localData) {
|
||||
ReadableMap attributedString = localData.getMap("attributedString");
|
||||
ReadableArray fragments = attributedString.getArray("fragments");
|
||||
String string = attributedString.getString("string");
|
||||
|
||||
Spannable spanned = TextLayoutManager.spannedFromTextFragments(view.getContext(),
|
||||
fragments, string);
|
||||
view.setSpanned(spanned);
|
||||
|
||||
TextAttributeProps textViewProps = new TextAttributeProps(props);
|
||||
|
||||
// TODO add textBreakStrategy prop into local Data
|
||||
int textBreakStrategy = Layout.BREAK_STRATEGY_HIGH_QUALITY;
|
||||
|
||||
return
|
||||
new ReactTextUpdate(
|
||||
spanned,
|
||||
-1, // TODO add this into local Data?
|
||||
false, // TODO add this into local Data
|
||||
textViewProps.getStartPadding(),
|
||||
textViewProps.getTopPadding(),
|
||||
textViewProps.getEndPadding(),
|
||||
textViewProps.getBottomPadding(),
|
||||
textViewProps.getTextAlign(),
|
||||
textBreakStrategy
|
||||
);
|
||||
}
|
||||
|
||||
@Override
|
||||
public @Nullable Map getExportedCustomDirectEventTypeConstants() {
|
||||
return MapBuilder.of("topTextLayout", MapBuilder.of("registrationName", "onTextLayout"));
|
||||
|
||||
@@ -241,10 +241,10 @@ public class TextAttributeProps {
|
||||
public void setBackgroundColor(Integer color) {
|
||||
//TODO: Don't apply background color to anchor TextView since it will be applied on the View directly
|
||||
//if (!isVirtualAnchor()) {
|
||||
mIsBackgroundColorSet = (color != null);
|
||||
if (mIsBackgroundColorSet) {
|
||||
mBackgroundColor = color;
|
||||
}
|
||||
mIsBackgroundColorSet = (color != null);
|
||||
if (mIsBackgroundColorSet) {
|
||||
mBackgroundColor = color;
|
||||
}
|
||||
//}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user