Extend Property Processor to support long properties

Summary:
This change is a preliminary change to add support to `Long` and `long` React props that are required for supporting WideGamut color space.

## Changelog
[Android][Added] - Extend Property Processor to support long props

Reviewed By: cortinico

Differential Revision: D56461183

fbshipit-source-id: 0f70388abe2b414a09df640f04e767f1164d63ce
This commit is contained in:
Riccardo Cipolleschi
2024-04-23 08:37:44 -07:00
committed by Facebook GitHub Bot
parent 0a9891a2f2
commit 0a80270187
4 changed files with 36 additions and 0 deletions
@@ -5414,6 +5414,7 @@ public abstract interface annotation class com/facebook/react/uimanager/annotati
public abstract fun defaultDouble ()D
public abstract fun defaultFloat ()F
public abstract fun defaultInt ()I
public abstract fun defaultLong ()J
public abstract fun name ()Ljava/lang/String;
}
@@ -5423,6 +5424,7 @@ public abstract interface annotation class com/facebook/react/uimanager/annotati
public abstract fun defaultDouble ()D
public abstract fun defaultFloat ()F
public abstract fun defaultInt ()I
public abstract fun defaultLong ()J
public abstract fun names ()[Ljava/lang/String;
}
@@ -108,10 +108,12 @@ public class ReactPropertyProcessor extends ProcessorBase {
DEFAULT_TYPES.put(TypeName.DOUBLE, "number");
DEFAULT_TYPES.put(TypeName.FLOAT, "number");
DEFAULT_TYPES.put(TypeName.INT, "number");
DEFAULT_TYPES.put(TypeName.LONG, "number");
// Boxed primitives
DEFAULT_TYPES.put(TypeName.BOOLEAN.box(), "boolean");
DEFAULT_TYPES.put(TypeName.INT.box(), "number");
DEFAULT_TYPES.put(TypeName.LONG.box(), "number");
// Class types
DEFAULT_TYPES.put(STRING_TYPE, "String");
@@ -124,6 +126,7 @@ public class ReactPropertyProcessor extends ProcessorBase {
BOXED_PRIMITIVES.add(TypeName.BOOLEAN.box());
BOXED_PRIMITIVES.add(TypeName.FLOAT.box());
BOXED_PRIMITIVES.add(TypeName.INT.box());
BOXED_PRIMITIVES.add(TypeName.LONG.box());
}
public ReactPropertyProcessor() {
@@ -409,6 +412,11 @@ public class ReactPropertyProcessor extends ProcessorBase {
return;
}
}
if (propertyType.equals(TypeName.LONG)) {
long defaultLong = info.mProperty.defaultLong();
builder.add("!(value instanceof Long) ? $L : (long)value", defaultLong);
return;
}
if ("Color".equals(info.mProperty.customType())) {
switch (classInfo.getType()) {
case VIEW_MANAGER:
@@ -502,6 +510,8 @@ public class ReactPropertyProcessor extends ProcessorBase {
int defaultInt();
long defaultLong();
boolean defaultBoolean();
}
@@ -537,6 +547,11 @@ public class ReactPropertyProcessor extends ProcessorBase {
return mProp.defaultInt();
}
@Override
public long defaultLong() {
return mProp.defaultLong();
}
@Override
public boolean defaultBoolean() {
return mProp.defaultBoolean();
@@ -577,6 +592,11 @@ public class ReactPropertyProcessor extends ProcessorBase {
return mProp.defaultInt();
}
@Override
public long defaultLong() {
return mProp.defaultLong();
}
@Override
public boolean defaultBoolean() {
throw new UnsupportedOperationException();
@@ -95,6 +95,13 @@ public @interface ReactProp {
*/
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
@@ -89,4 +89,11 @@ public @interface ReactPropGroup {
* 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;
}