How to add shadows to an image's border radius using React Native View manipulation?

Encountering styling challenges in React Native with shadows.

I am aiming to apply a shadow only on the image, which has rounded edges rather than being square due to the border-radius applied. However, when I try to add a shadow to the parent View element, it does not adhere to the curved edges of the Image. My goal is for the shadow to outline the curved edges of the Image, not the square view.

https://i.sstatic.net/LXd1H.png

Here is the code snippet:

  <View style={[styles.closedcontainer]}>
    <Image source={{uri: props.food.url}}
           style={styles.smallimage}
      />
  </View>

And here are the styles applied:

const styles = StyleSheet.create({
  closedcontainer: {
      height: 100,
      width: 100,
      flexDirection: 'row',
      flexWrap: 'wrap',
      paddingLeft: 50,
      paddingRight: 50,
      paddingBottom: 0,
      paddingTop: 0,
      flex: 1,
      alignItems: 'center',
      justifyContent: 'center',
      backgroundColor: '#fff9f9',
    shadowColor: 'black',
    shadowOffset: {width: 2, height: 5},
    shadowOpacity: .30,
    shadowRadius: 5,
    // overflow: 'hidden'
  },
  smallimage: {
      height: 100,
      width: 100,
      borderRadius: 30,
      borderColor: "#f97070",
      borderWidth: 2.75,
      margin: 10,
      backgroundColor: 'white',
      resizeMode: 'contain'
  }

I attempted to incorporate "overflow: hidden" into the parent View's style (closedcontainer) but it caused the entire shadow to disappear altogether.

https://i.sstatic.net/yvWfE.png

Any thoughts or suggestions? Thank you!

UPDATE: Following the suggestion, I tried setting the borderRadius directly in the <Image> tag, unfortunately without success. https://i.sstatic.net/O1EZH.png

Answer №1

Consider setting the borderRadius attribute directly on the image component instead of applying it as a style.

<Image borderRadius={25}/>

You can also try this approach.

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

What is the best way to ensure the submenu is visible on every menu when the cursor hovers over it

I am currently working on implementing a drop-down menu using react.js. I have been following a tutorial but encountered an issue when trying to add a submenu to the menu items. Instead of the submenu appearing only for the specific menu item hovered over, ...

Using React to simulate API calls outside of testing environments

For instance, I encounter issues when certain endpoints are inaccessible or causing errors, but I still need to continue developing. An example scenario is with a function like UserService.getUsers where I want to use fake data that I can define myself. I ...

Experiencing difficulties when attempting to launch a React application and Express/Node.js backend on a shared port

I'm trying to set up my react front-end on localhost:5000, with API requests going to localhost:5000/api/some-path. After looking at similar questions, I've come to understand the following: Include a proxy in the package.json file Serve st ...

React state change does not effectively adjust Grid Size

I am facing an issue with adjusting the grid size in my Conway game of life app. Whenever I click on the buttons to change the numCols or numRows, only one of them gets updated in the app. How can I effectively update the state so that the grid changes siz ...

The Battle of Dynamic Rendering versus Hybrid Rendering

After tuning into Google's SEO conference, I came across a discussion on Dynamic and Hybrid Rendering. However, the distinction between the two is not quite clear to me. Can you please explain the difference? Thank you for your time. ...

Adjusting tab index in Reactjs when a change in action occurs in material-ui

I am currently utilizing the Tabs component from material-ui. The swipe-able tab opens on onTouchTap, and everything is working as expected. However, I am facing an issue where the tab index does not reset to 0 after a new action. Instead, it retains the ...

Tips for transitioning the li class from active to none

Struggling with changing the li class (of Home) from 'active' to none (or another class) when clicking on the profile tab, and then changing the li class (of Profile) from none to 'active' when the profile is activated. Snippet of my c ...

The Bootstrap modal is not properly clearing all attribute properties when it is hidden

Alrighty, so I've got this modal set up: <div id="modal-container" class="modal fade" tabindex="-1" role="dialog"> <div class="modal-dialog" role="document"> <div class="modal-content center-block" style="displ ...

Displaying error messages with react-hook-form in a React application

How can I implement validation to display an error message for the phone number field (using helperText with a minimum of 10 and maximum of 10 characters) and also show an error message if submitted without exactly 10 numeric digits? import ReactPhoneInp ...

What are the steps to getting Jarallax MDB up and running?

This is the code I am currently working with: <div class="view jarallax" data-jarallax = '{"speed":0.2 }' style="background- image: url('OFP/OFP_Group.jpg'); background-repeat: no-repeat; background- size: cover; background-positi ...

React Icons and Browser Tab Alerts

Is there a way to incorporate notifications into my website's favicon when the browser tab is not in focus? My tech stack includes React, Material UI, and TypeScript. I assume this is a frequent requirement, yet I haven't come across a simple so ...

Encountered error while running the `yarn dev` command in NextJS: Assertion `args[0]->IsInt32()' failed

When I execute yarn dev for local development in NextJS, I encounter this error message: /opt/homebrew/Cellar/node/19.9.0/bin/node[8717]: ../src/tcp_wrap.cc:155:static void node::TCPWrap::New(const FunctionCallbackInfo<v8::Value> &): Assertion ` ...

Displaying a Next.js component depending on the environment setting

Having trouble displaying a maintenance message to users based on an environment value. In my .env.local file, I have the following value set: NEXT_PUBLIC_SHOW_MAINTENANCE=true This is how my page is structured: const Index = () => { const showMai ...

Are the menubar menus positioned beneath a different div element?

Currently facing an issue with an HTML Menubar where the menus are appearing below another div, and not getting displayed as expected: ...

The simulated function is not being invoked while inside an asynchronous function

Summary: I encountered issues with my tests after making some code changes. I recently added asynchronous conditional checks to some existing code, resulting in my tests failing unexpectedly. The tests were set up to ensure that a mock function passed as ...

Enhance the appearance of the circular heading

Is there anyway to customize the look of this rounded header? I am having trouble setting a white background. Update #1: This is my current header HTML code: Here is how it currently appears: I utilized Bootstrap along with some custom CSS. Update #2: ...

Adjusting the Aspect Ratio of an Embedded YouTube Video

<!DOCTYPE HTML> <head> <style> body { overflow: hidden; margin:0; } </style> </head> <body> <iframe id="video" src="https://www.youtube.com/embed/U4c9bBeUe4M?modestbranding=1&sh ...

Experiencing 404 errors while attempting to use MirageJs for mocking in a NextJs application with the App Router

It seems like my problem is arising because I may not be initializing the mock server in the correct location within my application. The mirageJs documentation still references the old 'pages router' setup, which states: Open your Next.js app&a ...

Encountering an 'Error: Page Not Found' message on the live Heroku website

I have a MERN stack application in progress. The Node server is running locally and connected to the MongoDB Database. It is also set up to build and deploy on Heroku. However, when I click on "Open App" on the Heroku page, it displays "Cannot GET /". I m ...

Issue with vertical alignment of text inside select dropdown in Material UI Core

Take a look at the image. The text isn't centered in the text box like the other fields on the form. Dropdown Alignment Issue Below is my code snippet: <FormControl style={{ width: "80%" }} size="small"> <InputLabel htmlFor="Implement ...