Tips for arranging left and right elements in a row of three items?

Adding a second Header (from react-native-element 3.4.2) to a React Native 0.70 app involves placing it under the first Header, with its centerComponent pointing to a search bar that spans only one line. Below is the code snippet:

import { Header } from 'react-native-elements';
import { Col, Row, Grid } from 'react-native-easy-grid';
import { widthPercentageToDP as wp, heightPercentageToDP as hp } from 'react-native-responsive-screen';

Bar = () => { // Search element
        return (
        <View style={{position: "absolute", bottom:-hp("2.2%"), alignContent:"flex-start", paddingTop:hp("2.5%"), flexDirection:"row", width:"100%"}}>
            <View style={{flex:1, alignItems:"center"}}>
                <TouchableOpacity onPress={()=>{submit()}} >
                    <Icon name="search-outline" color="black" size={hp("4.4%")}/> 
                </TouchableOpacity>
            </View>
            <View style={{flex:8}}>
                <TextInput placeholder={"placeholder"} onChangeText={strChg}></TextInput>
            </View>
            <View style={{flex:1, alignItems:"center"}}>
                <TouchableOpacity onPress={()=>{navigation.navigate("MyHelp")}} >
                    <Icon name="help-outline" color="black" size={hp("4.4%")}/> 
                </TouchableOpacity>  
            </View>             
        </View>
    )
}

return (
   
        <View style={styles.container}>
            <Header   // First header showing screen name
            containerStyle={{backgroundColor: '#f4511e'}}
            centerComponent={<HeaderCenter />}. // Show screen name
            />
            <Header // Second header displaying search bar
            containerStyle={{backgroundColor: 'white'}} // White background color
            centerComponent={<Bar/>} // Search bar component
            />
            <ScrollView>
                ....
            </ScrollView>
            
        </View>
    )
styles = StyleSheet.create({
    container: {
        flex:1
      },
    text: {
        alignItems:'center',
        alignContent:'center',  
        paddingTop:wp("20%"),
        fontSize:wp("5%"),
    },
}

Here is how the header bar looks:

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

The issue lies in the position of the two icons. The left icon should start from the far left and the right icon should be at the far right. Using `alignContent: "flex-start/flex-end"` on the icons did not work. Increasing TextInput flex to 10 resulted in cutting off a portion of the two icons without pushing them away. How can these icons be moved to their proper positions?

Answer №1

Simply add justifyContent: 'space-between' to align the left item on the far left and the right item on the far right.

Answer №2

A custom search bar was implemented in the code rather than utilizing the Header component from react-native-elements. The following snippet demonstrates this implementation:

return (
   
        <View style={styles.container}>
            <Header 
            containerStyle={{backgroundColor: '#f4511e'}}
            centerComponent={<HeadCenter />}
            />
             <View style={{ bottom:hp("0%"), alignContent:"space-between", paddingTop:hp("0.1%"),flexDirection:"row", width:"100%", height:hp("7%")}}>. //<<==this is the View bloc to hold search bar.
                
                <View style={{flex:1, alignContent:"flex-start",justifyContent:"center",alignItems:"center"}}>
                    <Pressable  onPress={()=>{submit()}} >
                        <Icon  name="search-outline" color="black" size={hp("4.4%")}/> 
                    </Pressable>
                </View>
                
                <View style={{flex:5}}>
                    <TextInput  style={{fontSize:hp("3%")}} placeholder={plcholder} onChangeText={strChg}></TextInput>
                </View>
                <TouchableOpacity  onPress={()=>{navigation.navigate("MyHelp")}} >
                <View style={{flex:2, alignContent:"flex-start", justifyContent:"center",alignItems:"center"}}>
                    
                        <Icon  name="help-outline" color="black" size={hp("4.4%")}/> 
                     
                </View>  
                </TouchableOpacity>            
            </View>
            
            <ScrollView>
    ....
            </ScrollView>
    )

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

Tips for maintaining the border radius of a container while changing the background color on hover

I am encountering an issue with a drop-down list where the bottom corners have a border-radius applied, and I would like to change the hover color of the li items. However, when hovering over the last item, the background-color covers up the border radiu ...

"I am facing an issue where the button does not appear centered after using jQuery

I can't help but notice that when applying CSS directly, my buttons end up centered horizontally. Yet, when I insert the same code using append(), the buttons seem to align towards one side instead. Here is the HTML/CSS code snippet: <div style=" ...

Eliminating the 'white-space' surrounding concealed images

I am currently working on a project where I have a list of images that need to be hidden or shown based on the click event of specific <li> elements. While I have managed to achieve this functionality successfully, I am facing an issue with white spa ...

Add CSS styling to a section of a canvas

I want to use a specific cursor png for just a portion of a canvas. Currently, I have code that applies the cursor to the entire canvas like so: .myClass { cursor: url('../img/myCursor.png') 7 33, auto; /* img hotspot centred*/ } However, I ...

The implementation of subnavbars within a navigation bar using HTML and CSS

I am looking to align the Login button with the settings icon on the same line above the links in my navbar. Is there a way to accomplish this? Check out this fiddle that demonstrates my issue: FIDDLE Here is the code I have written: <body> < ...

Incorporating and designing an external document

Another website has a file that I would like to include in one of my own pages. The URL format is as follows: http://example.com/path/with/some/variables I could use an iframe to accomplish this, but I also want to customize the CSS of elements within th ...

Assistance with changing styles

Hey there, I could really use some assistance. I've created a style switcher, but I'm struggling to figure out how to replace the stylesheet properly. Currently, my code empties the <head> element when what I really need is for it to simply ...

Listening for JS events on a CSS class called "int-only" which only accepts

Having an issue: I'm encountering a problem with this PHP code: <?php for($i = 0; $i < sizeof($floating_ips_json["floating_ips"]); $i++){ ?> <tr class="details-control-<?php echo $i; ?> cursor-pointer"> <t ...

What is the best way to expand a scrollbar's width with CSS?

Can the width of a scrollbar on a <div> element within the <body> be increased? I mean the scrollbar specifically on the inner <div> element, not the default browser scrollbar since this page is in full screen mode and does not display t ...

The command 'expo' is not valid, please check if it is a valid internal or external command, executable program, or batch file

Encountering an error message while attempting to utilize expo commands. npm ERR! code EPERM npm ERR! syscall rename npm ERR! path C:\Users\Sri\AppData\Roaming\npm\node_modules\expo-cli npm ERR! dest C:\Users\Sr ...

Tips on positioning a dropdown item to the far right of the page

I need help moving the language switcher and its items to the right side of the page. I tried using ml-auto but it didn't work for me. Whenever I try to adjust the position with padding-left, all the items end up in the center of the page. Any suggest ...

Sass flex order has no effect on elements that are generated

I encountered an issue with the rendering of SVGs in my project. Currently, they are displayed correctly in desktop mode, but in mobile portrait mode, I need to change the order of one specific SVG element within the row. To achieve this, I decided to use ...

What is the best way to implement two events in onPress using React Native?

I'm trying to implement the UploadB function and toggle the modal visibility using setModalVisible(!modalVisible)... However, my attempts so far have not been successful. const UploadB = useCallback(() => { dispatch({ type: ADD_P ...

How can one determine the dimensions of the browser window using a property?

Can someone please clarify how to find the width and height of the browser window specifically? Thanks in advance! ...

Encountering the error message: ERESOLVE unable to solve dependency tree while trying to install

I'm encountering an error when attempting to install a dependency. How can I resolve this issue? npm ERR! code ERESOLVE npm ERR! ERESOLVE unable to resolve dependency tree npm ERR! npm ERR! While resolving: <a href="/cdn-cgi/l/email-protection" cla ...

Restrictions on the number of characters based on the size of fonts in an html list sc

Recently, I attempted to implement a ticker message on my website using li scroller. However, it appears that there is a limitation on the number of characters that can be displayed in the ticker message when different font sizes are used. With a smaller ...

Selenium encountered an error: Element not found - Could not locate element: {"method":"CSS selector","selector":"*[data-test="email-input"]}

Recently, my application has been encountering an error when trying to log in through a web form. The issue seems to be with locating the email input field: "no such element: Unable to locate element: {"method": "css selector", "s ...

What are the steps to create a CSS 'shell' design?

How can I create an image displayed as a circle with border-radius:50%, along with some text on the same line that has a set width and background color? I want to achieve this without hard coding values. What is the best approach to do this? Check out the ...

Distributing elements evenly across the parent width using Angular FlexLayout for a responsive design

I need to create 3 div squares: div-left, div-middle, and div-right, each with a width of 300px. These squares should be arranged horizontally within the parent div main-section, which will adjust its size based on the screen width, being 1300px if the scr ...

Steps for aligning an image to the right using Bootstrap Vue

I'm currently learning Bootstrap Vue and I'm trying to align an image on the right using a b-card header. The challenge I'm facing is that when I add the image, it disrupts the perfect size of the template header, causing the image to show a ...