From ccd3b047709fda00123e8aec4294dce024b80244 Mon Sep 17 00:00:00 2001 From: Dmitry Rykun Date: Fri, 5 Jan 2024 02:47:17 -0800 Subject: [PATCH] Add Float and Int type support for Android modules (#42126) Summary: Pull Request resolved: https://github.com/facebook/react-native/pull/42126 This diff changes how numeric types are generated for Android native modules. Before this diff: |Codegen Type|Java Type| | -- | -- | |number|double| |Float|double| |Double|double| |Int32|double| After this diff: |Codegen Type|Java Type| | -- | -- | |number|double| |Float|**float**| |Double|double| |Int32|**int**| Changelog: [Android][Breaking] - Codegen: mapping for numeric types is changed for Android native modules. `Float` -> `float`; `Int32` -> `int`. Reviewed By: cipolleschi Differential Revision: D52420921 fbshipit-source-id: 32b3bbdf5fd24db8d7ac12c262bab5fde4e1f2bc --- .../src/generators/modules/GenerateModuleJavaSpec.js | 4 ++-- .../src/generators/modules/GenerateModuleJniCpp.js | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/packages/react-native-codegen/src/generators/modules/GenerateModuleJavaSpec.js b/packages/react-native-codegen/src/generators/modules/GenerateModuleJavaSpec.js index 219978bb3a5280..2dc407f303476f 100644 --- a/packages/react-native-codegen/src/generators/modules/GenerateModuleJavaSpec.js +++ b/packages/react-native-codegen/src/generators/modules/GenerateModuleJavaSpec.js @@ -136,11 +136,11 @@ function translateFunctionParamToJavaType( case 'NumberTypeAnnotation': return wrapOptional('double', isRequired); case 'FloatTypeAnnotation': - return wrapOptional('double', isRequired); + return wrapOptional('float', isRequired); case 'DoubleTypeAnnotation': return wrapOptional('double', isRequired); case 'Int32TypeAnnotation': - return wrapOptional('double', isRequired); + return wrapOptional('int', isRequired); case 'BooleanTypeAnnotation': return wrapOptional('boolean', isRequired); case 'EnumDeclaration': diff --git a/packages/react-native-codegen/src/generators/modules/GenerateModuleJniCpp.js b/packages/react-native-codegen/src/generators/modules/GenerateModuleJniCpp.js index d4544873fa2ac2..d024c4078a1fa9 100644 --- a/packages/react-native-codegen/src/generators/modules/GenerateModuleJniCpp.js +++ b/packages/react-native-codegen/src/generators/modules/GenerateModuleJniCpp.js @@ -334,9 +334,9 @@ function translateReturnTypeToJniType( case 'DoubleTypeAnnotation': return nullable ? 'Ljava/lang/Double;' : 'D'; case 'FloatTypeAnnotation': - return nullable ? 'Ljava/lang/Double;' : 'D'; + return nullable ? 'Ljava/lang/Float;' : 'F'; case 'Int32TypeAnnotation': - return nullable ? 'Ljava/lang/Double;' : 'D'; + return nullable ? 'Ljava/lang/Integer;' : 'I'; case 'PromiseTypeAnnotation': return 'Lcom/facebook/react/bridge/Promise;'; case 'GenericObjectTypeAnnotation':