Skip to content

[Feature Request] Limit shadow radius calculation to component dimensions #15

@jimmi-joensson

Description

@jimmi-joensson

The fast way to make completely round borders in React Native is to set a very high borderRadius like so:

const styles = StyleSheet.create({
  card: {
    backgroundColor: '#000',
    height: 300,
    borderRadius: 1000,
    width: 100,
  },
});

This technique have an interesting result used with react-native-shadow-2.
image

A failsafe to prevent something like this happening could be to limit the shadow calculation by the component's dimensions from the LayoutEvent Object using onLayout. The smallest value of either width or height should be used for the calculation.

Example of the calculation could look something like this:

// First get the smallest dimension of width or height
const smallestDims = e.layout.width <== e.layout.height ? e.layout.width : e.layout.height

// Second use the smallest dimension to calculate the failsafe shadow radius
const failsafeRadius = radius > smallestDims ? smallestDims / 2 : radius

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions