Javascript 使用文本响应本机图像滑块框
我是react native的新手,我安装了Javascript 使用文本响应本机图像滑块框,javascript,reactjs,react-native,Javascript,Reactjs,React Native,我是react native的新手,我安装了react native image slider box,但我也希望当图像幻灯片标题与用户幻灯片图像一样改变时,该图像的标题也会改变。我更改了react native image slider box包的代码,但它不起作用。 下面是代码 _renderItem({ item, index }) { const { ImageComponent, ImageComponentStyle = {}, slid
react native image slider box
,但我也希望当图像幻灯片标题与用户幻灯片图像一样改变时,该图像的标题也会改变。我更改了react native image slider box包的代码,但它不起作用。
下面是代码
_renderItem({ item, index }) {
const {
ImageComponent,
ImageComponentStyle = {},
sliderBoxHeight,
disableOnPress,
resizeMethod,
resizeMode,
imageLoadingColor = "#E91E63"
} = this.props;
return (
<View
style={{
position: "relative",
justifyContent: "center"
}}
>
<Text style={[style.fontSize30Semi, {marginRight: moderateScale(100)}]}>
{this.props.title}
</Text> //that's the code I added in react-native-image-slider-box
<ImageComponent
style={[
{
width: '100%',
height: moderateScaleVertical(350),
marginVertical: moderateScaleVertical(10),
},
ImageComponentStyle
]}
source={typeof item === "string" ? { uri: item } : item}
resizeMethod={resizeMethod || "resize"}
resizeMode={resizeMode || "cover"}
onLoad={() => {}}
onLoadStart={() => {}}
onLoadEnd={() => {
let t = this.state.loading;
t[index] = true;
this.setState({ loading: t });
}}
{...this.props}
/>
{!this.state.loading[index] && (
<ActivityIndicator
size="large"
color={imageLoadingColor}
style={{
position: "absolute",
alignSelf: "center"
}}
/>
)}
</View>
);
}
\u renderItem({item,index}){
常数{
图像组件,
ImageComponentStyle={},
滑块箱高度,
禁用OnPress,
树脂法,
resizeMode,
imageLoadingColor=“#E91E63”
}=这是道具;
返回(
{this.props.title}
//这是我在react native image slider框中添加的代码
{}}
onLoadStart={()=>{}
onLoadEnd={()=>{
设t=this.state.loading;
t[指数]=真;
this.setState({loading:t});
}}
{……这个。道具}
/>
{!this.state.loading[index]&&(
)}
);
}
欢迎光临
state = {
images: [imagePath.welcome1, imagePath.welcome2, imagePath.welcome3],
desc: ['Hello', 'My'],
};
...
<SliderBox images={this.state.images} title={this.state.desc} />
状态={
图像:[imagePath.welcome1,imagePath.welcome2,imagePath.welcome3],
描述:[“你好”,“我的”],
};
...
这是我的代码,我试图为不同的图像呈现不同的标题。有谁能帮我告诉我怎么做吗?图书馆不支持任何文本,你可以做如下操作
state = {
images: [imagePath.welcome1, imagePath.welcome2, imagePath.welcome3],
desc: ['Hello', 'My'],
currentIndex:0
};
<Text>{this.state.desc[this.state.currentIndex]}</Text>
<SliderBox images={this.state.images} title={this.state.desc} currentImageEmitter={i=>this.setState({currentIndex:i})}/>
状态={
图像:[imagePath.welcome1,imagePath.welcome2,imagePath.welcome3],
描述:[“你好”,“我的”],
当前索引:0
};
{this.state.desc[this.state.currentIndex]}
this.setState({currentIndex:i})}/>
currentImageEmitter将发送当前图像的索引,您可以使用它更新状态并根据索引显示文本。库不支持任何文本,是否要将文本放置在图像滑块下方?仍不更新text@SaadAhmed不明白吗?currentImageEmitter此事件未更新CurrentIndex的状态您是否使用相同的代码?也许可以做一份点心,这样我就可以帮你检查问题了