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:

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

Tips for dividing by a large number

I am currently attempting the following: const numerator = 268435456; const denominator = 2 ** 64; const decimalFraction = numerator / denominator; In order to achieve this, I have experimented with utilizing the code provided in this link: : const rawVal ...

Error: The npm-link library encountered an invalid hook call

Problem Description: I am working on developing a package named eformless. To set up the package, I utilized CRA to create a directory named sandbox where I linked the package. However, I keep encountering an error when attempting to launch the sand ...

Comparing Yii's CHtml::link() function with the use of regular <a href=''></a> HTML tags

When using elements like yii CHtml::link, what are the recommended practices? I'm working on a button that needs to include an icon, text, respond to hover events, and be wide. Are there any benefits to using CHtml instead of a regular tag that can e ...

I am having trouble implementing internal/inline styles on dynamic elements within NextJs

I am struggling with formatting a code snippet similar to this one: <p className="xyz" dangerouslySetInnerHTML={{__html: dynamicContent}}></p> In the dynamicContent variable, there is a string and an anchor tag. I want to apply some ...

When using Typescript with MUI styled components, there may be issues with recognizing common objects for styles

I'm facing a challenge where I have various styled components with some shared styles. To address this, I decided to create a function that takes in a `theme` parameter and outputs the common styles being used. Here's a glimpse of what I came up ...

image in responsive css design

Image 1 (Current Layout) Image 2 (Desired Layout) I am trying to achieve a responsive layout similar to the second image. However, I seem to be stuck with the layout from the first image. Here is the CSS code I'm currently using: @media (max-width ...

Equalizing the space between table headings and content

I am struggling with aligning the heading and entries in my table properly. https://i.stack.imgur.com/IYtY1.jpg My goal is to ensure that the heading and entries are perfectly aligned with each other. This is how my Table.jsx looks like: <div classNa ...

Discovering the status of a wrapped component using Jest

const wrapper = mount( <ContextProvider> <FreeformEquationQuestionPractice question={question} /> </ContextProvider> ) console.log('freeform state: ', wrapper.childAt(0).instance().state) FreeformEquationQues ...

What is the best way to retrieve information from a deeply nested JSON dataset?

I am facing an issue with accessing data from a nested JSON file. The JSON file I created has one parent object and three children within the parent. My goal is to retrieve the data inside the children. While I can view all the data in the JSON file usin ...

Transitioning images smoothly and responsively with jQuery, creating a beautiful

Hey there! I'm looking for some help with transforming this jQuery effect. Instead of having fixed sized images, I want to set the size in percentage (width:100%; height:auto) so they can be responsive. Any creative ideas or suggestions? <scri ...

Fixed headers remain in place as you scroll horizontally on a single table

Within my system, I have organized two tables: table one and table 2 are stacked on top of each other. I've managed to freeze the column headers so that they are displayed vertically, remaining static as users scroll horizontally. To achieve this effe ...

Issues with removing options from Autocomplete persist in React MaterialUI

Currently navigating the world of ReactJS and experimenting with Material UI's Autocomplete component. The challenge lies in managing a complex data structure where options are dynamically generated based on user selections, but removing previously se ...

Social media comments widget

Currently, I am incorporating the Facebook XML to implement a Facebook comments plugin within my MVC 3 application in the following manner: <fb:comments href="@Request.Url.AbsoluteUri" num_posts="15" width="900"></fb:comments> The issue lies ...

Is the ng-style not displaying the background image with the interpolated value?

I have been attempting to update the background image of a div using angular ng-style. Below is the code I am working with: <div class="cover-image" ng-style="{'background-image' : 'url({{data.image}})'}"></div> However, ...

For my Bootstrap website, it's a constant struggle to balance between having a responsive menu item and ensuring its correct visual appearance

I need help with creating a unique menu design for my website. On the desktop site, I want to display "username/password/sign in" buttons, while on the mobile responsive version I only want to show a single "sign in" option that redirects users to the sign ...

Facing issues with Heroku and Express/Nodejs crashing?

I have been working on a React/Express application that I am attempting to deploy on Heroku. While trying to do so, I encountered the following errors in my logs: 2020-01-13T03:39:48.733455+00:00 heroku[router]: at=error code=H10 desc="App crashed" method ...

The hidden Material UI Collapse component is still occupying space on the page

Currently, I am implementing Material UI Collapse in my React project and encountering an issue where it is causing unnecessary space on the interface when hidden <Collapse in={false}> //content here </Collapse> Even though I have not a ...

Tips for ensuring consistent sizing of card items using flexbox CSS

I'm attempting to create a list with consistent item sizes, regardless of the content inside each card. I have experimented with the following CSS: .GridContainer { display: flex; flex-wrap: wrap; justify-content: space-around; align-item ...

Maintain the alignment of content in the center while expanding background images

I am looking to create a website with a split background effect, similar to the design on this site . I want to maintain a content container width of 980px while achieving this look. I attempted to accomplish this by adding height and background color pro ...

Using Basic Authentication Headers in React Applications and IIS Servers

Our React App is now hosted within an ASP.NET Core site on an IIS Server. Previously, the React App was hosted separately on IIS and protected by HTTP Basic Auth on our Staging server without any issues. However, after moving the React App inside the ASP. ...