From 3f86d769c790a69c4a0732b1e2c6057e91655ce7 Mon Sep 17 00:00:00 2001 From: Eric Rozell Date: Wed, 19 May 2021 15:20:16 -0400 Subject: [PATCH 1/5] Allow pointer events on selectable Text When TextBlock::IsTextSelectionEnabled is set to true, pointer events are canceled because the events are always marked as handled by the TextBlock, thus the events never reach the React Native root view. This change subscribes a TouchEventHandler to Text when the `selectable` prop is set to true, and also conditionally fires the `onTouchEnd` event when PointerCaptureLost fires when text is *not* selected as a result of the pointer events (e.g., click-and-drag or the second click of a double click). This allows us to create `onPress` callbacks that mimic the behavior of the XAML hyperlink component. In order for the correct page layout dimensions to be reported, we also need to provide the root view to TouchEventHandler. Fixes #7812 --- .../LegacyTests/SelectableTextTestPage.tsx | 74 +++++++++++++++++ .../src/js/utils/RNTesterList.windows.js | 4 + .../test/LegacySelectableTextTest.test.ts | 60 ++++++++++++++ .../LegacySelectableTextTest.test.ts.snap | 81 +++++++++++++++++++ .../ReactPointerEventArgs.cpp | 6 ++ .../ReactPointerEventArgs.h | 1 + .../ReactPointerEventArgs.idl | 11 ++- .../Views/TextViewManager.cpp | 52 ++++++++++++ .../Views/TextViewManager.h | 2 + .../Views/TouchEventHandler.cpp | 51 ++++++++---- .../Views/TouchEventHandler.h | 15 ++-- 11 files changed, 332 insertions(+), 25 deletions(-) create mode 100644 packages/@react-native-windows/tester/src/js/examples-win/LegacyTests/SelectableTextTestPage.tsx create mode 100644 packages/e2e-test-app/test/LegacySelectableTextTest.test.ts create mode 100644 packages/e2e-test-app/test/__snapshots__/LegacySelectableTextTest.test.ts.snap diff --git a/packages/@react-native-windows/tester/src/js/examples-win/LegacyTests/SelectableTextTestPage.tsx b/packages/@react-native-windows/tester/src/js/examples-win/LegacyTests/SelectableTextTestPage.tsx new file mode 100644 index 00000000000..125ad20d1e3 --- /dev/null +++ b/packages/@react-native-windows/tester/src/js/examples-win/LegacyTests/SelectableTextTestPage.tsx @@ -0,0 +1,74 @@ +/** + * Copyright (c) Microsoft Corporation. + * Licensed under the MIT License. + * @format + */ + +import React from 'react'; +import {Button, StyleSheet, Text, View} from 'react-native'; + +interface IPressableTextState { + count: number; + isSelectable: boolean; +} + +const styles = StyleSheet.create({ + container: { + alignItems: 'flex-start', + }, + pressable: { + color: 'blue', + textDecorationLine: 'underline', + }, +}); + +export class SelectableTextTests extends React.Component< + {}, + IPressableTextState +> { + constructor(props: any) { + super(props); + this.state = { + count: 0, + isSelectable: false, + }; + } + public render() { + const increment = () => this.setState({count: this.state.count + 1}); + return ( + + Pressed: {this.state.count} times. + + Text before{' '} + + click here + {' '} + text after + +