Issue with React Native Flex Not Filling Width Equally

My Custom Component, a Simple Counter, Has a Small Style Error. Despite Trying Multiple Solutions, I Couldn't Figure Out the Problem. Can Someone Please Tell Me What's Wrong and How to Fix It?

Mistake

I Have Added 3 Touchable Opacity Components with Flex: 1. The Issue Arises When I Apply a Background Color to the Parent Container, Changing the Area That Should Fill. I Want All Objects' Backgrounds to Be Equal.

import React, { Component } from "react";
import { StyleSheet, View, Text, ViewPropTypes} from "react-native";
import { TouchableOpacity } from "react-native-gesture-handler";
import PropTypes from "prop-types";

class Counter extends Component{
    constructor(props){
        super(props);

        this.style = StyleSheet.create({
            topContainer:{
                flex:1,
                width:"100%",
                flexDirection:"column",
                alignItems:"center",
                justifyContent:"center"
            },
            topPanel:{
                flex:1,
                flexDirection:"row",
                alignItems:"center",
                justifyContent:"center",
                width:"100%",
            },
            bottomPane:{
                flex:1,
                flexDirection:"row",
                width:"100%",
                alignItems:"center",
                justifyContent:"center",
            },
            buttonStyle:{
                flex:1,
                alignItems:"center",
                justifyContent:"center",  
            },
    });
}

static propTypes  = {
    backgroundStyle : ViewPropTypes.style,
    textStyle: Text.propTypes.style,
    buttonBackground: ViewPropTypes.style,
    returnFunc: PropTypes.func,
};

/*
this.props = 
{"buttonBackground":{"backgroundColor":"#cc99ff","borderRadius":20,"margin":4},
"backgroundStyle":{"backgroundColor":"#cc99ff","borderRadius":20,"margin":4},
"textStyle":{"fontSize":25.919999999999995,"textAlign":"center","color":"#ffffff"}}
*/

render(){
    console.log("Counter:56 " , JSON.stringify(this.props));
    return(
        <View style={this.style.topContainer}>
            <View style={[this.style.topPanel,this.props.backgroundStyle]}>
                <Text style={this.props.textStyle}>2</Text>
            </View>

            <View style={this.style.bottomPane}>
                <TouchableOpacity style={[this.style.buttonStyle,this.props.buttonBackground]}> 
                    <Text style={this.props.textStyle}>Increment</Text> 
                </TouchableOpacity>

                <TouchableOpacity style={[this.style.buttonStyle,this.props.buttonBackground]}> 
                    <Text style={this.props.textStyle}>Decrement</Text> 
                </TouchableOpacity>

                <TouchableOpacity style={[this.style.buttonStyle,this.props.buttonBackground]}>
                    <Text style={this.props.textStyle}>Save</Text>
                </TouchableOpacity>
            </View>

        </View>
    );
}
}
export default Counter;

This Is the Full Code for My Counter Component, all Styled with Flex Properties. Need help understanding why it's behaving this way.

Thank you for any assistance provided.

Answer №1

It appears that the issue lies with TouchableOpacity in the react-native-gesture-handler library.

You can test using the TouchableOpacity component from the react-native library instead.

import { StyleSheet, View, Text, ViewPropTypes, TouchableOpacity } from "react-native";

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

Issue: appbridgeError: APP::ERROR::INVALID_CONFIG: shopOrigin is a required field and must be provided

While developing my Shopify App using Koa and Nextjs, I encountered the following error: appbridgeError: APP::ERROR::INVALID_CONFIG: shopOrigin must be provided The behavior of the app is a bit odd as it works fine when accessed for the first time. Howev ...

There are a few elements that seem to be absent from Material

I encountered an issue with Material UI where every component was working perfectly, but when I attempted to use ImageList and ImageListItem for the first time, I received the following error: ERROR in ./client/src/user-imageboard.js 3:0-52 Module not foun ...

Utilizing CSS background sizing with jQuery for stunning website aesthetics

In my HTML file, there is a main div container with two nested divs inside it. Each of these inner divs has been assigned separate ids for content placement. By implementing a functionality that changes the background image of the parent div upon clicking ...

Challenges regarding the CSS styling of the ui bootstrap modal and its compatibility with

Currently, I am in the process of developing a webpage utilizing angularjs and ui bootstrap to generate modals. However, as I attempt to print just the modal using javascript, I have encountered an issue with my CSS. It seems that due to potential formatti ...

Leverage the power of NextJS by enforcing dependencies with the outputStandalone option

Introducing the innovative outputStandalone experimental feature (https://nextjs.org/docs/advanced-features/output-file-tracing#automatically-copying-traced-files-experimental) allows for the creation of a separate folder after building that includes all n ...

Utilize Enzyme to control the state of a Redux-connected React component

import configureMockStore from 'redux-mock-store'; import NavBar from '../components/NavBar/NavBar'; const mockStore = configureMockStore(middlewares); const store = mockStore(initialState); wrapper = mount( <BrowserRouter> ...

"Render Failure" JavaScript and CSS files

I'm encountering a peculiar issue while attempting to load certain JS and CSS files. Within my ASP.NET MVC Web Project, I have an Index.html file where I've specified the loading of script files. It's worth noting that I have modified the U ...

Steps for achieving a seamless delay fade-in effect

Can anyone provide a solution to my issue? I'm a CSS beginner and need some help. My landing page has a background Youtube video with buttons that appear after 8 seconds. I want these buttons to smoothly fade in, but I can't figure out how to do ...

Issues with padding and margin on iOS devices

On my iPhone (iPhone 6, iOS 8), I noticed that the loader is positioned slightly above the button. However, when I use the Chrome mobile emulator, I can't see this issue. I'm puzzled about how to resolve it. What do you think could be causing thi ...

LightDM Webkit2 picture problem

Currently, I am immersed in my personal project, which involves creating a theme for lightdm webkit2. I have opted for the React framework as it is a tool that I am very comfortable using. Please find the repository link here: https://github.com/gitneeraj/ ...

How can I repeatedly trigger an eventListener in JavaScript?

I'm currently facing an issue with calling the event listener for all 4 progress bars on my page. The problem is that it's only working on the first progress bar. I cloned the div with the id of 'mycontainer' using a for loop, but the e ...

Tips for aligning pagination block at the center using react-bootstrap

Currently, I have implemented a custom pagination system for a small web application that I am developing using react-bootstrap. I have successfully integrated and set up the pagination functionality. As someone who is still new to react and bootstrap, wit ...

Tips for customizing the color of pagination in bootstrap

I'm currently in the process of designing a website and I've chosen to implement Bootstrap's pagination for navigating between pages. Due to time constraints, I was wondering if anyone knows how I can utilize classes like "bg-dark", "bg-prim ...

The function react.default.memo is not recognized at the createSvgIcon error

After updating my Material-UI version to 1.0.0, I encountered a peculiar error message stating that _react.default.memo is not a function at createSvgIcon Despite attempting to downgrade the react redux library to version 6.0.0 as suggested by some ...

Text in various styles is layered on top of an image, ensuring that text in one style does not overlap text in another style

Struggling with placing text over an image? Trying to achieve different text styles but ending up with overlapping lines? Here's a snippet of HTML that works with only one text style: <li style="" class="portfolio-content-CV"> <div class ...

What is the process for importing components from a Stencil library into a React application?

After successfully creating: a stencilJS component library named "my-lib" using the "npm init stencil" wizard and an Ionic React app using "ionic start myApp tabs" I am now trying to incorporate the default "my-component," aka MyComponent from my-lib. H ...

Quick inquiry about referencing state variables in the render method in React Native

Initially, I assumed it was just a simple syntax error, but now I'm beginning to think that it might be related to a bigger concept concerning hierarchy and inheritance. I am currently working on an app in react native (expo) where I aim to display a ...

React: Issue accessing URL parameters using useParams() within a nested component

In my demo application, there are two components - QuoteDetail and Comments. Both require URL parameters, but I am only able to access them in the parent component. App.tsx: <Switch> // ... <Route path="/quotes" exact> <Al ...

Unable to execute the React application on another device

After transferring my React project folder to a new system, I encountered an issue when trying to run the app. The error message displayed: [email protected] start react-scripts start run The error 'react-scripts' is not recognized as an ...

Horizontal rule spans the full width of the content, appearing within an ordered list

Check out this example to see the issue with the horizontal rule not extending all the way across under the number. I've tried using list-style-position:inside;, but that interferes with positioning the number correctly due to the left image being flo ...