using outlines for FontAwesome icons in React Native

I am struggling to use the fontAwesome + icon in the middle of a circle as one item. I have tried placing it inside a circle icon, but it doesn't seem to work properly.

import IconFA from 'react-native-vector-icons/FontAwesome';

        <IconFA
         name="plus"
         size={moderateScale(30)}
         color="black"
         style={styles.thumbnail}
         />

  thumbnail: {
    height: 68,
    width: 68,
    position: 'relative',
  },

I have also looked into using 'stacked' font awesome icons in react native, but I couldn't figure out how to implement it.

If anyone has any insights or solutions, please let me know.

Reference: https://jsfiddle.net/1d7fvLy5/1/

Snack Expo:

I am aiming to create something similar to this design:

https://i.sstatic.net/2elh1.png

If there are any free icon resources or alternatives like using a <Thumbnail>, feel free to share them with me as well.

Answer №1

The example on JSFiddle you shared demonstrates how to create a circular shape using CSS border properties and the border-radius. We can achieve a similar effect in react-native, although it's worth noting that the borderRadius in react-native requires a fixed number and doesn't support percentages when using typescript (however, percentage strings do work at runtime).

You have the flexibility to customize this code to suit your needs, but the code provided will serve its purpose effectively. You can opt to use both IconFA and CircleBorder as distinct nested components or utilize the combined component IconInCircle.

const IconInCircle = ({ circleSize, borderWidth = 2, borderColor = 'black', ...props}) => (
  <CircleBorder
    size={circleSize}
    borderWidth={borderWidth}
    borderColor={borderColor}
  >
    <IconFA {...props} />
  </CircleBorder>
);

const CircleBorder = ({ size, borderWidth, borderColor, children }) => (
  <View
    style={{
      width: size,
      height: size,
      borderRadius: 0.5 * size,
      display: 'flex',
      justifyContent: 'center',
      alignItems: 'center',
      borderColor,
      borderWidth,
    }}>
    {children}
  </View>
);

The IconInCircle component accepts three specific props related to the border: circleSize, borderWidth, and borderColor. Other props are simply passed down to the child component IconFA.

In essence, we're placing the icon within a fixed-size View with a circular border and centered content.

You can implement it like so:

      <IconInCircle
        name="plus"
        size={30}
        color="black"
        style={styles.thumbnail}
        borderWidth={1}
        circleSize={50}
      />

Expo Link

Answer №2

Give this a try, make sure to customize it to fit your requirements, and remember to ensure compatibility with various browsers when using flex.

const styles = StyleSheet.create({
  profileImage: {
    height: 100,
    width: 100,
    position: 'absolute',
    display: 'flex',
    justifyContent: 'center',
    alignItems: 'center',
    border: '1px solid #333',
    borderRadius: '50%'
  },
});

Answer №3

import IconFA from 'react-native-vector-icons/FontAwesome';

<View style={{
  position:'relative',
  justifyContent:'center',
  alignItems:'center',
  width:40,
  height:40,
  backgroundColor:'black'
}}>
  <IconFA name='circle-thin' size={40} color='grey'/>
  <IconFA name='plus' size={20} color='white' style={{position: 'absolute', zIndex: 99}} />  
</View>

If you are new to ReactNative, the code provided above should work well for your needs.

Try it out on Snack Expo!

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

Having a hard time finding the perfect styling solution for Material UI

Is there a way for me to customize the styling of Material UI's components in addition to their default rules by injecting my own CSS? I'm unsure how I would go about setting these parameters using the styled-components API. Is this even doable? ...

Synchronizing two navigation menus on a single-page application website

Let me start by saying that I specialize in back end development and am facing a specific challenge with building a website that includes two navigation menus. The main navigation menu features links like Home, while the sub-navigation menu includes option ...

Bootstrap 4 and Angular 7 application experiencing issues with toggle button functionality in the navigation bar

I am currently working with Angular7 and Bootstrap4. I am attempting to integrate a navbar into my application, but I am facing an issue where the toggle button does not work when the navbar is collapsed. It is important for me to mention that I do not wa ...

How can I make a dropdown menu appear when I select a checkbox?

Is it possible to have a dropdown menu with changing options appear when I click on a checkbox using HTML and JavaScript? I have experimented with some code snippets in JavaScript as a beginner, but I am unsure if they are needed here. Is there an altern ...

React is unable to properly utilize Mui icons in a basic Card example

C:\Users\Yeap\Documents\react sitio web\my-app\node_modules\react-scripts\scripts\start.js:19 throw err; ^ [Error: ENOENT: no such file or directory, stat 'C:\Users\All Users'] { errno ...

Establish a table containing rows derived from an object

I am currently dealing with a challenge in creating a table that contains an array of nested objects. The array I have follows this schema: array = [ { id: 'Column1', rows: { row1: 'A', row2 ...

I am encountering a 404 error when trying to send a POST request from a React application to an

Utilizing Axios within my react-app. The react app is running on server port 3000 and the express server on port 31001. My react component: import React from 'react'; import {Form,Button} from 'react-bootstrap'; import { Link,useHistor ...

Guide on retrieving a value from a function that invokes $.getJSON

function searchAndRetrieve(searchTerm) { var defaultResult = 1010; var resultValue = defaultResult; $.getJSON(remote, function(data) { if (data != null) { $.each(data.items, function(i, item) { ...

MERN stack project encountering PUT 401 Unauthorized error despite passing Bearer token

After successfully integrating the Razorpay payment gateway into my e-commerce website, I encountered an issue where a failure action was dispatched instead of a success action right after the payment process. The error message indicated that it was 401 un ...

Next.js configuration: Redirecting / to the basePath

Whenever a user accesses the path /, I need it to redirect to the basePath that has been previously set. Below is my configuration in next.config.js: module.exports = { basePath: '/docs', } This means that whenever the path / is visited, it s ...

Tips for handling an incorrect date entry when a field loses focus in AngularJS

If I have an <input> field with the type='date' attribute in its untouched state, it displays mm/dd/yyyy as the date format. I am looking to see if there is a way to utilize AngularJS ng-blur directive to reset the field to this original fo ...

Tips for preventing repetition of code in components with varying designs:

How can I avoid repeating code between two components that share some methods but have different layouts? Below are sample components with a method "renderLastItem" that uses prop "something" passed by the parent component. I considered using the Higher ...

The UI is not reflecting the updated value from the Spotify API in the component

Currently, I am able to successfully retrieve the playlist values and display them in the console. However, I am facing an issue when it comes to displaying these values on the UI. function Sidebar() { const [{ playlists }, dispatch] = useStateProvid ...

Experiencing issues while attempting basic private key encryption with the Node crypto library

Currently, I am in the process of creating a quick proof of concept (POC) to encrypt an incoming string using a standard key. Below is the code snippet from my middleware: import Crypto from 'crypto'; export default async function encrypt(req, r ...

Exploring the realm of unit testing in the NestJS CQRS architecture journey

We're currently working on writing unit tests using Jest for our application and are facing difficulties in testing sagas. Specifically, we're having trouble testing the saga itself. During our unit testing process, we've encountered an iss ...

Tips for accessing all translation keys in next-i18next

Query Overview How do the majority of users incorporate the translation key into the json file during the translation process? By manual input...? ...

Setting the parent's height to match one of its children

I'm struggling to align the height of the pink '#images-wrap' with the main image. When there are too many small rollover images on the right, it causes the pink div to extend beyond the main image's height. If I could make them match i ...

Navigating with Next.js Router: Dynamic URLs and the power of the back button

Utilizing the Router from the package next/router allows for a dynamic URL and loading of different content on the page: Router.push('/contract', `/contract/${id}`); An issue arises where the back button does not function as expected after runni ...

Utilizing AJAX to send an array of data in JSON format

I have successfully extracted specific elements from a form, stored them in an array and now want to convert this array into a JSON object to send it to a PHP file via AJAX. However, I am facing some issues with my code. Here's what I have done so far ...

Is there a way to access the Context in the _app.js file in Next.js with React?

Hey there! I'm currently working with a context provider file and _app.js file. I need to access AppContext in the _app.js file. Can anyone provide guidance on how to successfully access the AppContext within the _app.js file? I have imp ...