[BUG] onPress on G only work for first child (Android Only)
See original GitHub issuethe problem is in android onPress on G element working only for first child but in IOS working very well that means in bellow image only for big square top left working
Each square is like this
import * as React from 'react'
import { G, Rect, ClipPath } from 'react-native-svg'
import { View, Platform } from 'react-native'
import { Typography } from 'src/theme'
import { NodeProps } from './NodeProps'
import { NodeState } from './NodeState'
class Node extends React.Component<NodeProps, NodeState> {
render() {
const {
x0,
x1,
y0,
y1,
xScaleFactor,
yScaleFactor,
xScaleFunction,
yScaleFunction,
zoomEnabled,
url,
treemapId,
bgColor,
onClick,
id,
label,
depth,
} = this.props
const xTranslated = zoomEnabled === true ? xScaleFunction(x0) : x0
const yTranslated = zoomEnabled === true ? yScaleFunction(y0) : y0
const width = xScaleFactor * (x1 - x0)
const height = yScaleFactor * (y1 - y0)
const fSize = width < 60 ? 6.5 : width < 80 ? 8 : width < 120 ? 10 : 12
if (depth === 0) {
return null
}
const pointerEvents = Platform.OS === 'android' ? { pointerEvents: 'box-none' } : null
return (
<G
// transform={`translate(${xTranslated},${yTranslated})`}
id={id.toString()}
x={xTranslated}
y={yTranslated}
onPress={(e) => {
onClick(e, this.props)
}}
>
<Rect id={'rect-' + id} width={width} height={height} rx={2} fill={bgColor} {...pointerEvents} />
<ClipPath id={'clip-'.concat(treemapId, '-', id.toString())} {...pointerEvents}>
<Rect width={Math.max(0, width - 5)} height={height} {...pointerEvents} />
</ClipPath>
<View
style={{ width, height, alignContent: 'center', justifyContent: 'center', zIndex: 2, overflow: 'hidden' }}
{...pointerEvents}
>
{width <= 20 ? null : (
<Typography
style={{ width, fontSize: fSize }}
color="initial"
align={'center'}
text={label}
{...pointerEvents}
/>
)}
</View>
</G>
)
}
}
export default Node
“react-native-svg”: “^11.0.1”, “react-native”: “0.61.5”,
Issue Analytics
- State:
- Created 3 years ago
- Comments:20
Top Results From Across the Web
[BUG] onPress on G only work for first child (Android Only)
I can reproduce the same issue on iOS. When G elements are nested onPress is only working on the top level one.
Read more >onClick not triggered on LinearLayout with child - Stack Overflow
After a hour of looking for solution a found out that I set android:inputType to TextView inside my ViewGroup which was blocking onClick() ......
Read more >Manage touch events in a ViewGroup - Android Developers
Use ViewConfiguration constants; Extend a child view's touchable area ... This method will only be called if the touch event was intercepted ......
Read more >React onClick event handlers: A complete guide
Learn the basics of React's onClick event handler, including event listening, onClick buttons, synthetic events, custom events, and more.
Read more >CoffeeScript
The golden rule of CoffeeScript is: “It's just JavaScript. ... To install, first make sure you have a working copy of the latest...
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
For me worked by wrapping pie chart into Svg tag
I can reproduce the same issue on iOS. When
G
elements are nested onPress is only working on the top level one.