Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/430.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript (0,_reactioniveredash.onScroll)不是函数_Javascript_React Native_React Native Reanimated - Fatal编程技术网

Javascript (0,_reactioniveredash.onScroll)不是函数

Javascript (0,_reactioniveredash.onScroll)不是函数,javascript,react-native,react-native-reanimated,Javascript,React Native,React Native Reanimated,我曾尝试将其集成到我的代码库中(没有TSX),但在尝试onScroll={onScroll({y})}时。我得到以下错误(0,_reactationveredash.onScroll)不是函数 我不确定问题的原因是什么,因为我完全遵循了这个示例(只是将其更改为常规JS) 每当我用console.log(“y”,y)注释掉onScroll={onScroll({y})}并尝试将y值记录在ListBody组件中,我得到一个内存泄漏(已使用的内存不断攀升) 仍然不确定为什么会发生内存泄漏,或者我做错了

我曾尝试将其集成到我的代码库中(没有TSX),但在尝试
onScroll={onScroll({y})}
时。我得到以下错误
(0,_reactationveredash.onScroll)不是函数

我不确定问题的原因是什么,因为我完全遵循了这个示例(只是将其更改为常规JS)

每当我用
console.log(“y”,y)注释掉
onScroll={onScroll({y})}
并尝试将
y
值记录在
ListBody
组件中,我得到一个内存泄漏(已使用的内存不断攀升)

仍然不确定为什么会发生内存泄漏,或者我做错了什么导致了错误

问题:我得到以下错误
(0,\u reactationveredash.onScroll)不是一个函数(

我尝试过的:删除了scrollView的所有内部内容,通过不同的方式传递道具,如
y={y}
animV={y}
,在线找到解决方案

我所期望的:
y
值随滚动变化

 <Container>
      {/* <ListHeader {...{ y, album }} /> */}
      <ListBody {...{ y, album }} />
    </Container>

{/*  */}
这里是我创建列表和动画值的地方

import React from "react";
import styled from "styled-components";
import Animated from "react-native-reanimated";
import ListHeader from "./ListHeader";
import ListBody from "./ListBody";

const { Value } = Animated;

export default (TransitionList = ({ album }) => {
  const y = new Value(0);

  return (
    <Container>
      <ListHeader {...{ y, album }} />
      <ListBody {...{ y, album }} />
    </Container>
  );
});

const Container = styled.View`
  flex: 1;
  background-color: white;
`;
从“React”导入React;
从“样式化组件”导入样式化;
从“react native reanimated”导入动画;
从“/ListHeader”导入ListHeader;
从“/ListBody”导入ListBody;
常量{Value}=动画;
导出默认值(TransitionList=({album})=>{
常数y=新值(0);
返回(
);
});
const Container=styled.View`
弹性:1;
背景色:白色;
`;
标题

import React from "react";
import styled from "styled-components";
import Animated from "react-native-reanimated";
import { Image, StyleSheet } from "react-native";

import { MAX_HEADER_HEIGHT, HEADER_DELTA, BUTTON_HEIGHT } from "../../helpers";

const { interpolate, Extrapolate } = Animated;

export default (ListHeader = ({ album: { cover }, y }) => {
  const scale = interpolate(y, {
    inputRange: [-MAX_HEADER_HEIGHT, 0],
    outputRange: [4, 1],
    extrapolateRight: Extrapolate.CLAMP,
  });
  const opacity = interpolate(y, {
    inputRange: [-64, 0, HEADER_DELTA],
    outputRange: [0, 0.2, 1],
    extrapolate: Extrapolate.CLAMP,
  });

  return (
    <Animated.View style={[styles.container, { transform: [{ scale }] }]}>
      <Image style={styles.image} source={cover} />
      <Animated.View
        style={{
          ...StyleSheet.absoluteFillObject,
          backgroundColor: "black",
          opacity,
        }}
      />
    </Animated.View>
  );
});

const BodyText = styled.Text``;

const styles = StyleSheet.create({
  container: {
    ...StyleSheet.absoluteFillObject,
    height: MAX_HEADER_HEIGHT + BUTTON_HEIGHT * 2,
  },
  image: {
    ...StyleSheet.absoluteFillObject,
    width: undefined,
    height: undefined,
  },
});

从“React”导入React;
从“样式化组件”导入样式化;
从“react native reanimated”导入动画;
从“react native”导入{Image,StyleSheet};
从“./../helpers”导入{MAX_HEADER_HEIGHT,HEADER_DELTA,BUTTON_HEIGHT}”;
常量{插值,外推}=动画;
导出默认值(ListHeader=({album:{cover},y})=>{
常量比例=插值(y{
输入范围:[-最大割台高度,0],
输出范围:[4,1],
ExterpolateRight:Exterpolated.CLAMP,
});
常数不透明度=插值(y{
输入范围:[-64,0,标头_DELTA],
输出范围:[0,0.2,1],
外推法:外推法,
});
返回(
);
});
const BodyText=styled.Text`;
const styles=StyleSheet.create({
容器:{
…StyleSheet.absoluteFillObject,
高度:最大割台高度+按钮高度*2,
},
图片:{
…StyleSheet.absoluteFillObject,
宽度:未定义,
高度:未定义,
},
});
正文(这是onscroll错误发生的地方)

从“React”导入React;
从“样式化组件”导入样式化;
从“react native”导入{StyleSheet,View};
从“react native redash”导入{onScroll};
从“expo linear gradient”导入{LinearGradient};
从“react native reanimated”导入动画;
从“/ListTitle”导入ListTitle;
从“/ListItem”导入ListItem;
进口{
最大割台高度,
最小割台高度,
按钮高度,
}来自“../../helpers”;
常量{插值,外推}=动画;
导出默认值(ListBody=({album:{Artister,tracks},y})=>{
常数高度=插值(y{
输入范围:[-最大割台高度,-按钮高度/2],
输出范围:[0,最大页眉高度+按钮高度],
外推法:外推法,
});
常数不透明度=插值(y{
输入范围:[-最大割台高度/2,0,最大割台高度/2],
outputRange:[0,1,0],
外推法:外推法,
});
返回(
{艺术家}
{tracks.map((轨迹,关键点)=>
)}
);
});
const BodyText=styled.Text`;
const styles=StyleSheet.create({
容器:{
弹性:1,
paddingTop:最小收割台高度-按钮高度/2,
},
封面:{
高度:最大割台高度-按钮高度,
},
坡度:{
位置:“绝对”,
左:0,,
底部:0,
右:0,,
对齐项目:“中心”,
},
艺人容器:{
…StyleSheet.absoluteFillObject,
辩护内容:“中心”,
对齐项目:“中心”,
},
艺术家:{
textAlign:“居中”,
颜色:“白色”,
尺寸:48,
fontWeight:“粗体”,
},
标题:{
marginTop:-按钮高度,
},
轨道:{
paddingTop:32,
背景颜色:“黑色”,
},
});

找到了答案,这很明显,当我阅读较新的文档时,我发现
onScroll
已更改为
onScrollEvent
,问题已得到解决

找到了答案,这很明显,当我阅读较新的文档时,我发现
onScroll
已更改为
onScrollEvent
,问题已得到解决

以补充@Salman提供的内容。从
lib/module/v1
Import{onScrolleEvent,}从'react native redash/lib/module/v1'导入函数
添加到@Salman提供的内容中。从
lib/module/v1
Import{onScrolleEvent,}从'react native redash/lib/module/v1'导入函数
import React from "react";
import styled from "styled-components";
import { StyleSheet, View } from "react-native";
import { onScroll } from "react-native-redash";
import { LinearGradient } from "expo-linear-gradient";
import Animated from "react-native-reanimated";
import ListTitle from "./ListTitle";
import ListItem from "./ListItem";
import {
  MAX_HEADER_HEIGHT,
  MIN_HEADER_HEIGHT,
  BUTTON_HEIGHT,
} from "../../helpers";

const { interpolate, Extrapolate } = Animated;

export default (ListBody = ({ album: { artist, tracks }, y }) => {
  const height = interpolate(y, {
    inputRange: [-MAX_HEADER_HEIGHT, -BUTTON_HEIGHT / 2],
    outputRange: [0, MAX_HEADER_HEIGHT + BUTTON_HEIGHT],
    extrapolate: Extrapolate.CLAMP,
  });
  const opacity = interpolate(y, {
    inputRange: [-MAX_HEADER_HEIGHT / 2, 0, MAX_HEADER_HEIGHT / 2],
    outputRange: [0, 1, 0],
    extrapolate: Extrapolate.CLAMP,
  });
  return (
    <Animated.ScrollView
      onScroll={onScroll({ y })}
      style={styles.container}
      showsVerticalScrollIndicator={false}
      scrollEventThrottle={1}
      stickyHeaderIndices={[1]}
    >
      <View style={styles.cover}>
        <Animated.View style={[styles.gradient, { height }]}>
          <LinearGradient
            style={StyleSheet.absoluteFill}
            start={[0, 0.3]}
            end={[0, 1]}
            colors={["transparent", "rgba(0, 0, 0, 0.2)", "black"]}
          />
        </Animated.View>
        <View style={styles.artistContainer}>
          <Animated.Text style={[styles.artist, { opacity }]}>
            {artist}
          </Animated.Text>
        </View>
      </View>
      <View style={styles.header}>
        <ListTitle {...{ y, artist }} />
      </View>
      <View style={styles.tracks}>
        {tracks.map((track, key) =>
          <ListItem index={key + 1} {...{ track, key, artist }} />
        )}
      </View>
    </Animated.ScrollView>
  );
});

const BodyText = styled.Text``;

const styles = StyleSheet.create({
  container: {
    flex: 1,
    paddingTop: MIN_HEADER_HEIGHT - BUTTON_HEIGHT / 2,
  },
  cover: {
    height: MAX_HEADER_HEIGHT - BUTTON_HEIGHT,
  },
  gradient: {
    position: "absolute",
    left: 0,
    bottom: 0,
    right: 0,
    alignItems: "center",
  },
  artistContainer: {
    ...StyleSheet.absoluteFillObject,
    justifyContent: "center",
    alignItems: "center",
  },
  artist: {
    textAlign: "center",
    color: "white",
    fontSize: 48,
    fontWeight: "bold",
  },
  header: {
    marginTop: -BUTTON_HEIGHT,
  },
  tracks: {
    paddingTop: 32,
    backgroundColor: "black",
  },
});