Skip to content

Fix: Text component pressRetentionOffset issue on Windows #14596

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

Merged
merged 9 commits into from
Apr 25, 2025

Conversation

iamAbhi-916
Copy link
Contributor

@iamAbhi-916 iamAbhi-916 commented Apr 21, 2025

Description

Text component pressRetentionOffset on Windows wasnt working as expected behaviour as it is on native components

Problem:
PressRetentionOffset implementation is wasnt working correctly for windows.
(Expected behaviour )-> allowing touches to remain active within the expanded area while canceling them when moving beyond it.

1> when press is moved away from retention offset , it wasnt cancelling then .
2> JS side was handling in pressability and this was hooked to text using usePressability but the issue was that the
PressRetentionOffset  was called within onResponderMove which was never triggered from native side .


Fix:
1>When a component claims responder status (via onStartShouldSetResponder), the pointer is marked as an "active touch"
2>As that pointer moves across the screen, all move events are correctly dispatched to JavaScript
3> This allows the Pressability component in JavaScript to properly track the movement and apply the pressRetentionOffset logic

Type of Change

New feature (non-breaking change which adds functionality)

Why

the current code wasn't dispatching pointer move events through the touch event system for active touches with responders. The touch event system is what RNW uses to track touch interactions.

Resolves [Add Relevant Issue Here]
#13837

What

1>When a component claims responder status (via onStartShouldSetResponder), the pointer is marked as an "active touch"
2>As that pointer moves across the screen, all move events are correctly dispatched to JavaScript
3> This allows the Pressability component in JavaScript to properly track the movement and apply the pressRetentionOffset logic

Screenshots

pressOffsetrect_fix.mp4

Testing

using playground

import React from 'react';
import {
  StyleSheet,
  View,
  AppRegistry,
} from 'react-native';
import {Text} from 'react-native-windows';

const App = () => {
  const handlePressIn = () => console.log('🔵 Press In');
  const handlePressOut = () => console.log('🟡 Press Out');
  const handlePress = () => console.log('🟢 Press');
  return (
    <View style={styles.container}>
      <View style={styles.retentionZone}>
        <Text
          style={styles.pressableText}
          pressRetentionOffset={{top: 30, bottom: 30, left: 30, right: 30}}
          onPressIn={handlePressIn}
          onPressOut={handlePressOut}
          onPress={handlePress}>
          Tap and move slightly to test pressRetentionOffset
        </Text>
      </View>
    </View>
  );
};

Changelog

yes

Add a brief summary of the change to use in the release notes for the next release.

Text component pressRetentionOffset on Windows is added : allowing touches to remain active within the expanded area while canceling them when moving beyond it.

@iamAbhi-916 iamAbhi-916 requested a review from a team as a code owner April 21, 2025 18:45
@iamAbhi-916 iamAbhi-916 self-assigned this Apr 21, 2025
bool hasMoveEventListeners =
IsAnyViewInPathListeningToEvent(eventPathViews, facebook::react::ViewEvents::Offset::PointerMove) ||
IsAnyViewInPathListeningToEvent(eventPathViews, facebook::react::ViewEvents::Offset::PointerMoveCapture);
if (hasMoveEventListeners) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we need to remove the hasMoveEventListeners check here? Isn't there a perf cost to this (now all move events will always have to be fired and propagated to JS, even if no-one is listening?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

only applies to active touches that have already claimed responder status - not to all pointer moves so sending these extra events for ongoing interactions, which is actually a small subset of all pointer movements

Copy link
Contributor

@acoates-ms acoates-ms left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It looks like pressRetentionOffset isn't supported on Text in core. It is a property on Pressable, not view/text.

Does it work on Pressable already? -- Is this change even needed?

@microsoft-github-policy-service microsoft-github-policy-service bot added the Needs: Author Feedback The issue/PR needs activity from its author (label drives bot activity) label Apr 21, 2025
@iamAbhi-916
Copy link
Contributor Author

It looks like pressRetentionOffset isn't supported on Text in core. It is a property on Pressable, not view/text.

Does it work on Pressable already? -- Is this change even needed?

so Official react docs explicitly lists pressRetentionOffset as a prop for [Text] components, showing that the functionality
When the touch is released outside this view, the press gesture continues to be detected, and onPress is triggered.

core support : on both iOS and Android this is supported , making Windows inconsistent without it.
so this should be added so that Users expect the same touch behavior across platforms

@microsoft-github-policy-service microsoft-github-policy-service bot added Needs: Attention 👋 An issue that had been tagged "Needs: Author Feedback" has received activity (label applied by bot) and removed Needs: Author Feedback The issue/PR needs activity from its author (label drives bot activity) labels Apr 21, 2025
@iamAbhi-916 iamAbhi-916 requested a review from acoates-ms April 21, 2025 20:45
* Insets for press retention.
* Example: { top: 20, left: 20, bottom: 20, right: 20 }
*/
pressRetentionOffset?:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks like a bug in core. -- This property should be added to Text.d.ts upstream.
Fine to add it here too.. but we should open a PR in RN to add this.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yeah this a bug , they are handling it textprops.js file but didnt add as a prop ins text.d.ts file

@iamAbhi-916 iamAbhi-916 merged commit d2bf5ea into microsoft:main Apr 25, 2025
59 checks passed
facebook-github-bot pushed a commit to facebook/react-native that referenced this pull request May 6, 2025
…typescript (#51068)

Summary:
Added decalaration for  pressRetentionOffset prop to be recognised by typescript

## Changelog:
Added decalaration for  pressRetentionOffset prop to be recognised by typescript in Text.d.ts

<!-- Help reviewers and the release process by writing your own changelog entry.

Pick one each for the category and type tags:
[General] [Added] - Add  pressRetentionOffset prop to be recognised by typescript in Text.d.ts

Pull Request resolved: #51068

Test Plan:
Before fix

https://github.com/user-attachments/assets/476364c4-6602-4916-84f2-1ede56bce285

After fix

https://github.com/user-attachments/assets/e5f720d9-cd7d-4cf0-8499-ebe9f83eb17b

Tested here: Related PR: (microsoft/react-native-windows#14596)

Reviewed By: yungsters

Differential Revision: D74208617

Pulled By: philIip

fbshipit-source-id: 625996bec64058e4e4cdbe108ed53a62426d1222
acoates-ms pushed a commit to acoates-ms/react-native-windows that referenced this pull request May 29, 2025
…14596)

* Fix: Text component pressRetentionOffset issue on Windows

* Change files

* lint formatting fixed

---------

Co-authored-by: Abhijeet Jha <[email protected]>
acoates-ms added a commit that referenced this pull request May 30, 2025
* Initial support for UIA and tab navigation for a child Island (#14305)

* Basic support for stitching the UIA tree for a ContentIslandComponentView's child

* Updated comment

* Change files

* Support shift+tab, and move Automation event handlers to ContentIslandComponentView

* Allow portals to have independent layout constraints and scale factor (#14315)

* Allow portals to have independent layout constraints and scale factor

* format

* change files

* fix

* Round Focus visuals by default, fix nudge rendering (#14312)

* Round Focus visuals by default, fix nudge rendering

* Change files

* Fix react devtools hitting an assert on launch (#14320)

* ignore unsupported methods

* delete Super::DispatchCommand call

* Change files

* [Fabric] Fix PlatformColor (#14325)

* Fix platform color

* Change files

* Add missing theme colors

* snapshots

* TurboModule spec checking should accept hstring for string arguments (#14322)

* TurboModule spec checking should accept hstring for string arguments

* Change files

* example

* Fix Number.h not copied from react-native core (#14331)

## Description

### Type of Change
- Bug fix (non-breaking change which fixes an issue)

### Why

react-native-windows currently maintains its own forked C++ TurboModule bridging files.
For untouched stuff we copy JSI and TurboModule files from core react-native in `Layout-MSRN-Headers.ps1`.
However, this script misses to copy `Number.h`.

This causes compilation error when trying to import `react/bridging/Bridging.h`, which would be the case for example when using codegen to generate C++ TurboModule (JSI) bindings (note: this is for C++ JSI TurboModules, not react-native-windows's TurboModule system).

```
PS C:\Users\CocoT1\Projects\rn77> yarn example windows
[...]
Time Elapsed 00:00:00.61
✔ Restoring NuGet packages
 ✔ Auto-linking...
Success: No auto-linking changes necessary. (69ms)
 ✔ Found Solution: C:\Users\CocoT1\Projects\rn77\example\windows\rn77Example.sln
 ℹ Build configuration: Debug
 ℹ Build platform: x64
 ✖ Building Solution: Generating Code...
 ✖ Build failed with message 4:7>C:\Users\CocoT1\.nuget\packages\microsoft.reactnative.cxx\0.77.0-fabric\tools\Microsoft.ReactNative.Cxx\ReactCommon\react\bridging\Bridging.h(18,10): error C1083: Cannot open include file: 'react/bridging/Number.h': No such file or directory [C:\Users\CocoT1\Projects\rn77\example\windows\rn77Example\rn77Example.vcxproj]. Check your build configuration.
```

### What

I'm changing the `Layout-MSRN-Headers.ps1` script to also copy `Number.h`.
I think this should be enough for the nuget the contain to file, but I'm no expert here.

## Testing

Monkeypatched by copying over Number.h to the microsoft.reactnative.cxx nuget (`C:\Users\CocoT1\.nuget\packages\microsoft.reactnative.cxx\0.77.0-fabric\tools\Microsoft.ReactNative.Cxx\ReactCommon\react\bridging\`).

Works all good.

I don't know how to run the `Layout-MSRN-Headers.ps1` script locally.


Here's a create-react-native-library project:
https://github.com/hsjoberg/rnw-cxx-turbomodule
Note: it will fail to build unless you copy Number.h over to the nuget cache as explained earlier.

* Fix stale focus rects left in UI when last focusable component is removed (#14359)

* Fix stale focus rects left in UI when last focusable component is removed

* Change files

---------

Co-authored-by: Tatiana Kapos <[email protected]>

* Fix issue when calling arrange on an RN Island during load (#14362)

* Fix issue when calling arrange on an RN Island during load

* Change files

---------

Co-authored-by: Tatiana Kapos <[email protected]>

* Fix tooltips in high dpi (#14397)

* Fix tooltips in high dpi

* Change files

* format

* tooltips dont respect textscalefactor

* Fix build issue building component codegen using clang (#14393)

* Fix build issue building component codegen using clang

* Change files

* Components do not lose hover state if pointer leaves window before it leaves the component (#14375)

* Components do not lost hover state if pointer leaves window before it leaves the component

* format

* Change files

---------

Co-authored-by: Tatiana Kapos <[email protected]>

* Property updates switching between PlatformColors would no-op (#14398)

* Property updates switching between PlatformColors would no-op

* Change files

* format

* Fix bool operator on transparent colors returning false (#14413)

* Fix crash loading logbox

* Fix bool operator on transparent colors returning false

* Change files

* format

* [Fabric] Implement textAlign prop in TextInput (#14407)

* Introduce support for textAlign

* Add playground textinputs demonstrating textAlign

* Oops, let's remove textAlignOnUpdateProps

* Change files

* Lint fixes

* Nit

* Make textAlign to be of facebook::react::TextAlignment type

* Lint fixes

* Don't reinvent the wheel :D

* Nit: yarn format

* [Fabric] Allow text components to have children (#14438)

* get images/views inline with text on fabric

* add back in comments

* Change files

* remove duplicate code

* add baseline for textinput

* add checks for paper vs fabric

* try fixing image

* add resize:none and tests

* fix override

* comment out test

* fix tests

* fix typo

* try to fix tests

* comment out text test

* mark windows-specific changes

* Allow TextInput to scroll (#14448)

* Allow TextInput to scroll

* Change files

* update snapshot

* Implement onScrollBeginDrag property for ScrollView for fabric (#14446)

 Implement onScrollBeginDrag property for ScrollView for fabric (#14446)

* [Fabric] Implement letterSpacing for TextInput (#14460)

* Implement letterSpacing for TextInput

* Change files

* Update react-native-windows-9ee8d633-698c-476d-9334-170be2c5dc25.json

* Update textinput.tsx

* optimize code

* Added tooltip property for Text  (#14470)

* Added tooltip property in Text.windows.js TextProps.windows.js for typescript to recognise it as an attribute of Text component

* Added override Text.d.ts to src-win/Libraries/Text/ to add  tooltip prop to Text component

* Change files

* Added Sample/text for tooltip prop tests

* Added TextPropsWindows to include windows specific prop tooltip

* updated TextProps interface to extednd TextPropsWindows

* lint fix for Sample/text.tsx file

---------

Co-authored-by: Abhijeet Jha <[email protected]>

* [Fabric] Add Custom Font Family in Text Input (#14495)

* [Fabric] Fix Bug in Narrator Navigation (#14498)

* Fix Narrator Bug

* Change files

* Revert Codegen Changes

* Implemented on onEndEditing for TextInput component (#14489)

* implemented on onEndEditing

* Change files

* Update textinput.tsx to remove keyboard=dismiss which actually will cause blur or lost focus implicitly

* lint fixes

* updated legacy textInput snapshot for component update

---------

Co-authored-by: Abhijeet Jha <[email protected]>

* [Fabric] Add ImageRequestParams for Image Component (#14494)

* [Fabric] Implement onProgress for Image (#14493)

* [Fabric] Implement SpellCheck and AutoCorrect for TextInput (#14509)

* Textinput double clicking selects text (#14515)

* added check for double click on textInput component view connecting it to WM_LBUTTONDBLCLK

* Change files

* updated for lint fix

* updated to remove position( Distance check)

---------

Co-authored-by: Abhijeet Jha <[email protected]>

* [Fabric] Implement decelerationRate in ScrollView (#14528)

* [Fabric] Implement showsVerticalScrollIndicatorValue and showsHorizontalScrollIndicatorValue for ScrollView (#14526)

* SetProperties is not exposed on ReactNativeIsland (#14517)

* Add SetAppProperties method to ReactNativeIsland

* Change files

* rename SetAppProperties to SetProperties

* change file

* fix

* fix

* [Fabric] Implement Image body in Image Source RequestImage API (#14568)

* Implement body in Image Source

* Change files

* Add test in playground

* [Fabric] Implement zoomScale, maximumZoomScale and minimumZoomScale in ScrollView (#14562)

* Implemet maximumZoomScale and minimumZoomScalein ScrollView

* Change files

* lint fix

* Add zoomScale

* Implement adjustsFontSizeToFit property for Text in Fabric (#14519)

* Implementation of adjustFontSizeToFit

* Final Changes using TextLayout

* Lint Issue Fixes

* Change files

* prop change detection added

* review Changes and E2E test cases added

* Lint and Format Changes added

* Test Cases Fix added

* Update SnapShot

* Removed the additional Check for resizing Font

* Updated SnapShot

* Review Changes

* Lint and Format Changes

---------

Co-authored-by: Vineeth K <[email protected]>

* [Fabric] Implement scrollEventThrottle for ScrollView (#14555)

* Update WindowsAppSDK version to 1.7.250401001  (#14605)

* Update WindowsAppSDK version to 1.7.250401001

* Change files

* Update nuget lock files

* more nuget lock file updates

* Bump webview props

* updated lock files

* Implement accessibilityLevel for Fabric (#14593)

* Implement accessibilityLevel for Fabric

* Change files

* Added Test Cases for the accessibility Label, Level etc.

* Updating snapshots

---------

Co-authored-by: Vineeth K <[email protected]>

* [Fabric] Implement hidesWhenStopped in ActivityIndicator (#14615)

* Fix: Text component pressRetentionOffset issue on Windows (#14596)

* Fix: Text component pressRetentionOffset issue on Windows

* Change files

* lint formatting fixed

---------

Co-authored-by: Abhijeet Jha <[email protected]>

* [Fabric] Implement minimumFontScale in Text (#14617)

* Fix InitialProps (#14620)

* Fix InitialProps

* Change files

* [Fabric] Implement the onPressIn property for the fabric implementation of TextInput (#14480)

* Implemented OnPressIn event for textinput
---------

* Implement OnScrollEndDrag Event Handler for ScrollView (#14473)

* Implement onScrollEndDrag prop

* Change files

* lint fix

* Address comments

* add noexcept

* Address feedback

* Fix : Incorrect view access to obtain ContentIsland from for the DesktopPopupSiteBridge (#14628)

* solved access read violation due to incorrect view access to obtain contentIsland

* rolling back text.tsx

* Update end of line  text.tsx

* rolled back Playground-Composition.vcxproj

* rolled back Playground-Composition.vcxproj

* fixed lint Playground-Composition.vcxproj

* master Playground-Composition.vcxproj

* rolled back Playground-Composition.vcxproj

* indentation fix Playground-Composition.vcxproj

* Revert unintended changes in Playground-Composition.vcxproj

* added patch for winUiex[erimental removal

* Change files

---------

Co-authored-by: Abhijeet Jha <[email protected]>
Co-authored-by: Vineeth <[email protected]>

* [Fabric] Implement selectTextOnFocus prop in TextInput (#14641)

* fix change file type

* format

* Bump hermes version - enable hermes native microtasks (#14635)

* Bump hermes version

* Change files

* Bump JSI_VERSION to 19

* Opt into microtasks

* buidl fix

* update playground packages.lock with the script

* temp: gather crash dmp

* try larger machine

* Pickup microsoft/node-api-jsi#13

* Update hermes with uap nuget fix

* [Fabric] Implementation of accessibiltyAnnotation and adding support for IAnnotationProvider (#14626)

* Implement accessibilityAnnotation for RNW Fabric

* AccessibilityAnnotation Prop implementation final changes

* Playground Changes

* IAnnotationProvider Implementation

* Adding CompositionAnnotationProvider to the project

* Adding Test Cases

* Change files

* Lint issue Fixes

* Lint fix

* Updating SnapShots

* Review Changes

* Updating snapshot

* Properly hook up root uia provider to island (#14643)

* Properly hook up root uia provider to island

* Change files

* Modal : Added Titlebar , title , X handling  and movable for windows (#14636)

* addded titlebar , title handling , X handling , resizable

* Change files

* lint and format fix

* removed debug logs and resizable property

* removed unused imports from modalHostView .cpp file

* lint and format fix

* Update Modal.windows.js syntax after resolve conflict

* updated overrides

* updated rctmodalhostview file override structure

---------

Co-authored-by: Abhijeet Jha <[email protected]>

* [Fabric] Implementation of accessibilityAccessKey and accessibilityItemType (#14658)

* {Fabric] Implementation of accessibilityAccessKey and accessibilityItemType

* Change Files

* Updating snapShot

* Implement CallInvoker as replacement for JSDispatcher (#14648)

* Remove usage of JSDispatcher in various built-in modules

* Change files

* format

* Implement public JSDispatcher on top of CallInvoker

* format

* Add ReactContext.CallInvoker and JsiInitializers

* format

* format

* build fix

* build fixes

* Cleanup

* Add runtime handle to instance created and instance loaded events

* fix

* fix

* fix

* fix

* Remove unused JSDispatcherWriter

* Bump folly to 2024.10.14.00 (#14532)

* merge in folly 2024.10.14.00

* download fastfloat into node_modules

* Change files

* fix includes

* fix cachelocality

* fix desktop.dll

* clean paths and fix ARM64EC

* add FastFloatCommitHash to folly CGManifest

* fix types

* revert package.lock and fix json file path

* manually fix spacing

* fix

* feedback

* Scale loading bar text when island is super small (#14680)

* Scale loading bar text when island is super small

* Change files

* Fix crash when reloading an instance with an active ReactNativeIsland (#14676)

* Fix crash when reloading an instance with an active ReactNativeIsland

* Change files

* Update simple sample to use function component rather than component class

* More cleanup

* Fix warnings

* Reenable optimization in TMs to avoid going through a dynamic for callbacks/promises (#14691)

* Reenable optimization in TMs to avoid going through a dynamic for callbacks/promises

* Change files

* [Fabric] Implement maxFontSizeMultiplier in Text (#14622)

* Clean up error messages (#14695)

* Clean up error messages

* Change files

* JSValue exports data fields - should export value reference accessors (#14707)

* JSValue shouldn't export data fields, which make it hard to use MS.RN.Cxx across dll boundaries

* Change files

* missing functions

* fix

* Fix unreferenced parameter warning in glog stub (#14708)

* Fix warning in glog stub

* Change files

* Update folly exports from rn-win32 (#14710)

* Update folly exports from rn-win32

* Change files

* change files

* lint fix

* lint fix

* update override

* update snapshots

* arm64ec fix

* Pointer events (#14713)

* PointerEvent fixes

* Change files

* format

* Fix integration test

---------

Co-authored-by: JesseCol <[email protected]>
Co-authored-by: Tatiana Kapos <[email protected]>
Co-authored-by: Hampus Sjöberg <[email protected]>
Co-authored-by: Daniel Ayala <[email protected]>
Co-authored-by: Anupriya Verma <[email protected]>
Co-authored-by: Abhijeet Jha <[email protected]>
Co-authored-by: Abhijeet Jha <[email protected]>
Co-authored-by: Chiara Mooney <[email protected]>
Co-authored-by: Vineeth <[email protected]>
Co-authored-by: Vineeth K <[email protected]>
Co-authored-by: Harini Malothu <[email protected]>
Co-authored-by: Sharath Manchala <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Needs: Attention 👋 An issue that had been tagged "Needs: Author Feedback" has received activity (label applied by bot)
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants