Skip to content

Commit a2fa40f

Browse files
committed
Added constraint of child type to touchablewithoutfeedback
Summary: Added constraint of child type to touchablewithoutfeedback to match touchablehighlight (this would have failed silently previously), also added the cloneWithProps as by note of @vjeux Closes facebook/react-native#517 Github Author: Daniele Zannotti <d.zannotti@me.com> Test Plan: Imported from GitHub, without a `Test Plan:` line.
1 parent b6eeb61 commit a2fa40f

1 file changed

Lines changed: 22 additions & 3 deletions

File tree

Libraries/Components/Touchable/TouchableWithoutFeedback.js

100644100755
Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,10 @@
1313

1414
var React = require('React');
1515
var Touchable = require('Touchable');
16-
16+
var keyOf = require('keyOf');
1717
var onlyChild = require('onlyChild');
18+
var cloneWithProps = require('cloneWithProps');
19+
var ensureComponentIsNative = require('ensureComponentIsNative');
1820

1921
/**
2022
* When the scroll view is disabled, this defines how far your touch may move
@@ -49,6 +51,14 @@ var TouchableWithoutFeedback = React.createClass({
4951
return this.touchableGetInitialState();
5052
},
5153

54+
componentDidMount: function() {
55+
ensureComponentIsNative(this.refs[CHILD_REF]);
56+
},
57+
58+
componentDidUpdate: function() {
59+
ensureComponentIsNative(this.refs[CHILD_REF]);
60+
},
61+
5262
/**
5363
* `Touchable.Mixin` self callbacks. The mixin will invoke these if they are
5464
* defined on your component.
@@ -78,8 +88,15 @@ var TouchableWithoutFeedback = React.createClass({
7888
},
7989

8090
render: function(): ReactElement {
81-
// Note(vjeux): use cloneWithProps once React has been upgraded
82-
var child = onlyChild(this.props.children);
91+
var child = cloneWithProps(
92+
onlyChild(this.props.children),
93+
{
94+
ref: CHILD_REF,
95+
accessible: true,
96+
testID: this.props.testID,
97+
}
98+
);
99+
83100
// Note(avik): remove dynamic typecast once Flow has been upgraded
84101
return (React: any).cloneElement(child, {
85102
accessible: true,
@@ -94,4 +111,6 @@ var TouchableWithoutFeedback = React.createClass({
94111
}
95112
});
96113

114+
var CHILD_REF = keyOf({childRef: null});
115+
97116
module.exports = TouchableWithoutFeedback;

0 commit comments

Comments
 (0)