Transform BubbleEvent and DirectEvent into DirectEventHandler and BubblingEventHandler
Summary: It appears that `(e: BubblingEvent<T>) = mixed` exists only in given context and it's pointless to keep in this way. It could be simplified to `BubblingEventHandler<T>` without any negative consequences and that's the motivation of this diff. The only tradeoff of this decision is leaving an opportunity to declare Bubbling/Direct event in the top of the file bc then analysing the code becomes much more difficult. However, it's not used anywhere so it's not a problem now and probably any time. Also, changes the names to `DirectEventHandler` and `BubblingEventHandler` which are more related to current state. The names were updated in many places in code. Reviewed By: rubennorte Differential Revision: D16054571 fbshipit-source-id: 741d075eb46b80bac8eb73a6b30fc0b448cb3902
This commit is contained in:
Родитель
58d87940a1
Коммит
0f83dfab8e
|
@ -12,7 +12,11 @@
|
|||
|
||||
import {requireNativeComponent} from 'react-native';
|
||||
|
||||
import type {DirectEvent, Int32, WithDefault} from '../../Types/CodegenTypes';
|
||||
import type {
|
||||
DirectEventHandler,
|
||||
Int32,
|
||||
WithDefault,
|
||||
} from '../../Types/CodegenTypes';
|
||||
import type {TextStyleProp} from '../../StyleSheet/StyleSheet';
|
||||
import type {ColorValue} from '../../StyleSheet/StyleSheetTypes';
|
||||
import type {NativeComponent} from '../../Renderer/shims/ReactNative';
|
||||
|
@ -39,7 +43,7 @@ type NativeProps = $ReadOnly<{|
|
|||
selected: WithDefault<Int32, 0>,
|
||||
|
||||
// Events
|
||||
onSelect?: (event: DirectEvent<PickerItemSelectEvent>) => void,
|
||||
onSelect?: DirectEventHandler<PickerItemSelectEvent>,
|
||||
|}>;
|
||||
|
||||
type ReactPicker = Class<NativeComponent<NativeProps>>;
|
||||
|
|
|
@ -12,7 +12,11 @@
|
|||
|
||||
import {requireNativeComponent} from 'react-native';
|
||||
|
||||
import type {DirectEvent, Int32, WithDefault} from '../../Types/CodegenTypes';
|
||||
import type {
|
||||
DirectEventHandler,
|
||||
Int32,
|
||||
WithDefault,
|
||||
} from '../../Types/CodegenTypes';
|
||||
import type {TextStyleProp} from '../../StyleSheet/StyleSheet';
|
||||
import type {ColorValue} from '../../StyleSheet/StyleSheetTypes';
|
||||
import type {NativeComponent} from '../../Renderer/shims/ReactNative';
|
||||
|
@ -39,7 +43,7 @@ type NativeProps = $ReadOnly<{|
|
|||
selected: WithDefault<Int32, 0>,
|
||||
|
||||
// Events
|
||||
onSelect?: (event: DirectEvent<PickerItemSelectEvent>) => void,
|
||||
onSelect?: DirectEventHandler<PickerItemSelectEvent>,
|
||||
|}>;
|
||||
|
||||
type ReactPicker = Class<NativeComponent<NativeProps>>;
|
||||
|
|
|
@ -13,7 +13,7 @@
|
|||
import codegenNativeComponent from '../../Utilities/codegenNativeComponent';
|
||||
|
||||
import type {
|
||||
DirectEvent,
|
||||
DirectEventHandler,
|
||||
Float,
|
||||
Int32,
|
||||
WithDefault,
|
||||
|
@ -56,7 +56,7 @@ type NativeProps = $ReadOnly<{|
|
|||
/**
|
||||
* Called when the view starts refreshing.
|
||||
*/
|
||||
onRefresh?: ?(event: DirectEvent<null>) => mixed,
|
||||
onRefresh?: ?DirectEventHandler<null>,
|
||||
|
||||
/**
|
||||
* Whether the view should be indicating an active refresh.
|
||||
|
|
|
@ -10,7 +10,7 @@
|
|||
|
||||
'use strict';
|
||||
|
||||
import type {DirectEvent, WithDefault} from '../../Types/CodegenTypes';
|
||||
import type {DirectEventHandler, WithDefault} from '../../Types/CodegenTypes';
|
||||
import type {ColorValue} from '../../StyleSheet/StyleSheetTypes';
|
||||
import type {ViewProps} from '../View/ViewPropTypes';
|
||||
|
||||
|
@ -35,7 +35,7 @@ type NativeProps = $ReadOnly<{|
|
|||
/**
|
||||
* Called when the view starts refreshing.
|
||||
*/
|
||||
onRefresh?: ?(event: DirectEvent<null>) => mixed,
|
||||
onRefresh?: ?DirectEventHandler<null>,
|
||||
|
||||
/**
|
||||
* Whether the view should be indicating an active refresh.
|
||||
|
|
|
@ -11,15 +11,17 @@
|
|||
|
||||
import codegenNativeComponent from '../../Utilities/codegenNativeComponent';
|
||||
import type {ViewProps} from '../View/ViewPropTypes';
|
||||
import type {BubblingEvent, WithDefault, Int32} from '../../Types/CodegenTypes';
|
||||
import type {
|
||||
BubblingEventHandler,
|
||||
WithDefault,
|
||||
Int32,
|
||||
} from '../../Types/CodegenTypes';
|
||||
import type {ColorValue} from '../../StyleSheet/StyleSheetTypes';
|
||||
|
||||
export type OnChangeEvent = BubblingEvent<
|
||||
$ReadOnly<{|
|
||||
value: Int32,
|
||||
selectedSegmentIndex: Int32,
|
||||
|}>,
|
||||
>;
|
||||
export type OnChangeEvent = $ReadOnly<{|
|
||||
value: Int32,
|
||||
selectedSegmentIndex: Int32,
|
||||
|}>;
|
||||
|
||||
type NativeProps = $ReadOnly<{|
|
||||
...ViewProps,
|
||||
|
@ -32,7 +34,7 @@ type NativeProps = $ReadOnly<{|
|
|||
momentary?: ?WithDefault<boolean, false>,
|
||||
|
||||
// Events
|
||||
onChange?: ?(event: OnChangeEvent) => mixed,
|
||||
onChange?: ?BubblingEventHandler<OnChangeEvent>,
|
||||
|}>;
|
||||
|
||||
export default codegenNativeComponent<NativeProps>('RCTSegmentedControl');
|
||||
|
|
|
@ -15,6 +15,7 @@ import StyleSheet from '../../StyleSheet/StyleSheet';
|
|||
import type {OnChangeEvent} from './RCTSegmentedControlNativeComponent';
|
||||
import type {ViewProps} from '../View/ViewPropTypes';
|
||||
import RCTSegmentedControlNativeComponent from './RCTSegmentedControlNativeComponent';
|
||||
import type {SyntheticEvent} from 'react-native/Libraries/Types/CoreEventTypes';
|
||||
|
||||
type SegmentedControlIOSProps = $ReadOnly<{|
|
||||
...ViewProps,
|
||||
|
@ -42,7 +43,7 @@ type SegmentedControlIOSProps = $ReadOnly<{|
|
|||
/**
|
||||
* Callback that is called when the user taps a segment
|
||||
*/
|
||||
onChange?: ?(event: OnChangeEvent) => mixed,
|
||||
onChange?: ?(event: SyntheticEvent<OnChangeEvent>) => mixed,
|
||||
/**
|
||||
* Callback that is called when the user taps a segment;
|
||||
* passes the segment's value as an argument
|
||||
|
@ -82,7 +83,7 @@ class SegmentedControlIOS extends React.Component<Props> {
|
|||
enabled: true,
|
||||
};
|
||||
|
||||
_onChange = (event: OnChangeEvent) => {
|
||||
_onChange = (event: SyntheticEvent<OnChangeEvent>) => {
|
||||
this.props.onChange && this.props.onChange(event);
|
||||
this.props.onValueChange &&
|
||||
this.props.onValueChange(event.nativeEvent.value);
|
||||
|
|
|
@ -12,8 +12,8 @@
|
|||
|
||||
import type {
|
||||
Float,
|
||||
BubblingEvent,
|
||||
DirectEvent,
|
||||
BubblingEventHandler,
|
||||
DirectEventHandler,
|
||||
WithDefault,
|
||||
} from '../../Types/CodegenTypes';
|
||||
|
||||
|
@ -25,7 +25,7 @@ import type {ViewProps} from '../View/ViewPropTypes';
|
|||
|
||||
type Event = $ReadOnly<{|
|
||||
value: Float,
|
||||
fromUser: boolean,
|
||||
fromUser?: boolean,
|
||||
|}>;
|
||||
|
||||
type NativeProps = $ReadOnly<{|
|
||||
|
@ -48,11 +48,9 @@ type NativeProps = $ReadOnly<{|
|
|||
value: ?WithDefault<Float, 0>,
|
||||
|
||||
// Events
|
||||
onChange?: ?(event: BubblingEvent<Event>) => void,
|
||||
onValueChange?: ?(event: BubblingEvent<Event, 'paperValueChange'>) => void,
|
||||
onSlidingComplete?: ?(
|
||||
event: DirectEvent<Event, 'paperSlidingComplete'>,
|
||||
) => void,
|
||||
onChange?: ?BubblingEventHandler<Event>,
|
||||
onValueChange?: ?BubblingEventHandler<Event, 'paperValueChange'>,
|
||||
onSlidingComplete?: ?DirectEventHandler<Event, 'paperSlidingComplete'>,
|
||||
|}>;
|
||||
|
||||
export default codegenNativeComponent<NativeProps>('Slider', {
|
||||
|
|
|
@ -10,7 +10,7 @@
|
|||
|
||||
'use strict';
|
||||
|
||||
import type {BubblingEvent, WithDefault} from '../../Types/CodegenTypes';
|
||||
import type {BubblingEventHandler, WithDefault} from '../../Types/CodegenTypes';
|
||||
import type {ColorValue} from '../../StyleSheet/StyleSheetTypes';
|
||||
import type {ViewProps} from '../View/ViewPropTypes';
|
||||
|
||||
|
@ -36,7 +36,7 @@ type NativeProps = $ReadOnly<{|
|
|||
trackColorForTrue?: ?ColorValue,
|
||||
|
||||
// Events
|
||||
onChange?: ?(event: BubblingEvent<SwitchChangeEvent>) => mixed,
|
||||
onChange?: ?BubblingEventHandler<SwitchChangeEvent>,
|
||||
|}>;
|
||||
|
||||
export default codegenNativeComponent<NativeProps>('Switch', {
|
||||
|
|
|
@ -13,8 +13,8 @@
|
|||
import codegenNativeComponent from '../Utilities/codegenNativeComponent';
|
||||
import type {
|
||||
WithDefault,
|
||||
BubblingEvent,
|
||||
DirectEvent,
|
||||
BubblingEventHandler,
|
||||
DirectEventHandler,
|
||||
Int32,
|
||||
} from '../Types/CodegenTypes';
|
||||
|
||||
|
@ -75,7 +75,7 @@ type NativeProps = $ReadOnly<{|
|
|||
*
|
||||
* See https://facebook.github.io/react-native/docs/modal.html#onrequestclose
|
||||
*/
|
||||
onRequestClose?: ?(event?: DirectEvent<null>) => mixed,
|
||||
onRequestClose?: ?DirectEventHandler<null>,
|
||||
|
||||
/**
|
||||
* The `onShow` prop allows passing a function that will be called once the
|
||||
|
@ -83,7 +83,7 @@ type NativeProps = $ReadOnly<{|
|
|||
*
|
||||
* See https://facebook.github.io/react-native/docs/modal.html#onshow
|
||||
*/
|
||||
onShow?: ?(event?: DirectEvent<null>) => mixed,
|
||||
onShow?: ?DirectEventHandler<null>,
|
||||
|
||||
/**
|
||||
* The `onDismiss` prop allows passing a function that will be called once
|
||||
|
@ -91,7 +91,7 @@ type NativeProps = $ReadOnly<{|
|
|||
*
|
||||
* See https://facebook.github.io/react-native/docs/modal.html#ondismiss
|
||||
*/
|
||||
onDismiss?: ?(event?: BubblingEvent<null>) => mixed,
|
||||
onDismiss?: ?BubblingEventHandler<null>,
|
||||
|
||||
/**
|
||||
* Deprecated. Use the `animationType` prop instead.
|
||||
|
@ -119,7 +119,7 @@ type NativeProps = $ReadOnly<{|
|
|||
*
|
||||
* See https://facebook.github.io/react-native/docs/modal.html#onorientationchange
|
||||
*/
|
||||
onOrientationChange?: ?(event: DirectEvent<OrientationChangeEvent>) => mixed,
|
||||
onOrientationChange?: ?DirectEventHandler<OrientationChangeEvent>,
|
||||
|
||||
/**
|
||||
* The `identifier` is the unique number for identifying Modal components.
|
||||
|
|
|
@ -14,14 +14,15 @@ import type {SyntheticEvent} from './CoreEventTypes';
|
|||
|
||||
// Event types
|
||||
// We're not using the PaperName, it is only used to codegen view config settings
|
||||
export type BubblingEvent<
|
||||
|
||||
export type BubblingEventHandler<
|
||||
T,
|
||||
PaperName: string | empty = empty, // eslint-disable-line no-unused-vars
|
||||
> = SyntheticEvent<T>;
|
||||
export type DirectEvent<
|
||||
> = (event: SyntheticEvent<T>) => mixed;
|
||||
export type DirectEventHandler<
|
||||
T,
|
||||
PaperName: string | empty = empty, // eslint-disable-line no-unused-vars
|
||||
> = SyntheticEvent<T>;
|
||||
> = (event: SyntheticEvent<T>) => mixed;
|
||||
|
||||
// Prop types
|
||||
export type Float = number;
|
||||
|
|
|
@ -23,8 +23,8 @@ const codegenNativeComponent = require('codegenNativeComponent');
|
|||
|
||||
import type {
|
||||
Int32,
|
||||
BubblingEvent,
|
||||
DirectEvent,
|
||||
BubblingEventHandler,
|
||||
DirectEventHandler,
|
||||
WithDefault,
|
||||
} from 'CodegenFlowtypes';
|
||||
|
||||
|
@ -42,8 +42,8 @@ type ModuleProps = $ReadOnly<{|
|
|||
boolean_default_true_optional_both?: ?WithDefault<boolean, true>,
|
||||
|
||||
// Events
|
||||
onDirectEventDefinedInlineNull: (event: DirectEvent<null>) => void,
|
||||
onBubblingEventDefinedInlineNull: (event: BubblingEvent<null>) => void,
|
||||
onDirectEventDefinedInlineNull: DirectEventHandler<null>,
|
||||
onBubblingEventDefinedInlineNull: BubblingEventHandler<null>,
|
||||
|}>;
|
||||
|
||||
export const Commands = codegenNativeCommands<NativeCommands>();
|
||||
|
|
|
@ -6,7 +6,7 @@ const codegenNativeCommands = require('codegenNativeCommands');
|
|||
|
||||
const codegenNativeComponent = require('codegenNativeComponent');
|
||||
|
||||
import type { Int32, BubblingEvent, DirectEvent, WithDefault } from 'CodegenFlowtypes';
|
||||
import type { Int32, BubblingEventHandler, DirectEventHandler, WithDefault } from 'CodegenFlowtypes';
|
||||
import type { ViewProps } from 'ViewPropTypes';
|
||||
interface NativeCommands {
|
||||
+hotspotUpdate: (viewRef: React.Ref<'RCTView'>, x: Int32, y: Int32) => void,
|
||||
|
@ -16,8 +16,8 @@ type ModuleProps = $ReadOnly<{| ...ViewProps,
|
|||
// Props
|
||||
boolean_default_true_optional_both?: ?WithDefault<boolean, true>,
|
||||
// Events
|
||||
onDirectEventDefinedInlineNull: (event: DirectEvent<null>) => void,
|
||||
onBubblingEventDefinedInlineNull: (event: BubblingEvent<null>) => void,
|
||||
onDirectEventDefinedInlineNull: DirectEventHandler<null>,
|
||||
onBubblingEventDefinedInlineNull: BubblingEventHandler<null>,
|
||||
|}>;
|
||||
export const Commands = codegenNativeCommands<NativeCommands>();
|
||||
|
||||
|
|
|
@ -12,7 +12,7 @@
|
|||
|
||||
import type {
|
||||
Int32,
|
||||
BubblingEvent,
|
||||
BubblingEventHandler,
|
||||
WithDefault,
|
||||
} from '../../../../Libraries/Types/CodegenTypes';
|
||||
import type {ViewProps} from '../../../../Libraries/Components/View/ViewPropTypes';
|
||||
|
@ -35,7 +35,7 @@ type NativeProps = $ReadOnly<{|
|
|||
disabled?: WithDefault<boolean, false>,
|
||||
|
||||
// Events
|
||||
onChange?: ?(event: BubblingEvent<OnChangeEvent>) => void,
|
||||
onChange?: ?BubblingEventHandler<OnChangeEvent>,
|
||||
|}>;
|
||||
|
||||
export default codegenNativeComponent<NativeProps>(
|
||||
|
|
|
@ -13,8 +13,8 @@
|
|||
import type {
|
||||
Int32,
|
||||
Float,
|
||||
BubblingEvent,
|
||||
DirectEvent,
|
||||
BubblingEventHandler,
|
||||
DirectEventHandler,
|
||||
WithDefault,
|
||||
} from '../../../../Libraries/Types/CodegenTypes';
|
||||
import type {ViewProps} from '../../../../Libraries/Components/View/ViewPropTypes';
|
||||
|
@ -42,16 +42,21 @@ type NativeProps = $ReadOnly<{|
|
|||
disabled?: WithDefault<boolean, false>,
|
||||
|
||||
// Events
|
||||
onChange?: ?(event: BubblingEvent<OnChangeEvent>) => void,
|
||||
onEventDirect?: ?(event: DirectEvent<OnEventDirect>) => void,
|
||||
onEventDirectWithPaperName?: ?(
|
||||
event: DirectEvent<OnEventDirect, 'paperDirectName'>,
|
||||
) => void,
|
||||
onOrientationChange?: ?(event: DirectEvent<OnOrientationChangeEvent>) => void,
|
||||
onEnd?: ?(event: BubblingEvent<null>) => void,
|
||||
onEventBubblingWithPaperName?: ?(
|
||||
event: BubblingEvent<null, 'paperBubblingName'>,
|
||||
) => void,
|
||||
onChange?: ?BubblingEventHandler<OnChangeEvent, 'paperDirectName'>,
|
||||
onEventDirect?: ?DirectEventHandler<OnEventDirect>,
|
||||
onEventDirectWithPaperName?: ?DirectEventHandler<
|
||||
OnEventDirect,
|
||||
'paperDirectName',
|
||||
>,
|
||||
onOrientationChange?: ?DirectEventHandler<
|
||||
OnOrientationChangeEvent,
|
||||
'paperBubblingName',
|
||||
>,
|
||||
onEnd?: ?BubblingEventHandler<null>,
|
||||
onEventBubblingWithPaperName?: ?BubblingEventHandler<
|
||||
null,
|
||||
'paperBubblingName',
|
||||
>,
|
||||
|}>;
|
||||
|
||||
export default codegenNativeComponent<NativeProps>('EventPropsNativeComponent');
|
||||
|
|
|
@ -11,7 +11,7 @@
|
|||
'use strict';
|
||||
|
||||
import type {
|
||||
BubblingEvent,
|
||||
BubblingEventHandler,
|
||||
WithDefault,
|
||||
} from '../../../../Libraries/Types/CodegenTypes';
|
||||
import type {ViewProps} from '../../../../Libraries/Components/View/ViewPropTypes';
|
||||
|
@ -24,7 +24,7 @@ type NativeProps = $ReadOnly<{|
|
|||
accessibilityHint?: WithDefault<string, ''>,
|
||||
|
||||
// Events
|
||||
onChange?: ?(event: BubblingEvent<$ReadOnly<{|value: boolean|}>>) => void,
|
||||
onChange?: ?BubblingEventHandler<$ReadOnly<{|value: boolean|}>>,
|
||||
|}>;
|
||||
|
||||
export default codegenNativeComponent<NativeProps>(
|
||||
|
|
|
@ -78,8 +78,8 @@ const ONE_OF_EACH_PROP_EVENT_DEFAULT_AND_OPTIONS = `
|
|||
const codegenNativeComponent = require('codegenNativeComponent');
|
||||
|
||||
import type {
|
||||
BubblingEvent,
|
||||
DirectEvent,
|
||||
BubblingEventHandler,
|
||||
DirectEventHandler,
|
||||
WithDefault,
|
||||
} from 'CodegenTypes';
|
||||
|
||||
|
@ -92,8 +92,8 @@ type ModuleProps = $ReadOnly<{|
|
|||
boolean_default_true_optional_both?: ?WithDefault<boolean, true>,
|
||||
|
||||
// Events
|
||||
onDirectEventDefinedInlineNull: (event: DirectEvent<null>) => void,
|
||||
onBubblingEventDefinedInlineNull: (event: BubblingEvent<null>) => void,
|
||||
onDirectEventDefinedInlineNull: DirectEventHandler<null>,
|
||||
onBubblingEventDefinedInlineNull: BubblingEventHandler<null>,
|
||||
|}>;
|
||||
|
||||
export default codegenNativeComponent<ModuleProps>('Module', {
|
||||
|
@ -331,8 +331,8 @@ const codegenNativeComponent = require('codegenNativeComponent');
|
|||
import type {
|
||||
Int32,
|
||||
Float,
|
||||
BubblingEvent,
|
||||
DirectEvent,
|
||||
BubblingEventHandler,
|
||||
DirectEventHandler,
|
||||
} from 'CodegenTypes';
|
||||
|
||||
import type {ViewProps} from 'ViewPropTypes';
|
||||
|
@ -342,226 +342,77 @@ type ModuleProps = $ReadOnly<{|
|
|||
// No Props
|
||||
|
||||
// Events
|
||||
onDirectEventDefinedInline: (
|
||||
event: DirectEvent<
|
||||
onDirectEventDefinedInline:
|
||||
DirectEventHandler<
|
||||
$ReadOnly<{|
|
||||
${EVENT_DEFINITION}
|
||||
|}>,
|
||||
>,
|
||||
) => void,
|
||||
|
||||
onDirectEventDefinedInlineOptionalKey?: (
|
||||
event: DirectEvent<
|
||||
onDirectEventDefinedInlineOptionalKey?:
|
||||
DirectEventHandler<
|
||||
$ReadOnly<{|
|
||||
${EVENT_DEFINITION}
|
||||
|}>,
|
||||
>,
|
||||
) => void,
|
||||
|
||||
onDirectEventDefinedInlineOptionalValue: ?(
|
||||
event: DirectEvent<
|
||||
onDirectEventDefinedInlineOptionalValue: ?
|
||||
DirectEventHandler<
|
||||
$ReadOnly<{|
|
||||
${EVENT_DEFINITION}
|
||||
|}>,
|
||||
>,
|
||||
) => void,
|
||||
|
||||
onDirectEventDefinedInlineOptionalBoth?: ?(
|
||||
event: DirectEvent<
|
||||
onDirectEventDefinedInlineOptionalBoth?: ?
|
||||
DirectEventHandler<
|
||||
$ReadOnly<{|
|
||||
${EVENT_DEFINITION}
|
||||
|}>,
|
||||
>,
|
||||
) => void,
|
||||
|
||||
onDirectEventDefinedInlineWithPaperName?: ?(
|
||||
event: DirectEvent<
|
||||
onDirectEventDefinedInlineWithPaperName?: ?
|
||||
DirectEventHandler<
|
||||
$ReadOnly<{|
|
||||
${EVENT_DEFINITION}
|
||||
|}>,
|
||||
'paperDirectEventDefinedInlineWithPaperName',
|
||||
>,
|
||||
) => void,
|
||||
|
||||
onBubblingEventDefinedInline: (
|
||||
event: BubblingEvent<
|
||||
onBubblingEventDefinedInline:
|
||||
BubblingEventHandler<
|
||||
$ReadOnly<{|
|
||||
${EVENT_DEFINITION}
|
||||
|}>,
|
||||
>,
|
||||
) => void,
|
||||
|
||||
onBubblingEventDefinedInlineOptionalKey?: (
|
||||
event: BubblingEvent<
|
||||
onBubblingEventDefinedInlineOptionalKey?:
|
||||
BubblingEventHandler<
|
||||
$ReadOnly<{|
|
||||
${EVENT_DEFINITION}
|
||||
|}>,
|
||||
>,
|
||||
) => void,
|
||||
|
||||
onBubblingEventDefinedInlineOptionalValue: ?(
|
||||
event: BubblingEvent<
|
||||
onBubblingEventDefinedInlineOptionalValue: ?
|
||||
BubblingEventHandler<
|
||||
$ReadOnly<{|
|
||||
${EVENT_DEFINITION}
|
||||
|}>,
|
||||
>,
|
||||
) => void,
|
||||
|
||||
onBubblingEventDefinedInlineOptionalBoth?: ?(
|
||||
event: BubblingEvent<
|
||||
onBubblingEventDefinedInlineOptionalBoth?: ?
|
||||
BubblingEventHandler<
|
||||
$ReadOnly<{|
|
||||
${EVENT_DEFINITION}
|
||||
|}>,
|
||||
>,
|
||||
) => void,
|
||||
|
||||
onBubblingEventDefinedInlineWithPaperName?: ?(
|
||||
event: BubblingEvent<
|
||||
onBubblingEventDefinedInlineWithPaperName?: ?
|
||||
BubblingEventHandler<
|
||||
$ReadOnly<{|
|
||||
${EVENT_DEFINITION}
|
||||
|}>,
|
||||
'paperBubblingEventDefinedInlineWithPaperName'
|
||||
>,
|
||||
'paperBubblingEventDefinedInlineWithPaperName',
|
||||
) => void,
|
||||
|}>;
|
||||
|
||||
export default codegenNativeComponent<ModuleProps>('Module');
|
||||
`;
|
||||
|
||||
const EVENTS_DEFINED_IN_FILE_WITH_ALL_TYPES = `
|
||||
/**
|
||||
* Copyright (c) Facebook, Inc. and its affiliates.
|
||||
*
|
||||
* This source code is licensed under the MIT license found in the
|
||||
* LICENSE file in the root directory of this source tree.
|
||||
*
|
||||
* @format
|
||||
* @flow
|
||||
*/
|
||||
|
||||
'use strict';
|
||||
|
||||
const codegenNativeComponent = require('codegenNativeComponent');
|
||||
|
||||
import type {Float, Int32, BubblingEvent, DirectEvent} from 'CodegenTypes';
|
||||
|
||||
import type {ViewProps} from 'ViewPropTypes';
|
||||
|
||||
type EventInFile = $ReadOnly<{|
|
||||
${EVENT_DEFINITION}
|
||||
|}>;
|
||||
|
||||
type DirectEventInFile = DirectEvent<EventInFile>;
|
||||
type BubblingEventInFile = BubblingEvent<EventInFile>;
|
||||
|
||||
type DirectEventInFileWithPaperName = DirectEvent<
|
||||
EventInFile,
|
||||
'paperDirectEventInFileWithPaperName',
|
||||
>;
|
||||
type BubblingEventInFileWithPaperName = BubblingEvent<
|
||||
EventInFile,
|
||||
'paperBubblingEventInFileWithPaperName',
|
||||
>;
|
||||
|
||||
type ModuleProps = $ReadOnly<{|
|
||||
...ViewProps,
|
||||
|
||||
// No props
|
||||
|
||||
// Events
|
||||
// Events defined elsewhere in file
|
||||
|
||||
onDirectEventDefinedInFile: (event: DirectEventInFile) => void,
|
||||
onDirectEventDefinedInFileOptionalKey?: (event: DirectEventInFile) => void,
|
||||
onDirectEventDefinedInFileOptionalValue: ?(event: DirectEventInFile) => void,
|
||||
onDirectEventDefinedInFileOptionalBoth?: ?(event: DirectEventInFile) => void,
|
||||
onDirectEventDefinedInFileWithPaperName?: ?(
|
||||
event: DirectEventInFileWithPaperName,
|
||||
) => void,
|
||||
|
||||
onBubblingEventDefinedInFile: (event: BubblingEventInFile) => void,
|
||||
onBubblingEventDefinedInFileOptionalKey?: (
|
||||
event: BubblingEventInFile,
|
||||
) => void,
|
||||
onBubblingEventDefinedInFileOptionalValue: ?(
|
||||
event: BubblingEventInFile,
|
||||
) => void,
|
||||
onBubblingEventDefinedInFileOptionalBoth?: ?(
|
||||
event: BubblingEventInFile,
|
||||
) => void,
|
||||
onBubblingEventDefinedInFileWithPaperName?: ?(
|
||||
event: BubblingEventInFileWithPaperName,
|
||||
) => void,
|
||||
|}>;
|
||||
|
||||
export default codegenNativeComponent<ModuleProps>('Module');
|
||||
`;
|
||||
|
||||
const EVENTS_DEFINED_AS_NULL_IN_FILE = `
|
||||
/**
|
||||
* Copyright (c) Facebook, Inc. and its affiliates.
|
||||
*
|
||||
* This source code is licensed under the MIT license found in the
|
||||
* LICENSE file in the root directory of this source tree.
|
||||
*
|
||||
* @format
|
||||
* @flow
|
||||
*/
|
||||
|
||||
'use strict';
|
||||
|
||||
import type {BubblingEvent, DirectEvent} from 'CodegenTypes';
|
||||
import type {ViewProps} from 'ViewPropTypes';
|
||||
|
||||
const codegenNativeComponent = require('codegenNativeComponent');
|
||||
|
||||
type DirectEventDefinedInFileNull = DirectEvent<null>;
|
||||
type BubblingEventDefinedInFileNull = BubblingEvent<null>;
|
||||
|
||||
type DirectEventDefinedInFileNullWithPaperName = DirectEvent<
|
||||
null,
|
||||
'paperDirectEventDefinedInFileNullWithPaperName',
|
||||
>;
|
||||
type BubblingEventDefinedInFileNullWithPaperName = DirectEvent<
|
||||
null,
|
||||
'paperBubblingEventDefinedInFileNullWithPaperName',
|
||||
>;
|
||||
|
||||
type ModuleProps = $ReadOnly<{|
|
||||
...ViewProps,
|
||||
|
||||
// No props
|
||||
|
||||
// Events defined elsewhere in file
|
||||
onDirectEventDefinedInFileNull: (event: DirectEventDefinedInFileNull) => void,
|
||||
onDirectEventDefinedInFileNullOptionalKey?: (
|
||||
event: DirectEventDefinedInFileNull,
|
||||
) => void,
|
||||
onDirectEventDefinedInFileNullOptionalValue: ?(
|
||||
event: DirectEventDefinedInFileNull,
|
||||
) => void,
|
||||
onDirectEventDefinedInFileNullOptionalBoth?: ?(
|
||||
event: DirectEventDefinedInFileNull,
|
||||
) => void,
|
||||
onDirectEventDefinedInFileNullWithPaperName?: ?(
|
||||
event: DirectEventDefinedInFileNullWithPaperName,
|
||||
) => void,
|
||||
|
||||
onBubblingEventDefinedInFileNull: (
|
||||
event: BubblingEventDefinedInFileNull,
|
||||
) => void,
|
||||
onBubblingEventDefinedInFileNullOptionalKey?: (
|
||||
event: BubblingEventDefinedInFileNull,
|
||||
) => void,
|
||||
onBubblingEventDefinedInFileNullOptionalValue: ?(
|
||||
event: BubblingEventDefinedInFileNull,
|
||||
) => void,
|
||||
onBubblingEventDefinedInFileNullOptionalBoth?: ?(
|
||||
event: BubblingEventDefinedInFileNull,
|
||||
) => void,
|
||||
onBubblingEventDefinedInFileNullOptionalBoth?: ?(
|
||||
event: BubblingEventDefinedInFileNullWithPaperName,
|
||||
) => void,
|
||||
|}>;
|
||||
|
||||
export default codegenNativeComponent<ModuleProps>('Module');
|
||||
|
@ -581,7 +432,13 @@ const EVENTS_DEFINED_AS_NULL_INLINE = `
|
|||
|
||||
'use strict';
|
||||
|
||||
import type {BubblingEvent, DirectEvent} from 'CodegenTypes';
|
||||
const codegenNativeComponent = require('codegenNativeComponent');
|
||||
|
||||
import type {
|
||||
BubblingEventHandler,
|
||||
DirectEventHandler,
|
||||
} from 'CodegenTypese';
|
||||
|
||||
import type {ViewProps} from 'ViewPropTypes';
|
||||
|
||||
const codegenNativeComponent = require('codegenNativeComponent');
|
||||
|
@ -592,36 +449,25 @@ type ModuleProps = $ReadOnly<{|
|
|||
// No props
|
||||
|
||||
// Events defined inline
|
||||
onDirectEventDefinedInlineNull: (event: DirectEvent<null>) => void,
|
||||
onDirectEventDefinedInlineNullOptionalKey?: (
|
||||
event: DirectEvent<null>,
|
||||
) => void,
|
||||
onDirectEventDefinedInlineNullOptionalValue: ?(
|
||||
event: DirectEvent<null>,
|
||||
) => void,
|
||||
onDirectEventDefinedInlineNullOptionalBoth?: ?(
|
||||
event: DirectEvent<null>,
|
||||
) => void,
|
||||
onDirectEventDefinedInlineNullWithPaperName?: ?(
|
||||
event: DirectEvent<null, 'paperDirectEventDefinedInlineNullWithPaperName'>,
|
||||
) => void,
|
||||
onDirectEventDefinedInlineNull:DirectEventHandler<null>,
|
||||
onDirectEventDefinedInlineNullOptionalKey?: DirectEventHandler<null>,
|
||||
onDirectEventDefinedInlineNullOptionalValue: ?DirectEventHandler<null>,
|
||||
onDirectEventDefinedInlineNullOptionalBoth?: DirectEventHandler<null>,
|
||||
onDirectEventDefinedInlineNullWithPaperName?: ?
|
||||
DirectEventHandler<
|
||||
null,
|
||||
'paperDirectEventDefinedInlineNullWithPaperName',
|
||||
>,
|
||||
|
||||
onBubblingEventDefinedInlineNull: (event: BubblingEvent<null>) => void,
|
||||
onBubblingEventDefinedInlineNullOptionalKey?: (
|
||||
event: BubblingEvent<null>,
|
||||
) => void,
|
||||
onBubblingEventDefinedInlineNullOptionalValue: ?(
|
||||
event: BubblingEvent<null>,
|
||||
) => void,
|
||||
onBubblingEventDefinedInlineNullOptionalBoth?: ?(
|
||||
event: BubblingEvent<null>,
|
||||
) => void,
|
||||
onBubblingEventDefinedInlineNullWithPaperName?: ?(
|
||||
event: BubblingEvent<
|
||||
onBubblingEventDefinedInlineNull: BubblingEventHandler<null>,
|
||||
onBubblingEventDefinedInlineNullOptionalKey?: BubblingEventHandler<null>,
|
||||
onBubblingEventDefinedInlineNullOptionalValue: ?BubblingEventHandler<null>,
|
||||
onBubblingEventDefinedInlineNullOptionalBoth?: ?BubblingEventHandler<null>,
|
||||
onBubblingEventDefinedInlineNullWithPaperName?: ?
|
||||
BubblingEventHandler<
|
||||
null,
|
||||
'paperBubblingEventDefinedInlineNullWithPaperName',
|
||||
>,
|
||||
) => void,
|
||||
|}>;
|
||||
|
||||
export default codegenNativeComponent<ModuleProps>('Module');
|
||||
|
@ -640,7 +486,11 @@ const PROPS_AND_EVENTS_TYPES_EXPORTED = `
|
|||
|
||||
'use strict';
|
||||
|
||||
import type {BubblingEvent, DirectEvent} from 'CodegenTypes';
|
||||
import type {
|
||||
BubblingEventHandler,
|
||||
DirectEventHandler,
|
||||
} from 'CodegenTypes';
|
||||
|
||||
import type {ViewProps} from 'ViewPropTypes';
|
||||
|
||||
const codegenNativeComponent = require('codegenNativeComponent');
|
||||
|
@ -655,21 +505,10 @@ export type ModuleProps = $ReadOnly<{|
|
|||
// No props
|
||||
|
||||
// Events defined inline
|
||||
onBubblingEventDefinedInline: (event: BubblingEvent<EventInFile>) => void,
|
||||
onBubblingEventDefinedInlineWithPaperName: (
|
||||
event: BubblingEvent<
|
||||
EventInFile,
|
||||
'paperBubblingEventDefinedInlineWithPaperName',
|
||||
>,
|
||||
) => void,
|
||||
|
||||
onDirectEventDefinedInline: (event: DirectEvent<EventInFile>) => void,
|
||||
onDirectEventDefinedInlineWithPaperName: (
|
||||
event: DirectEvent<
|
||||
EventInFile,
|
||||
'paperDirectEventDefinedInlineWithPaperName',
|
||||
>,
|
||||
) => void,
|
||||
onBubblingEventDefinedInline: BubblingEventHandler<EventInFile>,
|
||||
onBubblingEventDefinedInlineWithPaperName: BubblingEventHandler<EventInFile, 'paperBubblingEventDefinedInlineWithPaperName'>,
|
||||
onDirectEventDefinedInline: DirectEventHandler<EventInFile>,
|
||||
onDirectEventDefinedInlineWithPaperName: DirectEventHandler<EventInFile, 'paperDirectEventDefinedInlineWithPaperName'>,
|
||||
|}>;
|
||||
|
||||
export default codegenNativeComponent<ModuleProps>('Module');
|
||||
|
@ -693,8 +532,8 @@ const codegenNativeCommands = require('codegenNativeCommands');
|
|||
|
||||
import type {
|
||||
Int32,
|
||||
BubblingEvent,
|
||||
DirectEvent,
|
||||
BubblingEventHandler,
|
||||
DirectEventHandler,
|
||||
} from 'CodegenTypes';
|
||||
|
||||
import type {ViewProps} from 'ViewPropTypes';
|
||||
|
@ -720,8 +559,6 @@ module.exports = {
|
|||
ONE_OF_EACH_PROP_EVENT_DEFAULT_AND_OPTIONS,
|
||||
NO_PROPS_EVENTS_ONLY_DEPRECATED_VIEW_CONFIG_NAME_OPTION,
|
||||
EVENTS_DEFINED_INLINE_WITH_ALL_TYPES,
|
||||
EVENTS_DEFINED_IN_FILE_WITH_ALL_TYPES,
|
||||
EVENTS_DEFINED_AS_NULL_IN_FILE,
|
||||
EVENTS_DEFINED_AS_NULL_INLINE,
|
||||
PROPS_AND_EVENTS_TYPES_EXPORTED,
|
||||
COMMANDS_DEFINED_WITH_ALL_TYPES,
|
||||
|
|
Разница между файлами не показана из-за своего большого размера
Загрузить разницу
|
@ -76,8 +76,8 @@ function findEventArgumentsAndType(
|
|||
paperTopLevelNameDeprecated: paperName,
|
||||
bubblingType,
|
||||
};
|
||||
} else if (name === 'BubblingEvent' || name === 'DirectEvent') {
|
||||
const eventType = name === 'BubblingEvent' ? 'bubble' : 'direct';
|
||||
} else if (name === 'BubblingEventHandler' || name === 'DirectEventHandler') {
|
||||
const eventType = name === 'BubblingEventHandler' ? 'bubble' : 'direct';
|
||||
const paperTopLevelNameDeprecated =
|
||||
typeAnnotation.typeParameters.params.length > 1
|
||||
? typeAnnotation.typeParameters.params[1].value
|
||||
|
@ -146,7 +146,11 @@ function buildEventSchema(
|
|||
? property.value.typeAnnotation
|
||||
: property.value;
|
||||
|
||||
if (typeAnnotation.type !== 'FunctionTypeAnnotation') {
|
||||
if (
|
||||
typeAnnotation.type !== 'GenericTypeAnnotation' ||
|
||||
(typeAnnotation.id.name !== 'BubblingEventHandler' &&
|
||||
typeAnnotation.id.name !== 'DirectEventHandler')
|
||||
) {
|
||||
return null;
|
||||
}
|
||||
|
||||
|
@ -154,7 +158,7 @@ function buildEventSchema(
|
|||
argumentProps,
|
||||
bubblingType,
|
||||
paperTopLevelNameDeprecated,
|
||||
} = findEventArgumentsAndType(typeAnnotation.params[0].typeAnnotation, types);
|
||||
} = findEventArgumentsAndType(typeAnnotation, types);
|
||||
|
||||
if (bubblingType && argumentProps) {
|
||||
if (paperTopLevelNameDeprecated != null) {
|
||||
|
|
|
@ -194,7 +194,11 @@ function buildPropSchema(property): ?PropTypeShape {
|
|||
: property.value;
|
||||
|
||||
let type = typeAnnotation.type;
|
||||
if (type === 'FunctionTypeAnnotation') {
|
||||
if (
|
||||
type === 'GenericTypeAnnotation' &&
|
||||
(typeAnnotation.id.name === 'DirectEventHandler' ||
|
||||
typeAnnotation.id.name === 'BubblingEventHandler')
|
||||
) {
|
||||
return null;
|
||||
}
|
||||
|
||||
|
|
Загрузка…
Ссылка в новой задаче