Skip to content

Commit 56ed15e

Browse files
coadofacebook-github-bot
authored andcommitted
Add optional reference to the TouchableHighlight and new types test (facebook#49591)
Summary: Pull Request resolved: facebook#49591 Changelog: [Internal] - Added optional reference to the TouchableHighlight and new types test Reviewed By: huntie Differential Revision: D69984286 fbshipit-source-id: f6757720d0914ea3da3a32c824eb9aaeb5a1f39b
1 parent 7b5b7b2 commit 56ed15e

File tree

3 files changed

+31
-21
lines changed

3 files changed

+31
-21
lines changed

packages/react-native/Libraries/Components/Touchable/TouchableHighlight.js

Lines changed: 19 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -32,11 +32,7 @@ type IOSProps = $ReadOnly<{
3232
hasTVPreferredFocus?: ?boolean,
3333
}>;
3434

35-
type Props = $ReadOnly<{
36-
...TouchableWithoutFeedbackProps,
37-
...AndroidProps,
38-
...IOSProps,
39-
35+
type TouchableHighlightBaseProps = $ReadOnly<{
4036
/**
4137
* Determines what the opacity of the wrapped view should be when touch is active.
4238
*/
@@ -62,6 +58,13 @@ type Props = $ReadOnly<{
6258
hostRef: React.RefSetter<React.ElementRef<typeof View>>,
6359
}>;
6460

61+
type TouchableHighlightProps = $ReadOnly<{
62+
...TouchableWithoutFeedbackProps,
63+
...AndroidProps,
64+
...IOSProps,
65+
...TouchableHighlightBaseProps,
66+
}>;
67+
6568
type ExtraStyles = $ReadOnly<{
6669
child: ViewStyleProp,
6770
underlay: ViewStyleProp,
@@ -168,7 +171,10 @@ type State = $ReadOnly<{
168171
* ```
169172
*
170173
*/
171-
class TouchableHighlight extends React.Component<Props, State> {
174+
class TouchableHighlightImpl extends React.Component<
175+
TouchableHighlightProps,
176+
State,
177+
> {
172178
_hideTimeout: ?TimeoutID;
173179
_isMounted: boolean = false;
174180

@@ -383,7 +389,7 @@ class TouchableHighlight extends React.Component<Props, State> {
383389
this.state.pressability.configure(this._createPressabilityConfig());
384390
}
385391

386-
componentDidUpdate(prevProps: Props, prevState: State) {
392+
componentDidUpdate(prevProps: TouchableHighlightProps, prevState: State) {
387393
this.state.pressability.configure(this._createPressabilityConfig());
388394
}
389395

@@ -396,13 +402,13 @@ class TouchableHighlight extends React.Component<Props, State> {
396402
}
397403
}
398404

399-
const Touchable: component(
400-
ref: React.RefSetter<React.ElementRef<typeof View>>,
401-
...props: $ReadOnly<$Diff<Props, {+hostRef: mixed}>>
405+
const TouchableHighlight: component(
406+
ref?: React.RefSetter<React.ElementRef<typeof View>>,
407+
...props: $ReadOnly<$Diff<TouchableHighlightProps, {+hostRef: mixed}>>
402408
) = React.forwardRef((props, hostRef) => (
403-
<TouchableHighlight {...props} hostRef={hostRef} />
409+
<TouchableHighlightImpl {...props} hostRef={hostRef} />
404410
));
405411

406-
Touchable.displayName = 'TouchableHighlight';
412+
TouchableHighlight.displayName = 'TouchableHighlight';
407413

408-
export default Touchable;
414+
export default TouchableHighlight;

packages/react-native/Libraries/__tests__/__snapshots__/public-api-test.js.snap

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3372,10 +3372,7 @@ exports[`public API should not change unintentionally Libraries/Components/Touch
33723372
type IOSProps = $ReadOnly<{
33733373
hasTVPreferredFocus?: ?boolean,
33743374
}>;
3375-
type Props = $ReadOnly<{
3376-
...TouchableWithoutFeedbackProps,
3377-
...AndroidProps,
3378-
...IOSProps,
3375+
type TouchableHighlightBaseProps = $ReadOnly<{
33793376
activeOpacity?: ?number,
33803377
underlayColor?: ?ColorValue,
33813378
style?: ?ViewStyleProp,
@@ -3384,11 +3381,17 @@ type Props = $ReadOnly<{
33843381
testOnly_pressed?: ?boolean,
33853382
hostRef: React.RefSetter<React.ElementRef<typeof View>>,
33863383
}>;
3387-
declare const Touchable: component(
3388-
ref: React.RefSetter<React.ElementRef<typeof View>>,
3389-
...props: $ReadOnly<$Diff<Props, { +hostRef: mixed }>>
3384+
type TouchableHighlightProps = $ReadOnly<{
3385+
...TouchableWithoutFeedbackProps,
3386+
...AndroidProps,
3387+
...IOSProps,
3388+
...TouchableHighlightBaseProps,
3389+
}>;
3390+
declare const TouchableHighlight: component(
3391+
ref?: React.RefSetter<React.ElementRef<typeof View>>,
3392+
...props: $ReadOnly<$Diff<TouchableHighlightProps, { +hostRef: mixed }>>
33903393
);
3391-
declare export default typeof Touchable;
3394+
declare export default typeof TouchableHighlight;
33923395
"
33933396
`;
33943397

packages/react-native/types/__typetests__/index.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -490,6 +490,7 @@ export class TouchableHighlightTest extends React.Component {
490490
render() {
491491
return (
492492
<>
493+
<TouchableHighlight />
493494
<TouchableHighlight ref={this.buttonRef} />
494495
<TouchableHighlight
495496
ref={ref => {

0 commit comments

Comments
 (0)