mirror of
https://github.com/facebook/react-native.git
synced 2025-11-01 09:14:26 +00:00
8c8f7a510f
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
59 lines
1.7 KiB
JavaScript
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);
|