Tips on positioning a button at the bottom of the screen in React Native

I am using the FAB component from the react native paper library. I want to align the button at the bottom, but it is overlapping with a text field. How can I position it below the text field? Please refer to the screenshot below:

Here is the code snippet:

//Inside return
    <ScrollView>

                    <Text style={styles.title}>Add a Lead</Text>

                    <View style={styles.inputContainer}>
                        <Image source={require('../../assets/images/name.png')} style={{
                            marginTop: 15, width: 32, height: 32, resizeMode: 'contain'}}/>
                        <TextInput
                            placeholder='Name'
                            value={this.state.name}
                            style={styles.input}
                            onChangeText={ name => this.setState({name})}
                            error={this.state.nameError}
                        />
                    </View>
                    <HelperText type="error" visible={this.state.emailError}>
                        {this.state.emailError}
                    </HelperText>

            // Add more input elements for phone, email, etc.

            <View style={{marginTop: 20, flex: 1, flexDirection: 'row'}}>
                        <Image source={require('../../assets/images/comment.png')} style={{
                            marginTop: 20, width: 32, height: 32, resizeMode: 'contain'}}/>
                        <Text style={{marginTop: 25, marginLeft: 15}}>Comment</Text>
                    </View> 

                    <View>
                        <TextInput
                            style={{height: 65, marginTop: 15, borderColor: 'gray', borderWidth: 1}}
                            onChangeText={(comment) => this.setState({comment})}
                            value={this.state.comment}
                            error={this.state.commentError}
                            multiline = {true}
                            numberOfLines = {4}
                        />
                    </View>
            <FAB
                    style={styles.fab}
                    small
                    icon="arrow_forward"
                    onPress={this.handleCreateNewLead}
                />
    </ScrollView>

CSS styling for the FAB component:

fab: {
        position: 'absolute',
        margin: 16,
        right: 0,
        bottom: -20,
    },

Screenshot illustrating the issue:

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

Answer №1

To fix the issue with the textarea (marked by the ? icon), you need to add position:relative.

<TextInput style={{height: 65, marginTop: 15, borderColor: 'gray', borderWidth: 1, position: relative}}

Additionally, update the style for the fab component as shown below:

fab: {
        position: 'absolute',
        margin: 16,
        right: 10,
        bottom: 10,
    }

Try implementing these changes and see if it resolves the problem.

Answer №2

To properly structure your layout, you should enclose both the TextField and FAB components within a View component:

<View style={styles.container}>
    <TextInput
        style={styles.textField}
        onChangeText={(comment) => this.setState({comment})}
        value={this.state.comment}
        error={this.state.commentError}
        multiline={true}
        numberOfLines={4}
    />
    <FAB
        style={styles.fab}
        small
        icon="arrow_forward"
        onPress={this.handleCreateNewLead}
    />
</View>

Make sure to update your styles accordingly with the following adjustments:

const styles={
    container:{
        flexDirection:"row",
        alignItems:"center",
        marginTop: 15
    },
    textField:{
        flex:1,
        height: 65,
        borderColor: 'gray',
        borderWidth: 1
    },
    fab: {
        position:"absolute",
        right:0,
    },
};

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

Could there be an issue with the directory path for the file?

https://i.stack.imgur.com/m8F9y.pngThe background-url() function was utilized to set the background screen to PurpleCloud.png. Despite multiple attempts, the image is still not being displayed. What could be the issue? Even after understanding file path w ...

Tips for increasing the size of Material-ui Rating icons

I am currently utilizing npm to develop a widget. I aim to utilize the material-ui Rating component and have successfully integrated it. However, when I embed the widget on a webpage, the html font-size is set at 62.5%, causing the component to appear too ...

Can someone please explain how to use the prevState in REACT?

Can you explain the difference between how to define the counterHandler function in these two examples? counterHandler = () => { this.setState(() => { return { times: this.state.times + 1 } }); } versus counterHandle ...

Tips for creating a filter in React JS using checkboxes

In my current situation, I have a constant that will eventually be replaced with an API. For now, it resembles the future API in the following way: const foo = { {'id':1, 'price':200, 'type':1,}, {'id':2, &apo ...

Error message in Typescript: "Property cannot be assigned to because it is immutable, despite not being designated as read-only"

Here is the code snippet I am working with: type SetupProps = { defaults: string; } export class Setup extends React.Component<SetupProps, SetupState> { constructor(props: any) { super(props); this.props.defaults = "Whatever ...

React - passing down a ref as a prop isn't functioning as expected

In my current project, I am utilizing the react-mui library and aiming to incorporate a MenuList component from the MenuList composition available here. An issue arises when passing a ref as a prop down to a child component containing a menu. For reference ...

Tips for recalling the display and concealment of a div element using cookies

My HTML code looks like this: <div id='mainleft-content'>content is visible</div> <div id="expand-hidden">Button Expand +</div> To show/hide the divs, I am using JQuery as shown below: $(document).ready(function () { ...

Issue: Module not found; Typescript error encountered in a react application

I have a load_routes.js file in the node_express folder that is responsible for loading all the routes for my project. Everything was working smoothly until I decided to change the file extension from .js to .ts. Suddenly, I started encountering the follow ...

Activate the jquery function when the content of the <ul> element changes

Looking for a way to trigger a jQuery function when the content of an unordered list (ul) changes. Check out the code I've written below: JavaScript jQuery(document).ready(function($) { $('.ProductList').on('change', fun ...

Deactivate a button when clicked on a card that has been mapped

After creating a card component and mapping through each card, I added an onClick function to disable the button of the clicked card. However, my logic ended up disabling all buttons instead. Here is the code snippet where I define the rendering of the UI ...

Experiencing the 'Page prerendering error' message within Next.js

I encountered a prerender error during the deployment phase that I'm struggling to comprehend: Error occurred prerendering page "/about". Read more: https://nextjs.org/docs/messages/prerender-error ⨯ useSearchParams() should be wrapped in ...

Ensuring the validity of float and non-empty values in JavaScript

Embarking on the journey of web development, I'm delving into basic applications. My current project involves creating a straightforward webpage to add two numbers and implementing preliminary validations - ensuring that the input fields are not left ...

Looking to extract specific information from a webpage using VBA

I'm trying to extract the text 'Catalog Manager/ Sales' & 'EOL (product/component)' from the view source tab using VBA. Here is an excerpt of the view source code: <tr> <td nowrap="true" valign="top" width="165px" cl ...

The click event fails to trigger while trying to parse external HTML

Currently, I am working on a project that requires me to load HTML from an external file and insert it into an existing div element. Although the process is successful overall, I have encountered an issue where the .click() events do not trigger when click ...

Is it possible for three.js to integrate information from REST APIs?

Currently, I am in the process of learning three.js and have successfully created basic 3D models using hardcoded values. My goal now is to retrieve these values from a database that I have set up in MSSQL Server. These x, y, and z parameters are stored ...

Adjust the button's color even after it has been clicked

My goal is to update the button's color when it's clicked. I found some examples that helped me achieve this, but there's an issue - once I click anywhere outside of the button, the CSS class is removed. These buttons are part of a form, and ...

Tips for displaying specific information using Javascript depending on the input value of an HTML form

I am working on an HTML form that includes a dropdown list with four different names to choose from. window.onload = function(){ document.getElementById("submit").onclick = displaySelectedStudent; } function displaySelectedStu ...

Using CSS to Showcase the Art Gallery Page

This is my unique gallery display: https://i.stack.imgur.com/RddD8.png Here is the look I am going for https://i.stack.imgur.com/kuOye.png I want to showcase images in a slightly messy yet awesome way However, I encounter an issue when some images have ...

How can communication be established between a Node backend and a React frontend on separate Heroku instances?

I'm developing an app that utilizes the MERN stack, which includes MySql, Express, React, and Node. The frontend and backend components are stored in separate Github repositories and hosted on individual Heroku instances. Both the frontend and backend ...

retrieve the values from an array and showcase them in a formatted table

I need assistance in displaying the values stored in the array isReferralAvailable from my Google Firestore database. To provide a visual representation, here is an image of my Firebase database structure: The challenge lies in fetching the values of isRe ...