Setting button height dynamically in React Native

I've implemented a button using React Native Elements in my layout. Here's the code snippet:

<Button
                title="Login"
                buttonStyle={{ backgroundColor: Colour.green }}
                containerStyle={{
                    paddingLeft: '20%',
                    paddingRight: '20%',
                    alignSelf: 'center',
                    position: 'absolute',
                    bottom: '-5.2%',
                    elevation: Platform.OS === 'android' ? 5 : 0,
                }}
                titleStyle={{ fontSize: normalize(10) }}
                loading={loggingIn}
                onPress={login}
            />

The issue I'm facing is that the loading spinner appears larger than the button text, causing the button height to increase while the spinner is visible, resulting in an unsightly fluctuation in button size. I've tried setting the loading spinner size using:

loadingProps={{size:normalize(10)}}

However, this approach isn't consistent across different Android and iOS devices. Some devices maintain the button size, while others adjust it based on the spinner size.

Is there a way to ensure the button height remains constant on all devices after rendering, while also accurately accommodating the loading spinner size?

Answer №1

Consider using specific dimensions for buttonStyle such as width and height.

<Button
          title="Login"
          buttonStyle={{ width: 150, height: 50, backgroundColor: null }}
          containerStyle={{
            backgroundColor: 'green',
            alignItems: 'center',
            alignSelf: 'center',
            // position: 'absolute',
            elevation: Platform.OS === 'android' ? 5 : 0,
          }}
          loadingProps={{ color: 'red' }}
          loading={true}
          onPress={login}
        />

If you have any questions, don't hesitate to ask.

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

How to assign values to an object within an array in React?

In React, I am currently working on creating a swipeable card that consists of 4 slides. The data displayed within the card is entirely dependent on user input. To start off, I define a sample object like so: const initialState = { id: '', title ...

Creating a dynamic page footer for a PDF document using Rotativa's content generation capabilities

As I work on generating a PDF, my employer has requested that I add a footer to each page of the document. Currently, the PDF is being created using Rotativa, where an HTML page is converted into a PDF. However, I am facing a challenge in determining the ...

The Boostrap Datepicker fails to display

I'm having trouble integrating a Bootstrap Datepicker into my form. I got it working outside of the form, but when I try to include the code in my form, it doesn't seem to work. All necessary files are present and the code is identical. <!D ...

When the back button is clicked, pagination returns to number 1

I'm currently working on implementing Pagination in ReactJS and facing an issue where the pagination resets to page 1 when I navigate away from the current page and then come back. Ideally, I would like to resume from the same page where I left off. H ...

flexbox layout with a fixed sidebar that stays in place

Is there a way to make the sidebars in the holy grail layout sticky using flexbox? Specifically, I want the aside and nav sections of the HTML to stop scrolling down further once the last element is reached. I've tried various methods but with limited ...

How to Exclude ress.css in Vuetify.js

How can I prevent ress.css from conflicting with Bootstrap and my custom styles in Vuetify? I attempted to remove it from the Vuetify directory within node_modules, but that did not resolve the issue. ...

The reason for its failure was that the React runtime for native development does not incorporate the Node standard library

An error occurred in the package located at node_modules\crypto-js\core.js when it attempted to import the Node standard library module crypto. This failure is due to the fact that the React runtime does not include the Node standard library. For ...

Is it possible to combine CSS with Tailwind, Bootstrap, or other frameworks when building a React application?

Is it possible to combine CSS with Tailwind, Bootstrap, or other styling frameworks in a React application? ...

Styling Tip: Aligning text to the baseline of a height-adjusted input field using CSS

As per the information from the Mozilla documentation, it states that I can align the text in an input field to the baseline if the element's display property is set to inline-block. I have made adjustments to the height of several input elements, bu ...

The calendar component React-nice-calendar is not showing the year

I have incorporated the react-nice-calendar into my application, but I am facing an issue where the year is missing from the calendar display, as shown in the image. How can I rectify this problem? Here is the code snippet: const [date, setDate] = useSta ...

What separates npm run dev from npm run start when working with Next.js?

I'm curious about the distinction between running npm run dev and npm run start. Surprisingly, there isn't much information available online regarding this topic. Specifically, I'm interested in understanding this difference within React an ...

The Ant Design form.setFieldsValue method does not trigger a re-render when a Form.Item contains multiple elements

Struggling to update a Cascader field value using an "onClick" event within a Form.Item element in the Antd Form Component. It seems that the issue lies in the inability of Form.Item to update the field value when there are multiple elements inside the ta ...

Solid white border encasing the full page

While I know there have been similar questions asked before, I believe mine is unique because I haven't found a solution anywhere. Recently, I started a new project in React. I decided to remove App.css and index.css, and created a single component wh ...

What is the best method for managing an event loop during nested or recursive calculations?

When it comes to breaking a computation and releasing using setTimeout(), most examples seen involve having a shallow call stack. But what about scenarios where the computation is deeply nested or mutually-recursive, like in a tree search, with plenty of c ...

Autofill functions may not be compatible with input fields generated using JavaScript

Having trouble with browsers not using autocomplete in login overlays generated with JavaScript? It can be really annoying. Any suggestions on how to fix this issue? Should I create a hidden form within the original HTML and then move it into the overlay? ...

I am encountering a problem with IE11 where I am unable to enter any text into my

When using Firefox, I can input text in the fields without any issues in the following code. However, this is not the case when using IE11. <li class="gridster-form" aria-labeledby="Gridster Layout Form" alt="Tile Display Input column Input Row ...

Having trouble initiating the React Project launch

Could you please locate the error logs showing up in my terminal? <a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="f1978384988582dc879496948590939d9482b1c1dfc0dfc1">[email protected]</a> start C:\Users\MY ...

Encountering a problem with Alias in webpack while trying to render client-side React components

When using an Alias defined in webpack for client-side React rendering, I encountered an issue when attempting to render on a Node server using Express. In my webpack configuration, I have set up some aliases as shown below: resolve: { extensions: [& ...

using a ternary operator within the map function

Currently, I'm developing a web application that allows users to view a list of items and mark certain items as favorites. The favorites are stored in an array of IDs assigned to a prop (this.props.favorites). To ensure there are no duplicate entries, ...

When trying to set previous data in my React app upon cancel click, I encountered an issue

After successfully rendering dynamic fields from JSON data on the UI, I encountered a specific issue. Initially, all the fields are disabled. Upon clicking the edit button, I am able to make a particular row editable, which works fine. However, when I cli ...