From 2caa696b94c5338fc2e96a180e70e5d1499b0c8e Mon Sep 17 00:00:00 2001 From: David Vacca Date: Thu, 13 Feb 2025 09:18:25 -0800 Subject: [PATCH 1/2] Remove legacy codegen of $PropSetter classes for ViewManagers that are migrated to new architecture (#49404) Summary: This diff disables codegen of legacy $PropSetter for viewManagers that implement the interface com.facebook.react.uimanager.ViewManagerWithGeneratedInterface. This logic will only be enabled for apps that are configured with BuildConfig.UNSTABLE_ENABLE_MINIFY_LEGACY_ARCHITECTURE = true changelog: [internal] internal Reviewed By: javache Differential Revision: D67412734 --- .../processing/ReactPropertyProcessor.java | 29 +++++++++++++++++-- 1 file changed, 27 insertions(+), 2 deletions(-) diff --git a/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/processing/ReactPropertyProcessor.java b/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/processing/ReactPropertyProcessor.java index 7e062bbc876c..b4bf0f510c02 100644 --- a/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/processing/ReactPropertyProcessor.java +++ b/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/processing/ReactPropertyProcessor.java @@ -20,6 +20,7 @@ import com.facebook.react.bridge.ReadableArray; import com.facebook.react.bridge.ReadableMap; import com.facebook.react.common.annotations.UnstableReactNativeAPI; +import com.facebook.react.common.build.ReactBuildConfig; import com.facebook.react.uimanager.annotations.ReactProp; import com.facebook.react.uimanager.annotations.ReactPropGroup; import com.facebook.react.uimanager.annotations.ReactPropertyHolder; @@ -93,6 +94,8 @@ public class ReactPropertyProcessor extends ProcessorBase { private static final TypeName PROPERTY_MAP_TYPE = ParameterizedTypeName.get(Map.class, String.class, String.class); + public static final String VIEW_MANAGER_INTERFACE = + "com.facebook.react.uimanager.ViewManagerWithGeneratedInterface"; private final Map mClasses; @@ -100,6 +103,7 @@ public class ReactPropertyProcessor extends ProcessorBase { @SuppressFieldNotInitialized private Messager mMessager; @SuppressFieldNotInitialized private Elements mElements; @SuppressFieldNotInitialized private Types mTypes; + @SuppressFieldNotInitialized private TypeMirror mViewManagerWithGeneratedInterface = null; static { DEFAULT_TYPES = new HashMap<>(); @@ -144,6 +148,17 @@ public synchronized void init(ProcessingEnvironment processingEnv) { mTypes = processingEnv.getTypeUtils(); } + private TypeMirror getViewManagerWithGeneratedInterface() { + if (mViewManagerWithGeneratedInterface == null) { + TypeElement typeElement = mElements.getTypeElement(VIEW_MANAGER_INTERFACE); + if (typeElement == null || typeElement.asType() == null) { + throw new IllegalStateException("Could not find " + VIEW_MANAGER_INTERFACE); + } + mViewManagerWithGeneratedInterface = typeElement.asType(); + } + return mViewManagerWithGeneratedInterface; + } + @Override public boolean processImpl(Set annotations, RoundEnvironment roundEnv) { // Clear properties from previous rounds @@ -154,7 +169,10 @@ public boolean processImpl(Set annotations, RoundEnvironm try { TypeElement classType = (TypeElement) element; ClassName className = ClassName.get(classType); - mClasses.put(className, parseClass(className, classType)); + ClassInfo classInfo = parseClass(className, classType); + if (classInfo != null) { + mClasses.put(className, classInfo); + } } catch (Exception e) { error(element, e.getMessage()); } @@ -192,9 +210,16 @@ private static boolean isShadowNodeType(TypeName typeName) { return typeName.equals(SHADOW_NODE_IMPL_TYPE); } - private ClassInfo parseClass(ClassName className, TypeElement typeElement) { + private @Nullable ClassInfo parseClass(ClassName className, TypeElement typeElement) { TypeName targetType = getTargetType(typeElement.asType()); TypeName viewType = isShadowNodeType(targetType) ? null : targetType; + boolean implementsViewManagerWithGeneratedInterface = + mTypes.isAssignable(typeElement.asType(), getViewManagerWithGeneratedInterface()); + + if (ReactBuildConfig.UNSTABLE_ENABLE_MINIFY_LEGACY_ARCHITECTURE + && implementsViewManagerWithGeneratedInterface) { + return null; + } ClassInfo classInfo = new ClassInfo(className, typeElement, viewType); findProperties(classInfo, typeElement); From 342ee6cda922f2337a315bc0f2639c3a58bd5756 Mon Sep 17 00:00:00 2001 From: David Vacca Date: Thu, 13 Feb 2025 09:18:25 -0800 Subject: [PATCH 2/2] Remove legacy codegen of $PropSetter classes for ShadowNode classes on apps running on new architecture by default Summary: This diff removes legacy codegen of $PropSetter classes for ShadowNode classes when the app has UNSTABLE_ENABLE_MINIFY_LEGACY_ARCHITECTURE enabled These classes are not used in the new architecture, let's just remove them from the apk. This change won't affect OSS changelog: [internal] internal Reviewed By: javache Differential Revision: D69569205 --- .../facebook/react/processing/ReactPropertyProcessor.java | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/processing/ReactPropertyProcessor.java b/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/processing/ReactPropertyProcessor.java index b4bf0f510c02..c264000703ab 100644 --- a/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/processing/ReactPropertyProcessor.java +++ b/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/processing/ReactPropertyProcessor.java @@ -217,7 +217,10 @@ private static boolean isShadowNodeType(TypeName typeName) { mTypes.isAssignable(typeElement.asType(), getViewManagerWithGeneratedInterface()); if (ReactBuildConfig.UNSTABLE_ENABLE_MINIFY_LEGACY_ARCHITECTURE - && implementsViewManagerWithGeneratedInterface) { + && (implementsViewManagerWithGeneratedInterface || viewType == null)) { + // When "MINIFY_LEGACY_ARCHITECTURE" is enabled, we don't want to generate the props setter + // for classes that implement ViewManagerWithGeneratedInterface or that are not a ViewManager. + // This is because we will be using the new architecture for these classes. return null; }