Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/185.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
Android 我得到这个错误;更新属性时出错';src&x27;由:RCTImageView“管理的视图的;在这个密码之后?_Android_Reactjs_React Native - Fatal编程技术网

Android 我得到这个错误;更新属性时出错';src&x27;由:RCTImageView“管理的视图的;在这个密码之后?

Android 我得到这个错误;更新属性时出错';src&x27;由:RCTImageView“管理的视图的;在这个密码之后?,android,reactjs,react-native,Android,Reactjs,React Native,我正在使用react native构建一个旋转木马项目, 在数据中添加“image”“title”部分之前,当我只使用图像时,代码工作得非常好 我得到这个错误“更新由:RCTImageView管理的视图的属性'src'时出错”。在这段代码之后,我尝试了许多可能的方法,但仍然没有结果 import * as React from 'react'; import { StatusBar, FlatList, Image, Animated, Text, View, Dimensions, Style

我正在使用react native构建一个旋转木马项目, 在数据中添加“image”“title”部分之前,当我只使用图像时,代码工作得非常好 我得到这个错误“更新由:RCTImageView管理的视图的属性'src'时出错”。在这段代码之后,我尝试了许多可能的方法,但仍然没有结果

import * as React from 'react';
import { StatusBar, FlatList, Image, Animated, Text, View, Dimensions, StyleSheet, TouchableOpacity } from 'react-native';
const { width, height } = Dimensions.get('screen');

const data = [
   {imageUrl:'https://images.unsplash.com/photo-1509023464722-18d996393ca8?ixid=MXwxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHw%3D&ixlib=rb-1.2.1&auto=format&fit=crop&w=1050&q=80',
  title: "Hope"},
   {imageUrl:'https://images.unsplash.com/photo-1494587351196-bbf5f29cff42?ixid=MXwxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHw%3D&ixlib=rb-1.2.1&auto=format&fit=crop&w=1051&q=80',
  title: "Hope2"},
   {imageUrl:'https://images.unsplash.com/photo-1439792675105-701e6a4ab6f0?ixid=MXwxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHw%3D&ixlib=rb-1.2.1&auto=format&fit=crop&w=1052&q=80' ,
  title: "Hope3"} 
  
];
export default () => {
  const scrollX=React.useRef(new Animated.Value(0)).current;
    return (
        <View >
            <StatusBar hidden />
            <View
            style={StyleSheet.absoluteFillObject}>
               {data.map((image,index)=>{
                 const inputRange=[
                   (index -1)*width,
                   index*width,
                   (index+1)*width
                 ]
                 const opacity = scrollX.interpolate({
                   inputRange,
                   outputRange:[0,1,0]
                 })
                 return <Animated.Image
                 key={'image-${index}'}
                 source={{uri:image}}
                 style={[
                   StyleSheet.absoluteFillObject,
                   {opacity}
                 ]}
                 
                 />
               })}
            </View>
            <Animated.FlatList
            data={data}
            onScroll={Animated.event(
              [{nativeEvent:{contentOffset:{x:scrollX}}}],
              {useNativeDriver: true}
            )}
            
            keyExtractor={(_,index)=> index.toString()}
            renderItem={({item})=> {
                return <View >
                  <Text style={{color:'white'}}> {item.title} </Text>
                  <Image source={{uri:item.imageUrl}} 
                  />
                </View>
            }}
            />
        </View>
    );
};
import*as React from'React';
从“react native”导入{状态栏、平面列表、图像、动画、文本、视图、尺寸、样式表、TouchableOpacity};
const{width,height}=Dimensions.get('screen');
常数数据=[
{imageUrl:'https://images.unsplash.com/photo-1509023464722-18d996393ca8?ixid=MXwxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHw%3D&ixlib=rb-1.2.1&auto=格式&fit=裁剪&w=1050&q=80',
标题:“希望”},
{imageUrl:'https://images.unsplash.com/photo-1494587351196-bbf5f29cff42?ixid=MXwxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHw%3D&ixlib=rb-1.2.1&auto=格式&fit=裁剪&w=1051&q=80',
标题:“Hope2”},
{imageUrl:'https://images.unsplash.com/photo-1439792675105-701e6a4ab6f0?ixid=MXwxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHw%3D&ixlib=rb-1.2.1&auto=format&fit=crop&w=1052&q=80',
标题:“希望3”}
];
导出默认值()=>{
const scrollX=React.useRef(新的动画.Value(0)).current;
返回(
{data.map((图像,索引)=>{
常量输入范围=[
(索引-1)*宽度,
索引*宽度,
(索引+1)*宽度
]
常量不透明度=scrollX.interpolate({
输入范围,
输出范围:[0,1,0]
})
返回
})}
index.toString()}
renderItem={({item})=>{
返回
{item.title}
}}
/>
);
};

试试这个。将动画.Image中的源更新为Image.ImageUrl,而不仅仅是“Image”



这很有效,谢谢。我还有一个问题,如果我想使用来自资产的图像,我应该更改什么?如果你想使用本地/静态图像,那么使用这个,“require”参数应该包含从组件文件到图像资产的相对路径。我的意思是,如果我想在平面列表中使用本地图像列表,而不仅仅是一个,我应该怎么做。因为当我保留相同的代码,并且仅将url中的数据图像更改为require(./assets/…)时,我只会得到一个黑屏
   <Animated.Image
             key={'image-${index}'}
             source={{uri:image.imageUrl}}
             style={[
               StyleSheet.absoluteFillObject,
               {opacity}
             ]}
             
             />