Skip to content

Commit ebf7d75

Browse files
yungstersfacebook-github-bot
authored andcommitted
RN: New TouchableWithoutFeedback
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
1 parent c5cc181 commit ebf7d75

File tree

3 files changed

+212
-285
lines changed

3 files changed

+212
-285
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
/**
2+
* Copyright (c) Facebook, Inc. and its affiliates.
3+
*
4+
* This source code is licensed under the MIT license found in the
5+
* LICENSE file in the root directory of this source tree.
6+
*
7+
* @flow
8+
* @format
9+
*/
10+
11+
'use strict';
12+
13+
import invariant from 'invariant';
14+
import ReactNative from '../../Renderer/shims/ReactNative.js';
15+
import type {
16+
BlurEvent,
17+
FocusEvent,
18+
PressEvent,
19+
} from '../../Types/CoreEventTypes';
20+
import {Platform, TVEventHandler} from 'react-native';
21+
22+
type TVTouchableConfig = $ReadOnly<{|
23+
getDisabled: () => boolean,
24+
onBlur: (event: BlurEvent) => mixed,
25+
onFocus: (event: FocusEvent) => mixed,
26+
onPress: (event: PressEvent) => mixed,
27+
|}>;
28+
29+
export default class TVTouchable {
30+
_tvEventHandler: TVEventHandler;
31+
32+
constructor(component: any, config: TVTouchableConfig) {
33+
invariant(Platform.isTV, 'TVTouchable: Requires `Platform.isTV`.');
34+
this._tvEventHandler = new TVEventHandler();
35+
this._tvEventHandler.enable(component, (_, tvData) => {
36+
tvData.dispatchConfig = {};
37+
if (ReactNative.findNodeHandle(component) === tvData.tag) {
38+
if (tvData.eventType === 'focus') {
39+
config.onFocus(tvData);
40+
} else if (tvData.eventType === 'blur') {
41+
config.onBlur(tvData);
42+
} else if (tvData.eventType === 'select') {
43+
if (!config.getDisabled()) {
44+
config.onPress(tvData);
45+
}
46+
}
47+
}
48+
});
49+
}
50+
51+
destroy(): void {
52+
this._tvEventHandler.disable();
53+
}
54+
}

0 commit comments

Comments
 (0)