A bug report
it's not a react native bug.
I just test to Android.
I don't use it to prod. I check in my phone with react-native run-android.
Environment:
React: 16.8.6
React native: 0.60.5
react-native-snap-carousel: 3.8.2
Target Platform:
Android (6.0)
I have 3 items. Each item is a button that opens the camera. Once we take the picture, it should show the picture instead of the button for each item.
When I take the photo, it updates the state but it does not display the photo.
<Carousel
ref={(c) => { this._carousel = c; }}
data={[
{key: 0, urlImage: this.state.urlImage1,},
{key: 1, urlImage: this.state.urlImage2,},
{key: 2, urlImage: this.state.urlImage3,},
]}
extraData={this.state}
renderItem={this._renderItem}
sliderWidth={screen.width}
sliderHeight={300}
itemWidth={300}
itemHeight={300}
containerCustomStyle={{
flexGrow: 0,
}}
/>
```
_renderItem ({item, index}) {
return (
style={{ backgroundColor: 'transparent', borderColor: 'white', borderWidth: 1 ,width: 300, height: 300, zIndex: 9999, elevation: 9999, position: "absolute", top: 0, left: 0, right: 0, bottom: 0, justifyContent: 'center', alignItems: 'center' }}
>
name="add-a-photo"
size={95}
color={"white"}
/>
:
}
style={{ width: 300, height: 300, backgroundColor: "#046381" }}
/>
);
}
takePhoto(e, item) {
ImagePicker.launchCamera(options, (response) => {
if (response.error) {
console.log('ImagePicker Error: ', response.error);
}
else {
const source = { uri: 'data:image/jpeg;base64,' + response.data };
this.setState({
[item]: source.uri,
refresh: !this.state.refresh
}, () => { console.log(this.state.refresh) });
}
})
}
```
I have an issue with updating the state in component.
In my case, I am changing the width of the sliderWidth and itemWidth when the layout of the container view changes.
In a first moment the carousel re-render it self, but it doesn麓t always apply.
Hi. I don't know if you've solved the problem, but I had the same problem today. If you do as in the example below, the high probability of the problem will be solved. I hope it helps.
state = {
refresh: false,
};
data={[
{key: 0, urlImage: this.state.urlImage1,},
{key: 1, urlImage: this.state.urlImage2,},
{key: 2, urlImage: this.state.urlImage3,},
]}
extraData={this.state.refresh}
renderItem={this._renderItem}
sliderWidth={screen.width}
sliderHeight={300}
itemWidth={300}
itemHeight={300}
containerCustomStyle={{
flexGrow: 0,
}}
/>
takePhoto(e, item) {
ImagePicker.launchCamera(options, (response) => {
if (response.error) {
console.log('ImagePicker Error: ', response.error);
}
else {
const source = { uri: 'data:image/jpeg;base64,' + response.data };
this.setState({
[item]: source.uri,
refresh: !this.state.refresh
}, () => { console.log(this.state.refresh) });
this.setState({ refresh: !refresh});
}
})
}
@kasim444 extraData props is available?
up!
currently having problems refreshing the component as well!
Any clue on how to force refresh?
Any news about this?
Also having this issue. I have the carousel sitting over a map screen and when users zoom out or changes the map view, the data set is then altered. This causes an issue with the scroll behavior of the carousel and prevents it from scrolling.