Skip to content

Commit 431155d

Browse files
yungsterszpao
authored andcommitted
Revert #1536
It's causing issues in product code. Reverting until it can be investigated further.
1 parent 0f7423f commit 431155d

6 files changed

+67
-67
lines changed

src/browser/eventPlugins/DefaultEventPluginOrder.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,8 @@ var DefaultEventPluginOrder = [
3838
keyOf({SelectEventPlugin: null}),
3939
keyOf({CompositionEventPlugin: null}),
4040
keyOf({BeforeInputEventPlugin: null}),
41-
keyOf({AnalyticsEventPlugin: null})
41+
keyOf({AnalyticsEventPlugin: null}),
42+
keyOf({MobileSafariClickEventPlugin: null})
4243
];
4344

4445
module.exports = DefaultEventPluginOrder;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
/**
2+
* Copyright 2013-2014 Facebook, Inc.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*
16+
* @providesModule MobileSafariClickEventPlugin
17+
* @typechecks static-only
18+
*/
19+
20+
"use strict";
21+
22+
var EventConstants = require('EventConstants');
23+
24+
var emptyFunction = require('emptyFunction');
25+
26+
var topLevelTypes = EventConstants.topLevelTypes;
27+
28+
/**
29+
* Mobile Safari does not fire properly bubble click events on non-interactive
30+
* elements, which means delegated click listeners do not fire. The workaround
31+
* for this bug involves attaching an empty click listener on the target node.
32+
*
33+
* This particular plugin works around the bug by attaching an empty click
34+
* listener on `touchstart` (which does fire on every element).
35+
*/
36+
var MobileSafariClickEventPlugin = {
37+
38+
eventTypes: null,
39+
40+
/**
41+
* @param {string} topLevelType Record from `EventConstants`.
42+
* @param {DOMEventTarget} topLevelTarget The listening component root node.
43+
* @param {string} topLevelTargetID ID of `topLevelTarget`.
44+
* @param {object} nativeEvent Native browser event.
45+
* @return {*} An accumulation of synthetic events.
46+
* @see {EventPluginHub.extractEvents}
47+
*/
48+
extractEvents: function(
49+
topLevelType,
50+
topLevelTarget,
51+
topLevelTargetID,
52+
nativeEvent) {
53+
if (topLevelType === topLevelTypes.topTouchStart) {
54+
var target = nativeEvent.target;
55+
if (target && !target.onclick) {
56+
target.onclick = emptyFunction;
57+
}
58+
}
59+
}
60+
61+
};
62+
63+
module.exports = MobileSafariClickEventPlugin;

src/browser/eventPlugins/SimpleEventPlugin.js

-23
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,8 @@
1919
"use strict";
2020

2121
var EventConstants = require('EventConstants');
22-
var EventListener = require('EventListener');
2322
var EventPluginUtils = require('EventPluginUtils');
2423
var EventPropagators = require('EventPropagators');
25-
var ReactMount = require('ReactMount');
2624
var SyntheticClipboardEvent = require('SyntheticClipboardEvent');
2725
var SyntheticEvent = require('SyntheticEvent');
2826
var SyntheticFocusEvent = require('SyntheticFocusEvent');
@@ -33,7 +31,6 @@ var SyntheticTouchEvent = require('SyntheticTouchEvent');
3331
var SyntheticUIEvent = require('SyntheticUIEvent');
3432
var SyntheticWheelEvent = require('SyntheticWheelEvent');
3533

36-
var emptyFunction = require('emptyFunction');
3734
var invariant = require('invariant');
3835
var keyOf = require('keyOf');
3936

@@ -296,9 +293,6 @@ for (var topLevelType in topLevelEventsToDispatchConfig) {
296293
topLevelEventsToDispatchConfig[topLevelType].dependencies = [topLevelType];
297294
}
298295

299-
var ON_CLICK_KEY = keyOf({onClick: null});
300-
var onClickListeners = {};
301-
302296
var SimpleEventPlugin = {
303297

304298
eventTypes: eventTypes,
@@ -418,23 +412,6 @@ var SimpleEventPlugin = {
418412
);
419413
EventPropagators.accumulateTwoPhaseDispatches(event);
420414
return event;
421-
},
422-
423-
didPutListener: function(id, registrationName, listener) {
424-
// Mobile Safari does not fire properly bubble click events on
425-
// non-interactive elements, which means delegated click listeners do not
426-
// fire. The workaround for this bug involves attaching an empty click
427-
// listener on the target node.
428-
if (registrationName === ON_CLICK_KEY) {
429-
var node = ReactMount.getNode(id);
430-
onClickListeners[id] = EventListener.listen(node, 'click', emptyFunction);
431-
}
432-
},
433-
434-
willDeleteListener: function(id, registrationName) {
435-
if (registrationName === ON_CLICK_KEY) {
436-
onClickListeners[id].remove();
437-
}
438415
}
439416

440417
};

src/browser/ui/ReactDefaultInjection.js

+2
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ var DefaultEventPluginOrder = require('DefaultEventPluginOrder');
2626
var EnterLeaveEventPlugin = require('EnterLeaveEventPlugin');
2727
var ExecutionEnvironment = require('ExecutionEnvironment');
2828
var HTMLDOMPropertyConfig = require('HTMLDOMPropertyConfig');
29+
var MobileSafariClickEventPlugin = require('MobileSafariClickEventPlugin');
2930
var ReactBrowserComponentMixin = require('ReactBrowserComponentMixin');
3031
var ReactComponentBrowserEnvironment =
3132
require('ReactComponentBrowserEnvironment');
@@ -70,6 +71,7 @@ function inject() {
7071
EnterLeaveEventPlugin: EnterLeaveEventPlugin,
7172
ChangeEventPlugin: ChangeEventPlugin,
7273
CompositionEventPlugin: CompositionEventPlugin,
74+
MobileSafariClickEventPlugin: MobileSafariClickEventPlugin,
7375
SelectEventPlugin: SelectEventPlugin,
7476
BeforeInputEventPlugin: BeforeInputEventPlugin
7577
});

src/browser/ui/__tests__/ReactDOMComponent-test.js

-20
Original file line numberDiff line numberDiff line change
@@ -348,26 +348,6 @@ describe('ReactDOMComponent', function() {
348348
'properties to values, not a string.'
349349
);
350350
});
351-
352-
it("should execute custom event plugin listening behavior", function() {
353-
var React = require('React');
354-
var SimpleEventPlugin = require('SimpleEventPlugin');
355-
356-
SimpleEventPlugin.didPutListener = mocks.getMockFunction();
357-
SimpleEventPlugin.willDeleteListener = mocks.getMockFunction();
358-
359-
var container = document.createElement('div');
360-
React.renderComponent(
361-
<div onClick={() => true} />,
362-
container
363-
);
364-
365-
expect(SimpleEventPlugin.didPutListener.mock.calls.length).toBe(1);
366-
367-
React.unmountComponentAtNode(container);
368-
369-
expect(SimpleEventPlugin.willDeleteListener.mock.calls.length).toBe(1);
370-
});
371351
});
372352

373353
describe('updateComponent', function() {

src/event/EventPluginHub.js

-23
Original file line numberDiff line numberDiff line change
@@ -171,12 +171,6 @@ var EventPluginHub = {
171171
var bankForRegistrationName =
172172
listenerBank[registrationName] || (listenerBank[registrationName] = {});
173173
bankForRegistrationName[id] = listener;
174-
175-
var PluginModule =
176-
EventPluginRegistry.registrationNameModules[registrationName];
177-
if (PluginModule && PluginModule.didPutListener) {
178-
PluginModule.didPutListener(id, registrationName, listener);
179-
}
180174
},
181175

182176
/**
@@ -196,14 +190,7 @@ var EventPluginHub = {
196190
* @param {string} registrationName Name of listener (e.g. `onClick`).
197191
*/
198192
deleteListener: function(id, registrationName) {
199-
var PluginModule =
200-
EventPluginRegistry.registrationNameModules[registrationName];
201-
if (PluginModule && PluginModule.willDeleteListener) {
202-
PluginModule.willDeleteListener(id, registrationName);
203-
}
204-
205193
var bankForRegistrationName = listenerBank[registrationName];
206-
// TODO: This should never be null -- when is it?
207194
if (bankForRegistrationName) {
208195
delete bankForRegistrationName[id];
209196
}
@@ -216,16 +203,6 @@ var EventPluginHub = {
216203
*/
217204
deleteAllListeners: function(id) {
218205
for (var registrationName in listenerBank) {
219-
if (!listenerBank[registrationName][id]) {
220-
continue;
221-
}
222-
223-
var PluginModule =
224-
EventPluginRegistry.registrationNameModules[registrationName];
225-
if (PluginModule && PluginModule.willDeleteListener) {
226-
PluginModule.willDeleteListener(id, registrationName);
227-
}
228-
229206
delete listenerBank[registrationName][id];
230207
}
231208
},

0 commit comments

Comments
 (0)