question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

[BUG] onPress on G only work for first child (Android Only)

See original GitHub issue

the 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 Screen Shot 2020-03-24 at 09 47 39

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:open
  • Created 3 years ago
  • Comments:20

github_iconTop GitHub Comments

2reactions
mohity777commented, Mar 11, 2021

For me worked by wrapping pie chart into Svg tag

2reactions
Elijencommented, Sep 15, 2020

I can reproduce the same issue on iOS. When G elements are nested onPress is only working on the top level one.

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found