Skip to content
Merged
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
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"type": "prerelease",
"comment": "Restore Previous Behavior Allowing onMouseEnter and onMouseLeave on Touchables",
"packageName": "react-native-windows",
"email": "ngerlem@microsoft.com",
"dependentChangeType": "patch",
"date": "2020-08-14T16:57:33.938Z"
}
1 change: 1 addition & 0 deletions packages/E2ETest/wdio/test/VisitAllPages.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ let pages = [
'Layout Events',
'Linking',
'Layout - Flexbox',
'Mouse Events',
'Native Animated Example',
'PanResponder Sample',
'PlatformColor',
Expand Down
1 change: 0 additions & 1 deletion packages/playground/windows/playground/MainPage.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,6 @@
<ComboBoxItem Content="Samples\image" />
<ComboBoxItem Content="Samples\index" />
<ComboBoxItem Content="Samples\messages" />
<ComboBoxItem Content="Samples\mouse" />
<ComboBoxItem Content="Samples\scrollViewSnapSample" />
<ComboBoxItem Content="Samples\simple" />
<ComboBoxItem Content="Samples\text" />
Expand Down
2 changes: 2 additions & 0 deletions vnext/.flowconfig
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@
<PROJECT_ROOT>/Libraries/Network/RCTNetworking.js
<PROJECT_ROOT>/Libraries/NewAppScreen/components/DebugInstructions.js
<PROJECT_ROOT>/Libraries/NewAppScreen/components/ReloadInstructions.js
<PROJECT_ROOT>/Libraries/Pressability/Pressability.js
<PROJECT_ROOT>/Libraries/Types/CoreEventTypes.js
<PROJECT_ROOT>/RNTester/js/components/ListExampleShared.js
<PROJECT_ROOT>/RNTester/js/components/RNTesterExampleList.js
<PROJECT_ROOT>/RNTester/js/examples/ScrollView/ScrollViewExample.js
Expand Down
2 changes: 1 addition & 1 deletion vnext/overrides.json
Original file line number Diff line number Diff line change
Expand Up @@ -437,7 +437,7 @@
},
{
"type": "patch",
"file": "src/Libraries/Types/CoreEventTypes.js",
"file": "src/Libraries/Types/CoreEventTypes.windows.js",
"baseFile": "Libraries/Types/CoreEventTypes.js",
"baseVersion": "0.0.0-d8e6c4578",
"baseHash": "83b203d547d9bdc57a8f3346ecee6f6e34b25f5d",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,8 @@ class TouchableHighlight extends React.Component<Props, State> {
delayPressOut: this.props.delayPressOut,
pressRectOffset: this.props.pressRetentionOffset,
android_disableSound: this.props.touchSoundDisabled,
onMouseEnter: this.props.onMouseEnter, // [Windows]
onMouseLeave: this.props.onMouseLeave, // [Windows]
onBlur: event => {
if (Platform.isTV) {
this._hideUnderlay();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,8 @@ class TouchableOpacity extends React.Component<Props, State> {
delayPressIn: this.props.delayPressIn,
delayPressOut: this.props.delayPressOut,
pressRectOffset: this.props.pressRetentionOffset,
onMouseEnter: this.props.onMouseEnter, // [Windows]
onMouseLeave: this.props.onMouseLeave, // [Windows]
onBlur: event => {
if (Platform.isTV) {
this._opacityInactive(250);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import type {
BlurEvent,
FocusEvent,
LayoutEvent,
MouseEvent, // [Windows]
PressEvent,
} from '../../Types/CoreEventTypes';
import Platform from '../../Utilities/Platform';
Expand Down Expand Up @@ -70,8 +71,8 @@ type Props = $ReadOnly<{|
accessibilityPosInSet?: ?number, // [Windows]
accessibilitySetSize?: ?number, // [Windows]
onAccessibilityTap?: ?() => void, // [Windows]
onMouseEnter?: ?(event: SyntheticEvent<{}>) => void, // [Windows]
onMouseLeave?: ?(event: SyntheticEvent<{}>) => void, // [Windows]
onMouseEnter?: ?(event: MouseEvent) => void, // [Windows]
onMouseLeave?: ?(event: MouseEvent) => void, // [Windows]
tabIndex?: ?number, // [Windows]
tooltip?: ?Stringish, // [Windows]
|}>;
Expand Down Expand Up @@ -206,6 +207,8 @@ function createPressabilityConfig(props: Props): PressabilityConfig {
onPress: props.onPress,
onPressIn: props.onPressIn,
onPressOut: props.onPressOut,
onMouseEnter: props.onMouseEnter, // [Windows]
onMouseLeave: props.onMouseLeave, // [Windows]
};
}

Expand Down
4 changes: 2 additions & 2 deletions vnext/src/Libraries/Components/View/ViewPropTypes.windows.js
Original file line number Diff line number Diff line change
Expand Up @@ -435,8 +435,8 @@ type WindowsViewProps = $ReadOnly<{|

onFocus?: ?(event: FocusEvent) => mixed,
onBlur?: ?(event: FocusEvent) => mixed,
onMouseLeave?: ?(event: SyntheticEvent<{}>) => mixed,
onMouseEnter?: ?(event: SyntheticEvent<{}>) => mixed,
onMouseLeave?: ?(event: MouseEvent) => mixed,
onMouseEnter?: ?(event: MouseEvent) => mixed,
|}>;
// Windows]

Expand Down
28 changes: 28 additions & 0 deletions vnext/src/Libraries/Pressability/Pressability.windows.js
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,22 @@ export type PressabilityConfig = $ReadOnly<{|
* @deprecated
*/
onStartShouldSetResponder_DEPRECATED?: ?() => boolean,

// [Windows
/**
* Raw handler for onMouseEnter that will be preferred if set over hover
* events. This is to preserve compatibility with pre-0.62 behavior which
* allowed attaching mouse event handlers to Touchables
*/
onMouseEnter?: ?(event: MouseEvent) => mixed,

/**
* Raw handler for onMouseLeave that will be preferred if set over hover
* events. This is to preserve compatibility with pre-0.62 behavior which
* allowed attaching mouse event handlers to Touchables
*/
onMouseLeave?: ?(event: MouseEvent) => mixed,
// Windows]
|}>;

export type EventHandlers = $ReadOnly<{|
Expand Down Expand Up @@ -562,6 +578,12 @@ export default class Pressability {
? null
: {
onMouseEnter: (event: MouseEvent): void => {
// [Windows Add attached raw mouse event handler for compat
if (this._config.onMouseEnter) {
this._config.onMouseEnter(event);
}
// Windows]

if (isHoverEnabled()) {
this._isHovered = true;
this._cancelHoverOutDelayTimeout();
Expand All @@ -582,6 +604,12 @@ export default class Pressability {
},

onMouseLeave: (event: MouseEvent): void => {
// [Windows Add attached raw mouse event handler for compat
if (this._config.onMouseLeave) {
this._config.onMouseLeave(event);
}
// Windows]

if (this._isHovered) {
this._isHovered = false;
this._cancelHoverInDelayTimeout();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -151,15 +151,32 @@ export type FocusEvent = SyntheticEvent<
|}>,
>;

// [Windows Mouse events on Windows don't match up with the version in core
// introduced for react-native-web. Replace typings with our values to catch
// anything dependent on react-native-web specific values
export type MouseEvent = SyntheticEvent<
$ReadOnly<{|
clientX: number,
clientY: number,
target: number,
identifier: number,
pageX: number,
pageY: number,
locationX: number,
locationY: number,
timestamp: number,
pointerType: string,
force: number,
isLeftButton: boolean,
isRightButton: boolean,
isMiddleButton: boolean,
isBarrelButtonPressed: boolean,
isHorizontalScrollWheel: boolean,
isEraser: boolean,
shiftKey: boolean,
ctrlKey: boolean,
altKey: boolean,
|}>,
>;
// Windows]

// [Windows
export type KeyEvent = SyntheticEvent<
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,31 @@
* Licensed under the MIT License.
* @format
*/
import * as React from 'react';
import {
AppRegistry,

'use strict';

const React = require('react');

const {
StyleSheet,
View,
Text,
GestureResponderEvent,
TouchableHighlight,
BackHandler,
} from 'react-native';
} = require('react-native');

exports.displayName = 'MouseExample';
exports.title = 'Mouse Events';
exports.description = 'Tests that mouse events can be observed';
exports.examples = [
{
title: 'onMouseEnter and onMouseLeave affect style\n',
render: function(): React.Node {
return <ExampleComponent />;
},
},
];

const styles = StyleSheet.create({
page: {
Expand Down Expand Up @@ -68,16 +83,16 @@ const styles = StyleSheet.create({
},
});

export default class Bootstrap extends React.Component<
export default class ExampleComponent extends React.Component<
{},
{
clicked: number;
pageHover: boolean;
contentHover: boolean;
contentChildHover: boolean;
overlayHover: boolean;
overlayChildHover: boolean;
}
clicked: number,
pageHover: boolean,
contentHover: boolean,
contentChildHover: boolean,
overlayHover: boolean,
overlayChildHover: boolean,
},
> {
constructor(props: {}) {
super(props);
Expand Down Expand Up @@ -225,5 +240,3 @@ export default class Bootstrap extends React.Component<
return true;
};
}

AppRegistry.registerComponent('Bootstrap', () => Bootstrap);
4 changes: 4 additions & 0 deletions vnext/src/RNTester/js/utils/RNTesterList.windows.ts
Original file line number Diff line number Diff line change
Expand Up @@ -221,6 +221,10 @@ const APIExamples: Array<IRNTesterExample> = [
key: 'LayoutExample',
module: require('react-native/RNTester/js/examples/Layout/LayoutExample'),
},
{
key: 'MouseExample',
module: require('./../examples-win/Mouse/MouseExample'),
},
{
key: 'NativeAnimationsExample',
module: require('react-native/RNTester/js/examples/NativeAnimation/NativeAnimationsExample'),
Expand Down