forked from facebook/react
-
Notifications
You must be signed in to change notification settings - Fork 105
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Allow user-specified click rejection
There are occasions where you might want to reject clicks using a different strategy than just based on time-between-events. This allows the consumer to supply their own way of deciding whether or not to trigger the click event.
- Loading branch information
1 parent
341ba52
commit 9915966
Showing
3 changed files
with
64 additions
and
56 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
module.exports = function rejectGhostClicks (lastTouchEventTimestamp, clickTimestamp) { | ||
return lastTouchEventTimestamp && (clickTimestamp - lastTouchEventTimestamp < 750); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,17 @@ | ||
module.exports = function injectTapEventPlugin () { | ||
"use strict"; | ||
|
||
var defaultClickRejectionStrategy = require("./defaultClickRejectionStrategy"); | ||
|
||
module.exports = function injectTapEventPlugin (strategyOverrides) { | ||
strategyOverrides = strategyOverrides || {}; | ||
|
||
var React = require("react"); | ||
React.initializeTouchEvents(true); | ||
|
||
require('react/lib/EventPluginHub').injection.injectEventPluginsByName({ | ||
"ResponderEventPlugin": require('./ResponderEventPlugin.js'), | ||
"TapEventPlugin": require('./TapEventPlugin.js') | ||
var shouldRejectClick = strategyOverrides.shouldRejectClick || defaultClickRejectionStrategy; | ||
|
||
require("react/lib/EventPluginHub").injection.injectEventPluginsByName({ | ||
"ResponderEventPlugin": require("./ResponderEventPlugin.js"), | ||
"TapEventPlugin": require("./TapEventPlugin.js")(shouldRejectClick) | ||
}); | ||
}; |