Skip to content

Commit e802bd0

Browse files
yungstersfacebook-github-bot
authored andcommitted
RN: Prepare More Touchable Experiments
Summary: Expands `TouchableWithoutFeedbackInjection` as `TouchableInjection` for use in testing out new implementations of all five `Touchable.Mixin` components. Changelog: [Internal] Reviewed By: TheSavior Differential Revision: D18278876 fbshipit-source-id: d511bdecefe38579f03a9d5ad52011f7cd71f4c0
1 parent 654d9d0 commit e802bd0

File tree

7 files changed

+88
-27
lines changed

7 files changed

+88
-27
lines changed

Libraries/Components/Touchable/TouchableBounce.js

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@
1010

1111
'use strict';
1212

13+
import TouchableInjection from './TouchableInjection';
14+
1315
const Animated = require('../../Animated/src/Animated');
1416
const DeprecatedViewPropTypes = require('../../DeprecatedPropTypes/DeprecatedViewPropTypes');
1517
const DeprecatedEdgeInsetsPropType = require('../../DeprecatedPropTypes/DeprecatedEdgeInsetsPropType');
@@ -52,7 +54,7 @@ type Props = $ReadOnly<{|
5254
* `TouchableMixin` expects us to implement some abstract methods to handle
5355
* interesting interactions such as `handleTouchablePress`.
5456
*/
55-
const TouchableBounce = ((createReactClass({
57+
const TouchableBounceImpl = ((createReactClass({
5658
displayName: 'TouchableBounce',
5759
mixins: [Touchable.Mixin.withoutDefaultFocusAndBlur, NativeMethodsMixin],
5860

@@ -212,4 +214,9 @@ const TouchableBounce = ((createReactClass({
212214
},
213215
}): any): React.ComponentType<Props>);
214216

217+
const TouchableBounce: React.ComponentType<Props> =
218+
TouchableInjection.unstable_TouchableBounce == null
219+
? TouchableBounceImpl
220+
: TouchableInjection.unstable_TouchableBounce;
221+
215222
module.exports = TouchableBounce;

Libraries/Components/Touchable/TouchableHighlight.js

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@
1010

1111
'use strict';
1212

13+
import TouchableInjection from './TouchableInjection';
14+
1315
const DeprecatedColorPropType = require('../../DeprecatedPropTypes/DeprecatedColorPropType');
1416
const DeprecatedViewPropTypes = require('../../DeprecatedPropTypes/DeprecatedViewPropTypes');
1517
const NativeMethodsMixin = require('../../Renderer/shims/NativeMethodsMixin');
@@ -160,7 +162,7 @@ export type Props = $ReadOnly<{|
160162
*
161163
*/
162164

163-
const TouchableHighlight = ((createReactClass({
165+
const TouchableHighlightImpl = ((createReactClass({
164166
displayName: 'TouchableHighlight',
165167
propTypes: {
166168
/* $FlowFixMe(>=0.89.0 site=react_native_fb) This comment suppresses an
@@ -436,4 +438,9 @@ const TouchableHighlight = ((createReactClass({
436438
},
437439
}): any): React.ComponentType<Props>);
438440

441+
const TouchableHighlight: React.ComponentType<Props> =
442+
TouchableInjection.unstable_TouchableHighlight == null
443+
? TouchableHighlightImpl
444+
: TouchableInjection.unstable_TouchableHighlight;
445+
439446
module.exports = TouchableHighlight;
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
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+
* @format
8+
* @flow
9+
*/
10+
11+
'use strict';
12+
13+
import typeof TouchableBounce from './TouchableBounce';
14+
import typeof TouchableHighlight from './TouchableHighlight';
15+
import typeof TouchableNativeFeedback from './TouchableNativeFeedback';
16+
import typeof TouchableOpacity from './TouchableOpacity';
17+
import typeof TouchableWithoutFeedback from './TouchableWithoutFeedback';
18+
19+
export default {
20+
unstable_TouchableBounce: (null: ?TouchableBounce),
21+
unstable_TouchableHighlight: (null: ?TouchableHighlight),
22+
unstable_TouchableNativeFeedback: (null: ?TouchableNativeFeedback),
23+
unstable_TouchableOpacity: (null: ?TouchableOpacity),
24+
unstable_TouchableWithoutFeedback: (null: ?TouchableWithoutFeedback),
25+
};

Libraries/Components/Touchable/TouchableNativeFeedback.android.js

Lines changed: 36 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@
1010

1111
'use strict';
1212

13+
import TouchableInjection from './TouchableInjection';
14+
1315
const Platform = require('../../Utilities/Platform');
1416
const PropTypes = require('prop-types');
1517
const React = require('react');
@@ -23,6 +25,7 @@ const createReactClass = require('create-react-class');
2325
const ensurePositiveDelayProps = require('./ensurePositiveDelayProps');
2426
const processColor = require('../../StyleSheet/processColor');
2527

28+
import type {Props as TouchableWithoutFeedbackProps} from './TouchableWithoutFeedback';
2629
import type {PressEvent} from '../../Types/CoreEventTypes';
2730

2831
const rippleBackgroundPropType = PropTypes.shape({
@@ -43,6 +46,31 @@ const backgroundPropType = PropTypes.oneOfType([
4346

4447
const PRESS_RETENTION_OFFSET = {top: 20, left: 20, right: 20, bottom: 30};
4548

49+
export type Props = $ReadOnly<{|
50+
...TouchableWithoutFeedbackProps,
51+
52+
background?: ?(
53+
| $ReadOnly<{|
54+
type: 'ThemeAttrAndroid',
55+
attribute:
56+
| 'selectableItemBackground'
57+
| 'selectableItemBackgroundBorderless',
58+
|}>
59+
| $ReadOnly<{|
60+
type: 'RippleAndroid',
61+
color: ?number,
62+
borderless: boolean,
63+
|}>
64+
),
65+
hasTVPreferredFocus?: ?boolean,
66+
nextFocusDown?: ?number,
67+
nextFocusForward?: ?number,
68+
nextFocusLeft?: ?number,
69+
nextFocusRight?: ?number,
70+
nextFocusUp?: ?number,
71+
useForeground?: ?boolean,
72+
|}>;
73+
4674
/**
4775
* A wrapper for making views respond properly to touches (Android only).
4876
* On Android this component uses native state drawable to display touch
@@ -72,7 +100,7 @@ const PRESS_RETENTION_OFFSET = {top: 20, left: 20, right: 20, bottom: 30};
72100
* ```
73101
*/
74102

75-
const TouchableNativeFeedback = createReactClass({
103+
const TouchableNativeFeedbackImpl = createReactClass({
76104
displayName: 'TouchableNativeFeedback',
77105
propTypes: {
78106
/* $FlowFixMe(>=0.89.0 site=react_native_android_fb) This comment
@@ -294,7 +322,7 @@ const TouchableNativeFeedback = createReactClass({
294322
}
295323
if (
296324
this.props.useForeground &&
297-
!TouchableNativeFeedback.canUseNativeForeground()
325+
!TouchableNativeFeedbackImpl.canUseNativeForeground()
298326
) {
299327
console.warn(
300328
'Requested foreground ripple, but it is not available on this version of Android. ' +
@@ -304,7 +332,7 @@ const TouchableNativeFeedback = createReactClass({
304332
}
305333
const drawableProp =
306334
this.props.useForeground &&
307-
TouchableNativeFeedback.canUseNativeForeground()
335+
TouchableNativeFeedbackImpl.canUseNativeForeground()
308336
? 'nativeForegroundAndroid'
309337
: 'nativeBackgroundAndroid';
310338
const childProps = {
@@ -348,4 +376,9 @@ const TouchableNativeFeedback = createReactClass({
348376
},
349377
});
350378

379+
const TouchableNativeFeedback: React.ComponentType<Props> =
380+
TouchableInjection.unstable_TouchableNativeFeedback == null
381+
? TouchableNativeFeedbackImpl
382+
: TouchableInjection.unstable_TouchableNativeFeedback;
383+
351384
module.exports = (TouchableNativeFeedback: $FlowFixMe);

Libraries/Components/Touchable/TouchableOpacity.js

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@
1010

1111
'use strict';
1212

13+
import TouchableInjection from './TouchableInjection';
14+
1315
const Animated = require('../../Animated/src/Animated');
1416
const Easing = require('../../Animated/src/Easing');
1517
const NativeMethodsMixin = require('../../Renderer/shims/NativeMethodsMixin');
@@ -133,7 +135,7 @@ export type Props = $ReadOnly<{|
133135
* ```
134136
*
135137
*/
136-
const TouchableOpacity = ((createReactClass({
138+
const TouchableOpacityImpl = ((createReactClass({
137139
displayName: 'TouchableOpacity',
138140
mixins: [Touchable.Mixin.withoutDefaultFocusAndBlur, NativeMethodsMixin],
139141

@@ -341,4 +343,9 @@ const TouchableOpacity = ((createReactClass({
341343
},
342344
}): any): React.ComponentType<Props>);
343345

346+
const TouchableOpacity: React.ComponentType<Props> =
347+
TouchableInjection.unstable_TouchableOpacity == null
348+
? TouchableOpacityImpl
349+
: TouchableInjection.unstable_TouchableOpacity;
350+
344351
module.exports = TouchableOpacity;

Libraries/Components/Touchable/TouchableWithoutFeedback.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010

1111
'use strict';
1212

13-
import TouchableWithoutFeedbackInjection from './TouchableWithoutFeedbackInjection';
13+
import TouchableInjection from './TouchableInjection';
1414

1515
const DeprecatedEdgeInsetsPropType = require('../../DeprecatedPropTypes/DeprecatedEdgeInsetsPropType');
1616
const React = require('react');
@@ -281,8 +281,8 @@ const TouchableWithoutFeedbackImpl = ((createReactClass({
281281
}): any): React.ComponentType<Props>);
282282

283283
const TouchableWithoutFeedback: React.ComponentType<Props> =
284-
TouchableWithoutFeedbackInjection.unstable_Override == null
284+
TouchableInjection.unstable_TouchableWithoutFeedback == null
285285
? TouchableWithoutFeedbackImpl
286-
: TouchableWithoutFeedbackInjection.unstable_Override;
286+
: TouchableInjection.unstable_TouchableWithoutFeedback;
287287

288288
module.exports = TouchableWithoutFeedback;

Libraries/Components/Touchable/TouchableWithoutFeedbackInjection.js

Lines changed: 0 additions & 18 deletions
This file was deleted.

0 commit comments

Comments
 (0)