Convert ReactProp.java to Kotlin (#50671)

Summary:
Pull Request resolved: https://github.com/facebook/react-native/pull/50671

Changelog:
[Internal]

Reviewed By: cortinico

Differential Revision: D72803988

fbshipit-source-id: 00bacd99f1bde19d905eba71a820496ad6328b2c
This commit is contained in:
Omar Bafagih authored and Facebook GitHub Bot committed 2025-04-14 13:22:09 -07:00
1 parent 47157aaf3a
commit 5aa8288e85
3 files changed
+102 -109

No files matched your search

@@ -4929,6 +4929,7 @@ public final class com/facebook/react/uimanager/ViewProps {
}
public abstract interface annotation class com/facebook/react/uimanager/annotations/ReactProp : java/lang/annotation/Annotation {
public static final field Companion Lcom/facebook/react/uimanager/annotations/ReactProp$Companion;
public static final field USE_DEFAULT_TYPE Ljava/lang/String;
public abstract fun customType ()Ljava/lang/String;
public abstract fun defaultBoolean ()Z
@@ -4939,6 +4940,10 @@ public abstract interface annotation class com/facebook/react/uimanager/annotati
public abstract fun name ()Ljava/lang/String;
}
public final class com/facebook/react/uimanager/annotations/ReactProp$Companion {
public static final field USE_DEFAULT_TYPE Ljava/lang/String;
}
public abstract interface annotation class com/facebook/react/uimanager/annotations/ReactPropGroup : java/lang/annotation/Annotation {
public static final field Companion Lcom/facebook/react/uimanager/annotations/ReactPropGroup$Companion;
public static final field USE_DEFAULT_TYPE Ljava/lang/String;
@@ -1,109 +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.uimanager.annotations;
import static java.lang.annotation.RetentionPolicy.RUNTIME;
import androidx.annotation.Nullable;
import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.Target;
/**
* Use this annotation to annotate properties of native views that should be exposed to JS. This
* annotation should only be used for setter methods of subclasses of {@link
* com.facebook.react.uimanager.ViewManager}.
*
* <p>Each annotated method should return {@code void} and take exactly two arguments: first being a
* view instance to be updated and second a value that should be set.
*
* <p>Allowed types of values are:
*
* <ul>
* <li>primitives (int, boolean, double, float)
* <li>{@link String}
* <li>{@link Boolean}
* <li>{@link com.facebook.react.bridge.ReadableArray}
* <li>{@link com.facebook.react.bridge.ReadableMap}
* </ul>
*
* <p>When property gets removed from the corresponding component in React, annotated setter will be
* called with {@code null} in case of non-primitive value type or with a default value in case when
* the value type is a primitive (use appropriate default field of this annotation to customize
* default value that is going to be used: {@link #defaultBoolean}, {@link #defaultDouble}, etc.)
*
* <p>Since in case of property removal for non-primitive value type setter will be called with
* value set to {@code null} it's required that value type is annotated with {@link Nullable}.
*
* <p>Note: Since boolean property type can be represented both as primitive and wrapped default
* value set through {@link #defaultBoolean} is only respected for primitive type and for the
* wrapped type {@code null} will be used as a default.
*/
@Retention(RUNTIME)
@Target(ElementType.METHOD)
public @interface ReactProp {
// Used as a default value for "customType" property as "null" is not allowed. Moreover, when this
// const is used in annotation declaration compiler will actually create a copy of it, so
// comparing it using "==" with this filed doesn't work either. We need to compare using "equals"
// which means that this value needs to be unique.
String USE_DEFAULT_TYPE = "__default_type__";
/**
* Name of the property exposed to JS that will be updated using setter method annotated with the
* given instance of {@code ReactProp} annotation
*/
String name();
/**
* Type of property that will be send to JS. In most of the cases {@code customType} should not be
* set in which case default type will be send to JS based on the type of value argument from the
* setter method (e.g. for {@code int}, {@code double} default is "number", for {@code
* ReadableArray} it's "Array"). Custom type may be used when additional processing of the value
* needs to be done in JS before sending it over the bridge. A good example of that would be
* backgroundColor property, which is expressed as a {@code String} in JS, but we use {@code
* processColor} JS module to convert it to {@code int} before sending over the bridge.
*/
@Nullable
String customType() default USE_DEFAULT_TYPE;
/**
* Default value for property of type {@code double}. This value will be provided to property
* setter method annotated with {@link ReactProp} if property with a given name gets removed from
* the component description in JS
*/
double defaultDouble() default 0.0;
/**
* Default value for property of type {@code float}. This value will be provided to property
* setter method annotated with {@link ReactProp} if property with a given name gets removed from
* the component description in JS
*/
float defaultFloat() default 0.0f;
/**
* Default value for property of type {@code int}. This value will be provided to property setter
* method annotated with {@link ReactProp} if property with a given name gets removed from the
* component description in JS
*/
int defaultInt() default 0;
/**
* Default value for property of type {@code long}. This value will be provided to property setter
* method annotated with {@link ReactProp} if property with a given name gets removed from the
* component description in JS
*/
long defaultLong() default 0L;
/**
* Default value for property of type {@code boolean}. This value will be provided to property
* setter method annotated with {@link ReactProp} if property with a given name gets removed from
* the component description in JS
*/
boolean defaultBoolean() default false;
}
@@ -0,0 +1,97 @@
/*
* 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.annotations
/**
* Use this annotation to annotate properties of native views that should be exposed to JS. This
* annotation should only be used for setter methods of subclasses of
* [com.facebook.react.uimanager.ViewManager].
*
* Each annotated method should return `void` and take exactly two arguments: first being a view
* instance to be updated and second a value that should be set.
*
* Allowed types of values are:
* * primitives (int, boolean, double, float)
* * [String]
* * [Boolean]
* * [com.facebook.react.bridge.ReadableArray]
* * [com.facebook.react.bridge.ReadableMap]
*
* When property gets removed from the corresponding component in React, annotated setter will be
* called with `null` in case of non-primitive value type or with a default value in case when the
* value type is a primitive (use appropriate default field of this annotation to customize default
* value that is going to be used: [defaultBoolean], [defaultDouble], etc.)
*
* Since in case of property removal for non-primitive value type setter will be called with value
* set to `null` it's required that value type is annotated with [Nullable].
*
* Note: Since boolean property type can be represented both as primitive and wrapped default value
* set through [defaultBoolean] is only respected for primitive type and for the wrapped type `null`
* will be used as a default.
*/
@Retention(AnnotationRetention.RUNTIME)
@Target(
AnnotationTarget.FUNCTION, AnnotationTarget.PROPERTY_GETTER, AnnotationTarget.PROPERTY_SETTER)
public annotation class ReactProp(
/**
* Name of the property exposed to JS that will be updated using setter method annotated with
* the given instance of `ReactProp` annotation
*/
public val name: String,
/**
* Type of property that will be send to JS. In most of the cases `customType` should not be set
* in which case default type will be send to JS based on the type of value argument from the
* setter method (e.g. for `int`, `double` default is "number", for `ReadableArray` it's
* "Array"). Custom type may be used when additional processing of the value needs to be done in
* JS before sending it over the bridge. A good example of that would be backgroundColor
* property, which is expressed as a `String` in JS, but we use `processColor` JS module to
* convert it to `int` before sending over the bridge.
*/
public val customType: String = USE_DEFAULT_TYPE,
/**
* Default value for property of type `double`. This value will be provided to property setter
* method annotated with [ReactProp] if property with a given name gets removed from the
* component description in JS
*/
public val defaultDouble: Double = 0.0,
/**
* Default value for property of type `float`. This value will be provided to property setter
* method annotated with [ReactProp] if property with a given name gets removed from the
* component description in JS
*/
public val defaultFloat: Float = 0.0f,
/**
* Default value for property of type `int`. This value will be provided to property setter
* method annotated with [ReactProp] if property with a given name gets removed from the
* component description in JS
*/
public val defaultInt: Int = 0,
/**
* Default value for property of type `long`. This value will be provided to property setter
* method annotated with [ReactProp] if property with a given name gets removed from the
* component description in JS
*/
public val defaultLong: Long = 0L,
/**
* Default value for property of type `boolean`. This value will be provided to property setter
* method annotated with [ReactProp] if property with a given name gets removed from the
* component description in JS
*/
public val defaultBoolean: Boolean = false
) {
public companion object {
// Used as a default value for "customType" property as "null" is not allowed. Moreover, when
// this
// const is used in annotation declaration compiler will actually create a copy of it, so
// comparing it using "==" with this filed doesn't work either. We need to compare using
// "equals"
// which means that this value needs to be unique.
public const val USE_DEFAULT_TYPE: String = "__default_type__"
}
}