React native 呈现未按预期工作的组件列表

React native 呈现未按预期工作的组件列表,react-native,jsx,React Native,Jsx,我正在绘制一个对象列表,并绘制一个其他对象的数组。在屏幕中,我切换高度以显示其内容。问题是,如果我单击按钮切换任何列表,则只有最后一个列表的高度发生了更改 screen.js const [days] = useState(['Domingo', 'Segunda', 'Terça', 'Quarta', 'Quinta', 'Sexta', 'Sábado']) [...] _renderSchedule = () => { if (_canRenderSchedule(

我正在绘制一个对象列表,并绘制一个其他对象的数组。在屏幕中,我切换高度以显示其内容。问题是,如果我单击按钮切换任何列表,则只有最后一个列表的高度发生了更改

screen.js

const [days] = useState(['Domingo', 'Segunda', 'Terça', 'Quarta', 'Quinta', 'Sexta', 'Sábado'])

[...]

  _renderSchedule = () => {
    if (_canRenderSchedule()) {
      return Object.keys(route.schedules.hour.weekdays).map((weekDay, index) => (
        <DayList days={days} route={route} weekDay={weekDay} key={`dayList-${weekDay}`} />
      )
      )
    }
  }
const DayList = (props) => {
  const { days, route, weekDay } = props

  const heightAnim = useRef(new Animated.Value(0)).current

  const weekdays = route.schedules.hour.weekdays

  const [isListOpen, setIsListOpen] = useState(true)

  const maxHeight = (height) => {
    setIsListOpen(true)

    Animated.timing(heightAnim, {
      toValue: height,
      duration: 300,
    }).start()
  }

  const minHeight = () => {
    setIsListOpen(false)
    Animated.timing(heightAnim, {
      toValue: 0,
      duration: 300,
    }).start()
  }

  _openHours = (day) => {
    if (isListOpen) {
      minHeight()
    } else {
      if (weekdays[weekDay]) {
        const height = weekdays[day].length * 42
        maxHeight(height)
      }
    }
  }

  _renderDay = (day) => {
    if (days[day]) {
      return (
        <Text style={styles.weekDayLabel}>{days[day]}</Text>
      )
    }
  }

  _renderHours = (day) => {
    console.log(day)

    if (weekdays[day]) {
      return weekdays[day].map((hour, index) => (
        <View style={styles.line} key={`day-${index}-${day}`}>
          <Text style={styles.lineText}>
            {hour.start} - {hour.end}
          </Text>
        </View>
      ))
    }
  }

  return (
    <View>
      <TouchableOpacity style={styles.dayButton} onPress={() => _openHours(weekDay)}>
        {_renderDay(weekDay)}
      </TouchableOpacity>

      <Animated.View style={{ height: heightAnim }}>
        <View style={styles.labels}>
          <Text style={styles.label}>Bairro - Centro</Text>
        </View>

        {_renderHours(weekDay)}
      </Animated.View>
    </View>
  )
}
const[days]=useState(['Domingo','Segunda','Terça','Quarta','Quinta','Sexta','Sábado'])
[...]
_渲染时间表=()=>{
如果(_canRenderSchedule()){
return Object.keys(route.schedules.hour.weekdays).map((weekDay,index)=>(
)
)
}
}
DayList.js

const [days] = useState(['Domingo', 'Segunda', 'Terça', 'Quarta', 'Quinta', 'Sexta', 'Sábado'])

[...]

  _renderSchedule = () => {
    if (_canRenderSchedule()) {
      return Object.keys(route.schedules.hour.weekdays).map((weekDay, index) => (
        <DayList days={days} route={route} weekDay={weekDay} key={`dayList-${weekDay}`} />
      )
      )
    }
  }
const DayList = (props) => {
  const { days, route, weekDay } = props

  const heightAnim = useRef(new Animated.Value(0)).current

  const weekdays = route.schedules.hour.weekdays

  const [isListOpen, setIsListOpen] = useState(true)

  const maxHeight = (height) => {
    setIsListOpen(true)

    Animated.timing(heightAnim, {
      toValue: height,
      duration: 300,
    }).start()
  }

  const minHeight = () => {
    setIsListOpen(false)
    Animated.timing(heightAnim, {
      toValue: 0,
      duration: 300,
    }).start()
  }

  _openHours = (day) => {
    if (isListOpen) {
      minHeight()
    } else {
      if (weekdays[weekDay]) {
        const height = weekdays[day].length * 42
        maxHeight(height)
      }
    }
  }

  _renderDay = (day) => {
    if (days[day]) {
      return (
        <Text style={styles.weekDayLabel}>{days[day]}</Text>
      )
    }
  }

  _renderHours = (day) => {
    console.log(day)

    if (weekdays[day]) {
      return weekdays[day].map((hour, index) => (
        <View style={styles.line} key={`day-${index}-${day}`}>
          <Text style={styles.lineText}>
            {hour.start} - {hour.end}
          </Text>
        </View>
      ))
    }
  }

  return (
    <View>
      <TouchableOpacity style={styles.dayButton} onPress={() => _openHours(weekDay)}>
        {_renderDay(weekDay)}
      </TouchableOpacity>

      <Animated.View style={{ height: heightAnim }}>
        <View style={styles.labels}>
          <Text style={styles.label}>Bairro - Centro</Text>
        </View>

        {_renderHours(weekDay)}
      </Animated.View>
    </View>
  )
}
const DayList=(道具)=>{
const{days,route,weekDay}=props
const heightAnim=useRef(新的动画.Value(0)).current
const weekdays=route.schedules.hour.weekdays
const[isListOpen,setIsListOpen]=useState(true)
常量最大高度=(高度)=>{
setIsListOpen(真)
动画。计时(heightAnim{
toValue:高度,
持续时间:300,
}).start()
}
常数最小高度=()=>{
setIsListOpen(错误)
动画。计时(heightAnim{
toValue:0,
持续时间:300,
}).start()
}
_开放时间=(天)=>{
如果(isListOpen){
最小高度()
}否则{
如果(工作日[工作日]){
常数高度=工作日[天]。长度*42
最大高度(高度)
}
}
}
_renderDay=(天)=>{
如果(天[天]){
返回(
{天[天]}
)
}
}
_renderHours=(天)=>{
控制台日志(天)
如果(工作日[日]){
返回工作日[day]。地图((小时,索引)=>(
{hour.start}-{hour.end}
))
}
}
返回(
_开放时间(工作日)}>
{{u renderDay(工作日)}

无论我点击“多明戈”、“塞贡达”还是“萨巴多”,它都会显示“萨巴多”列表。我不明白为什么

我在这个项目中使用React Native 0.60.5