Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

codegenNativeCommands, ReadonlyArray Unsupported param type error #36817

Closed
ysfzrn opened this issue Apr 5, 2023 · 8 comments
Closed

codegenNativeCommands, ReadonlyArray Unsupported param type error #36817

ysfzrn opened this issue Apr 5, 2023 · 8 comments
Labels
Needs: Triage 🔍 Newer Patch Available Type: New Architecture Issues and PRs related to new architecture (Fabric/Turbo Modules)

Comments

@ysfzrn
Copy link

ysfzrn commented Apr 5, 2023

Description

I am creating a fabric native component and adding native commands to this component. I haven't encountered any problems with simple data types or complex view props. However, when I define object types within an array as parameters for the addPolyLine command, I get the following error from codegen. Is this a bug or am I doing something wrong?
I couldn't find an example related to this in the documentation. (I'm using typeScript)
How can I define the codegenNativeCommands function with an array or object?

Sample Code

export interface OrangeMobileMapViewProps extends ViewProps {
  theme?: WithDefault<string, 'dark'>;
  showsUserLocation?: boolean;
  polylineOptions?: Readonly<PolyLine>;
  overlay?: Readonly<Overlay>;
  onMapReady?: DirectEventHandler<null>;
  onRegionChangeComplete?: BubblingEventHandler<
    Readonly<{ latitude: Double; longitude: Double }>
  >;
}

export type OrangeMobileMapViewComponent =
  HostComponent<OrangeMobileMapViewProps>;

export interface OrangeMobileMapViewNativeCommands {
  animateToRegion: (
    viewRef: React.ElementRef<OrangeMobileMapViewComponent>,
    latitude: Float,
    longitude: Float,
    latitudeDelta: Float,
    longitudeDelta: Float,
    duration: Int32
  ) => void;
  addMarker: (
    viewRef: React.ElementRef<OrangeMobileMapViewComponent>,
    id: string,
    title: string,
    snippet: string,
    latitude: Float,
    longitude: Float,
    imageURL?: string
  ) => void;
  addPolyLine: (
    viewRef: React.ElementRef<OrangeMobileMapViewComponent>,
    id: string,
    route: ReadonlyArray<Readonly<{ latitude: Float; longitude: Float }>>,
    width: Int32,
    color: string,
    geodesic: boolean
  ) => void;
}

export const OrangeMobileMapViewCommands =
  codegenNativeCommands<OrangeMobileMapViewNativeCommands>({
    supportedCommands: ['animateToRegion', 'addMarker', 'addPolyLine'],
  });

export default codegenNativeComponent<OrangeMobileMapViewProps>(
  'OrangeMobileMapView'
) as OrangeMobileMapViewComponent;

React Native Version

0.71.5

Output of npx react-native info

Error: Unsupported param type for method "addPolyLine", param "route". Found ReadonlyArray
    at /Users/yusuf.zeren/Documents/workspace/@trendyol/orange-mobile-map/example/node_modules/react-native-codegen/lib/parsers/typescript/components/commands.js:88:15
    at Array.map (<anonymous>)
    at buildCommandSchema (/Users/yusuf.zeren/Documents/workspace/@trendyol/orange-mobile-map/example/node_modules/react-native-codegen/lib/parsers/typescript/components/commands.js:43:44)
    at /Users/yusuf.zeren/Documents/workspace/@trendyol/orange-mobile-map/example/node_modules/react-native-codegen/lib/parsers/typescript/components/commands.js:112:22
    at Array.map (<anonymous>)
    at getCommands (/Users/yusuf.zeren/Documents/workspace/@trendyol/orange-mobile-map/example/node_modules/react-native-codegen/lib/parsers/typescript/components/commands.js:112:6)
    at buildComponentSchema (/Users/yusuf.zeren/Documents/workspace/@trendyol/orange-mobile-map/example/node_modules/react-native-codegen/lib/parsers/typescript/components/index.js:264:20)
    at buildSchemaFromConfigType (/Users/yusuf.zeren/Documents/workspace/@trendyol/orange-mobile-map/example/node_modules/react-native-codegen/lib/parsers/utils.js:169:34)
    at buildSchema (/Users/yusuf.zeren/Documents/workspace/@trendyol/orange-mobile-map/example/node_modules/react-native-codegen/lib/parsers/typescript/index.js:65:10)
    at parseFile (/Users/yusuf.zeren/Documents/workspace/@trendyol/orange-mobile-map/example/node_modules/react-native-codegen/lib/parsers/utils.js:135:10)

Steps to reproduce

  • Try to define the parameters of any function created with codegenNativeCommands as an array or object.

Snack, code example, screenshot, or link to a repository

@ysfzrn ysfzrn added Needs: Triage 🔍 Type: New Architecture Issues and PRs related to new architecture (Fabric/Turbo Modules) labels Apr 5, 2023
@github-actions
Copy link

github-actions bot commented Apr 5, 2023

⚠️ Newer Version of React Native is Available!
ℹ️ You are on a supported minor version, but it looks like there's a newer patch available. Please upgrade to the highest patch for your minor or latest and verify if the issue persists (alternatively, create a new project and repro the issue in it). If it does not repro, please let us know so we can close out this issue. This helps us ensure we are looking at issues that still exist in the most recent releases.

@ysfzrn
Copy link
Author

ysfzrn commented Apr 5, 2023

Screenshot 2023-04-05 at 23 18 58

Apparently, there is no Array in the supported types of the codegenNativeCommands array. I hope, in the future, it will support the Array type.

@ysfzrn ysfzrn closed this as completed Apr 5, 2023
@cipolleschi
Copy link
Contributor

Hi @ysfzrn! We know that array support for events and commands is not existent right now. We are tracking the task and working on that internally.
We hope to be able to release something soon!

@ysfzrn
Copy link
Author

ysfzrn commented Apr 6, 2023

Hi @cipolleschi thanks for answer. The new architecture is going great, I'm sure you'll add this soon as well. Good luck!

@ravindraguptacapgemini
Copy link

@cipolleschi do we have the support for array now for events and commands?

@cipolleschi
Copy link
Contributor

For events, yes.
Commands will come in next months. We have a project officially dedicated to Codegen for this half!

@ravindraguptacapgemini
Copy link

ravindraguptacapgemini commented Aug 24, 2023

@cipolleschi is it specifically added in 0.72.4, I could not find it working in 0.72.3, tried to use ReadOnlyArray and Array both for custom types.

@cipolleschi
Copy link
Contributor

You are right. The change landed on main on May, the 4th. So it was not cherry picked into 0.72 as it was not a fix but a new feature. They will be available starting from 0.73

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Needs: Triage 🔍 Newer Patch Available Type: New Architecture Issues and PRs related to new architecture (Fabric/Turbo Modules)
Projects
None yet
Development

No branches or pull requests

3 participants