From 94a9791f2f2513d9eeb4a0b80eb0d0d4ec080a2a Mon Sep 17 00:00:00 2001 From: Nick Gerleman Date: Thu, 25 Jan 2024 20:03:52 -0800 Subject: [PATCH] Remove unshipped view/layout props-parsing paths Summary: We are making some decently large changes around here, to transition Fabric away from Yoga's private API, and add new units, and CSS properties. Even confined to Fabric, we have a large matrix of different paths for parsing. This change consolidates layout props parsing to a single, tested path, used everywhere. Concretely, this means removing: 1. MapBuffer for ViewProps 2. Iterator style props parsing (for layout props only) MapBuffer for ViewProps to my understanding is not currently used at all, and has been live to edits, but untested, for quite some time. Iterator style props parsing is still enabled in some configurations, but we don't want to broadly ship its current form, and haven't been able to prioritize shipping it. Both MapBuffer, and iterator style props parser, are performance wins. If we look at seriously shipping one of these again, we should look at swapping out the current path. Changelog: [Internal] Reviewed By: mdvacca Differential Revision: D53072714 fbshipit-source-id: 0a737c8c8f50b1f2c5c0b7ff0415e84a26a06abb --- .../ReactAndroid/api/ReactAndroid.api | 20 - .../mounting/SurfaceMountingManager.java | 7 +- .../views/view/ReactMapBufferPropSetter.kt | 526 -------------- .../views/view/ReactMapBufferViewManager.kt | 76 -- .../components/view/AccessibilityProps.h | 5 - .../components/view/YogaStylableProps.cpp | 651 ++++++++++++++---- .../components/view/YogaStylableProps.h | 5 - .../view/AccessibilityPropsMapBuffer.cpp | 166 ----- .../view/AccessibilityPropsMapBuffer.h | 35 - .../components/view/HostPlatformViewProps.h | 3 - .../components/view/ViewPropsMapBuffer.cpp | 191 ----- .../components/view/ViewPropsMapBuffer.h | 51 -- .../view/YogaStylablePropsMapBuffer.cpp | 101 --- .../view/YogaStylablePropsMapBuffer.h | 22 - .../components/view/propsConversions.h | 518 -------------- .../components/view/viewPropConversions.h | 214 ------ .../ReactCommon/react/renderer/core/Props.cpp | 23 - .../ReactCommon/react/renderer/core/Props.h | 4 - 18 files changed, 509 insertions(+), 2109 deletions(-) delete mode 100644 packages/react-native/ReactAndroid/src/main/java/com/facebook/react/views/view/ReactMapBufferPropSetter.kt delete mode 100644 packages/react-native/ReactAndroid/src/main/java/com/facebook/react/views/view/ReactMapBufferViewManager.kt delete mode 100644 packages/react-native/ReactCommon/react/renderer/components/view/platform/android/react/renderer/components/view/AccessibilityPropsMapBuffer.cpp delete mode 100644 packages/react-native/ReactCommon/react/renderer/components/view/platform/android/react/renderer/components/view/AccessibilityPropsMapBuffer.h delete mode 100644 packages/react-native/ReactCommon/react/renderer/components/view/platform/android/react/renderer/components/view/ViewPropsMapBuffer.cpp delete mode 100644 packages/react-native/ReactCommon/react/renderer/components/view/platform/android/react/renderer/components/view/ViewPropsMapBuffer.h delete mode 100644 packages/react-native/ReactCommon/react/renderer/components/view/platform/android/react/renderer/components/view/YogaStylablePropsMapBuffer.cpp delete mode 100644 packages/react-native/ReactCommon/react/renderer/components/view/platform/android/react/renderer/components/view/YogaStylablePropsMapBuffer.h delete mode 100644 packages/react-native/ReactCommon/react/renderer/components/view/viewPropConversions.h diff --git a/packages/react-native/ReactAndroid/api/ReactAndroid.api b/packages/react-native/ReactAndroid/api/ReactAndroid.api index ed0695135a6..d6652f111ab 100644 --- a/packages/react-native/ReactAndroid/api/ReactAndroid.api +++ b/packages/react-native/ReactAndroid/api/ReactAndroid.api @@ -7574,26 +7574,6 @@ public class com/facebook/react/views/view/ReactDrawableHelper { public static fun createDrawableFromJSDescription (Landroid/content/Context;Lcom/facebook/react/bridge/ReadableMap;)Landroid/graphics/drawable/Drawable; } -public final class com/facebook/react/views/view/ReactMapBufferPropSetter { - public static final field INSTANCE Lcom/facebook/react/views/view/ReactMapBufferPropSetter; - public final fun setProps (Lcom/facebook/react/views/view/ReactViewGroup;Lcom/facebook/react/views/view/ReactViewManager;Lcom/facebook/react/common/mapbuffer/MapBuffer;)V -} - -public final class com/facebook/react/views/view/ReactMapBufferViewManager : com/facebook/react/views/view/ReactViewManagerWrapper { - public static final field INSTANCE Lcom/facebook/react/views/view/ReactMapBufferViewManager; - public fun createView (ILcom/facebook/react/uimanager/ThemedReactContext;Ljava/lang/Object;Lcom/facebook/react/uimanager/StateWrapper;Lcom/facebook/react/touch/JSResponderHandler;)Landroid/view/View; - public fun getName ()Ljava/lang/String; - public synthetic fun getViewGroupManager ()Lcom/facebook/react/uimanager/IViewGroupManager; - public fun getViewGroupManager ()Lcom/facebook/react/uimanager/ViewGroupManager; - public fun onDropViewInstance (Landroid/view/View;)V - public fun receiveCommand (Landroid/view/View;ILcom/facebook/react/bridge/ReadableArray;)V - public fun receiveCommand (Landroid/view/View;Ljava/lang/String;Lcom/facebook/react/bridge/ReadableArray;)V - public fun setPadding (Landroid/view/View;IIII)V - public fun updateExtraData (Landroid/view/View;Ljava/lang/Object;)V - public fun updateProperties (Landroid/view/View;Ljava/lang/Object;)V - public fun updateState (Landroid/view/View;Ljava/lang/Object;Lcom/facebook/react/uimanager/StateWrapper;)Ljava/lang/Object; -} - public class com/facebook/react/views/view/ReactViewBackgroundDrawable : android/graphics/drawable/Drawable { public fun (Landroid/content/Context;)V public fun draw (Landroid/graphics/Canvas;)V diff --git a/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/fabric/mounting/SurfaceMountingManager.java b/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/fabric/mounting/SurfaceMountingManager.java index 202ee4de6eb..4d1df189d50 100644 --- a/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/fabric/mounting/SurfaceMountingManager.java +++ b/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/fabric/mounting/SurfaceMountingManager.java @@ -30,7 +30,6 @@ import com.facebook.react.bridge.SoftAssertions; import com.facebook.react.bridge.UiThreadUtil; import com.facebook.react.bridge.WritableMap; import com.facebook.react.common.build.ReactBuildConfig; -import com.facebook.react.common.mapbuffer.ReadableMapBuffer; import com.facebook.react.config.ReactFeatureFlags; import com.facebook.react.fabric.GuardedFrameCallback; import com.facebook.react.fabric.events.EventEmitterWrapper; @@ -50,7 +49,6 @@ import com.facebook.react.uimanager.ThemedReactContext; import com.facebook.react.uimanager.ViewManager; import com.facebook.react.uimanager.ViewManagerRegistry; import com.facebook.react.uimanager.events.EventCategoryDef; -import com.facebook.react.views.view.ReactMapBufferViewManager; import com.facebook.react.views.view.ReactViewManagerWrapper; import java.util.ArrayDeque; import java.util.HashSet; @@ -833,10 +831,7 @@ public class SurfaceMountingManager { if (isLayoutable) { viewManager = - props instanceof ReadableMapBuffer - ? ReactMapBufferViewManager.INSTANCE - : new ReactViewManagerWrapper.DefaultViewManager( - mViewManagerRegistry.get(componentName)); + new ReactViewManagerWrapper.DefaultViewManager(mViewManagerRegistry.get(componentName)); // View Managers are responsible for dealing with initial state and props. view = viewManager.createView( diff --git a/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/views/view/ReactMapBufferPropSetter.kt b/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/views/view/ReactMapBufferPropSetter.kt deleted file mode 100644 index ef65868eca5..00000000000 --- a/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/views/view/ReactMapBufferPropSetter.kt +++ /dev/null @@ -1,526 +0,0 @@ -/* - * Copyright (c) Meta Platforms, Inc. and affiliates. - * - * This source code is licensed under the MIT license found in the - * LICENSE file in the root directory of this source tree. - */ - -package com.facebook.react.views.view - -import android.graphics.Color -import android.graphics.Rect -import androidx.core.view.ViewCompat -import com.facebook.react.R -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.MapBuffer -import com.facebook.react.uimanager.PixelUtil -import com.facebook.react.uimanager.PointerEvents -import com.facebook.react.uimanager.ReactAccessibilityDelegate.Role - -object ReactMapBufferPropSetter { - // ViewProps values - private const val VP_ACCESSIBILITY_ACTIONS = 0 - private const val VP_ACCESSIBILITY_HINT = 1 - private const val VP_ACCESSIBILITY_LABEL = 2 - private const val VP_ACCESSIBILITY_LABELLED_BY = 3 - private const val VP_ACCESSIBILITY_LIVE_REGION = 4 - private const val VP_ACCESSIBILITY_ROLE = 5 - private const val VP_ACCESSIBILITY_STATE = 6 - private const val VP_ACCESSIBILITY_VALUE = 7 - private const val VP_ACCESSIBLE = 8 - private const val VP_BACKFACE_VISIBILITY = 9 - private const val VP_BG_COLOR = 10 - private const val VP_BORDER_COLOR = 11 - private const val VP_BORDER_RADII = 12 - private const val VP_BORDER_STYLE = 13 - private const val VP_COLLAPSABLE = 14 - private const val VP_ELEVATION = 15 - private const val VP_FOCUSABLE = 16 - private const val VP_HAS_TV_FOCUS = 17 - private const val VP_HIT_SLOP = 18 - private const val VP_IMPORTANT_FOR_ACCESSIBILITY = 19 - private const val VP_NATIVE_BACKGROUND = 20 - private const val VP_NATIVE_FOREGROUND = 21 - private const val VP_NATIVE_ID = 22 - private const val VP_OFFSCREEN_ALPHA_COMPOSITING = 23 - private const val VP_OPACITY = 24 - private const val VP_POINTER_EVENTS = 25 - private const val VP_POINTER_ENTER = 26 - private const val VP_POINTER_LEAVE = 27 - private const val VP_POINTER_MOVE = 28 - private const val VP_REMOVE_CLIPPED_SUBVIEW = 29 - private const val VP_RENDER_TO_HARDWARE_TEXTURE = 30 - private const val VP_SHADOW_COLOR = 31 - private const val VP_TEST_ID = 32 - private const val VP_TRANSFORM = 33 - private const val VP_ZINDEX = 34 - private const val VP_POINTER_ENTER_CAPTURE = 38 - private const val VP_POINTER_LEAVE_CAPTURE = 39 - private const val VP_POINTER_MOVE_CAPTURE = 40 - private const val VP_POINTER_OUT = 41 - private const val VP_POINTER_OUT_CAPTURE = 42 - private const val VP_POINTER_OVER = 43 - private const val VP_POINTER_OVER_CAPTURE = 44 - private const val VP_BORDER_CURVES = 45 // iOS only - private const val VP_FG_COLOR = 46 // iOS only? - private const val VP_ROLE = 47 - - // Yoga values - private const val YG_BORDER_WIDTH = 100 - private const val YG_OVERFLOW = 101 - - // AccessibilityAction values - private const val ACCESSIBILITY_ACTION_NAME = 0 - private const val ACCESSIBILITY_ACTION_LABEL = 1 - - // AccessibilityState values - private const val ACCESSIBILITY_STATE_BUSY = 0 - private const val ACCESSIBILITY_STATE_DISABLED = 1 - private const val ACCESSIBILITY_STATE_EXPANDED = 2 - private const val ACCESSIBILITY_STATE_SELECTED = 3 - private const val ACCESSIBILITY_STATE_CHECKED = 4 - - private const val EDGE_TOP = 0 - private const val EDGE_LEFT = 1 - private const val EDGE_RIGHT = 2 - private const val EDGE_BOTTOM = 3 - private const val EDGE_START = 4 - private const val EDGE_END = 5 - private const val EDGE_ALL = 6 - private const val EDGE_BLOCK = 7 - private const val EDGE_BLOCK_END = 8 - private const val EDGE_BLOCK_START = 9 - - private const val CORNER_TOP_LEFT = 0 - private const val CORNER_TOP_RIGHT = 1 - private const val CORNER_BOTTOM_RIGHT = 2 - private const val CORNER_BOTTOM_LEFT = 3 - private const val CORNER_TOP_START = 4 - private const val CORNER_TOP_END = 5 - private const val CORNER_BOTTOM_END = 6 - private const val CORNER_BOTTOM_START = 7 - private const val CORNER_ALL = 8 - private const val CORNER_END_END = 9 - private const val CORNER_END_START = 10 - private const val CORNER_START_END = 11 - private const val CORNER_START_START = 12 - - private const val NATIVE_DRAWABLE_KIND = 0 - private const val NATIVE_DRAWABLE_ATTRIBUTE = 1 - private const val NATIVE_DRAWABLE_COLOR = 2 - private const val NATIVE_DRAWABLE_BORDERLESS = 3 - private const val NATIVE_DRAWABLE_RIPPLE_RADIUS = 4 - - private const val UNDEF_COLOR = Int.MAX_VALUE - - fun setProps(view: ReactViewGroup, viewManager: ReactViewManager, props: MapBuffer) { - for (entry in props) { - when (entry.key) { - VP_ACCESSIBILITY_ACTIONS -> { - viewManager.accessibilityActions(view, entry.mapBufferValue) - } - VP_ACCESSIBILITY_HINT -> { - viewManager.setAccessibilityHint(view, entry.stringValue.takeIf { it.isNotEmpty() }) - } - VP_ACCESSIBILITY_LABEL -> { - viewManager.setAccessibilityLabel(view, entry.stringValue.takeIf { it.isNotEmpty() }) - } - VP_ACCESSIBILITY_LABELLED_BY -> { - viewManager.accessibilityLabelledBy(view, entry.mapBufferValue) - } - VP_ACCESSIBILITY_LIVE_REGION -> { - view.accessibilityLiveRegion(entry.intValue) - } - VP_ACCESSIBILITY_ROLE -> { - viewManager.setAccessibilityRole(view, entry.stringValue.takeIf { it.isNotEmpty() }) - } - VP_ACCESSIBILITY_STATE -> { - viewManager.accessibilityState(view, entry.mapBufferValue) - } - VP_ACCESSIBILITY_VALUE -> { - viewManager.accessibilityValue(view, entry.stringValue) - } - VP_ACCESSIBLE -> { - viewManager.setAccessible(view, entry.booleanValue) - } - VP_BACKFACE_VISIBILITY -> { - 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.intValue) - } - VP_FG_COLOR -> { - // Prop not used on Android? - } - VP_BORDER_COLOR -> { - viewManager.borderColor(view, entry.mapBufferValue) - } - VP_BORDER_RADII -> { - viewManager.borderRadius(view, entry.mapBufferValue) - } - VP_BORDER_STYLE -> { - val styleBuffer = entry.mapBufferValue - if (styleBuffer.contains(CORNER_ALL)) { - viewManager.borderStyle(view, (styleBuffer.getDouble(CORNER_ALL)).toInt()) - } - } - VP_ELEVATION -> { - viewManager.setElevation(view, entry.doubleValue.toFloat()) - } - VP_FOCUSABLE -> { - viewManager.setFocusable(view, entry.booleanValue) - } - VP_HAS_TV_FOCUS -> { - viewManager.setTVPreferredFocus(view, entry.booleanValue) - } - VP_HIT_SLOP -> { - view.hitSlop(entry.mapBufferValue) - } - VP_IMPORTANT_FOR_ACCESSIBILITY -> { - view.importantForAccessibility(entry.intValue) - } - VP_ROLE -> { - view.role(entry.intValue) - } - VP_NATIVE_BACKGROUND -> { - viewManager.nativeBackground(view, entry.mapBufferValue) - } - VP_NATIVE_FOREGROUND -> { - viewManager.nativeForeground(view, entry.mapBufferValue) - } - VP_NATIVE_ID -> { - viewManager.setNativeId(view, entry.stringValue.takeIf { it.isNotEmpty() }) - } - VP_OFFSCREEN_ALPHA_COMPOSITING -> { - viewManager.setNeedsOffscreenAlphaCompositing(view, entry.booleanValue) - } - VP_OPACITY -> { - viewManager.setOpacity(view, entry.doubleValue.toFloat()) - } - VP_POINTER_EVENTS -> { - view.pointerEvents(entry.intValue) - } - VP_POINTER_ENTER -> { - viewManager.setPointerEnter(view, entry.booleanValue) - } - VP_POINTER_LEAVE -> { - viewManager.setPointerLeave(view, entry.booleanValue) - } - VP_POINTER_MOVE -> { - viewManager.setPointerMove(view, entry.booleanValue) - } - VP_POINTER_ENTER_CAPTURE -> { - viewManager.setPointerEnterCapture(view, entry.booleanValue) - } - VP_POINTER_LEAVE_CAPTURE -> { - viewManager.setPointerLeaveCapture(view, entry.booleanValue) - } - VP_POINTER_MOVE_CAPTURE -> { - viewManager.setPointerMoveCapture(view, entry.booleanValue) - } - VP_POINTER_OUT -> { - viewManager.setPointerOut(view, entry.booleanValue) - } - VP_POINTER_OUT_CAPTURE -> { - viewManager.setPointerOutCapture(view, entry.booleanValue) - } - VP_POINTER_OVER -> { - viewManager.setPointerOver(view, entry.booleanValue) - } - VP_POINTER_OVER_CAPTURE -> { - viewManager.setPointerOverCapture(view, entry.booleanValue) - } - VP_REMOVE_CLIPPED_SUBVIEW -> { - viewManager.setRemoveClippedSubviews(view, entry.booleanValue) - } - VP_RENDER_TO_HARDWARE_TEXTURE -> { - 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.intValue) - } - VP_TEST_ID -> { - viewManager.setTestId(view, entry.stringValue.takeIf { it.isNotEmpty() }) - } - VP_TRANSFORM -> { - viewManager.transform(view, entry.mapBufferValue) - } - VP_ZINDEX -> { - viewManager.setZIndex(view, entry.intValue.toFloat()) - } - YG_BORDER_WIDTH -> { - viewManager.borderWidth(view, entry.mapBufferValue) - } - YG_OVERFLOW -> { - viewManager.overflow(view, entry.intValue) - } - } - } - } - - private fun ReactViewManager.accessibilityActions(view: ReactViewGroup, mapBuffer: MapBuffer) { - val actions = mutableListOf() - for (entry in mapBuffer) { - val map = JavaOnlyMap() - val action = entry.mapBufferValue - map.putString("name", action.getString(ACCESSIBILITY_ACTION_NAME)) - if (action.contains(ACCESSIBILITY_ACTION_LABEL)) { - map.putString("label", action.getString(ACCESSIBILITY_ACTION_LABEL)) - } - actions.add(map) - } - - setAccessibilityActions(view, JavaOnlyArray.from(actions)) - } - - private fun ReactViewGroup.accessibilityLiveRegion(value: Int) { - val mode = - when (value) { - 0 -> ViewCompat.ACCESSIBILITY_LIVE_REGION_NONE - 1 -> ViewCompat.ACCESSIBILITY_LIVE_REGION_POLITE - 2 -> ViewCompat.ACCESSIBILITY_LIVE_REGION_ASSERTIVE - else -> ViewCompat.ACCESSIBILITY_LIVE_REGION_NONE - } - ViewCompat.setAccessibilityLiveRegion(this, mode) - } - - 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)) - accessibilityState.putBoolean("expanded", value.getBoolean(ACCESSIBILITY_STATE_EXPANDED)) - accessibilityState.putBoolean("disabled", value.getBoolean(ACCESSIBILITY_STATE_DISABLED)) - - when (value.getInt(ACCESSIBILITY_STATE_CHECKED)) { - // Unchecked - 0 -> accessibilityState.putBoolean("checked", false) - // Checked - 1 -> accessibilityState.putBoolean("checked", true) - // Mixed - 2 -> accessibilityState.putString("checked", "mixed") - // 3 -> None - } - - setViewState(view, accessibilityState) - } - - private fun ReactViewManager.accessibilityValue(view: ReactViewGroup, value: String) { - val map = JavaOnlyMap() - if (value.isNotEmpty()) { - map.putString("text", value) - } - setAccessibilityValue(view, map) - } - - 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.stringValue) - } - DynamicFromObject(array) - } - - setAccessibilityLabelledBy(view, converted) - } - - private fun ReactViewManager.backfaceVisibility(view: ReactViewGroup, value: Int) { - val stringName = - when (value) { - 1 -> "visible" - 2 -> "hidden" - else -> "auto" - } - setBackfaceVisibility(view, stringName) - } - - private fun ReactViewManager.backgroundColor(view: ReactViewGroup, value: Int) { - val color = value.takeIf { it != UNDEF_COLOR } ?: Color.TRANSPARENT - setBackgroundColor(view, color) - } - - private fun ReactViewManager.borderColor(view: ReactViewGroup, value: MapBuffer) { - for (entry in value) { - val index = - when (val key = entry.key) { - EDGE_ALL -> 0 - EDGE_LEFT -> 1 - EDGE_RIGHT -> 2 - EDGE_TOP -> 3 - EDGE_BOTTOM -> 4 - EDGE_START -> 5 - EDGE_END -> 6 - EDGE_BLOCK -> 7 - EDGE_BLOCK_END -> 8 - EDGE_BLOCK_START -> 9 - else -> throw IllegalArgumentException("Unknown key for border color: $key") - } - val colorValue = entry.intValue - setBorderColor(view, index, colorValue.takeIf { it != -1 }) - } - } - - private fun ReactViewManager.borderRadius(view: ReactViewGroup, value: MapBuffer) { - for (entry in value) { - val index = - when (val key = entry.key) { - CORNER_ALL -> 0 - CORNER_TOP_LEFT -> 1 - CORNER_TOP_RIGHT -> 2 - CORNER_BOTTOM_RIGHT -> 3 - CORNER_BOTTOM_LEFT -> 4 - CORNER_TOP_START -> 5 - CORNER_TOP_END -> 6 - CORNER_BOTTOM_START -> 7 - CORNER_BOTTOM_END -> 8 - CORNER_END_END -> 9 - CORNER_END_START -> 10 - CORNER_START_END -> 11 - CORNER_START_START -> 12 - else -> throw IllegalArgumentException("Unknown key for border style: $key") - } - val borderRadius = entry.doubleValue - if (!borderRadius.isNaN()) { - setBorderRadius(view, index, borderRadius.toFloat()) - } - } - } - - private fun ReactViewManager.borderStyle(view: ReactViewGroup, value: Int) { - val stringValue = - when (value) { - 0 -> "solid" - 1 -> "dotted" - 2 -> "dashed" - else -> null - } - setBorderStyle(view, stringValue) - } - - private fun ReactViewGroup.hitSlop(value: MapBuffer) { - val rect = - Rect( - PixelUtil.toPixelFromDIP(value.getDouble(EDGE_LEFT)).toInt(), - PixelUtil.toPixelFromDIP(value.getDouble(EDGE_TOP)).toInt(), - PixelUtil.toPixelFromDIP(value.getDouble(EDGE_RIGHT)).toInt(), - PixelUtil.toPixelFromDIP(value.getDouble(EDGE_BOTTOM)).toInt(), - ) - setHitSlopRect(rect) - } - - private fun ReactViewGroup.importantForAccessibility(value: Int) { - val mode = - when (value) { - 0 -> ViewCompat.IMPORTANT_FOR_ACCESSIBILITY_AUTO - 1 -> ViewCompat.IMPORTANT_FOR_ACCESSIBILITY_YES - 2 -> ViewCompat.IMPORTANT_FOR_ACCESSIBILITY_NO - 3 -> ViewCompat.IMPORTANT_FOR_ACCESSIBILITY_NO_HIDE_DESCENDANTS - else -> ViewCompat.IMPORTANT_FOR_ACCESSIBILITY_AUTO - } - ViewCompat.setImportantForAccessibility(this, mode) - } - - private fun ReactViewGroup.role(value: Int) { - setTag(R.id.role, Role.values()[value]) - } - - private fun ReactViewGroup.pointerEvents(value: Int) { - val pointerEvents = - when (value) { - 0 -> PointerEvents.AUTO - 1 -> PointerEvents.NONE - 2 -> PointerEvents.BOX_NONE - 3 -> PointerEvents.BOX_ONLY - else -> throw IllegalArgumentException("Unknown value for pointer events: $value") - } - setPointerEvents(pointerEvents) - } - - private fun ReactViewManager.transform(view: ReactViewGroup, value: MapBuffer) { - val list = JavaOnlyArray() - for (entry in value) { - list.pushDouble(entry.doubleValue) - } - setTransform(view, list) - } - - private fun ReactViewManager.borderWidth(view: ReactViewGroup, value: MapBuffer) { - for (entry in value) { - val index = - when (val key = entry.key) { - EDGE_ALL -> 0 - EDGE_LEFT -> 1 - EDGE_RIGHT -> 2 - EDGE_TOP -> 3 - EDGE_BOTTOM -> 4 - EDGE_START -> 5 - EDGE_END -> 6 - else -> throw IllegalArgumentException("Unknown key for border width: $key") - } - val borderWidth = entry.doubleValue - if (!borderWidth.isNaN()) { - setBorderWidth(view, index, borderWidth.toFloat()) - } - } - } - - private fun ReactViewManager.overflow(view: ReactViewGroup, value: Int) { - val stringValue = - when (value) { - 0 -> "visible" - 1 -> "hidden" - 2 -> "scroll" - else -> throw IllegalArgumentException("Unknown overflow value: $value") - } - - setOverflow(view, stringValue) - } - - private fun ReactViewManager.shadowColor(view: ReactViewGroup, value: Int) { - val color = value.takeIf { it != UNDEF_COLOR } ?: Color.BLACK - setShadowColor(view, color) - } - - private fun ReactViewManager.nativeBackground(view: ReactViewGroup, value: MapBuffer) { - setNativeBackground(view, value.toJsDrawableDescription()) - } - - private fun ReactViewManager.nativeForeground(view: ReactViewGroup, value: MapBuffer) { - setNativeForeground(view, value.toJsDrawableDescription()) - } - - private fun MapBuffer.toJsDrawableDescription(): ReadableMap? { - if (count == 0) { - return null - } - - val kind = getInt(NATIVE_DRAWABLE_KIND) - val result = JavaOnlyMap() - when (kind) { - 0 -> { - result.putString("type", "ThemeAttrAndroid") - result.putString("attribute", getString(NATIVE_DRAWABLE_ATTRIBUTE)) - } - 1 -> { - result.putString("type", "RippleAndroid") - if (contains(NATIVE_DRAWABLE_COLOR)) { - result.putInt("color", getInt(NATIVE_DRAWABLE_COLOR)) - } - result.putBoolean("borderless", getBoolean(NATIVE_DRAWABLE_BORDERLESS)) - if (contains(NATIVE_DRAWABLE_RIPPLE_RADIUS)) { - result.putDouble("rippleRadius", getDouble(NATIVE_DRAWABLE_RIPPLE_RADIUS)) - } - } - else -> throw IllegalArgumentException("Unknown native drawable: $kind") - } - return result - } -} diff --git a/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/views/view/ReactMapBufferViewManager.kt b/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/views/view/ReactMapBufferViewManager.kt deleted file mode 100644 index e1a19fd9dd1..00000000000 --- a/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/views/view/ReactMapBufferViewManager.kt +++ /dev/null @@ -1,76 +0,0 @@ -/* - * Copyright (c) Meta Platforms, Inc. and affiliates. - * - * This source code is licensed under the MIT license found in the - * LICENSE file in the root directory of this source tree. - */ - -package com.facebook.react.views.view - -import android.view.View -import com.facebook.react.bridge.ReadableArray -import com.facebook.react.common.mapbuffer.ReadableMapBuffer -import com.facebook.react.touch.JSResponderHandler -import com.facebook.react.uimanager.ReactStylesDiffMap -import com.facebook.react.uimanager.StateWrapper -import com.facebook.react.uimanager.ThemedReactContext -import com.facebook.react.uimanager.ViewGroupManager - -object ReactMapBufferViewManager : ReactViewManagerWrapper { - private val viewManager = ReactViewManager() - - override fun createView( - reactTag: Int, - reactContext: ThemedReactContext, - props: Any?, - stateWrapper: StateWrapper?, - jsResponderHandler: JSResponderHandler - ): View = - viewManager - .createView( - reactTag, - reactContext, - props as? ReactStylesDiffMap, - stateWrapper, - jsResponderHandler) - .also { view -> - if (props is ReadableMapBuffer) { - updateProperties(view, props) - } - } - - override fun updateProperties(viewToUpdate: View, props: Any?) { - if (props !is ReadableMapBuffer) { - viewManager.updateProperties(viewToUpdate as ReactViewGroup, props as? ReactStylesDiffMap) - } else { - ReactMapBufferPropSetter.setProps(viewToUpdate as ReactViewGroup, viewManager, props) - } - } - - override fun receiveCommand(root: View, commandId: String, args: ReadableArray?) { - viewManager.receiveCommand(root as ReactViewGroup, commandId, args) - } - - override fun receiveCommand(root: View, commandId: Int, args: ReadableArray?) { - viewManager.receiveCommand(root as ReactViewGroup, commandId, args) - } - - override fun setPadding(view: View, left: Int, top: Int, right: Int, bottom: Int) { - viewManager.setPadding(view as ReactViewGroup, left, top, right, bottom) - } - - override fun updateState(view: View, props: Any?, stateWrapper: StateWrapper?): Any? = null - - override fun updateExtraData(root: View, extraData: Any?) { - viewManager.updateExtraData(root as ReactViewGroup, extraData) - } - - override fun onDropViewInstance(view: View) { - viewManager.onDropViewInstance(view as ReactViewGroup) - } - - override fun getName(): String = viewManager.name - - override val viewGroupManager: ViewGroupManager<*> - get() = viewManager -} diff --git a/packages/react-native/ReactCommon/react/renderer/components/view/AccessibilityProps.h b/packages/react-native/ReactCommon/react/renderer/components/view/AccessibilityProps.h index e901761db56..a46c21412d5 100644 --- a/packages/react-native/ReactCommon/react/renderer/components/view/AccessibilityProps.h +++ b/packages/react-native/ReactCommon/react/renderer/components/view/AccessibilityProps.h @@ -29,11 +29,6 @@ class AccessibilityProps { const char* propName, const RawValue& value); -#ifdef ANDROID - void propsDiffMapBuffer(const Props* oldProps, MapBufferBuilder& builder) - const; -#endif - #pragma mark - Props bool accessible{false}; diff --git a/packages/react-native/ReactCommon/react/renderer/components/view/YogaStylableProps.cpp b/packages/react-native/ReactCommon/react/renderer/components/view/YogaStylableProps.cpp index 67c2a530b3b..a8907750ad5 100644 --- a/packages/react-native/ReactCommon/react/renderer/components/view/YogaStylableProps.cpp +++ b/packages/react-native/ReactCommon/react/renderer/components/view/YogaStylableProps.cpp @@ -13,9 +13,6 @@ #include #include #include -#include - -#include "conversions.h" namespace facebook::react { @@ -26,155 +23,523 @@ YogaStylableProps::YogaStylableProps( : Props() { initialize(context, sourceProps, rawProps); - yogaStyle = CoreFeatures::enablePropIteratorSetter - ? sourceProps.yogaStyle - : convertRawProp(context, rawProps, sourceProps.yogaStyle); + yogaStyle.setDirection(convertRawProp( + context, + rawProps, + "direction", + sourceProps.yogaStyle.direction(), + yogaStyle.direction())); - if (!CoreFeatures::enablePropIteratorSetter) { - convertRawPropAliases(context, sourceProps, rawProps); - } + yogaStyle.setFlexDirection(convertRawProp( + context, + rawProps, + "flexDirection", + sourceProps.yogaStyle.flexDirection(), + yogaStyle.flexDirection())); + + yogaStyle.setJustifyContent(convertRawProp( + context, + rawProps, + "justifyContent", + sourceProps.yogaStyle.justifyContent(), + yogaStyle.justifyContent())); + + yogaStyle.setAlignContent(convertRawProp( + context, + rawProps, + "alignContent", + sourceProps.yogaStyle.alignContent(), + yogaStyle.alignContent())); + + yogaStyle.setAlignItems(convertRawProp( + context, + rawProps, + "alignItems", + sourceProps.yogaStyle.alignItems(), + yogaStyle.alignItems())); + + yogaStyle.setAlignSelf(convertRawProp( + context, + rawProps, + "alignSelf", + sourceProps.yogaStyle.alignSelf(), + yogaStyle.alignSelf())); + + yogaStyle.setPositionType(convertRawProp( + context, + rawProps, + "position", + sourceProps.yogaStyle.positionType(), + yogaStyle.positionType())); + + yogaStyle.setFlexWrap(convertRawProp( + context, + rawProps, + "flexWrap", + sourceProps.yogaStyle.flexWrap(), + yogaStyle.flexWrap())); + + yogaStyle.setOverflow(convertRawProp( + context, + rawProps, + "overflow", + sourceProps.yogaStyle.overflow(), + yogaStyle.overflow())); + + yogaStyle.setDisplay(convertRawProp( + context, + rawProps, + "display", + sourceProps.yogaStyle.display(), + yogaStyle.display())); + + yogaStyle.setFlex(convertRawProp( + context, + rawProps, + "flex", + sourceProps.yogaStyle.flex(), + yogaStyle.flex())); + + yogaStyle.setFlexGrow(convertRawProp( + context, + rawProps, + "flexGrow", + sourceProps.yogaStyle.flexGrow(), + yogaStyle.flexGrow())); + + yogaStyle.setFlexShrink(convertRawProp( + context, + rawProps, + "flexShrink", + sourceProps.yogaStyle.flexShrink(), + yogaStyle.flexShrink())); + + yogaStyle.setFlexBasis(convertRawProp( + context, + rawProps, + "flexBasis", + sourceProps.yogaStyle.flexBasis(), + yogaStyle.flexBasis())); + + yogaStyle.setMargin( + yoga::Edge::Left, + convertRawProp( + context, + rawProps, + "marginLeft", + sourceProps.yogaStyle.margin(yoga::Edge::Left), + yogaStyle.margin(yoga::Edge::Left))); + + yogaStyle.setMargin( + yoga::Edge::Top, + convertRawProp( + context, + rawProps, + "marginTop", + sourceProps.yogaStyle.margin(yoga::Edge::Top), + yogaStyle.margin(yoga::Edge::Top))); + + yogaStyle.setMargin( + yoga::Edge::Right, + convertRawProp( + context, + rawProps, + "marginRight", + sourceProps.yogaStyle.margin(yoga::Edge::Right), + yogaStyle.margin(yoga::Edge::Right))); + + yogaStyle.setMargin( + yoga::Edge::Bottom, + convertRawProp( + context, + rawProps, + "marginBottom", + sourceProps.yogaStyle.margin(yoga::Edge::Bottom), + yogaStyle.margin(yoga::Edge::Bottom))); + + yogaStyle.setMargin( + yoga::Edge::Start, + convertRawProp( + context, + rawProps, + "marginStart", + sourceProps.yogaStyle.margin(yoga::Edge::Start), + yogaStyle.margin(yoga::Edge::Start))); + + yogaStyle.setMargin( + yoga::Edge::End, + convertRawProp( + context, + rawProps, + "marginEnd", + sourceProps.yogaStyle.margin(yoga::Edge::End), + yogaStyle.margin(yoga::Edge::End))); + + yogaStyle.setMargin( + yoga::Edge::Horizontal, + convertRawProp( + context, + rawProps, + "marginHorizontal", + sourceProps.yogaStyle.margin(yoga::Edge::Horizontal), + yogaStyle.margin(yoga::Edge::Horizontal))); + + yogaStyle.setMargin( + yoga::Edge::Vertical, + convertRawProp( + context, + rawProps, + "marginVertical", + sourceProps.yogaStyle.margin(yoga::Edge::Vertical), + yogaStyle.margin(yoga::Edge::Vertical))); + + yogaStyle.setMargin( + yoga::Edge::All, + convertRawProp( + context, + rawProps, + "margin", + sourceProps.yogaStyle.margin(yoga::Edge::All), + yogaStyle.margin(yoga::Edge::All))); + + yogaStyle.setPosition( + yoga::Edge::Left, + convertRawProp( + context, + rawProps, + "left", + sourceProps.yogaStyle.position(yoga::Edge::Left), + yogaStyle.position(yoga::Edge::Left))); + + yogaStyle.setPosition( + yoga::Edge::Top, + convertRawProp( + context, + rawProps, + "top", + sourceProps.yogaStyle.position(yoga::Edge::Top), + yogaStyle.position(yoga::Edge::Top))); + + yogaStyle.setPosition( + yoga::Edge::Right, + convertRawProp( + context, + rawProps, + "right", + sourceProps.yogaStyle.position(yoga::Edge::Right), + yogaStyle.position(yoga::Edge::Right))); + + yogaStyle.setPosition( + yoga::Edge::Bottom, + convertRawProp( + context, + rawProps, + "bottom", + sourceProps.yogaStyle.position(yoga::Edge::Bottom), + yogaStyle.position(yoga::Edge::Bottom))); + + yogaStyle.setPosition( + yoga::Edge::Start, + convertRawProp( + context, + rawProps, + "start", + sourceProps.yogaStyle.position(yoga::Edge::Start), + yogaStyle.position(yoga::Edge::Start))); + + yogaStyle.setPosition( + yoga::Edge::End, + convertRawProp( + context, + rawProps, + "end", + sourceProps.yogaStyle.position(yoga::Edge::End), + yogaStyle.position(yoga::Edge::End))); + + yogaStyle.setPosition( + yoga::Edge::Horizontal, + convertRawProp( + context, + rawProps, + "insetInline", + sourceProps.yogaStyle.position(yoga::Edge::Horizontal), + yogaStyle.position(yoga::Edge::Horizontal))); + + yogaStyle.setPosition( + yoga::Edge::Vertical, + convertRawProp( + context, + rawProps, + "insetBlock", + sourceProps.yogaStyle.position(yoga::Edge::Vertical), + yogaStyle.position(yoga::Edge::Vertical))); + + yogaStyle.setPosition( + yoga::Edge::All, + convertRawProp( + context, + rawProps, + "inset", + sourceProps.yogaStyle.position(yoga::Edge::All), + yogaStyle.position(yoga::Edge::All))); + + yogaStyle.setPadding( + yoga::Edge::Left, + convertRawProp( + context, + rawProps, + "paddingLeft", + sourceProps.yogaStyle.padding(yoga::Edge::Left), + yogaStyle.padding(yoga::Edge::Left))); + + yogaStyle.setPadding( + yoga::Edge::Top, + convertRawProp( + context, + rawProps, + "paddingTop", + sourceProps.yogaStyle.padding(yoga::Edge::Top), + yogaStyle.padding(yoga::Edge::Top))); + + yogaStyle.setPadding( + yoga::Edge::Right, + convertRawProp( + context, + rawProps, + "paddingRight", + sourceProps.yogaStyle.padding(yoga::Edge::Right), + yogaStyle.padding(yoga::Edge::Right))); + + yogaStyle.setPadding( + yoga::Edge::Bottom, + convertRawProp( + context, + rawProps, + "paddingBottom", + sourceProps.yogaStyle.padding(yoga::Edge::Bottom), + yogaStyle.padding(yoga::Edge::Bottom))); + + yogaStyle.setPadding( + yoga::Edge::Start, + convertRawProp( + context, + rawProps, + "paddingStart", + sourceProps.yogaStyle.padding(yoga::Edge::Start), + yogaStyle.padding(yoga::Edge::Start))); + + yogaStyle.setPadding( + yoga::Edge::End, + convertRawProp( + context, + rawProps, + "paddingEnd", + sourceProps.yogaStyle.padding(yoga::Edge::End), + yogaStyle.padding(yoga::Edge::End))); + + yogaStyle.setPadding( + yoga::Edge::Horizontal, + convertRawProp( + context, + rawProps, + "paddingHorizontal", + sourceProps.yogaStyle.padding(yoga::Edge::Horizontal), + yogaStyle.padding(yoga::Edge::Horizontal))); + + yogaStyle.setPadding( + yoga::Edge::Vertical, + convertRawProp( + context, + rawProps, + "paddingVertical", + sourceProps.yogaStyle.padding(yoga::Edge::Vertical), + yogaStyle.padding(yoga::Edge::Vertical))); + + yogaStyle.setPadding( + yoga::Edge::All, + convertRawProp( + context, + rawProps, + "padding", + sourceProps.yogaStyle.padding(yoga::Edge::All), + yogaStyle.padding(yoga::Edge::All))); + + yogaStyle.setGap( + yoga::Gutter::Row, + convertRawProp( + context, + rawProps, + "rowGap", + sourceProps.yogaStyle.gap(yoga::Gutter::Row), + yogaStyle.gap(yoga::Gutter::Row))); + + yogaStyle.setGap( + yoga::Gutter::Column, + convertRawProp( + context, + rawProps, + "columnGap", + sourceProps.yogaStyle.gap(yoga::Gutter::Column), + yogaStyle.gap(yoga::Gutter::Column))); + + yogaStyle.setGap( + yoga::Gutter::All, + convertRawProp( + context, + rawProps, + "gap", + sourceProps.yogaStyle.gap(yoga::Gutter::All), + yogaStyle.gap(yoga::Gutter::All))); + + yogaStyle.setBorder( + yoga::Edge::Left, + convertRawProp( + context, + rawProps, + "borderLeftWidth", + sourceProps.yogaStyle.border(yoga::Edge::Left), + yogaStyle.border(yoga::Edge::Left))); + + yogaStyle.setBorder( + yoga::Edge::Top, + convertRawProp( + context, + rawProps, + "borderTopWidth", + sourceProps.yogaStyle.border(yoga::Edge::Top), + yogaStyle.border(yoga::Edge::Top))); + + yogaStyle.setBorder( + yoga::Edge::Right, + convertRawProp( + context, + rawProps, + "borderRightWidth", + sourceProps.yogaStyle.border(yoga::Edge::Right), + yogaStyle.border(yoga::Edge::Right))); + + yogaStyle.setBorder( + yoga::Edge::Bottom, + convertRawProp( + context, + rawProps, + "borderBottomWidth", + sourceProps.yogaStyle.border(yoga::Edge::Bottom), + yogaStyle.border(yoga::Edge::Bottom))); + + yogaStyle.setBorder( + yoga::Edge::Start, + convertRawProp( + context, + rawProps, + "borderStartWidth", + sourceProps.yogaStyle.border(yoga::Edge::Start), + yogaStyle.border(yoga::Edge::Start))); + + yogaStyle.setBorder( + yoga::Edge::End, + convertRawProp( + context, + rawProps, + "borderEndWidth", + sourceProps.yogaStyle.border(yoga::Edge::End), + yogaStyle.border(yoga::Edge::End))); + + yogaStyle.setBorder( + yoga::Edge::Horizontal, + convertRawProp( + context, + rawProps, + "borderHorizontalWidth", + sourceProps.yogaStyle.border(yoga::Edge::Horizontal), + yogaStyle.border(yoga::Edge::Horizontal))); + + yogaStyle.setBorder( + yoga::Edge::Vertical, + convertRawProp( + context, + rawProps, + "borderVerticalWidth", + sourceProps.yogaStyle.border(yoga::Edge::Vertical), + yogaStyle.border(yoga::Edge::Vertical))); + + yogaStyle.setBorder( + yoga::Edge::All, + convertRawProp( + context, + rawProps, + "borderWidth", + sourceProps.yogaStyle.border(yoga::Edge::All), + yogaStyle.border(yoga::Edge::All))); + + yogaStyle.setDimension( + yoga::Dimension::Width, + convertRawProp( + context, + rawProps, + "width", + sourceProps.yogaStyle.dimension(yoga::Dimension::Width), + {})); + + yogaStyle.setDimension( + yoga::Dimension::Height, + convertRawProp( + context, + rawProps, + "height", + sourceProps.yogaStyle.dimension(yoga::Dimension::Height), + {})); + + yogaStyle.setMinDimension( + yoga::Dimension::Width, + convertRawProp( + context, + rawProps, + "minWidth", + sourceProps.yogaStyle.minDimension(yoga::Dimension::Width), + {})); + + yogaStyle.setMinDimension( + yoga::Dimension::Height, + convertRawProp( + context, + rawProps, + "minHeight", + sourceProps.yogaStyle.minDimension(yoga::Dimension::Height), + {})); + + yogaStyle.setMaxDimension( + yoga::Dimension::Width, + convertRawProp( + context, + rawProps, + "maxWidth", + sourceProps.yogaStyle.maxDimension(yoga::Dimension::Width), + {})); + + yogaStyle.setMaxDimension( + yoga::Dimension::Height, + convertRawProp( + context, + rawProps, + "maxHeight", + sourceProps.yogaStyle.maxDimension(yoga::Dimension::Height), + {})); + + yogaStyle.setAspectRatio(convertRawProp( + context, + rawProps, + "aspectRatio", + sourceProps.yogaStyle.aspectRatio(), + yogaStyle.aspectRatio())); }; -template -static inline T const getFieldValue( - const PropsParserContext& context, - const RawValue& value, - T const defaultValue) { - if (value.hasValue()) { - T res; - fromRawValue(context, value, res); - return res; - } - - return defaultValue; -} - -#define REBUILD_FIELD_SWITCH_CASE2(field, setter, fieldName) \ - case CONSTEXPR_RAW_PROPS_KEY_HASH(fieldName): { \ - yogaStyle.setter(getFieldValue(context, value, ygDefaults.field())); \ - return; \ - } - -#define REBUILD_FIELD_SWITCH_CASE_YSP(field, setter) \ - REBUILD_FIELD_SWITCH_CASE2(field, setter, #field) - -#define REBUILD_YG_FIELD_SWITCH_CASE_INDEXED(field, setter, index, fieldName) \ - case CONSTEXPR_RAW_PROPS_KEY_HASH(fieldName): { \ - yogaStyle.setter( \ - index, getFieldValue(context, value, ygDefaults.field(index))); \ - return; \ - } - -#define REBUILD_FIELD_YG_DIMENSION(field, setter, widthStr, heightStr) \ - REBUILD_YG_FIELD_SWITCH_CASE_INDEXED( \ - field, setter, yoga::Dimension::Width, widthStr); \ - REBUILD_YG_FIELD_SWITCH_CASE_INDEXED( \ - field, setter, yoga::Dimension::Height, heightStr); - -#define REBUILD_FIELD_YG_GUTTER( \ - field, setter, rowGapStr, columnGapStr, gapStr) \ - REBUILD_YG_FIELD_SWITCH_CASE_INDEXED( \ - field, setter, yoga::Gutter::Row, rowGapStr); \ - REBUILD_YG_FIELD_SWITCH_CASE_INDEXED( \ - field, setter, yoga::Gutter::Column, columnGapStr); \ - REBUILD_YG_FIELD_SWITCH_CASE_INDEXED( \ - field, setter, yoga::Gutter::All, gapStr); - -#define REBUILD_FIELD_YG_EDGES(field, setter, prefix, suffix) \ - REBUILD_YG_FIELD_SWITCH_CASE_INDEXED( \ - field, setter, yoga::Edge::Left, prefix "Left" suffix); \ - REBUILD_YG_FIELD_SWITCH_CASE_INDEXED( \ - field, setter, yoga::Edge::Top, prefix "Top" suffix); \ - REBUILD_YG_FIELD_SWITCH_CASE_INDEXED( \ - field, setter, yoga::Edge::Right, prefix "Right" suffix); \ - REBUILD_YG_FIELD_SWITCH_CASE_INDEXED( \ - field, setter, yoga::Edge::Bottom, prefix "Bottom" suffix); \ - REBUILD_YG_FIELD_SWITCH_CASE_INDEXED( \ - field, setter, yoga::Edge::Start, prefix "Start" suffix); \ - REBUILD_YG_FIELD_SWITCH_CASE_INDEXED( \ - field, setter, yoga::Edge::End, prefix "End" suffix); \ - REBUILD_YG_FIELD_SWITCH_CASE_INDEXED( \ - field, setter, yoga::Edge::Horizontal, prefix "Horizontal" suffix); \ - REBUILD_YG_FIELD_SWITCH_CASE_INDEXED( \ - field, setter, yoga::Edge::Vertical, prefix "Vertical" suffix); \ - REBUILD_YG_FIELD_SWITCH_CASE_INDEXED( \ - field, setter, yoga::Edge::All, prefix "" suffix); - -#define REBUILD_FIELD_YG_EDGES_POSITION() \ - REBUILD_YG_FIELD_SWITCH_CASE_INDEXED( \ - position, setPosition, yoga::Edge::Left, "left"); \ - REBUILD_YG_FIELD_SWITCH_CASE_INDEXED( \ - position, setPosition, yoga::Edge::Top, "top"); \ - REBUILD_YG_FIELD_SWITCH_CASE_INDEXED( \ - position, setPosition, yoga::Edge::Right, "right"); \ - REBUILD_YG_FIELD_SWITCH_CASE_INDEXED( \ - position, setPosition, yoga::Edge::Bottom, "bottom"); \ - REBUILD_YG_FIELD_SWITCH_CASE_INDEXED( \ - position, setPosition, yoga::Edge::Start, "start"); \ - REBUILD_YG_FIELD_SWITCH_CASE_INDEXED( \ - position, setPosition, yoga::Edge::End, "end"); \ - REBUILD_YG_FIELD_SWITCH_CASE_INDEXED( \ - position, setPosition, yoga::Edge::Horizontal, "insetInline"); \ - REBUILD_YG_FIELD_SWITCH_CASE_INDEXED( \ - position, setPosition, yoga::Edge::Vertical, "insetBlock"); \ - REBUILD_YG_FIELD_SWITCH_CASE_INDEXED( \ - position, setPosition, yoga::Edge::All, "inset"); - void YogaStylableProps::setProp( const PropsParserContext& context, RawPropsPropNameHash hash, const char* propName, const RawValue& value) { - static const auto ygDefaults = yoga::Style{}; - static const auto defaults = YogaStylableProps{}; - Props::setProp(context, hash, propName, value); - - switch (hash) { - REBUILD_FIELD_SWITCH_CASE_YSP(direction, setDirection); - REBUILD_FIELD_SWITCH_CASE_YSP(flexDirection, setFlexDirection); - REBUILD_FIELD_SWITCH_CASE_YSP(justifyContent, setJustifyContent); - REBUILD_FIELD_SWITCH_CASE_YSP(alignContent, setAlignContent); - REBUILD_FIELD_SWITCH_CASE_YSP(alignItems, setAlignItems); - REBUILD_FIELD_SWITCH_CASE_YSP(alignSelf, setAlignSelf); - REBUILD_FIELD_SWITCH_CASE_YSP(flexWrap, setFlexWrap); - REBUILD_FIELD_SWITCH_CASE_YSP(overflow, setOverflow); - REBUILD_FIELD_SWITCH_CASE_YSP(display, setDisplay); - REBUILD_FIELD_SWITCH_CASE_YSP(flex, setFlex); - REBUILD_FIELD_SWITCH_CASE_YSP(flexGrow, setFlexGrow); - REBUILD_FIELD_SWITCH_CASE_YSP(flexShrink, setFlexShrink); - REBUILD_FIELD_SWITCH_CASE_YSP(flexBasis, setFlexBasis); - REBUILD_FIELD_SWITCH_CASE2(positionType, setPositionType, "position"); - REBUILD_FIELD_YG_GUTTER(gap, setGap, "rowGap", "columnGap", "gap"); - REBUILD_FIELD_SWITCH_CASE_YSP(aspectRatio, setAspectRatio); - REBUILD_FIELD_YG_DIMENSION(dimension, setDimension, "width", "height"); - REBUILD_FIELD_YG_DIMENSION( - minDimension, setMinDimension, "minWidth", "minHeight"); - REBUILD_FIELD_YG_DIMENSION( - maxDimension, setMaxDimension, "maxWidth", "maxHeight"); - REBUILD_FIELD_YG_EDGES_POSITION(); - REBUILD_FIELD_YG_EDGES(margin, setMargin, "margin", ""); - REBUILD_FIELD_YG_EDGES(padding, setPadding, "padding", ""); - REBUILD_FIELD_YG_EDGES(border, setBorder, "border", "Width"); - - // Aliases - RAW_SET_PROP_SWITCH_CASE(insetBlockEnd, "insetBlockEnd"); - RAW_SET_PROP_SWITCH_CASE(insetBlockStart, "insetBlockStart"); - RAW_SET_PROP_SWITCH_CASE(insetInlineEnd, "insetInlineEnd"); - RAW_SET_PROP_SWITCH_CASE(insetInlineStart, "insetInlineStart"); - RAW_SET_PROP_SWITCH_CASE(marginInline, "marginInline"); - RAW_SET_PROP_SWITCH_CASE(marginInlineStart, "marginInlineStart"); - RAW_SET_PROP_SWITCH_CASE(marginInlineEnd, "marginInlineEnd"); - RAW_SET_PROP_SWITCH_CASE(marginBlock, "marginBlock"); - RAW_SET_PROP_SWITCH_CASE(marginBlockStart, "marginBlockStart"); - RAW_SET_PROP_SWITCH_CASE(marginBlockEnd, "marginBlockEnd"); - RAW_SET_PROP_SWITCH_CASE(paddingInline, "paddingInline"); - RAW_SET_PROP_SWITCH_CASE(paddingInlineStart, "paddingInlineStart"); - RAW_SET_PROP_SWITCH_CASE(paddingInlineEnd, "paddingInlineEnd"); - RAW_SET_PROP_SWITCH_CASE(paddingBlock, "paddingBlock"); - RAW_SET_PROP_SWITCH_CASE(paddingBlockStart, "paddingBlockStart"); - RAW_SET_PROP_SWITCH_CASE(paddingBlockEnd, "paddingBlockEnd"); - } } #pragma mark - DebugStringConvertible diff --git a/packages/react-native/ReactCommon/react/renderer/components/view/YogaStylableProps.h b/packages/react-native/ReactCommon/react/renderer/components/view/YogaStylableProps.h index 16520918372..ef120f4f432 100644 --- a/packages/react-native/ReactCommon/react/renderer/components/view/YogaStylableProps.h +++ b/packages/react-native/ReactCommon/react/renderer/components/view/YogaStylableProps.h @@ -29,11 +29,6 @@ class YogaStylableProps : public Props { const char* propName, const RawValue& value); -#ifdef ANDROID - void propsDiffMapBuffer(const Props* oldProps, MapBufferBuilder& builder) - const override; -#endif - #pragma mark - Props yoga::Style yogaStyle{}; diff --git a/packages/react-native/ReactCommon/react/renderer/components/view/platform/android/react/renderer/components/view/AccessibilityPropsMapBuffer.cpp b/packages/react-native/ReactCommon/react/renderer/components/view/platform/android/react/renderer/components/view/AccessibilityPropsMapBuffer.cpp deleted file mode 100644 index 1a53e2dc113..00000000000 --- a/packages/react-native/ReactCommon/react/renderer/components/view/platform/android/react/renderer/components/view/AccessibilityPropsMapBuffer.cpp +++ /dev/null @@ -1,166 +0,0 @@ -/* - * Copyright (c) Meta Platforms, Inc. and affiliates. - * - * This source code is licensed under the MIT license found in the - * LICENSE file in the root directory of this source tree. - */ - -#include "AccessibilityPropsMapBuffer.h" -#include - -namespace facebook::react { - -static MapBuffer convertAccessibilityActions( - const std::vector& actions) { - MapBufferBuilder builder(static_cast(actions.size())); - for (auto i = 0; i < actions.size(); i++) { - const auto& action = actions[i]; - MapBufferBuilder actionsBuilder(2); - actionsBuilder.putString(ACCESSIBILITY_ACTION_NAME, action.name); - if (action.label.has_value()) { - actionsBuilder.putString( - ACCESSIBILITY_ACTION_LABEL, action.label.value()); - } - builder.putMapBuffer(i, actionsBuilder.build()); - } - return builder.build(); -} - -static MapBuffer convertAccessibilityLabelledBy( - const AccessibilityLabelledBy& labelledBy) { - MapBufferBuilder builder(static_cast(labelledBy.value.size())); - for (auto i = 0; i < labelledBy.value.size(); i++) { - builder.putString(i, labelledBy.value[i]); - } - return builder.build(); -} - -// AccessibilityState values -constexpr MapBuffer::Key ACCESSIBILITY_STATE_BUSY = 0; -constexpr MapBuffer::Key ACCESSIBILITY_STATE_DISABLED = 1; -constexpr MapBuffer::Key ACCESSIBILITY_STATE_EXPANDED = 2; -constexpr MapBuffer::Key ACCESSIBILITY_STATE_SELECTED = 3; -constexpr MapBuffer::Key ACCESSIBILITY_STATE_CHECKED = 4; - -MapBuffer convertAccessibilityState(const AccessibilityState& state) { - MapBufferBuilder builder(5); - builder.putBool(ACCESSIBILITY_STATE_BUSY, state.busy); - builder.putBool(ACCESSIBILITY_STATE_DISABLED, state.disabled); - builder.putBool(ACCESSIBILITY_STATE_EXPANDED, state.expanded.value_or(false)); - builder.putBool(ACCESSIBILITY_STATE_SELECTED, state.selected); - int checked; - switch (state.checked) { - case AccessibilityState::Unchecked: - checked = 0; - break; - case AccessibilityState::Checked: - checked = 1; - break; - case AccessibilityState::Mixed: - checked = 2; - break; - case AccessibilityState::None: - checked = 3; - break; - } - builder.putInt(ACCESSIBILITY_STATE_CHECKED, checked); - return builder.build(); -} - -// TODO: Currently unsupported: nextFocusForward/Left/Up/Right/Down -void AccessibilityProps::propsDiffMapBuffer( - const Props* oldPropsPtr, - MapBufferBuilder& builder) const { - // Call with default props if necessary - if (oldPropsPtr == nullptr) { - AccessibilityProps defaultProps{}; - propsDiffMapBuffer(reinterpret_cast(&defaultProps), builder); - return; - } - - const AccessibilityProps& oldProps = - *(reinterpret_cast(oldPropsPtr)); - const AccessibilityProps& newProps = *this; - - if (oldProps.accessibilityActions != newProps.accessibilityActions) { - builder.putMapBuffer( - AP_ACCESSIBILITY_ACTIONS, - convertAccessibilityActions(newProps.accessibilityActions)); - } - - if (oldProps.accessibilityHint != newProps.accessibilityHint) { - builder.putString(AP_ACCESSIBILITY_HINT, newProps.accessibilityHint); - } - - if (oldProps.accessibilityLabel != newProps.accessibilityLabel) { - builder.putString(AP_ACCESSIBILITY_LABEL, newProps.accessibilityLabel); - } - - if (oldProps.accessibilityLabelledBy != newProps.accessibilityLabelledBy) { - builder.putMapBuffer( - AP_ACCESSIBILITY_LABELLED_BY, - convertAccessibilityLabelledBy(newProps.accessibilityLabelledBy)); - } - - if (oldProps.accessibilityLiveRegion != newProps.accessibilityLiveRegion) { - int value; - switch (newProps.accessibilityLiveRegion) { - case AccessibilityLiveRegion::None: - value = 0; - break; - case AccessibilityLiveRegion::Polite: - value = 1; - break; - case AccessibilityLiveRegion::Assertive: - value = 2; - break; - } - builder.putInt(AP_ACCESSIBILITY_LIVE_REGION, value); - } - - if (oldProps.accessibilityRole != newProps.accessibilityRole) { - builder.putString(AP_ACCESSIBILITY_ROLE, newProps.accessibilityRole); - } - - if (oldProps.accessibilityState != newProps.accessibilityState) { - builder.putMapBuffer( - AP_ACCESSIBILITY_STATE, - convertAccessibilityState( - newProps.accessibilityState.value_or(AccessibilityState{}))); - } - - if (oldProps.accessibilityValue != newProps.accessibilityValue) { - builder.putString( - AP_ACCESSIBILITY_VALUE, newProps.accessibilityValue.text.value_or("")); - } - - if (oldProps.accessible != newProps.accessible) { - builder.putBool(AP_ACCESSIBLE, newProps.accessible); - } - - if (oldProps.importantForAccessibility != - newProps.importantForAccessibility) { - int value; - switch (newProps.importantForAccessibility) { - case ImportantForAccessibility::Auto: - value = 0; - break; - case ImportantForAccessibility::Yes: - value = 1; - break; - case ImportantForAccessibility::No: - value = 2; - break; - case ImportantForAccessibility::NoHideDescendants: - value = 3; - break; - } - builder.putInt(AP_IMPORTANT_FOR_ACCESSIBILITY, value); - } - - if (oldProps.role != newProps.role) { - builder.putInt(AP_ROLE, static_cast(newProps.role)); - } -} - -} // namespace facebook::react diff --git a/packages/react-native/ReactCommon/react/renderer/components/view/platform/android/react/renderer/components/view/AccessibilityPropsMapBuffer.h b/packages/react-native/ReactCommon/react/renderer/components/view/platform/android/react/renderer/components/view/AccessibilityPropsMapBuffer.h deleted file mode 100644 index 46631bd4aed..00000000000 --- a/packages/react-native/ReactCommon/react/renderer/components/view/platform/android/react/renderer/components/view/AccessibilityPropsMapBuffer.h +++ /dev/null @@ -1,35 +0,0 @@ -/* - * Copyright (c) Meta Platforms, Inc. and affiliates. - * - * This source code is licensed under the MIT license found in the - * LICENSE file in the root directory of this source tree. - */ - -#pragma once - -#include -#include - -namespace facebook::react { - -// TODO: "AP" (Accessibility Props) are interleaved with "VP" (View Props). -// Ordinals must be unique between them. - -constexpr MapBuffer::Key AP_ACCESSIBILITY_ACTIONS = 0; -constexpr MapBuffer::Key AP_ACCESSIBILITY_HINT = 1; -constexpr MapBuffer::Key AP_ACCESSIBILITY_LABEL = 2; -constexpr MapBuffer::Key AP_ACCESSIBILITY_LABELLED_BY = 3; -constexpr MapBuffer::Key AP_ACCESSIBILITY_LIVE_REGION = 4; -constexpr MapBuffer::Key AP_ACCESSIBILITY_ROLE = 5; -constexpr MapBuffer::Key AP_ACCESSIBILITY_STATE = 6; -constexpr MapBuffer::Key AP_ACCESSIBILITY_VALUE = 7; -constexpr MapBuffer::Key AP_ACCESSIBLE = 8; -constexpr MapBuffer::Key AP_IMPORTANT_FOR_ACCESSIBILITY = 19; - -constexpr MapBuffer::Key AP_ROLE = 47; - -// AccessibilityAction values -constexpr MapBuffer::Key ACCESSIBILITY_ACTION_NAME = 0; -constexpr MapBuffer::Key ACCESSIBILITY_ACTION_LABEL = 1; - -} // namespace facebook::react diff --git a/packages/react-native/ReactCommon/react/renderer/components/view/platform/android/react/renderer/components/view/HostPlatformViewProps.h b/packages/react-native/ReactCommon/react/renderer/components/view/platform/android/react/renderer/components/view/HostPlatformViewProps.h index 2845d2a5645..89325ab7083 100644 --- a/packages/react-native/ReactCommon/react/renderer/components/view/platform/android/react/renderer/components/view/HostPlatformViewProps.h +++ b/packages/react-native/ReactCommon/react/renderer/components/view/platform/android/react/renderer/components/view/HostPlatformViewProps.h @@ -34,9 +34,6 @@ class HostPlatformViewProps : public BaseViewProps { const char* propName, const RawValue& value); - void propsDiffMapBuffer(const Props* oldProps, MapBufferBuilder& builder) - const override; - #pragma mark - Props Float elevation{}; diff --git a/packages/react-native/ReactCommon/react/renderer/components/view/platform/android/react/renderer/components/view/ViewPropsMapBuffer.cpp b/packages/react-native/ReactCommon/react/renderer/components/view/platform/android/react/renderer/components/view/ViewPropsMapBuffer.cpp deleted file mode 100644 index 1fd158c2035..00000000000 --- a/packages/react-native/ReactCommon/react/renderer/components/view/platform/android/react/renderer/components/view/ViewPropsMapBuffer.cpp +++ /dev/null @@ -1,191 +0,0 @@ -/* - * Copyright (c) Meta Platforms, Inc. and affiliates. - * - * This source code is licensed under the MIT license found in the - * LICENSE file in the root directory of this source tree. - */ - -#include "ViewPropsMapBuffer.h" - -#include -#include -#include -#include - -namespace facebook::react { - -// TODO: Currently unsupported: nextFocusForward/Left/Up/Right/Down -void ViewProps::propsDiffMapBuffer( - const Props* oldPropsPtr, - MapBufferBuilder& builder) const { - // Call with default props if necessary - if (oldPropsPtr == nullptr) { - ViewProps defaultProps{}; - propsDiffMapBuffer(&defaultProps, builder); - return; - } - - // Delegate to base classes - YogaStylableProps::propsDiffMapBuffer(oldPropsPtr, builder); - AccessibilityProps::propsDiffMapBuffer(oldPropsPtr, builder); - - const ViewProps& oldProps = *(static_cast(oldPropsPtr)); - const ViewProps& newProps = *this; - - if (oldProps.backfaceVisibility != newProps.backfaceVisibility) { - int value; - switch (newProps.backfaceVisibility) { - case BackfaceVisibility::Auto: - value = 0; - break; - case BackfaceVisibility::Visible: - value = 1; - break; - case BackfaceVisibility::Hidden: - value = 2; - break; - } - builder.putInt(VP_BACKFACE_VISIBILITY, value); - } - - if (oldProps.backgroundColor != newProps.backgroundColor) { - builder.putInt(VP_BG_COLOR, toAndroidRepr(newProps.backgroundColor)); - } - - if (oldProps.borderCurves != newProps.borderCurves) { - builder.putMapBuffer( - VP_BORDER_CURVES, convertCascadedCorners(newProps.borderCurves)); - } - - if (oldProps.borderColors != newProps.borderColors) { - builder.putMapBuffer( - VP_BORDER_COLOR, convertBorderColors(newProps.borderColors)); - } - - if (oldProps.borderRadii != newProps.borderRadii) { - builder.putMapBuffer( - VP_BORDER_RADII, convertCascadedCorners(newProps.borderRadii)); - } - - if (oldProps.borderStyles != newProps.borderStyles) { - builder.putMapBuffer( - VP_BORDER_STYLE, convertCascadedEdges(newProps.borderStyles)); - } - - if (oldProps.elevation != newProps.elevation) { - builder.putDouble(VP_ELEVATION, newProps.elevation); - } - - if (oldProps.focusable != newProps.focusable) { - builder.putBool(VP_FOCUSABLE, newProps.focusable); - } - - if (oldProps.hasTVPreferredFocus != newProps.hasTVPreferredFocus) { - builder.putBool(VP_HAS_TV_FOCUS, newProps.hasTVPreferredFocus); - } - - if (oldProps.hitSlop != newProps.hitSlop) { - builder.putMapBuffer(VP_HIT_SLOP, convertEdgeInsets(newProps.hitSlop)); - } - - if (oldProps.nativeBackground != newProps.nativeBackground) { - builder.putMapBuffer( - VP_NATIVE_BACKGROUND, - convertNativeBackground(newProps.nativeBackground)); - } - - if (oldProps.nativeForeground != newProps.nativeForeground) { - builder.putMapBuffer( - VP_NATIVE_FOREGROUND, - convertNativeBackground(newProps.nativeForeground)); - } - - if (oldProps.needsOffscreenAlphaCompositing != - newProps.needsOffscreenAlphaCompositing) { - builder.putBool( - VP_OFFSCREEN_ALPHA_COMPOSITING, - newProps.needsOffscreenAlphaCompositing); - } - - if (oldProps.opacity != newProps.opacity) { - builder.putDouble(VP_OPACITY, newProps.opacity); - } - - if (oldProps.pointerEvents != newProps.pointerEvents) { - int value; - switch (newProps.pointerEvents) { - case PointerEventsMode::Auto: - value = 0; - break; - case PointerEventsMode::None: - value = 1; - break; - case PointerEventsMode::BoxNone: - value = 2; - break; - case PointerEventsMode::BoxOnly: - value = 3; - break; - } - - builder.putInt(VP_POINTER_EVENTS, value); - } - - if (oldProps.events != newProps.events) { - builder.putBool( - VP_POINTER_ENTER, newProps.events[ViewEvents::Offset::PointerEnter]); - builder.putBool( - VP_POINTER_LEAVE, newProps.events[ViewEvents::Offset::PointerLeave]); - builder.putBool( - VP_POINTER_MOVE, newProps.events[ViewEvents::Offset::PointerMove]); - - builder.putBool( - VP_POINTER_ENTER_CAPTURE, - newProps.events[ViewEvents::Offset::PointerEnterCapture]); - builder.putBool( - VP_POINTER_LEAVE_CAPTURE, - newProps.events[ViewEvents::Offset::PointerLeaveCapture]); - builder.putBool( - VP_POINTER_MOVE_CAPTURE, - newProps.events[ViewEvents::Offset::PointerMoveCapture]); - builder.putBool( - VP_POINTER_OVER, newProps.events[ViewEvents::Offset::PointerOver]); - builder.putBool( - VP_POINTER_OVER_CAPTURE, - newProps.events[ViewEvents::Offset::PointerOverCapture]); - - builder.putBool( - VP_POINTER_OUT, newProps.events[ViewEvents::Offset::PointerOut]); - builder.putBool( - VP_POINTER_OUT_CAPTURE, - newProps.events[ViewEvents::Offset::PointerOutCapture]); - } - - if (oldProps.removeClippedSubviews != newProps.removeClippedSubviews) { - builder.putBool(VP_REMOVE_CLIPPED_SUBVIEW, newProps.removeClippedSubviews); - } - - if (oldProps.renderToHardwareTextureAndroid != - newProps.renderToHardwareTextureAndroid) { - builder.putBool( - VP_RENDER_TO_HARDWARE_TEXTURE, newProps.renderToHardwareTextureAndroid); - } - - if (oldProps.shadowColor != newProps.shadowColor) { - builder.putInt(VP_SHADOW_COLOR, toAndroidRepr(newProps.shadowColor)); - } - - if (oldProps.testId != newProps.testId) { - builder.putString(VP_TEST_ID, newProps.testId); - } - - if (oldProps.transform != newProps.transform) { - builder.putMapBuffer(VP_TRANSFORM, convertTransform(newProps.transform)); - } - - if (oldProps.zIndex != newProps.zIndex) { - builder.putInt(VP_ZINDEX, newProps.zIndex.value_or(0)); - } -} - -} // namespace facebook::react diff --git a/packages/react-native/ReactCommon/react/renderer/components/view/platform/android/react/renderer/components/view/ViewPropsMapBuffer.h b/packages/react-native/ReactCommon/react/renderer/components/view/platform/android/react/renderer/components/view/ViewPropsMapBuffer.h deleted file mode 100644 index 147d240df7f..00000000000 --- a/packages/react-native/ReactCommon/react/renderer/components/view/platform/android/react/renderer/components/view/ViewPropsMapBuffer.h +++ /dev/null @@ -1,51 +0,0 @@ -/* - * Copyright (c) Meta Platforms, Inc. and affiliates. - * - * This source code is licensed under the MIT license found in the - * LICENSE file in the root directory of this source tree. - */ - -#pragma once - -#include - -namespace facebook::react { - -constexpr MapBuffer::Key VP_BACKFACE_VISIBILITY = 9; -constexpr MapBuffer::Key VP_BG_COLOR = 10; -constexpr MapBuffer::Key VP_BORDER_COLOR = 11; -constexpr MapBuffer::Key VP_BORDER_RADII = 12; -constexpr MapBuffer::Key VP_BORDER_STYLE = 13; -constexpr MapBuffer::Key VP_COLLAPSABLE = 14; -constexpr MapBuffer::Key VP_ELEVATION = 15; -constexpr MapBuffer::Key VP_FOCUSABLE = 16; -constexpr MapBuffer::Key VP_HAS_TV_FOCUS = 17; -constexpr MapBuffer::Key VP_HIT_SLOP = 18; -constexpr MapBuffer::Key VP_NATIVE_BACKGROUND = 20; -constexpr MapBuffer::Key VP_NATIVE_FOREGROUND = 21; -constexpr MapBuffer::Key VP_OFFSCREEN_ALPHA_COMPOSITING = 23; -constexpr MapBuffer::Key VP_OPACITY = 24; -constexpr MapBuffer::Key VP_POINTER_EVENTS = 25; -constexpr MapBuffer::Key VP_POINTER_ENTER = 26; -constexpr MapBuffer::Key VP_POINTER_LEAVE = 27; -constexpr MapBuffer::Key VP_POINTER_MOVE = 28; -constexpr MapBuffer::Key VP_REMOVE_CLIPPED_SUBVIEW = 29; -constexpr MapBuffer::Key VP_RENDER_TO_HARDWARE_TEXTURE = 30; -constexpr MapBuffer::Key VP_SHADOW_COLOR = 31; -constexpr MapBuffer::Key VP_TEST_ID = 32; -constexpr MapBuffer::Key VP_TRANSFORM = 33; -constexpr MapBuffer::Key VP_ZINDEX = 34; -constexpr MapBuffer::Key VP_POINTER_ENTER_CAPTURE = 38; -constexpr MapBuffer::Key VP_POINTER_LEAVE_CAPTURE = 39; -constexpr MapBuffer::Key VP_POINTER_MOVE_CAPTURE = 40; -constexpr MapBuffer::Key VP_POINTER_OVER = 41; -constexpr MapBuffer::Key VP_POINTER_OVER_CAPTURE = 42; -constexpr MapBuffer::Key VP_POINTER_OUT = 43; -constexpr MapBuffer::Key VP_POINTER_OUT_CAPTURE = 44; -constexpr MapBuffer::Key VP_BORDER_CURVES = 45; - -// Yoga values -constexpr MapBuffer::Key YG_BORDER_WIDTH = 100; -constexpr MapBuffer::Key YG_OVERFLOW = 101; - -} // namespace facebook::react diff --git a/packages/react-native/ReactCommon/react/renderer/components/view/platform/android/react/renderer/components/view/YogaStylablePropsMapBuffer.cpp b/packages/react-native/ReactCommon/react/renderer/components/view/platform/android/react/renderer/components/view/YogaStylablePropsMapBuffer.cpp deleted file mode 100644 index 20474d7ec37..00000000000 --- a/packages/react-native/ReactCommon/react/renderer/components/view/platform/android/react/renderer/components/view/YogaStylablePropsMapBuffer.cpp +++ /dev/null @@ -1,101 +0,0 @@ -/* - * Copyright (c) Meta Platforms, Inc. and affiliates. - * - * This source code is licensed under the MIT license found in the - * LICENSE file in the root directory of this source tree. - */ - -#include "ViewPropsMapBuffer.h" - -#include -#include -#include - -namespace facebook::react { - -MapBuffer convertBorderWidths(const yoga::Style& style) { - MapBufferBuilder builder(7); - putOptionalFloat( - builder, - EDGE_TOP, - optionalFloatFromYogaValue(style.border(yoga::Edge::Top))); - putOptionalFloat( - builder, - EDGE_RIGHT, - optionalFloatFromYogaValue(style.border(yoga::Edge::Right))); - putOptionalFloat( - builder, - EDGE_BOTTOM, - optionalFloatFromYogaValue(style.border(yoga::Edge::Bottom))); - putOptionalFloat( - builder, - EDGE_LEFT, - optionalFloatFromYogaValue(style.border(yoga::Edge::Left))); - putOptionalFloat( - builder, - EDGE_START, - optionalFloatFromYogaValue(style.border(yoga::Edge::Start))); - putOptionalFloat( - builder, - EDGE_END, - optionalFloatFromYogaValue(style.border(yoga::Edge::End))); - putOptionalFloat( - builder, - EDGE_ALL, - optionalFloatFromYogaValue(style.border(yoga::Edge::All))); - return builder.build(); -} - -// TODO: Currently unsupported: nextFocusForward/Left/Up/Right/Down -void YogaStylableProps::propsDiffMapBuffer( - const Props* oldPropsPtr, - MapBufferBuilder& builder) const { - // Call with default props if necessary - if (oldPropsPtr == nullptr) { - YogaStylableProps defaultProps{}; - propsDiffMapBuffer(&defaultProps, builder); - return; - } - - // Delegate to base classes - Props::propsDiffMapBuffer(oldPropsPtr, builder); - - const YogaStylableProps& oldProps = - *(static_cast(oldPropsPtr)); - const YogaStylableProps& newProps = *this; - - if (oldProps.yogaStyle != newProps.yogaStyle) { - const auto& oldStyle = oldProps.yogaStyle; - const auto& newStyle = newProps.yogaStyle; - - bool areBordersEqual = true; - for (auto edge : yoga::ordinals()) { - if (oldStyle.border(edge) != newStyle.border(edge)) { - areBordersEqual = false; - break; - } - } - - if (!areBordersEqual) { - builder.putMapBuffer(YG_BORDER_WIDTH, convertBorderWidths(newStyle)); - } - - if (oldStyle.overflow() != newStyle.overflow()) { - int value; - switch (newStyle.overflow()) { - case yoga::Overflow::Visible: - value = 0; - break; - case yoga::Overflow::Hidden: - value = 1; - break; - case yoga::Overflow::Scroll: - value = 2; - break; - } - builder.putInt(YG_OVERFLOW, value); - } - } -} - -} // namespace facebook::react diff --git a/packages/react-native/ReactCommon/react/renderer/components/view/platform/android/react/renderer/components/view/YogaStylablePropsMapBuffer.h b/packages/react-native/ReactCommon/react/renderer/components/view/platform/android/react/renderer/components/view/YogaStylablePropsMapBuffer.h deleted file mode 100644 index 2d0c7c1456c..00000000000 --- a/packages/react-native/ReactCommon/react/renderer/components/view/platform/android/react/renderer/components/view/YogaStylablePropsMapBuffer.h +++ /dev/null @@ -1,22 +0,0 @@ -/* - * Copyright (c) Meta Platforms, Inc. and affiliates. - * - * This source code is licensed under the MIT license found in the - * LICENSE file in the root directory of this source tree. - */ - -#pragma once - -#ifdef ANDROID - -#include - -namespace facebook::react { - -// Yoga values -constexpr MapBuffer::Key YG_BORDER_WIDTH = 100; -constexpr MapBuffer::Key YG_OVERFLOW = 101; - -} // namespace facebook::react - -#endif diff --git a/packages/react-native/ReactCommon/react/renderer/components/view/propsConversions.h b/packages/react-native/ReactCommon/react/renderer/components/view/propsConversions.h index e68f15740c2..e7d9394c5ac 100644 --- a/packages/react-native/ReactCommon/react/renderer/components/view/propsConversions.h +++ b/packages/react-native/ReactCommon/react/renderer/components/view/propsConversions.h @@ -15,524 +15,6 @@ namespace facebook::react { -// Nearly this entire file can be deleted when iterator-style Prop parsing -// ships fully for View - -static inline yoga::Style convertRawProp( - const PropsParserContext& context, - const RawProps& rawProps, - const yoga::Style& sourceValue) { - yoga::Style yogaStyle{}; - - yogaStyle.setDirection(convertRawProp( - context, - rawProps, - "direction", - sourceValue.direction(), - yogaStyle.direction())); - - yogaStyle.setFlexDirection(convertRawProp( - context, - rawProps, - "flexDirection", - sourceValue.flexDirection(), - yogaStyle.flexDirection())); - - yogaStyle.setJustifyContent(convertRawProp( - context, - rawProps, - "justifyContent", - sourceValue.justifyContent(), - yogaStyle.justifyContent())); - - yogaStyle.setAlignContent(convertRawProp( - context, - rawProps, - "alignContent", - sourceValue.alignContent(), - yogaStyle.alignContent())); - - yogaStyle.setAlignItems(convertRawProp( - context, - rawProps, - "alignItems", - sourceValue.alignItems(), - yogaStyle.alignItems())); - - yogaStyle.setAlignSelf(convertRawProp( - context, - rawProps, - "alignSelf", - sourceValue.alignSelf(), - yogaStyle.alignSelf())); - - yogaStyle.setPositionType(convertRawProp( - context, - rawProps, - "position", - sourceValue.positionType(), - yogaStyle.positionType())); - - yogaStyle.setFlexWrap(convertRawProp( - context, - rawProps, - "flexWrap", - sourceValue.flexWrap(), - yogaStyle.flexWrap())); - - yogaStyle.setOverflow(convertRawProp( - context, - rawProps, - "overflow", - sourceValue.overflow(), - yogaStyle.overflow())); - - yogaStyle.setDisplay(convertRawProp( - context, - rawProps, - "display", - sourceValue.display(), - yogaStyle.display())); - - yogaStyle.setFlex(convertRawProp( - context, rawProps, "flex", sourceValue.flex(), yogaStyle.flex())); - - yogaStyle.setFlexGrow(convertRawProp( - context, - rawProps, - "flexGrow", - sourceValue.flexGrow(), - yogaStyle.flexGrow())); - - yogaStyle.setFlexShrink(convertRawProp( - context, - rawProps, - "flexShrink", - sourceValue.flexShrink(), - yogaStyle.flexShrink())); - - yogaStyle.setFlexBasis(convertRawProp( - context, - rawProps, - "flexBasis", - sourceValue.flexBasis(), - yogaStyle.flexBasis())); - - yogaStyle.setMargin( - yoga::Edge::Left, - convertRawProp( - context, - rawProps, - "marginLeft", - sourceValue.margin(yoga::Edge::Left), - yogaStyle.margin(yoga::Edge::Left))); - - yogaStyle.setMargin( - yoga::Edge::Top, - convertRawProp( - context, - rawProps, - "marginTop", - sourceValue.margin(yoga::Edge::Top), - yogaStyle.margin(yoga::Edge::Top))); - - yogaStyle.setMargin( - yoga::Edge::Right, - convertRawProp( - context, - rawProps, - "marginRight", - sourceValue.margin(yoga::Edge::Right), - yogaStyle.margin(yoga::Edge::Right))); - - yogaStyle.setMargin( - yoga::Edge::Bottom, - convertRawProp( - context, - rawProps, - "marginBottom", - sourceValue.margin(yoga::Edge::Bottom), - yogaStyle.margin(yoga::Edge::Bottom))); - - yogaStyle.setMargin( - yoga::Edge::Start, - convertRawProp( - context, - rawProps, - "marginStart", - sourceValue.margin(yoga::Edge::Start), - yogaStyle.margin(yoga::Edge::Start))); - - yogaStyle.setMargin( - yoga::Edge::End, - convertRawProp( - context, - rawProps, - "marginEnd", - sourceValue.margin(yoga::Edge::End), - yogaStyle.margin(yoga::Edge::End))); - - yogaStyle.setMargin( - yoga::Edge::Horizontal, - convertRawProp( - context, - rawProps, - "marginHorizontal", - sourceValue.margin(yoga::Edge::Horizontal), - yogaStyle.margin(yoga::Edge::Horizontal))); - - yogaStyle.setMargin( - yoga::Edge::Vertical, - convertRawProp( - context, - rawProps, - "marginVertical", - sourceValue.margin(yoga::Edge::Vertical), - yogaStyle.margin(yoga::Edge::Vertical))); - - yogaStyle.setMargin( - yoga::Edge::All, - convertRawProp( - context, - rawProps, - "margin", - sourceValue.margin(yoga::Edge::All), - yogaStyle.margin(yoga::Edge::All))); - - yogaStyle.setPosition( - yoga::Edge::Left, - convertRawProp( - context, - rawProps, - "left", - sourceValue.position(yoga::Edge::Left), - yogaStyle.position(yoga::Edge::Left))); - - yogaStyle.setPosition( - yoga::Edge::Top, - convertRawProp( - context, - rawProps, - "top", - sourceValue.position(yoga::Edge::Top), - yogaStyle.position(yoga::Edge::Top))); - - yogaStyle.setPosition( - yoga::Edge::Right, - convertRawProp( - context, - rawProps, - "right", - sourceValue.position(yoga::Edge::Right), - yogaStyle.position(yoga::Edge::Right))); - - yogaStyle.setPosition( - yoga::Edge::Bottom, - convertRawProp( - context, - rawProps, - "bottom", - sourceValue.position(yoga::Edge::Bottom), - yogaStyle.position(yoga::Edge::Bottom))); - - yogaStyle.setPosition( - yoga::Edge::Start, - convertRawProp( - context, - rawProps, - "start", - sourceValue.position(yoga::Edge::Start), - yogaStyle.position(yoga::Edge::Start))); - - yogaStyle.setPosition( - yoga::Edge::End, - convertRawProp( - context, - rawProps, - "end", - sourceValue.position(yoga::Edge::End), - yogaStyle.position(yoga::Edge::End))); - - yogaStyle.setPosition( - yoga::Edge::Horizontal, - convertRawProp( - context, - rawProps, - "insetInline", - sourceValue.position(yoga::Edge::Horizontal), - yogaStyle.position(yoga::Edge::Horizontal))); - - yogaStyle.setPosition( - yoga::Edge::Vertical, - convertRawProp( - context, - rawProps, - "insetBlock", - sourceValue.position(yoga::Edge::Vertical), - yogaStyle.position(yoga::Edge::Vertical))); - - yogaStyle.setPosition( - yoga::Edge::All, - convertRawProp( - context, - rawProps, - "inset", - sourceValue.position(yoga::Edge::All), - yogaStyle.position(yoga::Edge::All))); - - yogaStyle.setPadding( - yoga::Edge::Left, - convertRawProp( - context, - rawProps, - "paddingLeft", - sourceValue.padding(yoga::Edge::Left), - yogaStyle.padding(yoga::Edge::Left))); - - yogaStyle.setPadding( - yoga::Edge::Top, - convertRawProp( - context, - rawProps, - "paddingTop", - sourceValue.padding(yoga::Edge::Top), - yogaStyle.padding(yoga::Edge::Top))); - - yogaStyle.setPadding( - yoga::Edge::Right, - convertRawProp( - context, - rawProps, - "paddingRight", - sourceValue.padding(yoga::Edge::Right), - yogaStyle.padding(yoga::Edge::Right))); - - yogaStyle.setPadding( - yoga::Edge::Bottom, - convertRawProp( - context, - rawProps, - "paddingBottom", - sourceValue.padding(yoga::Edge::Bottom), - yogaStyle.padding(yoga::Edge::Bottom))); - - yogaStyle.setPadding( - yoga::Edge::Start, - convertRawProp( - context, - rawProps, - "paddingStart", - sourceValue.padding(yoga::Edge::Start), - yogaStyle.padding(yoga::Edge::Start))); - - yogaStyle.setPadding( - yoga::Edge::End, - convertRawProp( - context, - rawProps, - "paddingEnd", - sourceValue.padding(yoga::Edge::End), - yogaStyle.padding(yoga::Edge::End))); - - yogaStyle.setPadding( - yoga::Edge::Horizontal, - convertRawProp( - context, - rawProps, - "paddingHorizontal", - sourceValue.padding(yoga::Edge::Horizontal), - yogaStyle.padding(yoga::Edge::Horizontal))); - - yogaStyle.setPadding( - yoga::Edge::Vertical, - convertRawProp( - context, - rawProps, - "paddingVertical", - sourceValue.padding(yoga::Edge::Vertical), - yogaStyle.padding(yoga::Edge::Vertical))); - - yogaStyle.setPadding( - yoga::Edge::All, - convertRawProp( - context, - rawProps, - "padding", - sourceValue.padding(yoga::Edge::All), - yogaStyle.padding(yoga::Edge::All))); - - yogaStyle.setGap( - yoga::Gutter::Row, - convertRawProp( - context, - rawProps, - "rowGap", - sourceValue.gap(yoga::Gutter::Row), - yogaStyle.gap(yoga::Gutter::Row))); - - yogaStyle.setGap( - yoga::Gutter::Column, - convertRawProp( - context, - rawProps, - "columnGap", - sourceValue.gap(yoga::Gutter::Column), - yogaStyle.gap(yoga::Gutter::Column))); - - yogaStyle.setGap( - yoga::Gutter::All, - convertRawProp( - context, - rawProps, - "gap", - sourceValue.gap(yoga::Gutter::All), - yogaStyle.gap(yoga::Gutter::All))); - - yogaStyle.setBorder( - yoga::Edge::Left, - convertRawProp( - context, - rawProps, - "borderLeftWidth", - sourceValue.border(yoga::Edge::Left), - yogaStyle.border(yoga::Edge::Left))); - - yogaStyle.setBorder( - yoga::Edge::Top, - convertRawProp( - context, - rawProps, - "borderTopWidth", - sourceValue.border(yoga::Edge::Top), - yogaStyle.border(yoga::Edge::Top))); - - yogaStyle.setBorder( - yoga::Edge::Right, - convertRawProp( - context, - rawProps, - "borderRightWidth", - sourceValue.border(yoga::Edge::Right), - yogaStyle.border(yoga::Edge::Right))); - - yogaStyle.setBorder( - yoga::Edge::Bottom, - convertRawProp( - context, - rawProps, - "borderBottomWidth", - sourceValue.border(yoga::Edge::Bottom), - yogaStyle.border(yoga::Edge::Bottom))); - - yogaStyle.setBorder( - yoga::Edge::Start, - convertRawProp( - context, - rawProps, - "borderStartWidth", - sourceValue.border(yoga::Edge::Start), - yogaStyle.border(yoga::Edge::Start))); - - yogaStyle.setBorder( - yoga::Edge::End, - convertRawProp( - context, - rawProps, - "borderEndWidth", - sourceValue.border(yoga::Edge::End), - yogaStyle.border(yoga::Edge::End))); - - yogaStyle.setBorder( - yoga::Edge::Horizontal, - convertRawProp( - context, - rawProps, - "borderHorizontalWidth", - sourceValue.border(yoga::Edge::Horizontal), - yogaStyle.border(yoga::Edge::Horizontal))); - - yogaStyle.setBorder( - yoga::Edge::Vertical, - convertRawProp( - context, - rawProps, - "borderVerticalWidth", - sourceValue.border(yoga::Edge::Vertical), - yogaStyle.border(yoga::Edge::Vertical))); - - yogaStyle.setBorder( - yoga::Edge::All, - convertRawProp( - context, - rawProps, - "borderWidth", - sourceValue.border(yoga::Edge::All), - yogaStyle.border(yoga::Edge::All))); - - yogaStyle.setDimension( - yoga::Dimension::Width, - convertRawProp( - context, - rawProps, - "width", - sourceValue.dimension(yoga::Dimension::Width), - {})); - - yogaStyle.setDimension( - yoga::Dimension::Height, - convertRawProp( - context, - rawProps, - "height", - sourceValue.dimension(yoga::Dimension::Height), - {})); - - yogaStyle.setMinDimension( - yoga::Dimension::Width, - convertRawProp( - context, - rawProps, - "minWidth", - sourceValue.minDimension(yoga::Dimension::Width), - {})); - - yogaStyle.setMinDimension( - yoga::Dimension::Height, - convertRawProp( - context, - rawProps, - "minHeight", - sourceValue.minDimension(yoga::Dimension::Height), - {})); - - yogaStyle.setMaxDimension( - yoga::Dimension::Width, - convertRawProp( - context, - rawProps, - "maxWidth", - sourceValue.maxDimension(yoga::Dimension::Width), - {})); - - yogaStyle.setMaxDimension( - yoga::Dimension::Height, - convertRawProp( - context, - rawProps, - "maxHeight", - sourceValue.maxDimension(yoga::Dimension::Height), - {})); - - yogaStyle.setAspectRatio(convertRawProp( - context, - rawProps, - "aspectRatio", - sourceValue.aspectRatio(), - yogaStyle.aspectRatio())); - - return yogaStyle; -} - // This can be deleted when non-iterator ViewProp parsing is deleted template static inline CascadedRectangleCorners convertRawProp( diff --git a/packages/react-native/ReactCommon/react/renderer/components/view/viewPropConversions.h b/packages/react-native/ReactCommon/react/renderer/components/view/viewPropConversions.h deleted file mode 100644 index 0d99ea87f9d..00000000000 --- a/packages/react-native/ReactCommon/react/renderer/components/view/viewPropConversions.h +++ /dev/null @@ -1,214 +0,0 @@ -/* - * Copyright (c) Meta Platforms, Inc. and affiliates. - * - * This source code is licensed under the MIT license found in the - * LICENSE file in the root directory of this source tree. - */ - -#pragma once - -#include -#include -#include -#include -#include -#include - -#include - -namespace facebook::react { - -namespace { - -constexpr MapBuffer::Key EDGE_TOP = 0; -constexpr MapBuffer::Key EDGE_LEFT = 1; -constexpr MapBuffer::Key EDGE_RIGHT = 2; -constexpr MapBuffer::Key EDGE_BOTTOM = 3; -constexpr MapBuffer::Key EDGE_START = 4; -constexpr MapBuffer::Key EDGE_END = 5; -constexpr MapBuffer::Key EDGE_ALL = 6; -constexpr MapBuffer::Key EDGE_BLOCK = 7; -constexpr MapBuffer::Key EDGE_BLOCK_START = 8; -constexpr MapBuffer::Key EDGE_BLOCK_END = 9; - -constexpr MapBuffer::Key CORNER_TOP_LEFT = 0; -constexpr MapBuffer::Key CORNER_TOP_RIGHT = 1; -constexpr MapBuffer::Key CORNER_BOTTOM_RIGHT = 2; -constexpr MapBuffer::Key CORNER_BOTTOM_LEFT = 3; -constexpr MapBuffer::Key CORNER_TOP_START = 4; -constexpr MapBuffer::Key CORNER_TOP_END = 5; -constexpr MapBuffer::Key CORNER_BOTTOM_END = 6; -constexpr MapBuffer::Key CORNER_BOTTOM_START = 7; -constexpr MapBuffer::Key CORNER_ALL = 8; -constexpr MapBuffer::Key CORNER_END_END = 9; -constexpr MapBuffer::Key CORNER_END_START = 10; -constexpr MapBuffer::Key CORNER_START_END = 11; -constexpr MapBuffer::Key CORNER_START_START = 12; - -inline void putOptionalFloat( - MapBufferBuilder& builder, - MapBuffer::Key key, - const std::optional& value) { - builder.putDouble(key, value.value_or(NAN)); -} - -inline std::optional optionalFromValue( - const std::optional& value) { - if (!value) { - return {}; - } - - return {value.value() == BorderCurve::Circular ? 1 : 2}; -} - -inline std::optional optionalFromValue( - const std::optional& value) { - return value; -} - -inline std::optional optionalFromValue( - const std::optional& value) { - if (!value) { - return {}; - } - - int intValue = -1; - switch (value.value()) { - case BorderStyle::Solid: - intValue = 0; - break; - case BorderStyle::Dotted: - intValue = 1; - break; - case BorderStyle::Dashed: - intValue = 2; - break; - } - - return {intValue}; -} - -inline void putOptionalColor( - MapBufferBuilder& builder, - MapBuffer::Key key, - const std::optional& color) { - builder.putInt(key, color.has_value() ? toAndroidRepr(color.value()) : -1); -} - -inline MapBuffer convertBorderColors(const CascadedBorderColors& colors) { - MapBufferBuilder builder(7); - putOptionalColor(builder, EDGE_TOP, colors.top); - putOptionalColor(builder, EDGE_RIGHT, colors.right); - putOptionalColor(builder, EDGE_BOTTOM, colors.bottom); - putOptionalColor(builder, EDGE_LEFT, colors.left); - putOptionalColor(builder, EDGE_START, colors.start); - putOptionalColor(builder, EDGE_END, colors.end); - putOptionalColor(builder, EDGE_ALL, colors.all); - return builder.build(); -} - -template -MapBuffer convertCascadedEdges(const CascadedRectangleEdges& edges) { - MapBufferBuilder builder(10); - putOptionalFloat(builder, EDGE_TOP, optionalFromValue(edges.top)); - putOptionalFloat(builder, EDGE_RIGHT, optionalFromValue(edges.right)); - putOptionalFloat(builder, EDGE_BOTTOM, optionalFromValue(edges.bottom)); - putOptionalFloat(builder, EDGE_LEFT, optionalFromValue(edges.left)); - putOptionalFloat(builder, EDGE_START, optionalFromValue(edges.start)); - putOptionalFloat(builder, EDGE_END, optionalFromValue(edges.end)); - putOptionalFloat(builder, EDGE_BLOCK, optionalFromValue(edges.block)); - putOptionalFloat(builder, EDGE_BLOCK_END, optionalFromValue(edges.blockEnd)); - putOptionalFloat( - builder, EDGE_BLOCK_START, optionalFromValue(edges.blockStart)); - putOptionalFloat(builder, EDGE_ALL, optionalFromValue(edges.all)); - return builder.build(); -} - -template -MapBuffer convertCascadedCorners(const CascadedRectangleCorners& corners) { - MapBufferBuilder builder(13); - putOptionalFloat( - builder, CORNER_TOP_LEFT, optionalFromValue(corners.topLeft)); - putOptionalFloat( - builder, CORNER_TOP_RIGHT, optionalFromValue(corners.topRight)); - putOptionalFloat( - builder, CORNER_BOTTOM_RIGHT, optionalFromValue(corners.bottomRight)); - putOptionalFloat( - builder, CORNER_BOTTOM_LEFT, optionalFromValue(corners.bottomLeft)); - putOptionalFloat( - builder, CORNER_TOP_START, optionalFromValue(corners.topStart)); - putOptionalFloat(builder, CORNER_TOP_END, optionalFromValue(corners.topEnd)); - putOptionalFloat( - builder, CORNER_BOTTOM_END, optionalFromValue(corners.bottomEnd)); - putOptionalFloat( - builder, CORNER_BOTTOM_START, optionalFromValue(corners.bottomStart)); - putOptionalFloat(builder, CORNER_END_END, optionalFromValue(corners.endEnd)); - putOptionalFloat( - builder, CORNER_END_START, optionalFromValue(corners.endStart)); - putOptionalFloat( - builder, CORNER_START_END, optionalFromValue(corners.startEnd)); - putOptionalFloat( - builder, CORNER_START_START, optionalFromValue(corners.startStart)); - putOptionalFloat(builder, CORNER_ALL, optionalFromValue(corners.all)); - return builder.build(); -} - -inline MapBuffer convertEdgeInsets(const EdgeInsets& insets) { - MapBufferBuilder builder(4); - builder.putDouble(EDGE_TOP, insets.top); - builder.putDouble(EDGE_RIGHT, insets.right); - builder.putDouble(EDGE_BOTTOM, insets.bottom); - builder.putDouble(EDGE_LEFT, insets.left); - return builder.build(); -} - -#ifdef ANDROID - -constexpr MapBuffer::Key NATIVE_DRAWABLE_KIND = 0; -constexpr MapBuffer::Key NATIVE_DRAWABLE_ATTRIBUTE = 1; -constexpr MapBuffer::Key NATIVE_DRAWABLE_COLOR = 2; -constexpr MapBuffer::Key NATIVE_DRAWABLE_BORDERLESS = 3; -constexpr MapBuffer::Key NATIVE_DRAWABLE_RIPPLE_RADIUS = 4; - -inline MapBuffer convertNativeBackground( - const std::optional& value) { - if (!value.has_value()) { - return MapBufferBuilder::EMPTY(); - } - - const auto& drawable = value.value(); - MapBufferBuilder builder(4); - switch (drawable.kind) { - case NativeDrawable::Kind::ThemeAttr: - builder.putInt(NATIVE_DRAWABLE_KIND, 0); - builder.putString(NATIVE_DRAWABLE_ATTRIBUTE, drawable.themeAttr); - break; - case NativeDrawable::Kind::Ripple: - builder.putInt(NATIVE_DRAWABLE_KIND, 1); - if (drawable.ripple.color.has_value()) { - builder.putInt(NATIVE_DRAWABLE_COLOR, drawable.ripple.color.value()); - } - - builder.putBool(NATIVE_DRAWABLE_BORDERLESS, drawable.ripple.borderless); - if (drawable.ripple.rippleRadius.has_value()) { - builder.putDouble( - NATIVE_DRAWABLE_RIPPLE_RADIUS, - drawable.ripple.rippleRadius.value()); - } - break; - } - return builder.build(); -} - -#endif - -inline MapBuffer convertTransform(const Transform& transform) { - MapBufferBuilder builder(16); - for (int32_t i = 0; i < transform.matrix.size(); i++) { - builder.putDouble(i, transform.matrix[i]); - } - return builder.build(); -} -} // namespace - -} // namespace facebook::react diff --git a/packages/react-native/ReactCommon/react/renderer/core/Props.cpp b/packages/react-native/ReactCommon/react/renderer/core/Props.cpp index f096ddd1929..df133e8078e 100644 --- a/packages/react-native/ReactCommon/react/renderer/core/Props.cpp +++ b/packages/react-native/ReactCommon/react/renderer/core/Props.cpp @@ -44,27 +44,4 @@ void Props::setProp( } } -#ifdef ANDROID - -constexpr MapBuffer::Key PROPS_NATIVE_ID = 1; - -void Props::propsDiffMapBuffer( - const Props* oldPropsPtr, - MapBufferBuilder& builder) const { - // Call with default props if necessary - if (oldPropsPtr == nullptr) { - Props defaultProps{}; - propsDiffMapBuffer(&defaultProps, builder); - return; - } - - const Props& oldProps = *oldPropsPtr; - const Props& newProps = *this; - - if (oldProps.nativeId != newProps.nativeId) { - builder.putString(PROPS_NATIVE_ID, nativeId); - } -} -#endif - } // namespace facebook::react diff --git a/packages/react-native/ReactCommon/react/renderer/core/Props.h b/packages/react-native/ReactCommon/react/renderer/core/Props.h index b17a54541ee..0c34109850f 100644 --- a/packages/react-native/ReactCommon/react/renderer/core/Props.h +++ b/packages/react-native/ReactCommon/react/renderer/core/Props.h @@ -59,10 +59,6 @@ class Props : public virtual Sealable, public virtual DebugStringConvertible { #ifdef ANDROID folly::dynamic rawProps = folly::dynamic::object(); - - virtual void propsDiffMapBuffer( - const Props* oldProps, - MapBufferBuilder& builder) const; #endif protected: