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:

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

Exploring the compatibility between Node.js, React, and deployment on Linux, comparing the use of 'serve' versus

I recently cloned my repository to my Linux server and recompiled the modules using npm install The next step was to run serve -s build To do this, I had to first install it with npm install serve even though serve-index and serve_static were already pr ...

Tips for incorporating a hyperlink within a react component

I'm looking to include social media links in my React project, but the code I have isn't working. Can someone help me identify what mistake I might be making? import {L10n} from "@pythonbuddha/l10n"; ... ... <span className="soc ...

Issue with Tailwind classes not applying correctly upon refreshing the page in production settings

Challenge Description: Encountering an issue with my nextjs project that utilizes tailwindcss. The login page initially loads with the required classes for the UI, but upon refreshing the page, the classes disappear from the DOM, causing a broken UI. Her ...

Instructions on including a directory in the package.json file for publication on npm

I am facing an issue when attempting to publish a module in the npm repository as it is not recognizing the 'lib' folder. Even though I have included it in the package.json file as shown below, the 'lib' folder contents are not being re ...

Implementing JavaScript for showcasing weights

I've encountered a JavaScript function that modifies user preferences for weight units, allowing them to choose between metric and imperial measurements. When displaying weights on my page, I typically present them as follows: This is a brief explan ...

Issue: Module 'curl' is not located at Function.Module._resolveFilename (module.js:489:15)

After installing node.js using the Windows installer, I noticed that the folder structure created was C:\Program Files\nodejs\node_modules\npm\node_modules. It seems like all the module folders are in the last node_modules director ...

Is there a way to have a button function as a submit button for a form even when it is located in a separate component within a react application?

I am in the process of creating a user-friendly "My Account" page using react, where users can easily update their account information. I have divided my components into two sections: the navbar and the form itself. However, I am facing an issue with the s ...

Troubleshooting issue with refreshing selectpicker in Bootstrap-select and Vue.js

Incorporating the bootstrap-select plugin (found at ) into a ruby on rails app with Vue.js as the javascript framework has been my latest project. The goal is to have two select options where one selects a category and the other displays all available tea ...

apply a visible border to the item that is clicked or selected by utilizing css and vue

I have a list of items that I want to display as image cards with an active blue border when clicked. Only one item can be selected at a time. Below is the code snippet: Template Code <div class="container"> <div v-for="(obj ...

A foolproof guide to effortlessly incorporate an image into your banner while ensuring its perfect alignment even with varying screen widths

I'm facing an issue with adding a photo to the banner on my webpage. Currently, the photo remains in the same position within the banner regardless of screen size. However, I want it to stay right above my logo even when the screen size changes. How c ...

Unable to finalize submission of TextField using Formik

I am struggling to understand why one approach works and the other does not. One approach that works can be found here: pastebin. However, the second approach found here: pastebin does not work. The main difference between these two approaches is that in ...

The combination of MUI CardContent and flexBox seems to have issues when used in conjunction with typography and chips

Take a look at this React code using MUI. It's designed to create a Card that showcases Character Information. const CharacterPreview = ({ characterKey }: CharacterPreviewProps) => { return ( <Card sx={{ maxWidth: 256, borderRadius: 4 }}&g ...

NGRX reducer avoids generating errors due to incorrect assignments

My experience with ngrx is relatively new. In my typical TypeScript work, I usually encounter an incorrect assignment error like the one below due to a missing property in the interface declaration: interface IExample { count: number; } let initialState ...

Ensure the hour field is accurate using yup validators

I am using material-ui's TextField component with a field labeled as "hour." I need to implement Yup validation to enforce a specific format for the input value, which should follow this pattern: 02:30 Can someone guide me on how to achieve this usin ...

Issue with populating dropdown menu inside jquery modal dialog box

When I click on the 'create new button', a modal window form pops up with a dropdown menu. The dropdown is supposed to be populated via ajax with the help of the populateUserData() function. Even though the ajax call seems to be successful, I am ...

Activate a change or response when the input value in Javascript is altered

Currently, I am working on a small project using JQuery and facing an issue when trying to remove error classes from HTML elements. To handle the removal of the error classes, I am utilizing $('selector').on('input') event to target th ...

jQuery plugin is not effectively targeting the directive

Recently, I have been experimenting with using a sleek jQuery datepicker and decided to turn it into a directive for my angular app. The implementation of the directive is currently very straightforward: directive('datePicker', function() { ...

Managing Image Quality with Unsplash API

How can we ensure high quality images are embedded on the web using Unsplash API or other methods? The image displayed in the example below appears blurry and unclear compared to the original image. Original Image link: Example of embedding the image abo ...

Get the large data file in sections

I ran a test script that looks like this: async function testDownload() { try{ var urls = ['https://localhost:54373/analyzer/test1','https://localhost:54373/analyzer/test2'] var fullFile = new Blob(); for (le ...

Revamp the HTML page by automatically refreshing labels upon every Get request

My HTML webpage requires real-time updates for one or more labels. To achieve this, I have incorporated CSS and JS animations into the design. Currently, I am utilizing Flask to handle all the calls. I face a challenge where I need to consistently update ...