React Native List component with interactive items

I am currently developing a custom line style for a react-native FlatList.

My goal is to allow the user to navigate to item details by clicking on the line text, or to navigate to another page (drill down to the next level) by clicking on the right caret like this:

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

This is the code for my current list components:

class MyList extends Component {
  handleShowDetails = index => {
    ...
  };


  handleDrillDown = index => {
    ...
  }

  render = () => {
    let data = // Insert your own data here

    return (
      <View style={styles.container}>
        <FlatList
          data={data}
          keyExtractor={(item, index) => index.toString()}
          renderItem={({ item }) => (
            <MyListItem
              onTextPress={this.handleShowDetails}
              onCaretPress={this.handleDrillDown}
              item={item}
            />
          )}
        />
      </View>
    );
  };
}

export default MyList;

const styles = StyleSheet.create({
  container: {
    flex: 1
  },
  item: {
    padding: 10,
    fontSize: 18,
    height: 44,
    backgroundColor: colors.white,
    borderStyle: "solid",
    marginBottom: 1
  }
});

Below is the code for my list item component:

class MyListItem extends Component {
  handleTextPress = () => {
    if (this.props.onTextPress) this.props.onTextPress(this.props.item.id);
  };

  handleIconPress =() => {
    if (this.props.onCaretPress) this.props.onCaretPress(this.props.item.id)
  }

  render = () => {
    return (
      <View style={styles.container}>
        <View style={styles.textContainer}>
          <Text onPress={this.handleTextPress}>{this.props.item.title}</Text>
        </View>
        <View style={styles.iconContainer}>
          <Button onPress={this.handleIconPress}>
            <Icon name="ios-arrow-forward"/>
          </Button>
        </View>
      </View>
    );
  };
}

export default MyListItem;

const styles = StyleSheet.create({
  container: {
    flex: 1,
    flexDirection: "row",
    justifyContent: "space-between",
    alignItems: "center",
    backgroundColor: colors.white,
    marginBottom: 1,
    height: 30
  },
  textContainer: {
    backgroundColor: colors.light,
    paddingLeft: 5,
    fontSize: 26
  },
  iconContainer: {
    alignSelf: "flex-end",
    backgroundColor: colors.primary,
    paddingRight: 5, 
    fontSize: 26
  }
});

Issues I'm encountering with the code:

a. Clicking on the text is not functioning correctly. Navigation works sporadically, especially when clicking on the empty space between the text and the caret.

b. Adjusting the font size of the text seems impossible.

c. Struggling to properly space them out.

d. Need both items on the row to be vertically centered.

This is the result I currently have:

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

Answer ā„–1

To address the issue with clicking, consider implementing a TouchableHighlight or TouchableOpacity for the designated View.

If you are facing challenges with spacing and alignment, adjusting the text to flex: 9 and the icon to flex: 1 using FlexBox could be a solution. Refer to the documentation provided here for further guidance: https://facebook.github.io/react-native/docs/flexbox.html.

Answer ā„–2

1. Make sure the text fills the entire cell. Currently, it only occupies 50% of the space. Use the <Text> element with a height of at least 44.

2. The fontsize property should be applied to the <Text> component, not the <View> component.

3. Regarding your comment on spacing, can you provide more clarity so I can address it effectively?

4. Consider using justifyContent: 'center' within the iconContainer for better alignment.

Answer ā„–3

When considering part a, my recommendation for enhancing Anthu's response would be:

If you desire the entire textContainer to be interactive, I propose utilizing TouchableWithoutFeedback (or another applicable Touchable component) and enveloping it around the textContainer View.

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

Capture all div elements from the table and store them in an array

Check out this code snippet that includes draggable divs and a droppable table: http://jsbin.com/exetuk/1/edit When dragging a div to the table, copies of the div with the class .draggable appear. I am looking to create an array with divs from the table ...

Tips for achieving compatibility between systemjs module loading and .net mvc architecture

Upon finding the ng-book 2, I saw it as a promising resource to delve into Angular 2. Although I am new to module loaders and have minimal experience with npm and node, I find the terminology and assumed knowledge to be quite perplexing. I decided to use ...

Avoid connecting HTML input elements with both JavaScript and Java models

I am troubleshooting an issue with my login page code. <div ng-show="!loggedIn()"> <form ng-submit="login()"> Username: <input type="text" ng-model="userName"/> Password: <input ...

Is there a better method to organize an Array of Objects?

Greetings my fellow developers, Iā€™m looking to rearrange the Array of objects (array1) to match the order provided in array2. As you can see, array2 is a simple array with values that correspond to key names in array1, making it the reference for organi ...

Transfer dropzone files exclusively upon pressing a button

Greetings to all! I am a newcomer here, and I am also new to jquery. I came across an article that explains how to upload multiple files at once on a website using Dropzone.js in ASP.NET Webforms. You can find the article here. Upon implementing the code ...

Looking to optimize the JavaScript code for improved performance speed

Is there a more efficient way to avoid writing the same lines of code repeatedly without compromising performance? I've attempted using a for loop to categorize fields as 'mandatory' or 'optional', but it still requires duplicating ...

Finding the amount of memory that can be used in a WebView

I'm currently developing an application that features a WebView running JavaScript code. This particular JavaScript code tends to be memory-intensive and can sometimes exceed the allotted memory, leading to crashes in the WebView's Chromium proce ...

Is it possible to refresh a div on one .aspx page using content from another .aspx page?

Just beginning my journey with asp.net and currently tackling a project that involves two .aspx pages. Events.aspx: This page is where the site admin can update upcoming events and webinars using an available panel to input event title, date, information ...

Show loading GIF on the screen and hide it once the script has finished loading

I have implemented lazy loading for my Facebook comments plugin, but I am facing an issue where the plugin takes some time to load. To provide a better user experience, I want to display a loading GIF while the plugin is loading. However, once the comments ...

Is there a way to effectively combine @Model and @Emit in VueJs using Typescript?

I could really use some assistance with @Model and @Emit decorators. I'm attempting to alter the order on click within my component, and I referred to the documentation found here: https://github.com/kaorun343/vue-property-decorator. Below is the code ...

Develop an HTML table using either JSON or jQuery in Javascript

JavaScript is a bit of a mystery to me right now - I could really use some assistance in overcoming this obstacle that has me pulling my hair out! I'm struggling with constructing HTML code using JSON data. It's just not clicking for me at the m ...

Tips for adjusting the orientation of photos as you reposition your iPhone in an iOS application

Does anyone have suggestions on how to incorporate this? I built my app with cordova 4.0.0 and used JavaScript, HTML, and CSS. ...

Building a bespoke search input for the DataTables JQuery extension

As the title indicates, I am in the process of developing a custom search box for the DataTables JQuery plugin. The default options do not suit my needs, and configuring the DOM is also not ideal as I aim to integrate it within a table row for display purp ...

Interacting with an iframe within the same domain

I'm currently working on an application in Angular 6 that requires communication with an iframe on the same origin. I'm exploring alternative methods to communicate with the iframe without relying on the global window object. Is there a more effi ...

Having trouble with CSS text-align right not functioning properly? Here's how you can fix it

<div style="text-align: left;width: 21cm;"> <h4 style="text-align: center;font-weight: bold;font-size: 20px;margin: 0">Tax Invoice(Center) <span style="text-align: right;"> For Customer(Right)</span></h4> </div> I n ...

Limited achievements seen with AJAX. Occasionally, either no data is retrieved or an error is encountered

My experience with AJAX has been frustrating so far. I am trying to populate some textboxes with values from a database, but nothing is getting inserted. The only thing that's happening is the appearance of two errors related to specific values which ...

Every time I try to set up the MailChimp pop-up javascript, I encounter an Uncaught Error message saying that Bootstrap tooltips need Tether and an Uncaught ReferenceError message

Utilizing Wordpress and Understrap. Upon inserting the following code: <script type="text/javascript" src="//downloads.mailchimp.com/js/signup- forms/popup/embed.js" data-dojo-config="usePlainJson: true, isDebug: false"> </script><script ty ...

How to Display an HTML Page or DOM Element on the Surface of a Cube using Three.js?

Currently, I am working on customizing the sample file canvas_geometry_cube.html that comes with the Three.js package. My goal is to replace each face of the cube with an HTML page or DOM element (preferably DOM element). While exploring, I came across P ...

Steps for creating a div that appears on top of all other elements on a webpage

I have created a custom dropdown list with checkboxes from scratch because the project I am working on needs to be compatible with older versions of IE. Overall, the result is good but there is one issue - when I click on the drop down list, every other el ...

Utilizing JavaScript async over setInterval for improved efficiency

Let's say I want to execute the function update() every second. I have two options to achieve this: async function interval() { await new Promise((resolve, reject) => { setTimeout(resolve, 1000) }) update() interval() } or setInter ...