Set the fixed position using the RN StyleSheet

Currently, I have a rendering setup for an item in a list that looks like this:

 return (
    <View style={styles.item}>
      <View style={styles.nameAddressContainer}>
        <Text style={styles.customisedName}>{place.customisedName}</Text>
        <Text style={styles.address}>{place.placeName}</Text>
      </View>
      <View style={styles.deleteButtonContainer}>
        <Button
          rounded
          style={styles.deleteButton}
          onPress={() => onDeletePlace(place.id)}>
          <Icon name="trash-o" size={moderateScale(15)} color="black" />
        </Button>
      </View>
    </View>
  );

export const styles = StyleSheet.create({
  item: {
    backgroundColor: '#d7fce4',
    borderRadius: moderateScale(20),
    marginVertical: moderateScale(8),
    marginHorizontal: 16,
    height: moderateScale(60),
    justifyContent: 'space-between',
    flexDirection: 'row',
  },
  customisedName: {
    paddingTop: moderateScale(10),
  },
  deleteButton: {
    backgroundColor: 'white',
    width: moderateScale(35),
    height: moderateScale(35),
    justifyContent: 'center',
  },
  deleteButtonContainer: {
    paddingTop: 7,
    paddingRight: 7,
    position: 'relative',
  },
  nameAddressContainer: {
    flexDirection: 'column',
    paddingLeft: moderateScale(10),
  },
  address: {
    fontSize: moderateScale(9),
  },
});

My issue arises when the placeName text becomes too long, causing the button to shift rightwards and go beyond the green view's boundaries. Is there a way to prevent this from happening? Can we somehow lock the button's position while the placeName text wraps or hides?

position: fix is not a valid React Native stylesheet property. I've also attempted using zIndex without success.

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

Answer №1

Implement CSS code for the nameAddressContainer element:

style = {{ flex : 1}}

Answer №2

To ensure your style for "deleteButtonContainer" is properly positioned, set it to "absolute" and include a marginRight value for the placeName that is equal to or slightly larger than the width of the DeleteButton.

Consider something along these lines:

...,
deleteButtonContainer: {
    right: 8,
    top: 8,
    position: 'absolute',
},
...,
address: {
    fontSize: moderateScale(9),
    marginRight: moderateScale(38)
},

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

"When the onClick event occurs, ensure that a new button is displayed using React

I'm just starting out with reactJS and I'm working on a simple To-Do App. I've successfully implemented Edit and Delete functionalities, but now I'm facing an issue with Pagination. I am trying to display a new button under certain cond ...

Is there a way to dynamically insert page breaks in jspdf to ensure that tables do not split across multiple pages?

I am currently working on developing a website that can generate PDFs from database information, using PHP and MySQL to create tables with variable lengths. Sometimes, these tables may even span across multiple pages. If the first table takes up too much ...

Updating Django database records with ajax

I'm currently working on a feature that involves filtering table data and updating the table using ajax. Here's what I have so far: Filter Form: <form id="search" method="POST" action="{% url 'article-filter' %}"> <input ...

How can a component access its own template specified in the @Component decorator?

@Component({ selector: 'base-comp', template: '<div>hello</div>' <-- how to get this }) export class BaseComponent { someMethod( ) { <-- referenced here } Is there a way to access the entire template i ...

Combine the random results of two dice rolls using JavaScript for a specified amount of rolls, "n"

I'm currently working on a project that involves adding up the random rolls of a pair of dice for n rolls as specified by the user. Take a look at the code below: <!DOCTYPE html> <html> <head> <link rel="stylesheet" ...

Would it be acceptable to incorporate FontAwesome icons into a ReactJS project utilizing Material UI?

Currently working on a React project and wondering if it's advisable to incorporate FontAwesome icons in a MaterialUI-based ReactJS application. Experimented with both Material UI Icons and FontAwesome Icons, but noticed some redundancy. ...

What is the method for storing API status JSON in the state?

Can anyone help me figure out why the json in the register state is returning an empty object after console.log(register); from that state? import React, { useEffect, useState } from "react"; import { Formik } from "formik"; // * icons ...

Issue with default selection persisting in Angular 9 when using ngModel

I'm encountering an issue where I am able to successfully autofill a text box based on the state from another component. However, when I attempt to add ngModel to the text box in order to capture the value upon form submission, the value is getting cl ...

Tips for executing flushall just once across various clusters with Node.js and Redis

Whenever my server starts up, I find myself needing to clear out the Redis memory. However, each time a new cluster is formed, it triggers a flushall command that wipes out everything in memory. Is there a way to only run flushall once on the very first se ...

Is it possible to use line breaks to differentiate properties?

The handbook addresses The handbook states that you can separate properties using , or ;, and the last separator is optional in either case. Is it possible to use line breaks to separate object properties like this? If so, where is this information docu ...

Utilizing Angular's Local Storage Module to efficiently store and manage various elements within an array in Local Storage

I'm facing an issue with storing and retrieving an array from localStorage using the Angular Local Storage Module. Despite following the necessary steps, I am only able to retrieve the last element added to the array. Can anyone provide insights on wh ...

I'm experiencing difficulties with JS on my website. Details are provided below – any suggestions on how to resolve this issue

Can someone help me with a web project issue I'm facing? Everything was going smoothly until I tried to add some JS for dynamic functionality. However, when I attempt to access my elements by tag name, ID, or class, they always return null or undefine ...

Merging a variable and its corresponding value in JavaScript

I am attempting to achieve a similar functionality in Angular javascript (with simplified code): var modelName = "date"; if (attrs.hasOwnProperty('today')) { scope.modelName = new Date(); } In the scenario above, my intention is for scope.m ...

Unable to navigate beyond the boundaries of an app

I am currently facing an issue with my authentication service where it redirects to the identity server in case of certain errors. I attempted to achieve this using window.location.href = environment.authCodeFlowIssuer;, however, an error occurred: Ref ...

React JS - CORS error persists despite implementing cors settings

Currently utilizing Express and ReactJS Express Code: const Express = require('express'); const PORT = 5000; const cors = require('cors'); const server = Express(); server.use(cors()); // CORS added here server.get('/users&ap ...

Adding an active class on a selected chat list item in Angular - here's how!

We are currently developing a chat component where users can click on the left side chat item to open messages with the selected user. We have implemented an active class that changes the color of the selected chat list item. Our goal is to apply the activ ...

Ensuring the script waits for the complete loading of iframe prior to

I'm faced with an issue on the website I'm currently working on. There's a Live Chat plugin integrated on an iframe, and I need to change an image if no agents are available. Interestingly, my code works perfectly fine when tested on the con ...

What is the best method for serializing data associated with the current item in a jQueryUI sortable list?

Currently working with jQueryUI 1.8.14, I am interested in creating a sortable list and saving any changes to item positions in my application database whenever a user adjusts an item's position. To achieve this, my plan is to retrieve and serialize ...

The property 'createUploadWidget' cannot be read from an undefined source

While working on a React js tutorial, I encountered an issue related to using Cloudinary React SDK for image and video uploads. Specifically, I was using the Upload Widget provided by Cloudinary and faced an error when trying to open the widget - 'Typ ...

Utilizing Phantom Js with Apache server

After creating a JavaScript app, I realized the importance of making it SEO friendly. I am curious if anyone has experience setting up a crawlable webpage on Apache using Backbone.js (potentially with assistance from PHP and .htaccess files, or with Phant ...