0

I'm using react native svg and facing issue that it's onPress event is not working on real device but working fine on emulator. I search for solution but none of them worked for me.

Here is my code

         const Labels: FC<labelProps> = ({
  slices,
  images,
  onPress,
  isClicked,
  selectedIndex,
  budgetScreen,
  totalAmount,
}) => {
  return (
    <>
      {slices?.map((slice, index) => {
        const {labelCentroid} = slice;
        return (
          <G
            onPress={() => onPress(index)}
            key={index}
            x={labelCentroid[0]}
            y={labelCentroid[1]}>
            <Image
              x={-10}
              y={-10}
              width={20}
              height={20}
              href={images.pieImages[index]}
            />
           
                <Rect
                  rx={4}
                  ry={4}
                  y={-60}
                  x={budgetScreen ? -75 : -55}
                  height={budgetScreen ? 49 : 45}
                  width={budgetScreen ? 149 : 115}
                  fill={colors.whiteColor}
                  strokeWidth={0.5}
                  stroke={colors.blackOpacity10}
                />
                <SvgText
                  fill={colors.blackColor}
                  fontSize="12"
                  fontFamily={fonts.MEDIUM}
                  fontWeight="500"
                  y="-40"
                  x={budgetScreen ? '-1' : '5'}
                  textAnchor="middle">
                  {slice?.data?.category}
                </SvgText>
              </>
            )}
          </G>
        );
      })}
    </>
  );
};

export default Labels;

Can anyone tell me how can I fix that please.

Kanwarjeet Singh
  • 144
  • 1
  • 12
  • If it works fine on the emulator, then the error is probably not in the code you provided. You should copy all the component. i.e. I can't really know what that "index" is. – RamaProg Apr 12 '22 at 04:51
  • Looks good to me. Are you running the device on debug or building the app? Can you run in debug and check for logs and error messages? – RamaProg Apr 12 '22 at 05:26
  • I tried both didn't worked on both mode and It's not giving any error on debug mode – Kanwarjeet Singh Apr 12 '22 at 05:35
  • @KanwarjeetSingh I also found the same issue and it works in emulator however not in real devices. There is a workaround to add the onPress event on the children on `G` for android. May be you can add a children with full bound in your case. Try this and let me know if that helps. – if-else-switch Apr 28 '22 at 08:48

0 Answers0