-
Notifications
You must be signed in to change notification settings - Fork 24.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Summary: Launches a new implementation of `TouchableWithoutFeedback`. It is implemented using `Pressability` and extends `React.Component`. Notably, `propTypes` no longer exist. Changelog: [General] [Changed] - TouchableWithoutFeedback overhauled as a class without propTypes. Reviewed By: TheSavior Differential Revision: D18715852 fbshipit-source-id: f2eb28e3b8500bfcd8db44fc6bdbc0476193723a
- Loading branch information
1 parent
c5cc181
commit ebf7d75
Showing
3 changed files
with
212 additions
and
285 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
/** | ||
* 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. | ||
* | ||
* @flow | ||
* @format | ||
*/ | ||
|
||
'use strict'; | ||
|
||
import invariant from 'invariant'; | ||
import ReactNative from '../../Renderer/shims/ReactNative.js'; | ||
import type { | ||
BlurEvent, | ||
FocusEvent, | ||
PressEvent, | ||
} from '../../Types/CoreEventTypes'; | ||
import {Platform, TVEventHandler} from 'react-native'; | ||
|
||
type TVTouchableConfig = $ReadOnly<{| | ||
getDisabled: () => boolean, | ||
onBlur: (event: BlurEvent) => mixed, | ||
onFocus: (event: FocusEvent) => mixed, | ||
onPress: (event: PressEvent) => mixed, | ||
|}>; | ||
|
||
export default class TVTouchable { | ||
_tvEventHandler: TVEventHandler; | ||
|
||
constructor(component: any, config: TVTouchableConfig) { | ||
invariant(Platform.isTV, 'TVTouchable: Requires `Platform.isTV`.'); | ||
this._tvEventHandler = new TVEventHandler(); | ||
this._tvEventHandler.enable(component, (_, tvData) => { | ||
tvData.dispatchConfig = {}; | ||
if (ReactNative.findNodeHandle(component) === tvData.tag) { | ||
if (tvData.eventType === 'focus') { | ||
config.onFocus(tvData); | ||
} else if (tvData.eventType === 'blur') { | ||
config.onBlur(tvData); | ||
} else if (tvData.eventType === 'select') { | ||
if (!config.getDisabled()) { | ||
config.onPress(tvData); | ||
} | ||
} | ||
} | ||
}); | ||
} | ||
|
||
destroy(): void { | ||
this._tvEventHandler.disable(); | ||
} | ||
} |
Oops, something went wrong.