/** * 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 */ 'use strict'; const NOT_A_NATIVE_COMPONENT = ` const requireNativeComponent = require('requireNativeComponent').default; export default 'Not a view config' `; const FULL_NATIVE_COMPONENT = ` // @flow const codegenNativeCommands = require('codegenNativeCommands'); const codegenNativeComponent = require('codegenNativeComponent'); import type { Int32, BubblingEventHandler, DirectEventHandler, WithDefault, } from 'CodegenFlowtypes'; import type {NativeComponentType} from 'codegenNativeComponent'; import type {ViewProps} from 'ViewPropTypes'; type ModuleProps = $ReadOnly<{| ...ViewProps, // Props boolean_default_true_optional_both?: WithDefault, // Events onDirectEventDefinedInlineNull: DirectEventHandler, onBubblingEventDefinedInlineNull: BubblingEventHandler, |}>; type NativeType = NativeComponentType; interface NativeCommands { +hotspotUpdate: (viewRef: React.ElementRef, x: Int32, y: Int32) => void; +scrollTo: (viewRef: React.ElementRef, y: Int32, animated: boolean) => void; } export const Commands = codegenNativeCommands({ supportedCommands: ['hotspotUpdate', 'scrollTo'], }); export default codegenNativeComponent('Module', { interfaceOnly: true, paperComponentName: 'RCTModule', }); `; // Coverage instrumentation test cases - should be recognized as valid const COMMANDS_WITH_SIMPLE_COVERAGE = ` // @flow const codegenNativeCommands = require('codegenNativeCommands'); const codegenNativeComponent = require('codegenNativeComponent'); import type {ViewProps} from 'ViewPropTypes'; import type {NativeComponentType} from 'codegenNativeComponent'; type ModuleProps = $ReadOnly<{| ...ViewProps, |}>; type NativeType = NativeComponentType; interface NativeCommands { +pause: (viewRef: React.ElementRef) => void; +play: (viewRef: React.ElementRef) => void; } export const Commands = (cov_1234567890.s[0]++, codegenNativeCommands({ supportedCommands: ['pause', 'play'], })); export default codegenNativeComponent('Module'); `; const COMMANDS_WITH_COMPLEX_COVERAGE = ` // @flow const codegenNativeCommands = require('codegenNativeCommands'); const codegenNativeComponent = require('codegenNativeComponent'); import type {ViewProps} from 'ViewPropTypes'; import type {NativeComponentType} from 'codegenNativeComponent'; type ModuleProps = $ReadOnly<{| ...ViewProps, |}>; type NativeType = NativeComponentType; interface NativeCommands { +seek: (viewRef: React.ElementRef, position: number) => void; +stop: (viewRef: React.ElementRef) => void; } export const Commands = ( cov_abcdef123().f[2]++, cov_abcdef123().s[5]++, codegenNativeCommands({ supportedCommands: ['seek', 'stop'], }) ); export default codegenNativeComponent('Module'); `; const COMMANDS_WITH_TYPE_CAST_COVERAGE = ` // @flow const codegenNativeCommands = require('codegenNativeCommands'); const codegenNativeComponent = require('codegenNativeComponent'); import type {ViewProps} from 'ViewPropTypes'; import type {NativeComponentType} from 'codegenNativeComponent'; type ModuleProps = $ReadOnly<{| ...ViewProps, |}>; type NativeType = NativeComponentType; interface NativeCommands { +mute: (viewRef: React.ElementRef) => void; +unmute: (viewRef: React.ElementRef) => void; } export const Commands: NativeCommands = (cov_xyz789().s[1]++, codegenNativeCommands({ supportedCommands: ['mute', 'unmute'], })); export default codegenNativeComponent('Module'); `; const FULL_NATIVE_COMPONENT_WITH_TYPE_EXPORT = ` // @flow const codegenNativeCommands = require('codegenNativeCommands'); const codegenNativeComponent = require('codegenNativeComponent'); import type {NativeComponentType} from 'codegenNativeComponent'; import type { Int32, BubblingEventHandler, DirectEventHandler, WithDefault, } from 'CodegenFlowtypes'; import type {ViewProps} from 'ViewPropTypes'; type ModuleProps = $ReadOnly<{| ...ViewProps, // Props boolean_default_true_optional_both?: WithDefault, // Events onDirectEventDefinedInlineNull: DirectEventHandler, onBubblingEventDefinedInlineNull: BubblingEventHandler, |}>; type NativeType = NativeComponentType; interface NativeCommands { +hotspotUpdate: (viewRef: React.ElementRef, x: Int32, y: Int32) => void; +scrollTo: (viewRef: React.ElementRef, y: Int32, animated: boolean) => void; } export const Commands = codegenNativeCommands({ supportedCommands: ['hotspotUpdate', 'scrollTo'], }); export default (codegenNativeComponent('Module', { interfaceOnly: true, paperComponentName: 'RCTModule', }): NativeType); `; module.exports = { 'NotANativeComponent.js': NOT_A_NATIVE_COMPONENT, 'FullNativeComponent.js': FULL_NATIVE_COMPONENT, 'FullTypedNativeComponent.js': FULL_NATIVE_COMPONENT_WITH_TYPE_EXPORT, 'CommandsWithSimpleCoverageNativeComponent.js': COMMANDS_WITH_SIMPLE_COVERAGE, 'CommandsWithComplexCoverageNativeComponent.js': COMMANDS_WITH_COMPLEX_COVERAGE, 'CommandsWithTypeCastCoverageNativeComponent.js': COMMANDS_WITH_TYPE_CAST_COVERAGE, };