Guide to react native: aligning symbol in the middle

Currently, I am developing a simple app using React Native that targets both Android and IOS platforms. Within a View element, I have a Text component that displays a star symbol based on a conditional string {item.isFavourite ? "\u2605": "\u2606"}. My goal is to center this text within the View using a consistent style that works seamlessly on both Android and IOS, but so far, I haven't been able to find a solution.

Below is the code snippet I am currently working with:

<View style={styles.menuFavouriteStar} >
  <Text
    style={styles.favouriteStar}
    onPress={() => {
      const newData = toggleFavourite(item, data);
      saveFavourites(newData.favouritesData);
      setData(newData);
      }}
  >{item.isFavourite ? "\u2605": "\u2606"}</Text>
</View>

The associated styles are as follows:

menuFavouriteStar: {
    width: 40,
    height: 40,
    position: "absolute",
    top: "82%",
    right: "2%",
    backgroundColor: "white",
    borderRadius: 3
  },
  favouriteStar: {
    fontSize: 25,
    textAlign: "center",
    textAlignVertical: "center"
  }

I've experimented with various CSS properties in an attempt to achieve cross-platform consistency without success. Do you have any suggestions or should I consider creating separate styles for each operating system?

Answer №1

While I may not be a React Native expert, my expertise lies in web development using React.js. If you are able to incorporate these CSS styles, it should help resolve your issue:

menuFavouriteStar: {
  width: 40,
  height: 40,
  position: "absolute",
  top: "82%",
  right: "2%",
  backgroundColor: "white",
  borderRadius: 3,
  display: "flex",
  justifyContent: "center",
  alignItems: "center"
}

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 are the steps to build my Android application using Eclipse?

I'm currently working on the Android tutorials and facing issues with a specific resource ID. Within the res\menu\main.xml file, I have an action_entry that is defined inside the menu tag like this: <item android:id="@+id/acti ...

floating downward inside the container

Check out my website at . Everything looks great in Firefox, but when I view it in IE, the "top" button that should be floated inside the h2 titled "Unit 301: Pre-production skills" is floating to the right and getting pushed outside of the heading. Any i ...

Customizable trapezoid in SVG format with adjustable points relative to one another and the option to add gradients

I have explored numerous options while searching for a way to create a responsive, full-width trapezoid with a gradient but have come up short. Using SVG, I was able to get close to the desired shape, but encountered problems when the trapezoid's dime ...

Hiding an HTML image element by setting its display to none will prevent it from being visible if later changed to block display

I am currently developing a web-based game that can be played on both desktop computers and mobile devices. However, for the optimal experience on mobile devices, players need to rotate their device to landscape mode. To prompt users to rotate their devic ...

Populate Android RecyclerView with Images and Text from JSON Data

Hello, I am currently working on creating a RecyclerView list from JSON data that includes image URLs and names. I have spent the past two days searching Google and Stack Overflow for a solution, but I have not been able to figure out how to set the text a ...

What is the best way to sort items in a specific category within a UICollectionView using swift?

As a newcomer to Swift, I am encountering a challenge with filtering categories in my UICollectionView. Below is my code to retrieve all articles for all categories: func getArticlesforCategory(category: String) -> Int { var result : Int = 0 ...

Tips and tricks for ensuring images maintain their aspect ratio and height when resizing for responsiveness

I am facing an issue with my two-column layout. One column contains an image and the other column has text and buttons with a fixed height. To ensure the image is responsive, I have set the width to 100% and height to auto. However, upon resizing, the aspe ...

Leverage Java constants within arrays defined through XML

In setting up a ListPreference, I have defined the entry values in an array like this: <string-array name="sortSelectionEntryValues"> <item>0</item> <item>1</item> </string-array> But instead of using plain numbers in ...

How to Determine If an Image Returned by UIImagePickerController is in Landscape or Portrait Orientation?

It has come to my attention that the UIImagePickerController does not directly support landscape orientation. Yet, there is a crucial need for the application to distinguish whether an image retrieved from the controller is in portrait or landscape format. ...

Adjusting the width of a Material UI drawer: Tips and tricks

Currently, I am working on implementing the Material UI drawer and anchoring it to the top of my page. It is functioning correctly, however, I am encountering an issue where I am unable to adjust the width of the drawer. Despite trying to update the width ...

Automatically open the URL in Flutter app upon startup rather than requiring a button press

I need my app to automatically open a URL when it starts, without the need for any tap or press functions. Currently, the app only works with a tap function. How can I achieve this? ...

Words placed in the middle of the picture

<div> <img style="vertical-align:middle" src="https://placehold.it/60x60"> <span style="">New Product</span> </div> I require this specific layout to be responsive. Could you please provide instructions on achieving this? ...

Tips for relocating anchor elements to less desirable locations

My website has an issue with anchor elements appearing too frequently and not in the desired location. I need someone to help fix this so there are only two anchors displayed. After checking my code, it seems like there are not more than the specified num ...

Encountering difficulties while setting up an alarm with an intent

I'm brand new to Android Studio and Java, but I'm working on creating an app where users can input a time for a countdown timer to start. I've been researching using intents for this purpose, but I'm struggling with implementing it. Cur ...

unable to modify the content within a div by clicking on a link

Lately, I've been experimenting with a code snippet I found on this fiddle: http://jsfiddle.net/unbornink/LUKGt/. The goal is to change the content of a div when clicking on links to see if it will work on my website. However, no matter which link I c ...

I'm curious to know if there is a way to be notified when a UITableViewController has completed generating all the cells for a UITableView

Is it possible to identify a callback method in iOS/Swift 3.0 that indicates when a UITableViewController has completed loading the cells of a UITableView after invoking .reloadData on the table view in Swift? (or suggest an alternative approach) ...

New programmer seeking to apply a dim effect to the entire photo while also adding a highlight when the image is hovered over

I am looking to add a special effect to my photos where they appear dimmed but highlighted when hovered over. Any guidance on how to achieve this would be greatly appreciated! The image is contained within a flexbox div that also contains a clickable lin ...

Using JQuery to enable the movement of divs on a screen through clicking and dragging, without the use of

Recently, I've been experimenting with a small project involving draggable divs. However, the code I've written doesn't seem to be functioning properly, causing JQuery to become unresponsive. Is there an alternative method that is simple an ...

Using a label constraint of 0 in a UITableView header can cause Autolayout to malfunction

I am attempting to implement the conventional method of removing a label and having autolayout adjust accordingly. How to change label constraints during runtime. However, I am encountering this within a UITableView header. When I modify the height constr ...

Prevent checkboxes from appearing on the left side of a UITableView when in editing

In my app, I am using a UITableView that supports multiple-selection during editing. In the Storyboard, I have not configured any Accessory or EditingAccessory for the UITableViewCells. However, when I select a row and enter Edit mode, all rows display a ...