-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
Pressable Text substrings do not work properly when they're selectable #1679
Comments
We are not investing in new features or lower priority bug fixes on vCurrent. The bulk of investment is now in vNext as we prepare to make that the default choice. If this issue is still relevant on the vNext implementation please open a vNext issue. If this issue is of significant severity for a vCurrent app and vNext is not an option, re-open with justification. |
Reviving an oldie-but-goodie. This remains to be true in vnext. |
For now, we're using option 2 from the description above, but it's limiting that the ABIViewManager derives from FrameworkElementViewManager (so we need to keep the HyperlinkViewManager implementation in a fork of react-native-windows). Honestly option 2 wouldn't need to be a core feature if we fixed #5539. Ideally we would be able to create ViewManagers that returned DependencyObjects as opposed to only FrameworkElements. I experimented with option 1 (using AddHandler with |
@rectified95 You've got a change to restore the pressable events on nested text. See if |
@chrisglein @rectified95 - A while back, we used the However, this has it's own limitations, as I have a WIP approach that takes a more targeted approach, subscribing TouchEventHandler directly on TextBlocks when |
Summary: When `selectable={true}` on the Text component in react-native-windows, the TextBlock native component captures and handles all pointer events, thus none of the pointer events are sent to JS. We could just allow the TouchEventHandler to respond to all events, even handled ones, but I'm concerned that this may raise other issues with other components that are expected to handle events (e.g., getting onPress events before ScrollViewer gets a chance to capture the pointer). There are other limitations to that approach as well, including issues with the mouse cursor and how the control would interoperate with accessibility. Adding Hyperlink works around this limitation as we can emit direct events that can be tied to a JS `onPress` callback via the `Click` event, which "plays nicely" with `selectable={true}`. Also, Hyperlink has expected behavior out of the box for focusability and pointer cursor. The reason this needs to be implemented in our fork and not in Zeratul is because the `IViewManager` interface exposed from the ABI for react-native-windows uses `FrameworkElement` as a base class, so we could not create a ViewManager for `Hyperlink`, which derives from `DependencyObject` and not `FrameworkElement`. Here are the GitHub issues tracking that this is working around: microsoft#1679 microsoft#5539 Test Plan: - Can we invoke onPress for FocusableText when selectable=true? https://pxl.cl/1G90F - Does the mouse cursor change from the selection IBeam to signal that the FocusableText can be clicked? {F564338487} - Can I still set selection on link text? {F564343437} - Can we tab focus to FocusableText? Not currently, but I believe this is not a limitation of the Hyperlink approach, something else seems to be trapping focus in the chat window. - Can we use the Enter key to invoke onPress for FocusableText? Not currently because the hyperlink cannot get focus. - Stretch: Is there any feedback when onPressIn for FocusableText? No, and it's likely that if someone adds it using `onPressIn` or `onPressOut` it will be broken. Reviewers: skyle, lyahdav, mylando Reviewed By: lyahdav Subscribers: necolas, eliwhite Differential Revision: https://phabricator.intern.facebook.com/D27474588 Tasks: T87521248 Signature: 27474588:1617305556:de80de6759c483628f86d3453533eacf360ce234
Fixed by #7813 |
Summary: When `selectable={true}` on the Text component in react-native-windows, the TextBlock native component captures and handles all pointer events, thus none of the pointer events are sent to JS. We could just allow the TouchEventHandler to respond to all events, even handled ones, but I'm concerned that this may raise other issues with other components that are expected to handle events (e.g., getting onPress events before ScrollViewer gets a chance to capture the pointer). There are other limitations to that approach as well, including issues with the mouse cursor and how the control would interoperate with accessibility. Adding Hyperlink works around this limitation as we can emit direct events that can be tied to a JS `onPress` callback via the `Click` event, which "plays nicely" with `selectable={true}`. Also, Hyperlink has expected behavior out of the box for focusability and pointer cursor. The reason this needs to be implemented in our fork and not in Zeratul is because the `IViewManager` interface exposed from the ABI for react-native-windows uses `FrameworkElement` as a base class, so we could not create a ViewManager for `Hyperlink`, which derives from `DependencyObject` and not `FrameworkElement`. Here are the GitHub issues tracking that this is working around: microsoft#1679 microsoft#5539 Test Plan: - Can we invoke onPress for FocusableText when selectable=true? https://pxl.cl/1G90F - Does the mouse cursor change from the selection IBeam to signal that the FocusableText can be clicked? {F564338487} - Can I still set selection on link text? {F564343437} - Can we tab focus to FocusableText? Not currently, but I believe this is not a limitation of the Hyperlink approach, something else seems to be trapping focus in the chat window. - Can we use the Enter key to invoke onPress for FocusableText? Not currently because the hyperlink cannot get focus. - Stretch: Is there any feedback when onPressIn for FocusableText? No, and it's likely that if someone adds it using `onPressIn` or `onPressOut` it will be broken. Reviewers: skyle, lyahdav, mylando Reviewed By: lyahdav Subscribers: necolas, eliwhite Differential Revision: https://phabricator.intern.facebook.com/D27474588 Tasks: T87521248 Signature: 27474588:1617305556:de80de6759c483628f86d3453533eacf360ce234
Problem
You can create a pressable Text substring by nesting a
Text
component with anonPress
handler inside of anotherText
component. If the outerText
component marks the text asselectable
, then the press functionality of the innerText
component is broken. Here's an example:There are a couple of issues with this:
_handlePress
is not called.Potential Solutions
I have a few ideas for how to solve this but none are ideal so far:
Text
to see if a pressable region was hit. To do this, we'd have to sign up for theRichTextBlock's
pointer events usingAddHandler
so we can passtrue
for thehandledEventsToo
parameter. A major limitation is apparently we are stuck with the I-beam selection cursor when hovering over text. When trying to set it to something else like an arrow in thePointerMoved
handler, the cursor rapidly flickers between I-beam and arrow. To fix this, we'd likely need a feature from the XAML team. Another concern is around the performance of the code that would do the hit testing.Hyperlink
. This solution has some issues due to limitations withHyperlink
:Runs
and non-Hyperlink
Spans
inside of theHyperlink
(e.g. can't nest inline views). I suspect this won't be problematic in practice.The best option might be (2). We translate a
<Text>
with anonPress
handler to a XAMLHyperlink
. There will be a lot of limitations in styling but a hyperlink scenario is probably the most common use ofonPress
onText
nodes anyway. Also, I can't think of a more general way to solve this nicely given the APIs XAML exposes.The text was updated successfully, but these errors were encountered: