ForeignObject onPress() event not firing
See original GitHub issueBug
I created a line chart with each line being stored in a <G>
container together with a label inside a <ForeignObject>
(due to styling options). The code for one such plotted line looks like this:
<G>
<Path
d={*linePath*}
fill="transparent"
stroke={"black"}
strokeWidth={1}
/>
<ForeignObject
x={*pathEndPosition*}
y={*pathEndPosition*}
>
<TouchableOpacity
onPress={() => console.log("hello")}
style={{
position: "absolute",
backgroundColor: "red",
borderRadius: 3,
}}
>
<Text
style={{
color: "black",
fontSize: 10,
}}
>
{*data.myLabel*}
</Text>
</TouchableOpacity>
</ForeignObject>
</G>
The label should be interactive, as it should open a <Modal>
when pressed. Therefore, I wrapped the <Text>
with a TouchableOpacity>
component and added an onPress()
event to it.
However, this event is not triggered inside the <ForeignObject>
(also when adding the event to the <ForeignObject>
itself). But it does fire if I add the onPress()
event to the <G>
or <Path>
component. I am wondering what may cause this.
Expectation:
onPress()
event should be triggered in a <ForeignObject>
or nested <TouchableOpacity>
Environment info
react-native@0.61.4
react-native-svg@12.1.0
Related Issue
Issue Analytics
- State:
- Created 3 years ago
- Comments:12
Top Results From Across the Web
ForeignObject onPress() event not firing · Issue #1389 - GitHub
Bug I created a line chart with each line being stored in a container together with a label inside a (due to styling...
Read more >ForeignObject onPress() event not firing - - Bountysource
Bug. I created a line chart with each line being stored in a <G> container together with a label inside a <ForeignObject> (due...
Read more >Events not triggering in foreignObject for Firefox - Stack Overflow
When the my sub-meny items extended outside of my foreignObject's container size my mouseleave event triggered. I made a simpler example to show...
Read more >react-native-svg onPress not working since expo v39 - Snack
Try this project on your phone! Use Expo's online editor to make changes and save your own copy.
Read more >react-native-svg - npm
Touch Events; Serialize; Run example; TODO; Known issues ... Add RNSVG to your Podfile (with RN 0.60+ autolinking, this is not needed).
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Add a dummy
<Rect/>
inside of your<ForeignObject/>
in order to fire onPress event :(you must specify a width & a height for your Rect)
Part of this idea was a workaround for me. I put an onPressIn in the transparent Rect that was OUTSIDE of the ForeignObject component. It acted like an invisible touch zone on the thing I wanted to display in the ForeignObject.