mirror of
https://github.com/status-im/react-native.git
synced 2025-01-27 09:45:04 +00: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:
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;
|
||||
}
|
||||
//}
|
||||
}
|
||||
|
||||
|
@ -7,6 +7,7 @@
|
||||
|
||||
#include "ParagraphLocalData.h"
|
||||
|
||||
#include <fabric/components/text/conversions.h>
|
||||
#include <fabric/debug/debugStringConvertibleUtils.h>
|
||||
|
||||
namespace facebook {
|
||||
@ -30,6 +31,10 @@ void ParagraphLocalData::setTextLayoutManager(SharedTextLayoutManager textLayout
|
||||
textLayoutManager_ = textLayoutManager;
|
||||
}
|
||||
|
||||
folly::dynamic ParagraphLocalData::getDynamic() const {
|
||||
return toDynamic(*this);
|
||||
}
|
||||
|
||||
#pragma mark - DebugStringConvertible
|
||||
|
||||
std::string ParagraphLocalData::getDebugName() const {
|
||||
|
@ -41,6 +41,8 @@ public:
|
||||
SharedTextLayoutManager getTextLayoutManager() const;
|
||||
void setTextLayoutManager(SharedTextLayoutManager textLayoutManager);
|
||||
|
||||
folly::dynamic getDynamic() const override;
|
||||
|
||||
#pragma mark - DebugStringConvertible
|
||||
|
||||
std::string getDebugName() const override;
|
||||
|
@ -9,6 +9,7 @@
|
||||
|
||||
#include <fabric/core/Sealable.h>
|
||||
#include <fabric/debug/DebugStringConvertible.h>
|
||||
#include <folly/dynamic.h>
|
||||
|
||||
namespace facebook {
|
||||
namespace react {
|
||||
@ -29,6 +30,10 @@ class LocalData:
|
||||
public Sealable,
|
||||
public DebugStringConvertible {
|
||||
|
||||
public:
|
||||
virtual folly::dynamic getDynamic() const {
|
||||
return folly::dynamic::object();
|
||||
};
|
||||
};
|
||||
|
||||
} // namespace react
|
||||
|
@ -7,6 +7,7 @@
|
||||
|
||||
#include "TextLayoutManager.h"
|
||||
|
||||
#include <fabric/attributedstring/conversions.h>
|
||||
#include <react/jni/ReadableNativeMap.h>
|
||||
|
||||
using namespace facebook::jni;
|
||||
@ -37,7 +38,7 @@ Size TextLayoutManager::measure(
|
||||
int width = (int) layoutConstraints.maximumSize.width;
|
||||
int height = (int) layoutConstraints.maximumSize.height;
|
||||
local_ref<JString> componentName = make_jstring("RCTText");
|
||||
auto values = measure(fabricUIManager, reactTag, componentName.get(), ReadableNativeMap::newObjectCxxArgs(attributedString.toDynamic()).get(), ReadableNativeMap::newObjectCxxArgs(paragraphAttributes.toDynamic()).get(), width, height);
|
||||
auto values = measure(fabricUIManager, reactTag, componentName.get(), ReadableNativeMap::newObjectCxxArgs(toDynamic(attributedString)).get(), ReadableNativeMap::newObjectCxxArgs(toDynamic(paragraphAttributes)).get(), width, height);
|
||||
|
||||
std::vector<float> indices;
|
||||
indices.resize(values->size());
|
||||
|
Loading…
x
Reference in New Issue
Block a user