RN: Cleanup `TouchableWithoutFeedback` Flow Types
Summary: Cleans up the Flow types for `TouchableWithoutFeedback`. This required converting `TVEventHandler` into a class so that Flow understands it is a instantiable type. Changelog: [Internal] Reviewed By: TheSavior Differential Revision: D18029290 fbshipit-source-id: 7855f3286020c1a1fe8b72c0303cd6b0b3389fd2
This commit is contained in:
Родитель
1e9d4cde4b
Коммит
b15473fec4
|
@ -14,41 +14,39 @@ const Platform = require('../../Utilities/Platform');
|
|||
const NativeEventEmitter = require('../../EventEmitter/NativeEventEmitter');
|
||||
|
||||
import NativeTVNavigationEventEmitter from './NativeTVNavigationEventEmitter';
|
||||
import type EmitterSubscription from '../../vendor/emitter/EmitterSubscription';
|
||||
|
||||
function TVEventHandler() {
|
||||
this.__nativeTVNavigationEventListener = null;
|
||||
this.__nativeTVNavigationEventEmitter = null;
|
||||
class TVEventHandler {
|
||||
__nativeTVNavigationEventListener: ?EmitterSubscription = null;
|
||||
__nativeTVNavigationEventEmitter: ?NativeEventEmitter = null;
|
||||
|
||||
enable(component: ?any, callback: Function): void {
|
||||
if (Platform.OS === 'ios' && !NativeTVNavigationEventEmitter) {
|
||||
return;
|
||||
}
|
||||
|
||||
this.__nativeTVNavigationEventEmitter = new NativeEventEmitter(
|
||||
NativeTVNavigationEventEmitter,
|
||||
);
|
||||
this.__nativeTVNavigationEventListener = this.__nativeTVNavigationEventEmitter.addListener(
|
||||
'onHWKeyEvent',
|
||||
data => {
|
||||
if (callback) {
|
||||
callback(component, data);
|
||||
}
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
disable(): void {
|
||||
if (this.__nativeTVNavigationEventListener) {
|
||||
this.__nativeTVNavigationEventListener.remove();
|
||||
delete this.__nativeTVNavigationEventListener;
|
||||
}
|
||||
if (this.__nativeTVNavigationEventEmitter) {
|
||||
delete this.__nativeTVNavigationEventEmitter;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
TVEventHandler.prototype.enable = function(
|
||||
component: ?any,
|
||||
callback: Function,
|
||||
) {
|
||||
if (Platform.OS === 'ios' && !NativeTVNavigationEventEmitter) {
|
||||
return;
|
||||
}
|
||||
|
||||
this.__nativeTVNavigationEventEmitter = new NativeEventEmitter(
|
||||
NativeTVNavigationEventEmitter,
|
||||
);
|
||||
this.__nativeTVNavigationEventListener = this.__nativeTVNavigationEventEmitter.addListener(
|
||||
'onHWKeyEvent',
|
||||
data => {
|
||||
if (callback) {
|
||||
callback(component, data);
|
||||
}
|
||||
},
|
||||
);
|
||||
};
|
||||
|
||||
TVEventHandler.prototype.disable = function() {
|
||||
if (this.__nativeTVNavigationEventListener) {
|
||||
this.__nativeTVNavigationEventListener.remove();
|
||||
delete this.__nativeTVNavigationEventListener;
|
||||
}
|
||||
if (this.__nativeTVNavigationEventEmitter) {
|
||||
delete this.__nativeTVNavigationEventEmitter;
|
||||
}
|
||||
};
|
||||
|
||||
module.exports = TVEventHandler;
|
||||
|
|
|
@ -23,11 +23,7 @@ const {
|
|||
DeprecatedAccessibilityRoles,
|
||||
} = require('../../DeprecatedPropTypes/DeprecatedViewAccessibility');
|
||||
|
||||
import type {
|
||||
SyntheticEvent,
|
||||
LayoutEvent,
|
||||
PressEvent,
|
||||
} from '../../Types/CoreEventTypes';
|
||||
import type {LayoutEvent, PressEvent} from '../../Types/CoreEventTypes';
|
||||
import type {EdgeInsetsProp} from '../../StyleSheet/EdgeInsetsPropType';
|
||||
import type {
|
||||
AccessibilityRole,
|
||||
|
@ -37,15 +33,6 @@ import type {
|
|||
AccessibilityValue,
|
||||
} from '../View/ViewAccessibility';
|
||||
|
||||
type TargetEvent = SyntheticEvent<
|
||||
$ReadOnly<{|
|
||||
target: number,
|
||||
|}>,
|
||||
>;
|
||||
|
||||
type BlurEvent = TargetEvent;
|
||||
type FocusEvent = TargetEvent;
|
||||
|
||||
const PRESS_RETENTION_OFFSET = {top: 20, left: 20, right: 20, bottom: 30};
|
||||
|
||||
const OVERRIDE_PROPS = [
|
||||
|
@ -65,34 +52,44 @@ const OVERRIDE_PROPS = [
|
|||
'testID',
|
||||
];
|
||||
|
||||
type TVEvent = {
|
||||
dispatchConfig: {},
|
||||
tag: number,
|
||||
};
|
||||
|
||||
type TVTouchableProps = $ReadOnly<{|
|
||||
onBlur?: ?(event: TVEvent) => mixed,
|
||||
onFocus?: ?(event: TVEvent) => mixed,
|
||||
|}>;
|
||||
|
||||
export type Props = $ReadOnly<{|
|
||||
accessible?: ?boolean,
|
||||
accessibilityLabel?: ?Stringish,
|
||||
...TVTouchableProps,
|
||||
accessibilityActions?: ?$ReadOnlyArray<AccessibilityActionInfo>,
|
||||
accessibilityHint?: ?Stringish,
|
||||
accessibilityIgnoresInvertColors?: ?boolean,
|
||||
accessibilityLabel?: ?Stringish,
|
||||
accessibilityRole?: ?AccessibilityRole,
|
||||
accessibilityState?: ?AccessibilityState,
|
||||
accessibilityActions?: ?$ReadOnlyArray<AccessibilityActionInfo>,
|
||||
accessibilityValue?: ?AccessibilityValue,
|
||||
accessible?: ?boolean,
|
||||
children?: ?React.Node,
|
||||
delayLongPress?: ?number,
|
||||
delayPressIn?: ?number,
|
||||
delayPressOut?: ?number,
|
||||
disabled?: ?boolean,
|
||||
focusable?: ?boolean,
|
||||
hitSlop?: ?EdgeInsetsProp,
|
||||
nativeID?: ?string,
|
||||
touchSoundDisabled?: ?boolean,
|
||||
onBlur?: ?(e: BlurEvent) => void,
|
||||
onFocus?: ?(e: FocusEvent) => void,
|
||||
onAccessibilityAction?: ?(event: AccessibilityActionEvent) => mixed,
|
||||
onLayout?: ?(event: LayoutEvent) => mixed,
|
||||
onLongPress?: ?(event: PressEvent) => mixed,
|
||||
onPress?: ?(event: PressEvent) => mixed,
|
||||
onPressIn?: ?(event: PressEvent) => mixed,
|
||||
onPressOut?: ?(event: PressEvent) => mixed,
|
||||
onAccessibilityAction?: ?(event: AccessibilityActionEvent) => void,
|
||||
pressRetentionOffset?: ?EdgeInsetsProp,
|
||||
rejectResponderTermination?: ?boolean,
|
||||
testID?: ?string,
|
||||
touchSoundDisabled?: ?boolean,
|
||||
|}>;
|
||||
|
||||
/**
|
||||
|
|
Загрузка…
Ссылка в новой задаче