我正在尝试使cropWidth
的宽度与其父宽度相同,但是当我使用字符串时,出现此错误:unrecognized selector sent to instance
。这是代码:
<RkCard style={{width:'80%', marginLeft: 40, marginBottom: 50, backgroundColor:'#f5f5f5', position:'relative', shadowColor: 'black', shadowOffset: {width: 10, height: 10}, shadowOpacity: 1, shadowRadius: 2, elevation: 5}}>
<ImageZoom cropWidth={'100%'} <-- string here, error is thrown
cropHeight={300}
imageWidth={300}
imageHeight={300}
style={{left: 0, alignSelf:'center', justifyContent: 'center', alignItems: 'center', backgroundColor:'#D3D3D3',}}>
<FastImage rkCardImg source={{uri:`https://www.example.com/profiles/uploads/${item.images}`,
headers:{ Authorization: 'someAuthToken' },
priority: FastImage.priority.high,
}}
resizeMode={FastImage.resizeMode.contain}
style={{width: '100%', height: 300, left: 0, alignSelf:'center', justifyContent: 'center', alignItems: 'center'}}/>
</ImageZoom>
</RkCard>
如果我使用整数,则错误消失,因此它可能仅接受那些。有没有办法用字符串将宽度设置为与父级相同?
答案 0 :(得分:1)
您可以在return
之前自己计算。例如:
let width = Dimensions.get('window').width * .8;
,然后在您的RkCard
和cropWidth
中使用该值,例如:
<RkCard style={{width, marginLeft: 40, marginBottom: 50, backgroundColor:'#f5f5f5', position:'relative', shadowColor: 'black', shadowOffset: {width: 10, height: 10}, shadowOpacity: 1, shadowRadius: 2, elevation: 5}}>
<ImageZoom cropWidth={width}
顺便说一句,问题不是React Native风格的问题,而是ImageZoom
的编写方式。