Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions packages/react-native/ReactAndroid/api/ReactAndroid.api
Original file line number Diff line number Diff line change
Expand Up @@ -6091,6 +6091,7 @@ public class com/facebook/react/views/text/ReactTextViewManager : com/facebook/r
public final fun createShadowNodeInstance (Lcom/facebook/react/views/text/ReactTextViewManagerCallback;)Lcom/facebook/react/uimanager/LayoutShadowNode;
public synthetic fun createViewInstance (Lcom/facebook/react/uimanager/ThemedReactContext;)Landroid/view/View;
public fun createViewInstance (Lcom/facebook/react/uimanager/ThemedReactContext;)Lcom/facebook/react/views/text/ReactTextView;
protected fun getDelegate ()Lcom/facebook/react/uimanager/ViewManagerDelegate;
public fun getExportedCustomDirectEventTypeConstants ()Ljava/util/Map;
public fun getName ()Ljava/lang/String;
protected final fun getReactTextViewManagerCallback ()Lcom/facebook/react/views/text/ReactTextViewManagerCallback;
Expand Down Expand Up @@ -6530,6 +6531,7 @@ public class com/facebook/react/views/view/ReactViewManager : com/facebook/react
public synthetic fun createViewInstance (Lcom/facebook/react/uimanager/ThemedReactContext;)Landroid/view/View;
public fun createViewInstance (Lcom/facebook/react/uimanager/ThemedReactContext;)Lcom/facebook/react/views/view/ReactViewGroup;
public fun getCommandsMap ()Ljava/util/Map;
protected fun getDelegate ()Lcom/facebook/react/uimanager/ViewManagerDelegate;
public fun getName ()Ljava/lang/String;
public fun nextFocusDown (Lcom/facebook/react/views/view/ReactViewGroup;I)V
public fun nextFocusForward (Lcom/facebook/react/views/view/ReactViewGroup;I)V
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
/*
* 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.uimanager

/**
* Marks a [ViewManagerDelegate] that sets exactly the props its view manager declares with
* [com.facebook.react.uimanager.annotations.ReactProp] and
* [com.facebook.react.uimanager.annotations.ReactPropGroup]. [ViewManager.getNativeProps] reports
* those props for a manager with such a delegate even when
* `skipNativePropsForViewManagerWithDelegateAndroid` is on.
*/
internal interface AnnotatedPropsDelegate
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,8 @@ public abstract class BaseViewManagerDelegate<
ViewProps.ON_CLICK_CAPTURE -> mViewManager.setClickCapture(view, value as Boolean? ?: false)
ViewProps.ON_SAFE_AREA_INSETS_CHANGE ->
mViewManager.setOnSafeAreaInsetsChange(view, value as Boolean? ?: false)
"onStartShouldSetResponder" ->
mViewManager.setStartShouldSetResponder(view, value as Boolean? ?: false)
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -415,15 +415,15 @@ public void receiveCommand(@NonNull T view, String commandId, ReadableArray args
* Returns a mutable {@link Map<String, String>} representing the native props of the view
* manager. The Map contains the names (key) and types (value) of the ViewManager's props.
*
* <p>When {@code skipNativePropsForViewManagerWithDelegateAndroid} is enabled, managers with a
* non-generic delegate return an empty map. Enable this only when those components use static
* view configs rather than deriving their valid attributes from native prop metadata.
* <p>When {@code skipNativePropsForViewManagerWithDelegateAndroid} is enabled, managers whose
* delegate is not an {@link AnnotatedPropsDelegate} return an empty map. Enable this only when
* those components use static view configs rather than deriving their valid attributes from
* native prop metadata.
*/
public Map<String, String> getNativeProps() {
if (ReactNativeFeatureFlags.skipNativePropsForViewManagerWithDelegateAndroid()) {
ViewManagerDelegate<T> delegate = getOrCreateViewManagerDelegate();
if (delegate != null
&& !(delegate instanceof ViewManagerPropertyUpdater.GenericViewManagerDelegate)) {
if (delegate != null && !(delegate instanceof AnnotatedPropsDelegate)) {
return new HashMap<>();
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,7 @@ public object ViewManagerPropertyUpdater {
}

internal class GenericViewManagerDelegate<T : View>(private val manager: ViewManager<T, *>) :
ViewManagerDelegate<T> {
ViewManagerDelegate<T>, AnnotatedPropsDelegate {
private val setter = findManagerSetter(manager.javaClass)

@Suppress("ACCIDENTAL_OVERRIDE")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,17 @@ internal object ViewManagersPropertyCache {
private val CLASS_PROPS_CACHE: MutableMap<Class<*>, Map<String, PropSetter>> = ConcurrentHashMap()
private val EMPTY_PROPS_MAP: MutableMap<String, PropSetter> = HashMap()

/** Returns the exception thrown when setting [propName] on a view of [viewManager] fails. */
fun viewPropException(
propName: String,
viewManager: ViewManager<*, *>,
cause: Throwable,
): JSApplicationIllegalArgumentException =
JSApplicationIllegalArgumentException(
"Error while updating property '$propName' of a view managed by: ${viewManager.name}",
cause,
)

@JvmStatic
fun clear() {
CLASS_PROPS_CACHE.clear()
Expand Down Expand Up @@ -72,10 +83,7 @@ internal object ViewManagersPropertyCache {
}
} catch (t: Throwable) {
FLog.e(ViewManager::class.java, "Error while updating prop $propName", t)
throw JSApplicationIllegalArgumentException(
"Error while updating property '$propName' of a view managed by: ${viewManager.name}",
t,
)
throw viewPropException(propName, viewManager, t)
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import com.facebook.react.uimanager.LengthPercentage
import com.facebook.react.uimanager.LengthPercentageType
import com.facebook.react.uimanager.SimpleViewManager
import com.facebook.react.uimanager.ThemedReactContext
import com.facebook.react.uimanager.ViewManagerDelegate
import com.facebook.react.uimanager.ViewProps
import com.facebook.react.uimanager.annotations.ReactProp
import com.facebook.react.uimanager.annotations.ReactPropGroup
Expand Down Expand Up @@ -100,6 +101,8 @@ public constructor(

public override fun getName(): String = REACT_CLASS

override fun getDelegate(): ViewManagerDelegate<ReactImageView> = ReactImageManagerDelegate(this)

@ReactProp(name = "accessible")
public fun setAccessible(view: ReactImageView, accessible: Boolean) {
view.isFocusable = accessible
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
/*
* 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.image

import com.facebook.react.bridge.ColorPropConverter
import com.facebook.react.bridge.DynamicFromObject
import com.facebook.react.bridge.ReadableArray
import com.facebook.react.bridge.ReadableMap
import com.facebook.react.uimanager.AnnotatedPropsDelegate
import com.facebook.react.uimanager.BaseViewManagerDelegate
import com.facebook.react.uimanager.ViewManagersPropertyCache
import com.facebook.react.uimanager.ViewProps

/**
* Sets the props of [ReactImageManager] with direct calls, where the default delegate finds each
* setter by reflection.
*/
internal class ReactImageManagerDelegate(viewManager: ReactImageManager) :
BaseViewManagerDelegate<ReactImageView, ReactImageManager>(viewManager),
AnnotatedPropsDelegate {

override fun setProperty(view: ReactImageView, propName: String, value: Any?) {
// Name the prop and the manager when a value has the wrong type or a setter throws, as
// the reflective setters do
try {
when (propName) {
"accessible" -> mViewManager.setAccessible(view, value as Boolean? ?: false)
"src" -> mViewManager.setSrc(view, value as ReadableArray?)
"source" -> mViewManager.setSource(view, value as ReadableArray?)
"blurRadius" -> mViewManager.setBlurRadius(view, (value as Double?)?.toFloat() ?: 0f)
"internal_analyticTag" -> mViewManager.setInternal_AnalyticsTag(view, value as String?)
"defaultSource" -> mViewManager.setDefaultSource(view, DynamicFromObject(value))
"loadingIndicatorSrc" ->
mViewManager.setLoadingIndicatorSource(view, DynamicFromObject(value))
"borderColor" ->
mViewManager.setBorderColor(
view,
value?.let { ColorPropConverter.getColor(it, view.context) },
)
"overlayColor" ->
mViewManager.setOverlayColor(
view,
value?.let { ColorPropConverter.getColor(it, view.context) },
)
"borderWidth" -> mViewManager.setBorderWidth(view, (value as Double?)?.toFloat() ?: 0f)
ViewProps.BORDER_RADIUS -> mViewManager.setBorderRadius(view, 0, DynamicFromObject(value))
ViewProps.BORDER_TOP_LEFT_RADIUS ->
mViewManager.setBorderRadius(view, 1, DynamicFromObject(value))
ViewProps.BORDER_TOP_RIGHT_RADIUS ->
mViewManager.setBorderRadius(view, 2, DynamicFromObject(value))
ViewProps.BORDER_BOTTOM_RIGHT_RADIUS ->
mViewManager.setBorderRadius(view, 3, DynamicFromObject(value))
ViewProps.BORDER_BOTTOM_LEFT_RADIUS ->
mViewManager.setBorderRadius(view, 4, DynamicFromObject(value))
ViewProps.RESIZE_MODE -> mViewManager.setResizeMode(view, value as String?)
ViewProps.RESIZE_METHOD -> mViewManager.setResizeMethod(view, value as String?)
"resizeMultiplier" ->
mViewManager.setResizeMultiplier(view, (value as Double?)?.toFloat() ?: 0f)
"tintColor" ->
mViewManager.setTintColor(
view,
value?.let { ColorPropConverter.getColor(it, view.context) },
)
"progressiveRenderingEnabled" ->
mViewManager.setProgressiveRenderingEnabled(view, value as Boolean? ?: false)
"fadeDuration" -> mViewManager.setFadeDuration(view, (value as Double?)?.toInt() ?: -1)
"shouldNotifyLoadEvents" ->
mViewManager.setLoadHandlersRegistered(view, value as Boolean? ?: false)
"headers" -> mViewManager.setHeaders(view, value as ReadableMap?)
else -> super.setProperty(view, propName, value)
}
} catch (e: Exception) {
throw ViewManagersPropertyCache.viewPropException(propName, mViewManager, e)
}
}

override fun receiveCommand(
view: ReactImageView,
commandName: String,
args: ReadableArray,
): Unit = Unit
}
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ import com.facebook.react.uimanager.ReferenceStateWrapper
import com.facebook.react.uimanager.StateWrapper
import com.facebook.react.uimanager.ThemedReactContext
import com.facebook.react.uimanager.ViewDefaults
import com.facebook.react.uimanager.ViewManagerDelegate
import com.facebook.react.uimanager.ViewProps
import com.facebook.react.uimanager.annotations.ReactProp
import com.facebook.react.uimanager.annotations.ReactPropGroup
Expand Down Expand Up @@ -82,6 +83,18 @@ public constructor(

override fun getName(): String = REACT_CLASS

// Subclasses keep the reflective delegate, which also finds the props they declare.
// SelectableTextViewManager declares no props and is final.
override fun getDelegate(): ViewManagerDelegate<ReactTextView> =
if (
javaClass == ReactTextViewManager::class.java ||
javaClass == SelectableTextViewManager::class.java
) {
ReactTextViewManagerDelegate(this)
} else {
super.getDelegate()
}

override fun updateViewAccessibility(view: ReactTextView) {
ReactTextViewAccessibilityDelegate.setDelegate(
view,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,123 @@
/*
* 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.text

import com.facebook.react.bridge.ColorPropConverter
import com.facebook.react.bridge.DynamicFromObject
import com.facebook.react.bridge.ReadableArray
import com.facebook.react.uimanager.AnnotatedPropsDelegate
import com.facebook.react.uimanager.BaseViewManagerDelegate
import com.facebook.react.uimanager.ViewDefaults
import com.facebook.react.uimanager.ViewManagersPropertyCache
import com.facebook.react.uimanager.ViewProps

/**
* Sets the props of [ReactTextViewManager] with direct calls, where the default delegate finds each
* setter by reflection.
*/
internal class ReactTextViewManagerDelegate(viewManager: ReactTextViewManager) :
BaseViewManagerDelegate<ReactTextView, ReactTextViewManager>(viewManager),
AnnotatedPropsDelegate {

override fun setProperty(view: ReactTextView, propName: String, value: Any?) {
// Name the prop and the manager when a value has the wrong type or a setter throws, as
// the reflective setters do
try {
when (propName) {
"overflow" -> mViewManager.setOverflow(view, value as String?)
"accessible" -> mViewManager.setAccessible(view, value as Boolean? ?: false)
ViewProps.NUMBER_OF_LINES ->
mViewManager.setNumberOfLines(
view,
(value as Double?)?.toInt() ?: ViewDefaults.NUMBER_OF_LINES,
)
ViewProps.ELLIPSIZE_MODE -> mViewManager.setEllipsizeMode(view, value as String?)
ViewProps.ADJUSTS_FONT_SIZE_TO_FIT ->
mViewManager.setAdjustFontSizeToFit(view, value as Boolean? ?: false)
ViewProps.FONT_SIZE -> mViewManager.setFontSize(view, (value as Double?)?.toFloat() ?: 0f)
ViewProps.LETTER_SPACING ->
mViewManager.setLetterSpacing(view, (value as Double?)?.toFloat() ?: 0f)
ViewProps.TEXT_ALIGN_VERTICAL -> mViewManager.setTextAlignVertical(view, value as String?)
"selectable" -> mViewManager.setSelectable(view, value as Boolean? ?: false)
"selectionColor" ->
mViewManager.setSelectionColor(
view,
value?.let { ColorPropConverter.getColor(it, view.context) },
)
"android_hyphenationFrequency" ->
mViewManager.setAndroidHyphenationFrequency(view, value as String?)
"lineBreak" -> mViewManager.setLineBreak(view, value as String?)
"wordBreak" -> mViewManager.setWordBreak(view, value as String?)
ViewProps.BORDER_RADIUS -> mViewManager.setBorderRadius(view, 0, DynamicFromObject(value))
ViewProps.BORDER_TOP_LEFT_RADIUS ->
mViewManager.setBorderRadius(view, 1, DynamicFromObject(value))
ViewProps.BORDER_TOP_RIGHT_RADIUS ->
mViewManager.setBorderRadius(view, 2, DynamicFromObject(value))
ViewProps.BORDER_BOTTOM_RIGHT_RADIUS ->
mViewManager.setBorderRadius(view, 3, DynamicFromObject(value))
ViewProps.BORDER_BOTTOM_LEFT_RADIUS ->
mViewManager.setBorderRadius(view, 4, DynamicFromObject(value))
"borderStyle" -> mViewManager.setBorderStyle(view, value as String?)
ViewProps.BORDER_WIDTH ->
mViewManager.setBorderWidth(view, 0, (value as Double?)?.toFloat() ?: Float.NaN)
ViewProps.BORDER_LEFT_WIDTH ->
mViewManager.setBorderWidth(view, 1, (value as Double?)?.toFloat() ?: Float.NaN)
ViewProps.BORDER_RIGHT_WIDTH ->
mViewManager.setBorderWidth(view, 2, (value as Double?)?.toFloat() ?: Float.NaN)
ViewProps.BORDER_TOP_WIDTH ->
mViewManager.setBorderWidth(view, 3, (value as Double?)?.toFloat() ?: Float.NaN)
ViewProps.BORDER_BOTTOM_WIDTH ->
mViewManager.setBorderWidth(view, 4, (value as Double?)?.toFloat() ?: Float.NaN)
ViewProps.BORDER_START_WIDTH ->
mViewManager.setBorderWidth(view, 5, (value as Double?)?.toFloat() ?: Float.NaN)
ViewProps.BORDER_END_WIDTH ->
mViewManager.setBorderWidth(view, 6, (value as Double?)?.toFloat() ?: Float.NaN)
"borderColor" ->
mViewManager.setBorderColor(
view,
0,
value?.let { ColorPropConverter.getColor(it, view.context) },
)
"borderLeftColor" ->
mViewManager.setBorderColor(
view,
1,
value?.let { ColorPropConverter.getColor(it, view.context) },
)
"borderRightColor" ->
mViewManager.setBorderColor(
view,
2,
value?.let { ColorPropConverter.getColor(it, view.context) },
)
"borderTopColor" ->
mViewManager.setBorderColor(
view,
3,
value?.let { ColorPropConverter.getColor(it, view.context) },
)
"borderBottomColor" ->
mViewManager.setBorderColor(
view,
4,
value?.let { ColorPropConverter.getColor(it, view.context) },
)
ViewProps.INCLUDE_FONT_PADDING ->
mViewManager.setIncludeFontPadding(view, value as Boolean? ?: true)
"disabled" -> mViewManager.setDisabled(view, value as Boolean? ?: false)
"dataDetectorType" -> mViewManager.setDataDetectorType(view, value as String?)
else -> super.setProperty(view, propName, value)
}
} catch (e: Exception) {
throw ViewManagersPropertyCache.viewPropException(propName, mViewManager, e)
}
}

override fun receiveCommand(view: ReactTextView, commandName: String, args: ReadableArray): Unit =
Unit
}
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ import com.facebook.react.uimanager.ReactAxOrderHelper
import com.facebook.react.uimanager.Spacing
import com.facebook.react.uimanager.ThemedReactContext
import com.facebook.react.uimanager.UIManagerHelper
import com.facebook.react.uimanager.ViewManagerDelegate
import com.facebook.react.uimanager.ViewProps
import com.facebook.react.uimanager.annotations.ReactProp
import com.facebook.react.uimanager.annotations.ReactPropGroup
Expand Down Expand Up @@ -487,6 +488,11 @@ public open class ReactViewManager : ReactClippingViewManager<ReactViewGroup>()

override fun getName(): String = REACT_CLASS

// Subclasses keep the reflective delegate, which also finds the props they declare
override fun getDelegate(): ViewManagerDelegate<ReactViewGroup> =
if (javaClass == ReactViewManager::class.java) ReactViewManagerDelegate(this)
else super.getDelegate()

public override fun createViewInstance(context: ThemedReactContext): ReactViewGroup =
ReactViewGroup(context)

Expand Down
Loading
Loading