react-native-skia-shadow icon indicating copy to clipboard operation
react-native-skia-shadow copied to clipboard

Shadow Component Not Working as Expected with Nested TouchableOpacity

Open YOEL311 opened this issue 1 year ago • 3 comments

Hi,

Firstly, thank you for your hard work and professional effort in creating this repository.

I've encountered an issue where the shadow component does not behave as expected when a TouchableOpacity component is nested inside it. Specifically, the background color of the shadow becomes visible and appears prominently.

https://github.com/chsdwn/react-native-skia-shadow/assets/39925212/a82ac048-332e-4f05-bd61-420114cf0d5b

import React from 'react';
import {StyleSheet, TouchableOpacity, View} from 'react-native';
import {SkiaShadow} from 'react-native-skia-shadow';

const App = () => {
  return (
    <View style={styles.container}>
      <SkiaShadow blur={5} dx={0} dy={0} color="blue" borderRadius={9999}>
        <TouchableOpacity>
          <View style={styles.circle} />
        </TouchableOpacity>
      </SkiaShadow>
    </View>
  );
};

const styles = StyleSheet.create({
  container: {
    flex: 1,
    justifyContent: 'center',
    alignItems: 'center',
  },
  circle: {
    width: 150,
    height: 150,
    borderRadius: 9999,
    backgroundColor: 'red',
  },
});
export default App;


repo to reproduce it https://github.com/YOEL311/testRNSHhadow

YOEL311 avatar May 13 '24 12:05 YOEL311

i can do somting like this

export type SkiaShadowProps = {
  blur: number;
  dx: number;
  dy: number;
  color?: Color;
  backgroundColor?: Color;
  borderRadius?: number;
  borderTopLeftRadius?: number;
  borderTopRightRadius?: number;
  borderBottomLeftRadius?: number;
  borderBottomRightRadius?: number;
  children: React.ReactNode;
};
    <View onLayout={handleLayout}>
      <Canvas style={{ ...canvasStyle }}>
        <Path path={path} color={color}>
          <Shadow
            dx={dx}
            dy={dy}
            blur={blur}
            color={color}
            shadowOnly
          />
        </Path>
        {!isUndefined(backgroundColor) && (
          <Path path={path} color={backgroundColor} />
        )}
      </Canvas>
      {children}
    </View>

YOEL311 avatar May 15 '24 17:05 YOEL311

Thank you I'll try this idea and if it fixes the issue I'll release a new version later.

chsdwn avatar May 15 '24 18:05 chsdwn

That should solve it

The truth is, I didn't know if this code would be maintained, so I made a local patch in my app, now I see that it is a maintained library, thank you 😀

YOEL311 avatar May 15 '24 20:05 YOEL311