Skip to content

Commit

Permalink
RN: New TouchableWithoutFeedback
Browse files Browse the repository at this point in the history
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
yungsters authored and facebook-github-bot committed Nov 27, 2019
1 parent c5cc181 commit ebf7d75
Show file tree
Hide file tree
Showing 3 changed files with 212 additions and 285 deletions.
54 changes: 54 additions & 0 deletions Libraries/Components/Touchable/TVTouchable.js
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();
}
}
Loading

0 comments on commit ebf7d75

Please sign in to comment.