Skip to content

Support "onMouseEnter" and "onMouseLeave" props #231

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

Draft
wants to merge 15 commits into
base: window
Choose a base branch
from
Draft
Show file tree
Hide file tree
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
15 changes: 1 addition & 14 deletions Libraries/Components/ScrollResponder.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ const performanceNow = require('fbjs/lib/performanceNow');
const warning = require('fbjs/lib/warning');

const { ScrollViewManager } = require('NativeModules');
const { getInstanceFromNode } = require('ReactNativeComponentTree');

/**
* Mixin that can be integrated in order to handle scrolling that plays well
Expand Down Expand Up @@ -117,15 +116,6 @@ type State = {
};
type Event = Object;

function isTagInstanceOfTextInput(tag) {
const instance = getInstanceFromNode(tag);
return instance && instance.viewConfig && (
instance.viewConfig.uiViewClassName === 'AndroidTextInput' ||
instance.viewConfig.uiViewClassName === 'RCTMultilineTextInputView' ||
instance.viewConfig.uiViewClassName === 'RCTSinglelineTextInputView'
);
}

const ScrollResponderMixin = {
mixins: [Subscribable.Mixin],
scrollResponderMixinGetInitialState: function(): State {
Expand Down Expand Up @@ -208,10 +198,7 @@ const ScrollResponderMixin = {
const {keyboardShouldPersistTaps} = this.props;
const keyboardNeverPersistTaps = !keyboardShouldPersistTaps ||
keyboardShouldPersistTaps === 'never';
if (keyboardNeverPersistTaps &&
currentlyFocusedTextInput != null &&
!isTagInstanceOfTextInput(e.target)
) {
if (keyboardNeverPersistTaps && currentlyFocusedTextInput != null) {
return true;
}
return this.scrollResponderIsAnimating();
Expand Down
2 changes: 2 additions & 0 deletions Libraries/Components/Touchable/TouchableOpacity.js
Original file line number Diff line number Diff line change
Expand Up @@ -260,6 +260,8 @@ var TouchableOpacity = createReactClass({
onResponderRelease={this.touchableHandleResponderRelease}
onResponderTerminate={this.touchableHandleResponderTerminate}
onMouseMove={this.props.onMouseMove}
onMouseEnter={this.props.onMouseEnter}
onMouseLeave={this.props.onMouseLeave}
onMouseOver={this.props.onMouseOver}
onMouseOut={this.props.onMouseOut}
onContextMenu={this.props.onContextMenu}
Expand Down
4 changes: 4 additions & 0 deletions Libraries/Components/Touchable/TouchableWithoutFeedback.js
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,8 @@ const TouchableWithoutFeedback = createReactClass({
*/
hitSlop: EdgeInsetsPropType,
onMouseMove: PropTypes.func,
onMouseEnter: PropTypes.func,
onMouseLeave: PropTypes.func,
onMouseOver: PropTypes.func,
onMouseOut: PropTypes.func,
onContextMenu: PropTypes.func,
Expand Down Expand Up @@ -216,6 +218,8 @@ const TouchableWithoutFeedback = createReactClass({
onResponderRelease: this.touchableHandleResponderRelease,
onResponderTerminate: this.touchableHandleResponderTerminate,
onMouseMove: this.props.onMouseMove,
onMouseEnter: this.props.onMouseEnter,
onMouseLeave: this.props.onMouseLeave,
onMouseOver: this.props.onMouseOver,
onMouseOut: this.props.onMouseOut,
onContextMenu: this.props.onContextMenu,
Expand Down
2 changes: 2 additions & 0 deletions Libraries/Components/View/ReactNativeViewAttributes.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ ReactNativeViewAttributes.UIView = {
shouldRasterizeIOS: true,
onLayout: true,
onMouseMove: true,
onMouseEnter: true,
onMouseLeave: true,
onMouseOver: true,
onMouseOut: true,
onContextMenu: true,
Expand Down
4 changes: 2 additions & 2 deletions Libraries/Components/View/View.js
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,8 @@ const View = createReactClass({

render: function() {
invariant(
!(this.context.isInAParentText && Platform.OS === 'android'),
'Nesting of <View> within <Text> is not supported on Android.');
!this.context.isInAParentText,
'Nesting of <View> within <Text> is not currently supported.');

// WARNING: This method will not be used in production mode as in that mode we
// replace wrapper component View with generated native wrapper RCTView. Avoid
Expand Down
2 changes: 2 additions & 0 deletions Libraries/Components/View/ViewPropTypes.js
Original file line number Diff line number Diff line change
Expand Up @@ -434,6 +434,8 @@ module.exports = {
* @platform macos
*/
onMouseMove: PropTypes.func,
onMouseEnter: PropTypes.func,
onMouseLeave: PropTypes.func,
onMouseOver: PropTypes.func,
onMouseOut: PropTypes.func,
onDragEnter: PropTypes.func,
Expand Down
2 changes: 1 addition & 1 deletion Libraries/Core/InitializeCore.js
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ Object.defineProperty(global.process, 'argv',
// Setup the Systrace profiling hooks if necessary
if (global.__RCTProfileIsProfiling) {
const Systrace = require('Systrace');
Systrace.installReactHook(true);
Systrace.installReactHook();
Systrace.setEnabled(true);
}

Expand Down
2 changes: 1 addition & 1 deletion Libraries/Interaction/PanResponder.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
'use strict';

const InteractionManager = require('./InteractionManager');
const TouchHistoryMath = require('TouchHistoryMath');
const TouchHistoryMath = require('./TouchHistoryMath');

const currentCentroidXOfTouchesChangedAfter = TouchHistoryMath.currentCentroidXOfTouchesChangedAfter;
const currentCentroidYOfTouchesChangedAfter = TouchHistoryMath.currentCentroidYOfTouchesChangedAfter;
Expand Down
151 changes: 151 additions & 0 deletions Libraries/Interaction/TouchHistoryMath.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,151 @@
/**
* Copyright (c) 2016-present, Facebook, Inc.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/

const TouchHistoryMath = {
/**
* This code is optimized and not intended to look beautiful. This allows
* computing of touch centroids that have moved after `touchesChangedAfter`
* timeStamp. You can compute the current centroid involving all touches
* moves after `touchesChangedAfter`, or you can compute the previous
* centroid of all touches that were moved after `touchesChangedAfter`.
*
* @param {TouchHistoryMath} touchHistory Standard Responder touch track
* data.
* @param {number} touchesChangedAfter timeStamp after which moved touches
* are considered "actively moving" - not just "active".
* @param {boolean} isXAxis Consider `x` dimension vs. `y` dimension.
* @param {boolean} ofCurrent Compute current centroid for actively moving
* touches vs. previous centroid of now actively moving touches.
* @return {number} value of centroid in specified dimension.
*/
centroidDimension: function(
touchHistory,
touchesChangedAfter,
isXAxis,
ofCurrent,
) {
const touchBank = touchHistory.touchBank;
let total = 0;
let count = 0;

const oneTouchData =
touchHistory.numberActiveTouches === 1
? touchHistory.touchBank[touchHistory.indexOfSingleActiveTouch]
: null;

if (oneTouchData !== null) {
if (
oneTouchData.touchActive &&
oneTouchData.currentTimeStamp > touchesChangedAfter
) {
total +=
ofCurrent && isXAxis
? oneTouchData.currentPageX
: ofCurrent && !isXAxis
? oneTouchData.currentPageY
: !ofCurrent && isXAxis
? oneTouchData.previousPageX
: oneTouchData.previousPageY;
count = 1;
}
} else {
for (let i = 0; i < touchBank.length; i++) {
const touchTrack = touchBank[i];
if (
touchTrack !== null &&
touchTrack !== undefined &&
touchTrack.touchActive &&
touchTrack.currentTimeStamp >= touchesChangedAfter
) {
let toAdd; // Yuck, program temporarily in invalid state.
if (ofCurrent && isXAxis) {
toAdd = touchTrack.currentPageX;
} else if (ofCurrent && !isXAxis) {
toAdd = touchTrack.currentPageY;
} else if (!ofCurrent && isXAxis) {
toAdd = touchTrack.previousPageX;
} else {
toAdd = touchTrack.previousPageY;
}
total += toAdd;
count++;
}
}
}
return count > 0 ? total / count : TouchHistoryMath.noCentroid;
},

currentCentroidXOfTouchesChangedAfter: function(
touchHistory,
touchesChangedAfter,
) {
return TouchHistoryMath.centroidDimension(
touchHistory,
touchesChangedAfter,
true, // isXAxis
true, // ofCurrent
);
},

currentCentroidYOfTouchesChangedAfter: function(
touchHistory,
touchesChangedAfter,
) {
return TouchHistoryMath.centroidDimension(
touchHistory,
touchesChangedAfter,
false, // isXAxis
true, // ofCurrent
);
},

previousCentroidXOfTouchesChangedAfter: function(
touchHistory,
touchesChangedAfter,
) {
return TouchHistoryMath.centroidDimension(
touchHistory,
touchesChangedAfter,
true, // isXAxis
false, // ofCurrent
);
},

previousCentroidYOfTouchesChangedAfter: function(
touchHistory,
touchesChangedAfter,
) {
return TouchHistoryMath.centroidDimension(
touchHistory,
touchesChangedAfter,
false, // isXAxis
false, // ofCurrent
);
},

currentCentroidX: function(touchHistory) {
return TouchHistoryMath.centroidDimension(
touchHistory,
0, // touchesChangedAfter
true, // isXAxis
true, // ofCurrent
);
},

currentCentroidY: function(touchHistory) {
return TouchHistoryMath.centroidDimension(
touchHistory,
0, // touchesChangedAfter
false, // isXAxis
true, // ofCurrent
);
},

noCentroid: -1,
};

module.exports = TouchHistoryMath;
64 changes: 8 additions & 56 deletions Libraries/Performance/Systrace.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ let _asyncCookie = 0;
const _markStack = [];
let _markStackIndex = -1;
let _canInstallReactHook = false;
let _useFiber = false;

// Implements a subset of User Timing API necessary for React measurements.
// https://developer.mozilla.org/en-US/docs/Web/API/User_Timing_API
Expand Down Expand Up @@ -100,54 +99,13 @@ const userTimingPolyfill = __DEV__ ? {
},
} : null;

// A hook to get React Stack markers in Systrace.
const reactDebugToolHook = __DEV__ ? {
onBeforeMountComponent(debugID) {
const ReactComponentTreeHook = require('ReactGlobalSharedState').ReactComponentTreeHook;
const displayName = ReactComponentTreeHook.getDisplayName(debugID);
Systrace.beginEvent(`ReactReconciler.mountComponent(${displayName})`);
},
onMountComponent(debugID) {
Systrace.endEvent();
},
onBeforeUpdateComponent(debugID) {
const ReactComponentTreeHook = require('ReactGlobalSharedState').ReactComponentTreeHook;
const displayName = ReactComponentTreeHook.getDisplayName(debugID);
Systrace.beginEvent(`ReactReconciler.updateComponent(${displayName})`);
},
onUpdateComponent(debugID) {
Systrace.endEvent();
},
onBeforeUnmountComponent(debugID) {
const ReactComponentTreeHook = require('ReactGlobalSharedState').ReactComponentTreeHook;
const displayName = ReactComponentTreeHook.getDisplayName(debugID);
Systrace.beginEvent(`ReactReconciler.unmountComponent(${displayName})`);
},
onUnmountComponent(debugID) {
Systrace.endEvent();
},
onBeginLifeCycleTimer(debugID, timerType) {
const ReactComponentTreeHook = require('ReactGlobalSharedState').ReactComponentTreeHook;
const displayName = ReactComponentTreeHook.getDisplayName(debugID);
Systrace.beginEvent(`${displayName}.${timerType}()`);
},
onEndLifeCycleTimer(debugID, timerType) {
Systrace.endEvent();
},
} : null;

const Systrace = {
installReactHook(useFiber: boolean) {
installReactHook() {
if (_enabled) {
if (__DEV__) {
if (useFiber) {
global.performance = userTimingPolyfill;
} else {
require('ReactDebugTool').addHook(reactDebugToolHook);
}
global.performance = userTimingPolyfill;
}
}
_useFiber = useFiber;
_canInstallReactHook = true;
},

Expand All @@ -160,17 +118,8 @@ const Systrace = {
global.nativeTraceEndLegacy && global.nativeTraceEndLegacy(TRACE_TAG_JS_VM_CALLS);
}
if (_canInstallReactHook) {
if (_useFiber) {
if (enabled && global.performance === undefined) {
global.performance = userTimingPolyfill;
}
} else {
const ReactDebugTool = require('ReactDebugTool');
if (enabled) {
ReactDebugTool.addHook(reactDebugToolHook);
} else {
ReactDebugTool.removeHook(reactDebugToolHook);
}
if (enabled && global.performance === undefined) {
global.performance = userTimingPolyfill;
}
}
}
Expand Down Expand Up @@ -240,7 +189,10 @@ const Systrace = {
* therefore async variant of profiling is used
**/
attachToRelayProfiler(relayProfiler: RelayProfiler) {
relayProfiler.attachProfileHandler('*', (name) => {
relayProfiler.attachProfileHandler('*', (name, state?) => {
if (state != null && state.queryName !== undefined) {
name += '_' + state.queryName;
}
const cookie = Systrace.beginAsyncEvent(name);
return () => {
Systrace.endAsyncEvent(name, cookie);
Expand Down
6 changes: 0 additions & 6 deletions Libraries/ReactNative/requireNativeComponent.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
'use strict';

const Platform = require('Platform');
const ReactNativeBridgeEventPlugin = require('ReactNativeBridgeEventPlugin');
const ReactNativeStyleAttributes = require('ReactNativeStyleAttributes');
const UIManager = require('UIManager');

Expand Down Expand Up @@ -185,11 +184,6 @@ function requireNativeComponent(
hasAttachedDefaultEventTypes = true;
}

// Register this view's event types with the ReactNative renderer.
// This enables view managers to be initialized lazily, improving perf,
// While also enabling 3rd party components to define custom event types.
ReactNativeBridgeEventPlugin.processEventTypes(viewConfig);

return viewConfig;
}

Expand Down
Loading