Automatically adjust the height of a React Native view

I am working on a component that consists of three views - one at the top, another in the middle with a specific height, and the last one at the bottom. I want the top and bottom views to adjust their heights accordingly. Although this may seem straightforward for some, I'm still learning about flexbox...

Below is the code snippet:

export default function Cropper({ photo }) {
  const { colors } = useTheme();

  const [height, setHeight] = useState(WINDOW_HEIGHT / 2);

  return (
    <View style={styles.container}>
      <BlurView intensity={100} style={{ flex: 1 }} /> {/* auto height */}
      <View style={[styles.cropper, { height: height }]} />
      <BlurView intensity={100} style={{ flex: 1 }} /> {/* auto height */}
    </View>
  );
}

const styles = StyleSheet.create({
  container: {
    flex: 1,
    flexDirection: "column",
    alignItems: "flex-start",
    backgroundColor: "red",
  },
  cropper: {
    width: "100%",
  },
});

Answer №1

update

<View style={[styles.cropper,{height:height}]}/>

to

<View style={styles.sec}/>

modify

cropper:{width:'100%'}

to

cropper: {
    width: '100%',
    height: Dimensions.get('window').height/2,
}

also include

import { Dimensions } 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

Sequelize Authentication is unable to finalize

As I delve into the world of node.js and sequelize, I am encountering a persistent error: /home/cbaket/test/test.js:9 .complete(function(err) { ^ TypeError: undefined is not a function at Object.<anonymous> (/home/cbaket/test/test.js:9: ...

Error: Unable to convert value "undefined" to ObjectId (string) at reference " _id" for object "Product"

I'm encountering an error as a newcomer to node and react. CastError: Cast to ObjectId failed for value "undefined" (type string) at path "_id" for model "Product" at model.Query.exec (D:\Amazon Clone MERN\node_modules\mongoose\li ...

Set a restriction on the Bootstrap DatePicker to only show dates within a

My application features StartDate and EndDate datepickers, and I need to implement a 30-day limit on the selection range to prevent performance issues caused by loading too much data. I'm looking for a functionality where if the user picks today as t ...

Accessing JavaScript elements from PHP code

Is it possible to recognize JavaScript elements if they are nested within PHP tags? For example: <?php $username = "maniacal"; echo "<p class='welcome' id='greeting'>Hi, Welcome to the site!!</p>" ?> That's ...

How can I apply max-width and max-height to a background image?

It seems like a simple task. I am currently transitioning my layout to become more fluid by working on creating scalable images. While using the img tag and setting max-width to 100% is effective, I am considering using a div with the image set as its bac ...

Examining the contents of an array in JavaScript

I am currently conducting API testing. My objective is to verify the presence of a specific name within the API response. The data from the API response is structured in an array format. Despite my intention to check for the existence of the name "activ ...

Customizing upload directories in elfinder for dynamic path generation

In my CodeIgniter project, I am trying to configure elfinder to have a dynamic upload path for each unique ID. The folder structure I am working with is as follows: Below are my elfinder settings: $idce = $_GET['id_c']; $client_code = $this- ...

Tips for choosing at least three files in file upload control

How can I choose at least three files in a multiple file upload control? Should I integrate an AJAX FILE UPLOAD CONTROL TOOL KIT? I need to select a minimum of three files for the file upload control. If fewer than three files are selected, I want an ale ...

Could you provide guidance on implementing the delete HTTP request with Axios and try-catch in server.js within the MERN stack?

I'm struggling with my code for removing a resource using Axios in my MERN stack application. Here is the code I'm currently using: app.delete(`/delete/:id`, async (req, res) => { const { _id } = req.params; // use { id } instead of { _id } ...

traverse a deeply nested object within an array

Currently facing an issue with mapping over an array containing multiple nested objects. The map function seems to only return the outer object when executed. https://i.stack.imgur.com/7JNsN.png const [moreDetails, setMoreDetails] = useState([]); const [d ...

Twice the calls are being made by jQuery Ajax

I am using an <input> tag with the following attributes: <input type="button" id="btnSave2" value="Save" onclick="Event(1)" class="btn btn-primary col-lg-12" /> In addition, I have a script as ...

I am encountering issues with my THREE.js RawShaderMaterial

I haven't encountered any issues when loading shaders created by others into THREE.js, but I've hit a roadblock when trying to create and run my own shader. The shader works perfectly on the platform where I designed it (), but it doesn't fu ...

Positioning the Bootstrap4 Modal in React

I have a situation where a component opens a bootstrap modal using react-bootstrap4-modal. The opening and closing mechanism is as follows: {this.state.inEditMode ? <MemberModal /> : null} However, the issue arises because the component is nested ...

Cease the firing of ion-change until the values have been successfully loaded from storage

My settings page contains multiple ion-toggle's. There's an onChange method to update local storage when toggled. Standard procedure involves checking existing values in storage on page load and mapping them to the toggles using ngModel. <tab ...

Is it possible to center content with Bootstrap?

Is there a different method to center content with empty space on either side? For instance: <div class="col-md-3"></div> <div class="col-md-6"> <div class="form-group"> .... </div> </div> <div class="col ...

What causes the discrepancy in calculating marginTop on a desktop browser compared to a mobile browser?

In the top screenshot, you can see a representation of my Pixel 6XL connected to my laptop in USB debug mode. The checkered area represents the URL bar on the Chrome browser displayed on my Pixel device. Below that, the second screenshot shows the view fr ...

Is it truly possible to return a reactive variable that updates its value asynchronously?

While reviewing the code of a frontend project developed in Vue3, I came across a unique construction that I have not encountered before. This has led to some confusion as I try to grasp how it operates. The concept involves assigning the result of an asyn ...

Utilizing Javascript to Connect with Java Web API

I'm seeking assistance with transferring a file from a browser to another device connected to a server-operated machine. I am relatively new to web application and back-end programming. The current code allows for moving a file from the server to the ...

Overflow of text arranged horizontally within a span element situated inside a div container

I am currently working on developing a ticketing system that involves using nested div elements to organize content. Each ticket is represented by a main div containing various other nested divs and media such as images. While the functionality of the sys ...

Encountered an error while attempting to load next.config.js

Having cloned the repository, I proceeded to create and set up my .env.local file. After running npm i, I then executed npm run dev. The server initiated successfully, with the environment being loaded from .env.local. However, it abruptly failed, displayi ...