Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added constraint of child type to touchablewithoutfeedback #517

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 22 additions & 3 deletions Libraries/Components/Touchable/TouchableWithoutFeedback.js
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,10 @@

var React = require('React');
var Touchable = require('Touchable');

var keyOf = require('keyOf');
var onlyChild = require('onlyChild');
var cloneWithProps = require('cloneWithProps');
var ensureComponentIsNative = require('ensureComponentIsNative');

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

componentDidMount: function() {
ensureComponentIsNative(this.refs[CHILD_REF]);
},

componentDidUpdate: function() {
ensureComponentIsNative(this.refs[CHILD_REF]);
},

/**
* `Touchable.Mixin` self callbacks. The mixin will invoke these if they are
* defined on your component.
Expand Down Expand Up @@ -78,8 +88,15 @@ var TouchableWithoutFeedback = React.createClass({
},

render: function(): ReactElement {
// Note(vjeux): use cloneWithProps once React has been upgraded
var child = onlyChild(this.props.children);
var child = cloneWithProps(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually, can you use React.cloneElement, cloneWithProps isn't working because it blows away the key

onlyChild(this.props.children),
{
ref: CHILD_REF,
accessible: true,
testID: this.props.testID,
}
);

// Note(avik): remove dynamic typecast once Flow has been upgraded
return (React: any).cloneElement(child, {
accessible: true,
Expand All @@ -94,4 +111,6 @@ var TouchableWithoutFeedback = React.createClass({
}
});

var CHILD_REF = keyOf({childRef: null});

module.exports = TouchableWithoutFeedback;