我有一个react native项目正在建设中.在主屏幕上,我想呈现一个名为PropertyTile的组件列表,其中包含一些文本,仅供测试使用.在我当前的代码中,它正在呈现PropertyFile的第一个实例,但之后不会呈现任何内容.这是非常奇怪的,我无法找到解决这个问题的办法,因为某种原因.为什么它只显示第一个PropertyTile而不呈现其他任何内容.

代码:

import React from 'react'
import { View, Text, StyleSheet } from 'react-native'
import PropertyTile from '../components/PropertyTile.js'

const HomeScreen = () => {
  return (
    <View style={styles.screenContainer}>
      <PropertyTile/>
      <Text>Home Screen: Shows currentl asdfasdf!</Text>
      <Text>Home Screen: Shows currentl fe!</Text>
      <PropertyTile />
    </View>
  )
}

const styles = StyleSheet.create({
  header: {
    fontSize: 22
  },
  screenContainer: {
    display: 'flex',
    flexDirection: 'column'
  }
})

export default HomeScreen

current screen rendering

PropertyTile 代码:

import React from 'react'
import { Dimensions } from 'react-native'
import { View, Text, StyleSheet, Image } from 'react-native'

export default function PropertyTile() {

  let deviceWidth = Dimensions.get('window').width - 16
  var aspectHeight = (deviceWidth / 1.78) + 1

  return (
    <View style={styles.container}>
      <View style={[styles.imageContainer,{height: aspectHeight}]}>
        <Image style={styles.mainImage} source={require('../../assets/luxury-home-1.jpeg')}/>
      </View>
      <View style={styles.contentContainer}>
        <View style={styles.priceContainer}>
          <Text style={styles.price}>$ 1,259,999</Text>
          <Text style={styles.status}>For Sale</Text>
        </View>
        <View style={styles.addressContainer}>
          <Text style={styles.address}>23 Lowlette Lane.</Text>
          <Text style={styles.address}>Mission Viejo, CA 92692</Text>
        </View>
        <View style={styles.separator}></View>
        <View style={styles.details}>
          <Text style={styles.summary}>6 Beds | 6 Baths | 10,000 Sqft. | 1.3 acre Lot</Text>
          <Text style={styles.homeType}>Single Family Residence</Text>
        </View>
        <View style={styles.separator}></View>
        <View style={styles.details}>
          <View style={styles.metricContainer}>
            <Text style={styles.metricName}>Net Operating Income (Monthly): </Text>
            <Text style={styles.metricValue}>$5,789</Text>
          </View>
          <View style={styles.metricContainer}>
            <Text style={styles.metricName}>Cash on Cash Return: </Text>
            <Text style={styles.metricValue}>2.45%</Text>
          </View>
          <View style={styles.metricContainer}>
            <Text style={styles.metricName}>Return on Initial Investment: </Text>
            <Text style={styles.metricValue}>9.97%</Text>
          </View>
        </View>
        <View style={styles.disclaimerContainer}>
          <Text style={styles.disclaimer}>*** 30 year fixed, 20% down, 3.14% interest rate | $3,443 rent ***</Text>
        </View>
      </View>
    </View>
  )
}

const styles = StyleSheet.create({
  container: {
    height: '100%',
    paddingTop: 8,
    paddingHorizontal: 8,
    borderRadius: 6,
    overflow: 'hidden'
  },
  imageContainer: {
    width: '100%',
    borderTopLeftRadius: 6,
    borderTopRightRadius: 6,
    overflow: 'hidden'
  },
  mainImage: {
    width: '100%',
    height: '100%'
  },
  contentContainer: {
    width: '100%',
    backgroundColor: '#D3D3D3',
    borderBottomLeftRadius: 6,
    borderBottomRightRadius: 6,
    overflow: 'hidden',
    paddingHorizontal: 8
  },
  priceContainer: {
    display: 'flex',
    flexDirection: 'row',
    alignItems: 'center',
    justifyContent: 'space-between',
    paddingTop: 8,
  },
  price: {
    fontWeight: 'bold',
    fontSize: 24
  },   
  addressContainer: {
    display: 'flex',
    marginTop: 8
  },
  address: {
    fontSize: 14
  },
  separator: {
    marginHorizontal: '3%',
    marginVertical: 8,
    height: 2,
    width: '94%',
    backgroundColor: 'grey'
  },  
  homeType: {
    marginTop: 4,
  },
  metricContainer: {
    display: 'flex',
    flexDirection: 'row',
    justifyContent: 'space-between',
    marginTop: 4
  },
  metricValue: {
    fontWeight: 'bold'
  },
  disclaimerContainer: {
    display: 'flex',
    flexDirection: 'row',
    marginVertical: 8,
    width: '100%',
    justifyContent: 'center',
  },  
  disclaimer: {
    fontSize: 12,
  }
})

推荐答案

我相信PropertyTile组件中的aspectHeight变量阻止了第二个实例的出现.aspectHeight应用的高度跨越屏幕的高度,将其他实例推到视图之外.

您可以try 将主屏幕包装在滚动视图中,以便可以看到屏幕窗口下方渲染的所有元素,如下所示:

import React from 'react'
import { View, Text, StyleSheet, ScrollView } from 'react-native'
import PropertyTile from '../components/PropertyTile.js'

const HomeScreen = () => {
  return (
    <ScrollView>
    <View style={styles.screenContainer}>
      <PropertyTile/>
      <Text>Home Screen: Shows currentl asdfasdf!</Text>
      <Text>Home Screen: Shows currentl fe!</Text>
      <PropertyTile />
    </View>
    </ScrollView>
  )
}

Javascript相关问答推荐

为什么JavaScript双边字符串文字插值不是二次的?

RxJS setTimeout操作符等效

如何使用Echart 5.5.0创建箱形图

使用TMS Web Core中的HTML模板中的参数调用过程

为什么从liveWire info js代码传递数组我出现错误?

有条件的悲剧

zoom svg以适应圆

useNavigation更改URL,但不呈现或显示组件

判断表格单元格中是否存在文本框

如何粗体匹配的字母时输入搜索框使用javascript?

当Redux提供程序访问Reduxstore 时,可以安全地从Redux提供程序外部调用钩子?

无法读取未定义错误的属性路径名''

在css中放置所需 colored颜色 以填充图像的透明区域

如何在JAVASCRIPT中合并两组对象并返回一些键

如何确保预订系统跨不同时区的日期时间处理一致?

在查看网页时,如何使HTML中的按钮工作方式类似于鼠标上的滚轮或箭头键?

如何通过Axios在GraphQL查询中发送数组

为什么在运行于<;img>;事件处理程序中的JavaScript中x和y是不可变的?

如何在移动设备中使用JAVASSCRIPT移除点击时的焦点/悬停状态

更改管线时不渲染组件的react