mirror of
https://github.com/facebook/react-native.git
synced 2025-11-01 09:14:26 +00:00
Adapt ReadableMapBuffer to MapBuffer interface
Summary: Updates `ReadableMapBuffer` to conform to `MapBuffer` interface, to allow interchangeable use of `Readable/WritableMapBuffer` in the code. Notable changes: - MapBuffer.Entry getters are now represented as Kotlin properties and appended `Value` suffix (e.g. `entry.getInt()` becomes `entry.getIntValue()` in Java, or `entry.intValue` in Kotlin) - `ByteBuffer` is imported in constructor instead of on demand. This method doesn't copy the data as the bytes are read directly from native heap, and benchmarking a 500-byte `MapBuffer` shows no difference in import speed. - Internal logic of `ReadableMapBuffer` uses `UShort` kotlin type for key retrieval, for more correct representation of values. - Explicit exception throws are replaced with `require` and `check` methods for `IllegalArgumentException` and `IllegalStateException` (default FB conversion). The change also updates `ReadableMapBuffer` usages to `MapBuffer` interface where possible (virtually everywhere except JNI methods). Changelog: [Android][Changed] - Adopt `MapBuffer` interface for `ReadableMapBuffer` Reviewed By: mdvacca Differential Revision: D35218633 fbshipit-source-id: 515dd974c27b2978ade325b2e1750ab8f068a20a
This commit is contained in:
committed by
Facebook GitHub Bot
parent
cf6f3b680b
commit
81e4249315
@@ -9,6 +9,8 @@ rn_android_library(
|
||||
"pfh:ReactNative_CommonInfrastructurePlaceholde",
|
||||
"supermodule:xplat/default/public.react_native.infra",
|
||||
],
|
||||
language = "KOTLIN",
|
||||
pure_kotlin = False,
|
||||
required_for_source_only_abi = True,
|
||||
visibility = [
|
||||
"PUBLIC",
|
||||
|
||||
@@ -15,7 +15,7 @@ import com.facebook.react.bridge.ReadableMap;
|
||||
import com.facebook.react.bridge.ReadableNativeMap;
|
||||
import com.facebook.react.common.MapBuilder;
|
||||
import com.facebook.react.common.annotations.VisibleForTesting;
|
||||
import com.facebook.react.common.mapbuffer.ReadableMapBuffer;
|
||||
import com.facebook.react.common.mapbuffer.MapBuffer;
|
||||
import com.facebook.react.config.ReactFeatureFlags;
|
||||
import com.facebook.react.module.annotations.ReactModule;
|
||||
import com.facebook.react.uimanager.IViewManagerWithChildren;
|
||||
@@ -112,7 +112,7 @@ public class ReactTextViewManager
|
||||
}
|
||||
|
||||
if (ReactFeatureFlags.isMapBufferSerializationEnabled()) {
|
||||
ReadableMapBuffer stateMapBuffer = stateWrapper.getStateDataMapBuffer();
|
||||
MapBuffer stateMapBuffer = stateWrapper.getStateDataMapBuffer();
|
||||
if (stateMapBuffer != null) {
|
||||
return getReactTextUpdate(view, props, stateMapBuffer);
|
||||
}
|
||||
@@ -142,11 +142,10 @@ public class ReactTextViewManager
|
||||
TextAttributeProps.getJustificationMode(props));
|
||||
}
|
||||
|
||||
private Object getReactTextUpdate(
|
||||
ReactTextView view, ReactStylesDiffMap props, ReadableMapBuffer state) {
|
||||
private Object getReactTextUpdate(ReactTextView view, ReactStylesDiffMap props, MapBuffer state) {
|
||||
|
||||
ReadableMapBuffer attributedString = state.getMapBuffer(TX_STATE_KEY_ATTRIBUTED_STRING);
|
||||
ReadableMapBuffer paragraphAttributes = state.getMapBuffer(TX_STATE_KEY_PARAGRAPH_ATTRIBUTES);
|
||||
MapBuffer attributedString = state.getMapBuffer(TX_STATE_KEY_ATTRIBUTED_STRING);
|
||||
MapBuffer paragraphAttributes = state.getMapBuffer(TX_STATE_KEY_PARAGRAPH_ATTRIBUTES);
|
||||
Spannable spanned =
|
||||
TextLayoutManagerMapBuffer.getOrCreateSpannableForText(
|
||||
view.getContext(), attributedString, mReactTextViewManagerCallback);
|
||||
@@ -205,9 +204,9 @@ public class ReactTextViewManager
|
||||
@Override
|
||||
public long measure(
|
||||
Context context,
|
||||
ReadableMapBuffer localData,
|
||||
ReadableMapBuffer props,
|
||||
@Nullable ReadableMapBuffer state,
|
||||
MapBuffer localData,
|
||||
MapBuffer props,
|
||||
@Nullable MapBuffer state,
|
||||
float width,
|
||||
YogaMeasureMode widthMode,
|
||||
float height,
|
||||
|
||||
@@ -16,7 +16,7 @@ import androidx.annotation.Nullable;
|
||||
import com.facebook.react.bridge.JSApplicationIllegalArgumentException;
|
||||
import com.facebook.react.bridge.ReadableArray;
|
||||
import com.facebook.react.bridge.ReadableMap;
|
||||
import com.facebook.react.common.mapbuffer.ReadableMapBuffer;
|
||||
import com.facebook.react.common.mapbuffer.MapBuffer;
|
||||
import com.facebook.react.uimanager.PixelUtil;
|
||||
import com.facebook.react.uimanager.ReactAccessibilityDelegate;
|
||||
import com.facebook.react.uimanager.ReactStylesDiffMap;
|
||||
@@ -137,51 +137,48 @@ public class TextAttributeProps {
|
||||
|
||||
private TextAttributeProps() {}
|
||||
|
||||
/**
|
||||
* Build a TextAttributeProps using data from the {@link ReadableMapBuffer} received as a
|
||||
* parameter.
|
||||
*/
|
||||
public static TextAttributeProps fromReadableMapBuffer(ReadableMapBuffer props) {
|
||||
/** Build a TextAttributeProps using data from the {@link MapBuffer} received as a parameter. */
|
||||
public static TextAttributeProps fromMapBuffer(MapBuffer props) {
|
||||
TextAttributeProps result = new TextAttributeProps();
|
||||
|
||||
// TODO T83483191: Review constants that are not being set!
|
||||
Iterator<ReadableMapBuffer.MapBufferEntry> iterator = props.iterator();
|
||||
Iterator<MapBuffer.Entry> iterator = props.iterator();
|
||||
while (iterator.hasNext()) {
|
||||
ReadableMapBuffer.MapBufferEntry entry = iterator.next();
|
||||
MapBuffer.Entry entry = iterator.next();
|
||||
switch (entry.getKey()) {
|
||||
case TA_KEY_FOREGROUND_COLOR:
|
||||
result.setColor(entry.getInt());
|
||||
result.setColor(entry.getIntValue());
|
||||
break;
|
||||
case TA_KEY_BACKGROUND_COLOR:
|
||||
result.setBackgroundColor(entry.getInt());
|
||||
result.setBackgroundColor(entry.getIntValue());
|
||||
break;
|
||||
case TA_KEY_OPACITY:
|
||||
break;
|
||||
case TA_KEY_FONT_FAMILY:
|
||||
result.setFontFamily(entry.getString());
|
||||
result.setFontFamily(entry.getStringValue());
|
||||
break;
|
||||
case TA_KEY_FONT_SIZE:
|
||||
result.setFontSize((float) entry.getDouble());
|
||||
result.setFontSize((float) entry.getDoubleValue());
|
||||
break;
|
||||
case TA_KEY_FONT_SIZE_MULTIPLIER:
|
||||
break;
|
||||
case TA_KEY_FONT_WEIGHT:
|
||||
result.setFontWeight(entry.getString());
|
||||
result.setFontWeight(entry.getStringValue());
|
||||
break;
|
||||
case TA_KEY_FONT_STYLE:
|
||||
result.setFontStyle(entry.getString());
|
||||
result.setFontStyle(entry.getStringValue());
|
||||
break;
|
||||
case TA_KEY_FONT_VARIANT:
|
||||
result.setFontVariant(entry.getReadableMapBuffer());
|
||||
result.setFontVariant(entry.getMapBufferValue());
|
||||
break;
|
||||
case TA_KEY_ALLOW_FONT_SCALING:
|
||||
result.setAllowFontScaling(entry.getBoolean());
|
||||
result.setAllowFontScaling(entry.getBooleanValue());
|
||||
break;
|
||||
case TA_KEY_LETTER_SPACING:
|
||||
result.setLetterSpacing((float) entry.getDouble());
|
||||
result.setLetterSpacing((float) entry.getDoubleValue());
|
||||
break;
|
||||
case TA_KEY_LINE_HEIGHT:
|
||||
result.setLineHeight((float) entry.getDouble());
|
||||
result.setLineHeight((float) entry.getDoubleValue());
|
||||
break;
|
||||
case TA_KEY_ALIGNMENT:
|
||||
break;
|
||||
@@ -190,23 +187,23 @@ public class TextAttributeProps {
|
||||
case TA_KEY_TEXT_DECORATION_COLOR:
|
||||
break;
|
||||
case TA_KEY_TEXT_DECORATION_LINE:
|
||||
result.setTextDecorationLine(entry.getString());
|
||||
result.setTextDecorationLine(entry.getStringValue());
|
||||
break;
|
||||
case TA_KEY_TEXT_DECORATION_STYLE:
|
||||
break;
|
||||
case TA_KEY_TEXT_SHADOW_RADIUS:
|
||||
result.setTextShadowRadius((float) entry.getDouble());
|
||||
result.setTextShadowRadius((float) entry.getDoubleValue());
|
||||
break;
|
||||
case TA_KEY_TEXT_SHADOW_COLOR:
|
||||
result.setTextShadowColor(entry.getInt());
|
||||
result.setTextShadowColor(entry.getIntValue());
|
||||
break;
|
||||
case TA_KEY_IS_HIGHLIGHTED:
|
||||
break;
|
||||
case TA_KEY_LAYOUT_DIRECTION:
|
||||
result.setLayoutDirection(entry.getString());
|
||||
result.setLayoutDirection(entry.getStringValue());
|
||||
break;
|
||||
case TA_KEY_ACCESSIBILITY_ROLE:
|
||||
result.setAccessibilityRole(entry.getString());
|
||||
result.setAccessibilityRole(entry.getStringValue());
|
||||
break;
|
||||
}
|
||||
}
|
||||
@@ -419,17 +416,17 @@ public class TextAttributeProps {
|
||||
mFontFeatureSettings = ReactTypefaceUtils.parseFontVariant(fontVariant);
|
||||
}
|
||||
|
||||
private void setFontVariant(@Nullable ReadableMapBuffer fontVariant) {
|
||||
private void setFontVariant(@Nullable MapBuffer fontVariant) {
|
||||
if (fontVariant == null || fontVariant.getCount() == 0) {
|
||||
mFontFeatureSettings = null;
|
||||
return;
|
||||
}
|
||||
|
||||
List<String> features = new ArrayList<>();
|
||||
Iterator<ReadableMapBuffer.MapBufferEntry> iterator = fontVariant.iterator();
|
||||
Iterator<MapBuffer.Entry> iterator = fontVariant.iterator();
|
||||
while (iterator.hasNext()) {
|
||||
ReadableMapBuffer.MapBufferEntry entry = iterator.next();
|
||||
String value = entry.getString();
|
||||
MapBuffer.Entry entry = iterator.next();
|
||||
String value = entry.getStringValue();
|
||||
if (value != null) {
|
||||
switch (value) {
|
||||
case "small-caps":
|
||||
|
||||
+21
-24
@@ -28,7 +28,7 @@ import com.facebook.react.bridge.ReactNoCrashSoftException;
|
||||
import com.facebook.react.bridge.ReactSoftExceptionLogger;
|
||||
import com.facebook.react.bridge.WritableArray;
|
||||
import com.facebook.react.common.build.ReactBuildConfig;
|
||||
import com.facebook.react.common.mapbuffer.ReadableMapBuffer;
|
||||
import com.facebook.react.common.mapbuffer.MapBuffer;
|
||||
import com.facebook.react.uimanager.PixelUtil;
|
||||
import com.facebook.yoga.YogaConstants;
|
||||
import com.facebook.yoga.YogaMeasureMode;
|
||||
@@ -78,7 +78,7 @@ public class TextLayoutManagerMapBuffer {
|
||||
|
||||
private static final Object sSpannableCacheLock = new Object();
|
||||
private static final boolean DEFAULT_INCLUDE_FONT_PADDING = true;
|
||||
private static final LruCache<ReadableMapBuffer, Spannable> sSpannableCache =
|
||||
private static final LruCache<MapBuffer, Spannable> sSpannableCache =
|
||||
new LruCache<>(spannableCacheSize);
|
||||
private static final ConcurrentHashMap<Integer, Spannable> sTagToSpannableCache =
|
||||
new ConcurrentHashMap<>();
|
||||
@@ -97,39 +97,36 @@ public class TextLayoutManagerMapBuffer {
|
||||
sTagToSpannableCache.remove(reactTag);
|
||||
}
|
||||
|
||||
public static boolean isRTL(ReadableMapBuffer attributedString) {
|
||||
ReadableMapBuffer fragments = attributedString.getMapBuffer(AS_KEY_FRAGMENTS);
|
||||
public static boolean isRTL(MapBuffer attributedString) {
|
||||
MapBuffer fragments = attributedString.getMapBuffer(AS_KEY_FRAGMENTS);
|
||||
if (fragments.getCount() == 0) {
|
||||
return false;
|
||||
}
|
||||
|
||||
ReadableMapBuffer fragment = fragments.getMapBuffer((short) 0);
|
||||
ReadableMapBuffer textAttributes = fragment.getMapBuffer(FR_KEY_TEXT_ATTRIBUTES);
|
||||
MapBuffer fragment = fragments.getMapBuffer((short) 0);
|
||||
MapBuffer textAttributes = fragment.getMapBuffer(FR_KEY_TEXT_ATTRIBUTES);
|
||||
return TextAttributeProps.getLayoutDirection(
|
||||
textAttributes.getString(TextAttributeProps.TA_KEY_LAYOUT_DIRECTION))
|
||||
== LayoutDirection.RTL;
|
||||
}
|
||||
|
||||
private static void buildSpannableFromFragment(
|
||||
Context context,
|
||||
ReadableMapBuffer fragments,
|
||||
SpannableStringBuilder sb,
|
||||
List<SetSpanOperation> ops) {
|
||||
Context context, MapBuffer fragments, SpannableStringBuilder sb, List<SetSpanOperation> ops) {
|
||||
|
||||
for (int i = 0, length = fragments.getCount(); i < length; i++) {
|
||||
ReadableMapBuffer fragment = fragments.getMapBuffer(i);
|
||||
MapBuffer fragment = fragments.getMapBuffer(i);
|
||||
int start = sb.length();
|
||||
|
||||
TextAttributeProps textAttributes =
|
||||
TextAttributeProps.fromReadableMapBuffer(fragment.getMapBuffer(FR_KEY_TEXT_ATTRIBUTES));
|
||||
TextAttributeProps.fromMapBuffer(fragment.getMapBuffer(FR_KEY_TEXT_ATTRIBUTES));
|
||||
|
||||
sb.append(
|
||||
TextTransform.apply(fragment.getString(FR_KEY_STRING), textAttributes.mTextTransform));
|
||||
|
||||
int end = sb.length();
|
||||
int reactTag =
|
||||
fragment.hasKey(FR_KEY_REACT_TAG) ? fragment.getInt(FR_KEY_REACT_TAG) : View.NO_ID;
|
||||
if (fragment.hasKey(FR_KEY_IS_ATTACHMENT) && fragment.getBoolean(FR_KEY_IS_ATTACHMENT)) {
|
||||
fragment.contains(FR_KEY_REACT_TAG) ? fragment.getInt(FR_KEY_REACT_TAG) : View.NO_ID;
|
||||
if (fragment.contains(FR_KEY_IS_ATTACHMENT) && fragment.getBoolean(FR_KEY_IS_ATTACHMENT)) {
|
||||
float width = PixelUtil.toPixelFromSP(fragment.getDouble(FR_KEY_WIDTH));
|
||||
float height = PixelUtil.toPixelFromSP(fragment.getDouble(FR_KEY_HEIGHT));
|
||||
ops.add(
|
||||
@@ -203,7 +200,7 @@ public class TextLayoutManagerMapBuffer {
|
||||
// public because both ReactTextViewManager and ReactTextInputManager need to use this
|
||||
public static Spannable getOrCreateSpannableForText(
|
||||
Context context,
|
||||
ReadableMapBuffer attributedString,
|
||||
MapBuffer attributedString,
|
||||
@Nullable ReactTextViewManagerCallback reactTextViewManagerCallback) {
|
||||
|
||||
Spannable preparedSpannableText;
|
||||
@@ -228,7 +225,7 @@ public class TextLayoutManagerMapBuffer {
|
||||
|
||||
private static Spannable createSpannableFromAttributedString(
|
||||
Context context,
|
||||
ReadableMapBuffer attributedString,
|
||||
MapBuffer attributedString,
|
||||
@Nullable ReactTextViewManagerCallback reactTextViewManagerCallback) {
|
||||
|
||||
SpannableStringBuilder sb = new SpannableStringBuilder();
|
||||
@@ -351,8 +348,8 @@ public class TextLayoutManagerMapBuffer {
|
||||
|
||||
public static long measureText(
|
||||
Context context,
|
||||
ReadableMapBuffer attributedString,
|
||||
ReadableMapBuffer paragraphAttributes,
|
||||
MapBuffer attributedString,
|
||||
MapBuffer paragraphAttributes,
|
||||
float width,
|
||||
YogaMeasureMode widthYogaMeasureMode,
|
||||
float height,
|
||||
@@ -363,7 +360,7 @@ public class TextLayoutManagerMapBuffer {
|
||||
// TODO(5578671): Handle text direction (see View#getTextDirectionHeuristic)
|
||||
TextPaint textPaint = sTextPaintInstance;
|
||||
Spannable text;
|
||||
if (attributedString.hasKey(AS_KEY_CACHE_ID)) {
|
||||
if (attributedString.contains(AS_KEY_CACHE_ID)) {
|
||||
int cacheId = attributedString.getInt(AS_KEY_CACHE_ID);
|
||||
if (ENABLE_MEASURE_LOGGING) {
|
||||
FLog.e(TAG, "Get cached spannable for cacheId[" + cacheId + "]");
|
||||
@@ -387,7 +384,7 @@ public class TextLayoutManagerMapBuffer {
|
||||
TextAttributeProps.getTextBreakStrategy(
|
||||
paragraphAttributes.getString(PA_KEY_TEXT_BREAK_STRATEGY));
|
||||
boolean includeFontPadding =
|
||||
paragraphAttributes.hasKey(PA_KEY_INCLUDE_FONT_PADDING)
|
||||
paragraphAttributes.contains(PA_KEY_INCLUDE_FONT_PADDING)
|
||||
? paragraphAttributes.getBoolean(PA_KEY_INCLUDE_FONT_PADDING)
|
||||
: DEFAULT_INCLUDE_FONT_PADDING;
|
||||
int hyphenationFrequency =
|
||||
@@ -415,7 +412,7 @@ public class TextLayoutManagerMapBuffer {
|
||||
hyphenationFrequency);
|
||||
|
||||
int maximumNumberOfLines =
|
||||
paragraphAttributes.hasKey(PA_KEY_MAX_NUMBER_OF_LINES)
|
||||
paragraphAttributes.contains(PA_KEY_MAX_NUMBER_OF_LINES)
|
||||
? paragraphAttributes.getInt(PA_KEY_MAX_NUMBER_OF_LINES)
|
||||
: UNSET;
|
||||
|
||||
@@ -554,8 +551,8 @@ public class TextLayoutManagerMapBuffer {
|
||||
|
||||
public static WritableArray measureLines(
|
||||
@NonNull Context context,
|
||||
ReadableMapBuffer attributedString,
|
||||
ReadableMapBuffer paragraphAttributes,
|
||||
MapBuffer attributedString,
|
||||
MapBuffer paragraphAttributes,
|
||||
float width) {
|
||||
|
||||
TextPaint textPaint = sTextPaintInstance;
|
||||
@@ -566,7 +563,7 @@ public class TextLayoutManagerMapBuffer {
|
||||
TextAttributeProps.getTextBreakStrategy(
|
||||
paragraphAttributes.getString(PA_KEY_TEXT_BREAK_STRATEGY));
|
||||
boolean includeFontPadding =
|
||||
paragraphAttributes.hasKey(PA_KEY_INCLUDE_FONT_PADDING)
|
||||
paragraphAttributes.contains(PA_KEY_INCLUDE_FONT_PADDING)
|
||||
? paragraphAttributes.getBoolean(PA_KEY_INCLUDE_FONT_PADDING)
|
||||
: DEFAULT_INCLUDE_FONT_PADDING;
|
||||
int hyphenationFrequency =
|
||||
|
||||
+58
-64
@@ -14,7 +14,7 @@ import com.facebook.react.bridge.DynamicFromObject
|
||||
import com.facebook.react.bridge.JavaOnlyArray
|
||||
import com.facebook.react.bridge.JavaOnlyMap
|
||||
import com.facebook.react.bridge.ReadableMap
|
||||
import com.facebook.react.common.mapbuffer.ReadableMapBuffer
|
||||
import com.facebook.react.common.mapbuffer.MapBuffer
|
||||
import com.facebook.react.uimanager.PixelUtil
|
||||
import com.facebook.react.uimanager.PointerEvents
|
||||
|
||||
@@ -97,134 +97,131 @@ object ReactMapBufferPropSetter {
|
||||
|
||||
private const val UNDEF_COLOR = Int.MAX_VALUE
|
||||
|
||||
fun setProps(view: ReactViewGroup, viewManager: ReactViewManager, props: ReadableMapBuffer) {
|
||||
fun setProps(view: ReactViewGroup, viewManager: ReactViewManager, props: MapBuffer) {
|
||||
for (entry in props) {
|
||||
when (entry.key) {
|
||||
VP_ACCESSIBILITY_ACTIONS -> {
|
||||
viewManager.accessibilityActions(view, entry.readableMapBuffer)
|
||||
viewManager.accessibilityActions(view, entry.mapBufferValue)
|
||||
}
|
||||
VP_ACCESSIBILITY_HINT -> {
|
||||
viewManager.setAccessibilityHint(view, entry.string.takeIf { it.isNotEmpty() })
|
||||
viewManager.setAccessibilityHint(view, entry.stringValue.takeIf { it.isNotEmpty() })
|
||||
}
|
||||
VP_ACCESSIBILITY_LABEL -> {
|
||||
viewManager.setAccessibilityLabel(view, entry.string.takeIf { it.isNotEmpty() })
|
||||
viewManager.setAccessibilityLabel(view, entry.stringValue.takeIf { it.isNotEmpty() })
|
||||
}
|
||||
VP_ACCESSIBILITY_LABELLED_BY -> {
|
||||
viewManager.accessibilityLabelledBy(view, entry.readableMapBuffer)
|
||||
viewManager.accessibilityLabelledBy(view, entry.mapBufferValue)
|
||||
}
|
||||
VP_ACCESSIBILITY_LIVE_REGION -> {
|
||||
view.accessibilityLiveRegion(entry.int)
|
||||
view.accessibilityLiveRegion(entry.intValue)
|
||||
}
|
||||
VP_ACCESSIBILITY_ROLE -> {
|
||||
viewManager.setAccessibilityRole(view, entry.string.takeIf { it.isNotEmpty() })
|
||||
viewManager.setAccessibilityRole(view, entry.stringValue.takeIf { it.isNotEmpty() })
|
||||
}
|
||||
VP_ACCESSIBILITY_STATE -> {
|
||||
viewManager.accessibilityState(view, entry.readableMapBuffer)
|
||||
viewManager.accessibilityState(view, entry.mapBufferValue)
|
||||
}
|
||||
VP_ACCESSIBILITY_VALUE -> {
|
||||
viewManager.accessibilityValue(view, entry.string)
|
||||
viewManager.accessibilityValue(view, entry.stringValue)
|
||||
}
|
||||
VP_ACCESSIBLE -> {
|
||||
viewManager.setAccessible(view, entry.boolean)
|
||||
viewManager.setAccessible(view, entry.booleanValue)
|
||||
}
|
||||
VP_BACKFACE_VISIBILITY -> {
|
||||
viewManager.backfaceVisibility(view, entry.int)
|
||||
viewManager.backfaceVisibility(view, entry.intValue)
|
||||
}
|
||||
VP_BG_COLOR -> {
|
||||
// TODO: color for some reason can be object in Java but not in C++
|
||||
viewManager.backgroundColor(view, entry.int)
|
||||
viewManager.backgroundColor(view, entry.intValue)
|
||||
}
|
||||
VP_BORDER_COLOR -> {
|
||||
viewManager.borderColor(view, entry.readableMapBuffer)
|
||||
viewManager.borderColor(view, entry.mapBufferValue)
|
||||
}
|
||||
VP_BORDER_RADII -> {
|
||||
viewManager.borderRadius(view, entry.readableMapBuffer)
|
||||
viewManager.borderRadius(view, entry.mapBufferValue)
|
||||
}
|
||||
VP_BORDER_STYLE -> {
|
||||
viewManager.borderStyle(view, entry.int)
|
||||
viewManager.borderStyle(view, entry.intValue)
|
||||
}
|
||||
VP_ELEVATION -> {
|
||||
viewManager.setElevation(view, entry.double.toFloat())
|
||||
viewManager.setElevation(view, entry.doubleValue.toFloat())
|
||||
}
|
||||
VP_FOCUSABLE -> {
|
||||
viewManager.setFocusable(view, entry.boolean)
|
||||
viewManager.setFocusable(view, entry.booleanValue)
|
||||
}
|
||||
VP_HAS_TV_FOCUS -> {
|
||||
viewManager.setTVPreferredFocus(view, entry.boolean)
|
||||
viewManager.setTVPreferredFocus(view, entry.booleanValue)
|
||||
}
|
||||
VP_HIT_SLOP -> {
|
||||
view.hitSlop(entry.readableMapBuffer)
|
||||
view.hitSlop(entry.mapBufferValue)
|
||||
}
|
||||
VP_IMPORTANT_FOR_ACCESSIBILITY -> {
|
||||
view.importantForAccessibility(entry.int)
|
||||
view.importantForAccessibility(entry.intValue)
|
||||
}
|
||||
VP_NATIVE_BACKGROUND -> {
|
||||
viewManager.nativeBackground(view, entry.readableMapBuffer)
|
||||
viewManager.nativeBackground(view, entry.mapBufferValue)
|
||||
}
|
||||
VP_NATIVE_FOREGROUND -> {
|
||||
viewManager.nativeForeground(view, entry.readableMapBuffer)
|
||||
viewManager.nativeForeground(view, entry.mapBufferValue)
|
||||
}
|
||||
VP_NATIVE_ID -> {
|
||||
viewManager.setNativeId(view, entry.string.takeIf { it.isNotEmpty() })
|
||||
viewManager.setNativeId(view, entry.stringValue.takeIf { it.isNotEmpty() })
|
||||
}
|
||||
VP_OFFSCREEN_ALPHA_COMPOSITING -> {
|
||||
viewManager.setNeedsOffscreenAlphaCompositing(view, entry.boolean)
|
||||
viewManager.setNeedsOffscreenAlphaCompositing(view, entry.booleanValue)
|
||||
}
|
||||
VP_OPACITY -> {
|
||||
viewManager.setOpacity(view, entry.double.toFloat())
|
||||
viewManager.setOpacity(view, entry.doubleValue.toFloat())
|
||||
}
|
||||
VP_POINTER_EVENTS -> {
|
||||
view.pointerEvents(entry.int)
|
||||
view.pointerEvents(entry.intValue)
|
||||
}
|
||||
VP_POINTER_ENTER -> {
|
||||
viewManager.setPointerEnter(view, entry.boolean)
|
||||
viewManager.setPointerEnter(view, entry.booleanValue)
|
||||
}
|
||||
VP_POINTER_LEAVE -> {
|
||||
viewManager.setPointerLeave(view, entry.boolean)
|
||||
viewManager.setPointerLeave(view, entry.booleanValue)
|
||||
}
|
||||
VP_POINTER_MOVE -> {
|
||||
viewManager.setPointerMove(view, entry.boolean)
|
||||
viewManager.setPointerMove(view, entry.booleanValue)
|
||||
}
|
||||
VP_REMOVE_CLIPPED_SUBVIEW -> {
|
||||
viewManager.setRemoveClippedSubviews(view, entry.boolean)
|
||||
viewManager.setRemoveClippedSubviews(view, entry.booleanValue)
|
||||
}
|
||||
VP_RENDER_TO_HARDWARE_TEXTURE -> {
|
||||
viewManager.setRenderToHardwareTexture(view, entry.boolean)
|
||||
viewManager.setRenderToHardwareTexture(view, entry.booleanValue)
|
||||
}
|
||||
VP_SHADOW_COLOR -> {
|
||||
// TODO: color for some reason can be object in Java but not in C++
|
||||
viewManager.shadowColor(view, entry.int)
|
||||
viewManager.shadowColor(view, entry.intValue)
|
||||
}
|
||||
VP_TEST_ID -> {
|
||||
viewManager.setTestId(view, entry.string.takeIf { it.isNotEmpty() })
|
||||
viewManager.setTestId(view, entry.stringValue.takeIf { it.isNotEmpty() })
|
||||
}
|
||||
VP_TRANSFORM -> {
|
||||
viewManager.transform(view, entry.readableMapBuffer)
|
||||
viewManager.transform(view, entry.mapBufferValue)
|
||||
}
|
||||
VP_ZINDEX -> {
|
||||
viewManager.setZIndex(view, entry.int.toFloat())
|
||||
viewManager.setZIndex(view, entry.intValue.toFloat())
|
||||
}
|
||||
YG_BORDER_WIDTH -> {
|
||||
viewManager.borderWidth(view, entry.readableMapBuffer)
|
||||
viewManager.borderWidth(view, entry.mapBufferValue)
|
||||
}
|
||||
YG_OVERFLOW -> {
|
||||
viewManager.overflow(view, entry.int)
|
||||
viewManager.overflow(view, entry.intValue)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private fun ReactViewManager.accessibilityActions(
|
||||
view: ReactViewGroup,
|
||||
mapBuffer: ReadableMapBuffer
|
||||
) {
|
||||
private fun ReactViewManager.accessibilityActions(view: ReactViewGroup, mapBuffer: MapBuffer) {
|
||||
val actions = mutableListOf<ReadableMap>()
|
||||
for (entry in mapBuffer) {
|
||||
val map = JavaOnlyMap()
|
||||
val action = entry.readableMapBuffer
|
||||
val action = entry.mapBufferValue
|
||||
if (action != null) {
|
||||
map.putString("name", action.getString(ACCESSIBILITY_ACTION_NAME))
|
||||
if (action.hasKey(ACCESSIBILITY_ACTION_LABEL)) {
|
||||
if (action.contains(ACCESSIBILITY_ACTION_LABEL)) {
|
||||
map.putString("label", action.getString(ACCESSIBILITY_ACTION_LABEL))
|
||||
}
|
||||
}
|
||||
@@ -245,7 +242,7 @@ object ReactMapBufferPropSetter {
|
||||
ViewCompat.setAccessibilityLiveRegion(this, mode)
|
||||
}
|
||||
|
||||
private fun ReactViewManager.accessibilityState(view: ReactViewGroup, value: ReadableMapBuffer) {
|
||||
private fun ReactViewManager.accessibilityState(view: ReactViewGroup, value: MapBuffer) {
|
||||
val accessibilityState = JavaOnlyMap()
|
||||
accessibilityState.putBoolean("selected", value.getBoolean(ACCESSIBILITY_STATE_SELECTED))
|
||||
accessibilityState.putBoolean("busy", value.getBoolean(ACCESSIBILITY_STATE_BUSY))
|
||||
@@ -273,17 +270,14 @@ object ReactMapBufferPropSetter {
|
||||
setAccessibilityValue(view, map)
|
||||
}
|
||||
|
||||
private fun ReactViewManager.accessibilityLabelledBy(
|
||||
view: ReactViewGroup,
|
||||
value: ReadableMapBuffer
|
||||
) {
|
||||
private fun ReactViewManager.accessibilityLabelledBy(view: ReactViewGroup, value: MapBuffer) {
|
||||
val converted =
|
||||
if (value.count == 0) {
|
||||
DynamicFromObject(null)
|
||||
} else {
|
||||
val array = JavaOnlyArray()
|
||||
for (label in value) {
|
||||
array.pushString(label.string)
|
||||
array.pushString(label.stringValue)
|
||||
}
|
||||
DynamicFromObject(array)
|
||||
}
|
||||
@@ -306,7 +300,7 @@ object ReactMapBufferPropSetter {
|
||||
setBackgroundColor(view, color)
|
||||
}
|
||||
|
||||
private fun ReactViewManager.borderColor(view: ReactViewGroup, value: ReadableMapBuffer) {
|
||||
private fun ReactViewManager.borderColor(view: ReactViewGroup, value: MapBuffer) {
|
||||
for (entry in value) {
|
||||
val index =
|
||||
when (val key = entry.key) {
|
||||
@@ -319,12 +313,12 @@ object ReactMapBufferPropSetter {
|
||||
EDGE_END -> 6
|
||||
else -> throw IllegalArgumentException("Unknown key for border color: $key")
|
||||
}
|
||||
val colorValue = entry.int
|
||||
val colorValue = entry.intValue
|
||||
setBorderColor(view, index, colorValue.takeIf { it != -1 })
|
||||
}
|
||||
}
|
||||
|
||||
private fun ReactViewManager.borderRadius(view: ReactViewGroup, value: ReadableMapBuffer) {
|
||||
private fun ReactViewManager.borderRadius(view: ReactViewGroup, value: MapBuffer) {
|
||||
for (entry in value) {
|
||||
val index =
|
||||
when (val key = entry.key) {
|
||||
@@ -339,7 +333,7 @@ object ReactMapBufferPropSetter {
|
||||
CORNER_BOTTOM_END -> 8
|
||||
else -> throw IllegalArgumentException("Unknown key for border style: $key")
|
||||
}
|
||||
val borderRadius = entry.double
|
||||
val borderRadius = entry.doubleValue
|
||||
if (!borderRadius.isNaN()) {
|
||||
setBorderRadius(view, index, borderRadius.toFloat())
|
||||
}
|
||||
@@ -357,7 +351,7 @@ object ReactMapBufferPropSetter {
|
||||
setBorderStyle(view, stringValue)
|
||||
}
|
||||
|
||||
private fun ReactViewGroup.hitSlop(value: ReadableMapBuffer) {
|
||||
private fun ReactViewGroup.hitSlop(value: MapBuffer) {
|
||||
val rect =
|
||||
Rect(
|
||||
PixelUtil.toPixelFromDIP(value.getDouble(EDGE_LEFT)).toInt(),
|
||||
@@ -392,15 +386,15 @@ object ReactMapBufferPropSetter {
|
||||
setPointerEvents(pointerEvents)
|
||||
}
|
||||
|
||||
private fun ReactViewManager.transform(view: ReactViewGroup, value: ReadableMapBuffer) {
|
||||
private fun ReactViewManager.transform(view: ReactViewGroup, value: MapBuffer) {
|
||||
val list = JavaOnlyArray()
|
||||
for (entry in value) {
|
||||
list.pushDouble(entry.double)
|
||||
list.pushDouble(entry.doubleValue)
|
||||
}
|
||||
setTransform(view, list)
|
||||
}
|
||||
|
||||
private fun ReactViewManager.borderWidth(view: ReactViewGroup, value: ReadableMapBuffer) {
|
||||
private fun ReactViewManager.borderWidth(view: ReactViewGroup, value: MapBuffer) {
|
||||
for (entry in value) {
|
||||
val index =
|
||||
when (val key = entry.key) {
|
||||
@@ -413,7 +407,7 @@ object ReactMapBufferPropSetter {
|
||||
EDGE_END -> 6
|
||||
else -> throw IllegalArgumentException("Unknown key for border width: $key")
|
||||
}
|
||||
val borderWidth = entry.double
|
||||
val borderWidth = entry.doubleValue
|
||||
if (!borderWidth.isNaN()) {
|
||||
setBorderWidth(view, index, borderWidth.toFloat())
|
||||
}
|
||||
@@ -437,15 +431,15 @@ object ReactMapBufferPropSetter {
|
||||
setShadowColor(view, color)
|
||||
}
|
||||
|
||||
private fun ReactViewManager.nativeBackground(view: ReactViewGroup, value: ReadableMapBuffer) {
|
||||
private fun ReactViewManager.nativeBackground(view: ReactViewGroup, value: MapBuffer) {
|
||||
setNativeBackground(view, value.toJsDrawableDescription())
|
||||
}
|
||||
|
||||
private fun ReactViewManager.nativeForeground(view: ReactViewGroup, value: ReadableMapBuffer) {
|
||||
private fun ReactViewManager.nativeForeground(view: ReactViewGroup, value: MapBuffer) {
|
||||
setNativeForeground(view, value.toJsDrawableDescription())
|
||||
}
|
||||
|
||||
private fun ReadableMapBuffer.toJsDrawableDescription(): ReadableMap? {
|
||||
private fun MapBuffer.toJsDrawableDescription(): ReadableMap? {
|
||||
if (count == 0) {
|
||||
return null
|
||||
}
|
||||
@@ -459,11 +453,11 @@ object ReactMapBufferPropSetter {
|
||||
}
|
||||
1 -> {
|
||||
result.putString("type", "RippleAndroid")
|
||||
if (hasKey(NATIVE_DRAWABLE_COLOR)) {
|
||||
if (contains(NATIVE_DRAWABLE_COLOR)) {
|
||||
result.putInt("color", getInt(NATIVE_DRAWABLE_COLOR))
|
||||
}
|
||||
result.putBoolean("borderless", getBoolean(NATIVE_DRAWABLE_BORDERLESS))
|
||||
if (hasKey(NATIVE_DRAWABLE_RIPPLE_RADIUS)) {
|
||||
if (contains(NATIVE_DRAWABLE_RIPPLE_RADIUS)) {
|
||||
result.putDouble("rippleRadius", getDouble(NATIVE_DRAWABLE_RIPPLE_RADIUS))
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user