Struggling to achieve the desired vertical text alignment in a React Native layout

I am in need of assistance with a follow-up question related to my issue. I have a specific layout that I would like to use as a component, but I am struggling to make it more square-shaped using CSS in React Native. Can someone provide guidance on how to achieve this? My main focus is on centering the text on the left side. Any help is greatly appreciated.

type TeamsProps = {
    name: string,    
}

const TeamCard = (props: TeamsProps) => {
    const [showOptions, setShowOptions] = useState<Boolean>(false)

    const toggleOptions = () => {
        setShowOptions(!showOptions)
    }

    return (
        <View style={[styles.container, { height: (Dimensions.get("window").width - 3 * 15) / 2 }]}>
            <TouchableOpacity onLongPress={toggleOptions} style={styles.card}>
                <View style={styles.nameFlag}>
                    <Text style={styles.name}>{props.name}</Text>
                </View>
                <View style={styles.member}>                    
                </View>
            </TouchableOpacity>
            { showOptions ?
                <TouchableOpacity onPress={toggleOptions} style={styles.options}>
                    <TextInput style={styles.input} value="Team Name"></TextInput>
                    <View style={styles.buttons}>
                        <TouchableOpacity style={[styles.button, styles.delete]}>
                            <Delete style={{ fontSize: 20, color: "white", margin: "auto" }} />
                        </TouchableOpacity>
                        <TouchableOpacity style={[styles.button, styles.confirm]}>
                            <Check style={{ fontSize: 20, color: "white", margin: "auto" }} />
                        </TouchableOpacity>
                    </View>
                </TouchableOpacity>
                : <></>
            }
        </View>
    )
}

const styles = StyleSheet.create({
    container: {
        flexBasis: "calc(50% - 7.5px)"
    },
    card: {
        backgroundColor: constants.mainColor,
        borderRadius: 15,
        shadowOpacity: 0.6,
        shadowRadius: 10,
        flex: 1,
        flexDirection: "row",
        alignItems: "center"
    },
    nameFlag: {
        backgroundColor: constants.mainColorLight,
        height: "calc(100% - 30px)",
        width: "15%",
        marginVertical: 15,
        borderTopRightRadius: 30,
        borderBottomRightRadius: 30,
        justifyContent: "center"
    },
    ...
})

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

I have noticed a strange issue where the text shifts oddly when it becomes longer, as shown in the images linked below. Any insights on resolving this would be appreciated. @Hammad Hassan https://i.sstatic.net/7D0b6.png

Answer №1

Feel free to test this snippet and give me your feedback

 interface CardProperties= {
            title: string
            }
            
            const CardComponent = (properties: CardProperties) => {
                return (
                    <View style={styles.cardContainer}>
                        <View style={styles.cardTitle}>
                            <Text style={styles.titleText}>{properties.title}</Text>
                        </View>
                        <View style={styles.cardContent}>
            
                        </View>
                    </View>
                )
            }
            
            const designStyles = StyleSheet.create({
                cardContainer: {
                    backgroundColor: designConstants.primaryColor,
                    flex: 1,
                    flexDirection: "row"
                },
                cardTitle: {
                    backgroundColor: designConstants.secondaryColor,
                    height: "95%",
                    width: "15%",
                    marginVertical: "5%",
                    borderTopRightRadius: 50,
                    borderBottomRightRadius: 50,
                    justifyContent: "center"
                },
                titleText: {           
                    transform: [{ rotate: "-90deg" }, { translateY: -12 }],
                    fontFamily: designConstants.fontFamily,
                    fontSize: designConstants.headerFontSize,
        textAlign: 'center',
        marginRight: 'auto',
        marginLeft: 'auto',
marginTop: 'auto',
marginBottom: 'auto'
                },
                cardContent: {
                    backgroundColor: designConstants.secondaryColor,
                    height: "95%",
                    width: "75%",
                    margin: "5%",
                    borderRadius: 50
                }
            })
            
        export { CardComponent }

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

The functionality to move forward and backward in Modal Bootsrap seems to be malfunctioning

I am in need of assistance as I have encountered a major issue that has halted my work progress for several days. My goal is to implement a feature that allows users to navigate between different days both forwards and backwards. While the functionality it ...

"When you hover over an element, extra information will pop up that only pertains to that specific element and will not impact any surrounding

As I dive into the world of HTML and CSS, I've come across a hurdle when it comes to hovering over divs and displaying hidden elements. The goal is for the card to change color on hover (which I've achieved), expand in size, and reveal hidden con ...

Applying custom CSS designs to images using Thymeleaf

Currently working on a web application using Spring MVC and Thymeleaf for templating. I'm struggling to figure out how to apply rules to an image, especially when using an external CSS file. I have tested code that works: page.html <a class="nav ...

What is the best way to avoid adding duplicate HTML content to Bootstrap modal divs using jQuery?

In my project, I wanted to create a functionality where clicking on an image would trigger a modal box to pop up with additional content added once. However, I encountered two issues that I'm currently facing. Firstly, the header text that I intended ...

Fixing TypeError in React App: How to Resolve the "Cannot read property 'prototype' of undefined" Issue

I am completely new to JavaScript and I am struggling to understand the error that keeps popping up. After doing some research, it seems like the error could be due to a poorly written function or something along those lines. Here are the classes involved ...

The element type provided is not valid: it is expected to be a string (for built-in components) or a class/function (for composite components) but instead it is undefined. This error

I am encountering an error of Element type is invalid: expected a string (for built-in components) or a class/function (for composite components). It seems like I may have forgotten to export my component from the file it was defined in, or there could be ...

Broken CSS dropdown menu issue

Recently, I encountered an issue with a hoverable drop-down menu that has been functioning smoothly for years. After adding a new sub link, the code broke. Here is the code for the menu: #divMenu, ul, li, li li { margin: 0; padding: 0; } #divMenu { ...

What is the best way to pass the image source as a prop to a child component in React?

I have created a reusable component that includes a title, image, and onPress function. However, the image is not being rendered or displayed properly. Can someone please advise me on how to pass the image source dynamically? Is there a method to reference ...

Updating text color with Ajax response value

I need assistance with updating the text color of a sensor value displayed using html/ajax. Currently, the sensor value is being displayed successfully, but I want the text color to change based on the value. Here's an example: if value < 50 then f ...

Achieving Dynamic Alignment in CSS: How to Responsively Align a Div to the Width of its Parent Using Padding and Margins

My dilemma could not be clearer - I am struggling to properly align 4 divs within a width of 1150px (the maximum width of the content div). When resizing the screen, I want them to adjust accordingly: 4 in a row when possible, then 3 in the center, and so ...

What are the steps to incorporating the League Gothic font into my website design?

Is there a way to incorporate League Gothic font into my website design? Visit the League Gothic GitHub repository Appreciate any guidance on this matter, ...

Utilizing CSS classes and IDs for unordered lists

What's the correct way to write it when the ul is a class instead of an id? ul#Menu li a{} ul.Menu li a{} isn't functioning correctly ...

Can unresolved commitments lead to memory leaks in React applications?

Within our React application, we have implemented a debouncing mechanism for keyboard input before triggering a search action. Below is a simplified example of how this functionality works: function App() { const inputRef = useRef(); const [result, set ...

Difficulty in converting class-based JS useState array to TypeScript Hook

Recently, I've delved into the world of React / TypeScript and have taken on a personal project to enhance my skills. As part of this project, I am in the process of transitioning some class-based code into hooks. Here is the (JS) class-based code th ...

Sending data between components in Next.js layout.tsx

Trying to figure out how to pass properties between a page and a layout in Next.js has got me scratching my head. The situation I'm facing is as follows: I've got a standard Material UI stepper component (you can find it here: link) in my layou ...

React app experiencing crashes due to Material UI Select component issues

I am facing a challenge while trying to incorporate a material ui select component into the React application I am currently developing. Whenever I attempt to add a select functionality to a form, it results in a crash. Despite following the example provid ...

Material UI is failing to apply its styles

I tried customizing the default theme provided by Material UI, but unfortunately, the styles are not applying. Can anyone help me with this issue? In My Header.js file, I faced an issue where the customized style was not being applied as expected. const u ...

Is there a way to conceal a Select element so that it is not visible on the screen, yet can still activate the dropdown menu when another element is clicked

One idea for my website is to replace a select element with a button that triggers the dropdown. The plan is to place the select element inside a button DIV, position the select element on top of the button, and set its opacity to 0 so it appears hidden. W ...

How can I create a table in material-table that is both selectable and editable?

Can someone help me figure out how to handle multiple actions for each row in my project? I am using material-table with ReactJS and struggling to make it work properly. Any assistance would be greatly appreciated, thank you! https://i.sstatic.net/ijilW.p ...

What are the best practices for properly deploying a React Vite project in production mode?

Currently, I am utilizing Vite alongside React and my aim is to deploy the project in production mode on a server. Below is the content of my vite.config.js file: export default defineConfig({ esbuild: { loader: "jsx", }, optimizeDeps: ...