Dynamic Swiper Index Prop Fails on Android
See original GitHub issueCurrently trying to render an initial swiper page using the following code:
render() {
const deviceWidth = Dimensions.get('window').width
const deviceHeight = Dimensions.get('window').height
return (
<Swiper showsButtons loop = { false } index = { this.state.key }>
{ this.state.items.map((item) => {
return (
<View key = { item.id }>
<Image
style = {{ width: deviceWidth, height: deviceHeight }}
resizeMode = 'contain'
source = {{ uri: item.photo.image_url }}
/>
</View>
)
})}
</Swiper>
)
}
Where this.state.key
is the index of a photo when pressed on a grid (going from grid -> full screen, hence why I want this image to be rendered first).
The following code works as it should on iOS, but I’m not having any luck on Android. If someone wants to point me in the right direction, I can look into submitting a PR.
Issue Analytics
- State:
- Created 7 years ago
- Reactions:3
- Comments:10
Top Results From Across the Web
Dot does not work properly while rendering dynamic array ...
Steps to reproduce. set pagingEnabled true; use map to render screens inside a Swiper; try to swipe the screens and the active dot...
Read more >react-native-swiper add child dynamically - Stack Overflow
I want to add dynamically component in <Swiper> ? ... [index]) return ( <Swiper horizontal={true} loop={false} onIndexChanged={(i)=>{ if (i ...
Read more >Swiper Changelog
3.0.8 - Released on June 14th, 2015. Fixed issue with wrong active index and callbacks in Fade effect; New mousewheel parameters:.
Read more >react swiper active index | The AI Search Engine You Control
you have to set the initialSlide prop on the Swiper element to an index of the slide in the middle. so that the...
Read more >Custom View Components | Android Developers
If you fail to call this method from an overridden onMeasure() method, the result will be an exception at measurement time. At a...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
@pgonzalez-santiago try adding a
componentDidMount()
method to your component. I had myrender()
,componentDidMount()
andconstructor
set up like this:I believe the issue is that the
index
prop of theSwiper
isn’t being updated fast enough when it comes to the Android platform, and is defaulting to a value of zero.Note that I have a bit more going on here in my
render()
than you probably need - I was adding a custom footer component to the bottom of the swiper.Hope this helps.
I try to solve this problem…