Files
react-native/packages/babel-plugin-codegen/__test_fixtures__/fixtures.js
T
Andres Suarez 8bd3edec88 Update copyright headers from Facebook to Meta
Reviewed By: aaronabramov

Differential Revision: D33367752

fbshipit-source-id: 4ce94d184485e5ee0a62cf67ad2d3ba16e285c8f
2021-12-30 15:11:21 -08:00

111 lines
2.9 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
*/
'use strict';
const NOT_A_NATIVE_COMPONENT = `
const requireNativeComponent = require('requireNativeComponent');
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<boolean, true>,
// Events
onDirectEventDefinedInlineNull: DirectEventHandler<null>,
onBubblingEventDefinedInlineNull: BubblingEventHandler<null>,
|}>;
type NativeType = NativeComponentType<ModuleProps>;
interface NativeCommands {
+hotspotUpdate: (viewRef: React.ElementRef<NativeType>, x: Int32, y: Int32) => void;
+scrollTo: (viewRef: React.ElementRef<NativeType>, y: Int32, animated: boolean) => void;
}
export const Commands = codegenNativeCommands<NativeCommands>({
supportedCommands: ['hotspotUpdate', 'scrollTo'],
});
export default codegenNativeComponent<ModuleProps>('Module', {
interfaceOnly: true,
paperComponentName: 'RCTModule',
});
`;
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<boolean, true>,
// Events
onDirectEventDefinedInlineNull: DirectEventHandler<null>,
onBubblingEventDefinedInlineNull: BubblingEventHandler<null>,
|}>;
type NativeType = NativeComponentType<ModuleProps>;
interface NativeCommands {
+hotspotUpdate: (viewRef: React.ElementRef<NativeType>, x: Int32, y: Int32) => void;
+scrollTo: (viewRef: React.ElementRef<NativeType>, y: Int32, animated: boolean) => void;
}
export const Commands = codegenNativeCommands<NativeCommands>({
supportedCommands: ['hotspotUpdate', 'scrollTo'],
});
export default (codegenNativeComponent<ModuleProps>('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,
};