From b15473fec44f0a68d41437e25319af9b2520d0ae Mon Sep 17 00:00:00 2001 From: Tim Yung Date: Sat, 19 Oct 2019 09:49:38 -0700 Subject: [PATCH] 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 --- .../Components/AppleTV/TVEventHandler.js | 66 +++++++++---------- .../Touchable/TouchableWithoutFeedback.js | 39 +++++------ 2 files changed, 50 insertions(+), 55 deletions(-) diff --git a/Libraries/Components/AppleTV/TVEventHandler.js b/Libraries/Components/AppleTV/TVEventHandler.js index 852038ba12..d5cd47afdc 100644 --- a/Libraries/Components/AppleTV/TVEventHandler.js +++ b/Libraries/Components/AppleTV/TVEventHandler.js @@ -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; diff --git a/Libraries/Components/Touchable/TouchableWithoutFeedback.js b/Libraries/Components/Touchable/TouchableWithoutFeedback.js index adc2422898..8d065ba916 100755 --- a/Libraries/Components/Touchable/TouchableWithoutFeedback.js +++ b/Libraries/Components/Touchable/TouchableWithoutFeedback.js @@ -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, accessibilityHint?: ?Stringish, accessibilityIgnoresInvertColors?: ?boolean, + accessibilityLabel?: ?Stringish, accessibilityRole?: ?AccessibilityRole, accessibilityState?: ?AccessibilityState, - accessibilityActions?: ?$ReadOnlyArray, 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, |}>; /**