/
githubmr
/
facebook-react-native
Обзор
Документация
Войти
/
githubmr
/
facebook-react-native
Код
Запросы
0
Задачи
Вики
Пакеты
0
Релизы
0
Аналитика
main
packages/rn-tester/NativeComponentExample/js/MyNativeViewNativeComponent.js
75 строк
2 KB
Dawid Małecki
Migrate `rn-tester` codegen types imports to use root exported `CodegenTypes` namespace (#50976)
29 апр 2025, 16:06
29 апр 2025, 16:06
7959a63
Код
Авторство
О чём код?
/** * 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 type {CodegenTypes, HostComponent, ViewProps} from 'react-native'; import * as React from 'react'; import {codegenNativeCommands, codegenNativeComponent} from 'react-native'; type Event = $ReadOnly<{ values: $ReadOnlyArray<CodegenTypes.Int32>, boolValues: $ReadOnlyArray<boolean>, floats: $ReadOnlyArray<CodegenTypes.Float>, doubles: $ReadOnlyArray<CodegenTypes.Double>, yesNos: $ReadOnlyArray<'yep' | 'nope'>, strings: $ReadOnlyArray<string>, latLons: $ReadOnlyArray<{lat: CodegenTypes.Double, lon: CodegenTypes.Double}>, multiArrays: $ReadOnlyArray<$ReadOnlyArray<CodegenTypes.Int32>>, }>; type LegacyStyleEvent = $ReadOnly<{ string: string, }>; type NativeProps = $ReadOnly<{ ...ViewProps, opacity?: CodegenTypes.Float, values: $ReadOnlyArray<CodegenTypes.Int32>, // Events onIntArrayChanged?: ?CodegenTypes.BubblingEventHandler<Event>, onLegacyStyleEvent?: ?CodegenTypes.BubblingEventHandler< LegacyStyleEvent, 'alternativeLegacyName', >, }>; export type MyNativeViewType = HostComponent<NativeProps>; interface NativeCommands { +callNativeMethodToChangeBackgroundColor: ( viewRef: React.ElementRef<MyNativeViewType>, color: string, ) => void; +callNativeMethodToAddOverlays: ( viewRef: React.ElementRef<MyNativeViewType>, overlayColors: $ReadOnlyArray<string>, ) => void; +callNativeMethodToRemoveOverlays: ( viewRef: React.ElementRef<MyNativeViewType>, ) => void; +fireLagacyStyleEvent: (viewRef: React.ElementRef<MyNativeViewType>) => void; } export const Commands: NativeCommands = codegenNativeCommands<NativeCommands>({ supportedCommands: [ 'callNativeMethodToChangeBackgroundColor', 'callNativeMethodToAddOverlays', 'callNativeMethodToRemoveOverlays', 'fireLagacyStyleEvent', ], }); export default (codegenNativeComponent<NativeProps>( 'RNTMyNativeView', ): MyNativeViewType);