Files
react-native/packages/rn-tester/NativeComponentExample/js/MyNativeViewNativeComponent.js
T
Riccardo Cipolleschi 8c8f7a510f Add example in RNTester to use events with arrays (#37143)
Summary:
Pull Request resolved: https://github.com/facebook/react-native/pull/37143

This change add an example on how to use events with arrays in the New Architecture in RNTester.

## Changelog:
[Internal] - Add Examples on RNTester on how to send events with arrays from Native to JS

Reviewed By: cortinico

Differential Revision: D45357873

fbshipit-source-id: 812521aad070181759c0a1c76b5e8c628166229c
2023-05-04 04:11:49 -07:00

59 lines
1.7 KiB
JavaScript

/**
* 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.
*
* @flow strict-local
* @format
*/
import codegenNativeComponent from 'react-native/Libraries/Utilities/codegenNativeComponent';
import codegenNativeCommands from 'react-native/Libraries/Utilities/codegenNativeCommands';
import type {HostComponent} from 'react-native/Libraries/Renderer/shims/ReactNativeTypes';
import type {ViewProps} from 'react-native/Libraries/Components/View/ViewPropTypes';
import type {
Float,
Double,
Int32,
BubblingEventHandler,
} from 'react-native/Libraries/Types/CodegenTypes';
import * as React from 'react';
type Event = $ReadOnly<{
values: $ReadOnlyArray<Int32>,
boolValues: $ReadOnlyArray<boolean>,
floats: $ReadOnlyArray<Float>,
doubles: $ReadOnlyArray<Double>,
yesNos: $ReadOnlyArray<'yep' | 'nope'>,
strings: $ReadOnlyArray<string>,
latLons: $ReadOnlyArray<{|lat: Double, lon: Double|}>,
multiArrays: $ReadOnlyArray<$ReadOnlyArray<Int32>>,
}>;
type NativeProps = $ReadOnly<{|
...ViewProps,
opacity?: Float,
values: $ReadOnlyArray<Int32>,
// Events
onIntArrayChanged?: ?BubblingEventHandler<Event>,
|}>;
export type MyNativeViewType = HostComponent<NativeProps>;
interface NativeCommands {
+callNativeMethodToChangeBackgroundColor: (
viewRef: React.ElementRef<MyNativeViewType>,
color: string,
) => void;
}
export const Commands: NativeCommands = codegenNativeCommands<NativeCommands>({
supportedCommands: ['callNativeMethodToChangeBackgroundColor'],
});
export default (codegenNativeComponent<NativeProps>(
'RNTMyNativeView',
): MyNativeViewType);