Comments (11)
Have you apply style={{flex:1}}
to your ListView or it's parent view ? Refer to this
from react-native-viewpager.
Yes. I used flex:1 on it, as in the code above. Also used flex:1 in the listView style. No difference. Just as i move the indicator out of the listView, it works perfectly. But not in its renderHeader.
from react-native-viewpager.
I just try it on my project used in ListView header, it works well. Which version of RN do you use?
from react-native-viewpager.
React Native 0.31
Try adding more components to the header, before the indicatorviewpager. And my list view items load data from the server, so they are rendered after 3,4 sec.
from react-native-viewpager.
Hey i tried it with the basic facebook movies tutorial also. Same problem. Below is the example code.
The IndicatorViewPager outsisde the listVIew works perfect. The one inside doesnt.
import React, { Component } from 'react';
import {
AppRegistry,
Image,
ListView,
StyleSheet,
Text,
View,
Dimensions,
} from 'react-native';
import {IndicatorViewPager, PagerTitleIndicator, PagerDotIndicator} from 'rn-viewpager';
var MOCKED_MOVIES_DATA = [
{
title: 'Title',
year: '2015',
posters: {
thumbnail: 'http://i.imgur.com/UePbdph.jpg',
}
},
];
const {height, width} = Dimensions.get('window');
var REQUEST_URL = 'https://raw.githubusercontent.com/facebook/react-native/master/docs/MoviesExample.json';
class testApp extends Component {
constructor(props) {
super(props);
this.state = {
dataSource: new ListView.DataSource({
rowHasChanged: (row1, row2) => row1 !== row2,
}),
loaded: false,
};
}
componentDidMount() {
this.fetchData();
}
fetchData() {
fetch(REQUEST_URL)
.then((response) => response.json())
.then((responseData) => {
this.setState({
dataSource: this.state.dataSource.cloneWithRows(responseData.movies),
loaded: true,
});
})
.done();
}
starter()
{
return (
<View style = {{flex: 1}}>
<Image style = {{flex:1}} source = {{uri: 'http://i.imgur.com/UePbdph.jpg'}}/>
<View style = {{flex: 1}}>
<IndicatorViewPager
style={{height: height/2.78, backgroundColor: 'crimson'}}
>
<View>
<Image style = {{flex:1}} source = {{uri: 'http://i.imgur.com/UePbdph.jpg'}}/>
</View>
<View>
<Image style = {{flex:1}} source = {{uri: 'http://i.imgur.com/UePbdph.jpg'}}/>
</View>
<View>
<Image style = {{flex:1}} source = {{uri: 'http://i.imgur.com/UePbdph.jpg'}}/>
</View>
<View>
<Image style = {{flex:1}} source = {{uri: 'http://i.imgur.com/UePbdph.jpg'}}/>
</View>
</IndicatorViewPager>
</View>
</View>
);
}
render() {
if(!this.state.loaded) {
return this.renderLoadingView();
}
return (
<View style = {{flex:1}}>
<IndicatorViewPager
style={{height: height/2.78, backgroundColor: 'crimson'}}
>
<View>
<Image style = {{flex:1}} source = {{uri: 'http://i.imgur.com/UePbdph.jpg'}}/>
</View>
<View>
<Image style = {{flex:1}} source = {{uri: 'http://i.imgur.com/UePbdph.jpg'}}/>
</View>
<View>
<Image style = {{flex:1}} source = {{uri: 'http://i.imgur.com/UePbdph.jpg'}}/>
</View>
<View>
<Image style = {{flex:1}} source = {{uri: 'http://i.imgur.com/UePbdph.jpg'}}/>
</View>
</IndicatorViewPager>
<ListView
renderHeader = {this.starter}
dataSource={this.state.dataSource}
renderRow={this.renderMovie}
style={styles.listView}
/>
</View>
);
}
renderLoadingView() {
return (
<View style={styles.container} >
<Text>Loading Images...</Text>
</View>
);
}
renderMovie(movie) {
return (
<View style={styles.container}>
<Image
source={{uri: movie.posters.thumbnail}}
style={styles.thumbnail}
/>
<View style={styles.rightContainer}>
<Text style={styles.title}>{movie.title}</Text>
<Text style={styles.year}>{movie.year}</Text>
</View>
</View>
);
}
} // End of class 'MyFirstRNProject'
const styles = StyleSheet.create({
container: {
flex: 1,
flexDirection: 'row',
justifyContent: 'center',
alignItems: 'center',
backgroundColor: '#F5FCFF',
},
rightContainer: {
flex: 1,
},
thumbnail: {
marginLeft: 5,
width: 53,
height: 81,
},
title: {
fontSize: 28,
marginBottom: 8,
textAlign: 'center',
},
year: {
textAlign: 'center',
},
listView: {
paddingTop: 20,
backgroundColor: '#F5FCFF',
flex: 1,
},
});
AppRegistry.registerComponent('testApp', () => testApp);
from react-native-viewpager.
I change some your layout code, and it works. You can't use flex:1
everywhere.
The code is here:
/**
* Sample React Native App
* https://github.com/facebook/react-native
* @flow
*/
import React, {Component} from 'react';
import {
AppRegistry,
Image,
ListView,
StyleSheet,
Text,
View,
Dimensions,
} from 'react-native';
import {IndicatorViewPager, PagerTitleIndicator, PagerDotIndicator} from 'rn-viewpager';
var MOCKED_MOVIES_DATA = [
{
title: 'Title',
year: '2015',
posters: {
thumbnail: 'http://i.imgur.com/UePbdph.jpg',
}
},
];
const {height, width} = Dimensions.get('window');
var REQUEST_URL = 'https://raw.githubusercontent.com/facebook/react-native/master/docs/MoviesExample.json';
class TestViewPager extends Component {
constructor(props) {
super(props);
this.state = {
dataSource: new ListView.DataSource({
rowHasChanged: (row1, row2) => row1 !== row2,
}),
loaded: false,
};
}
componentDidMount() {
this.fetchData();
}
fetchData() {
fetch(REQUEST_URL)
.then((response) => response.json())
.then((responseData) => {
this.setState({
dataSource: this.state.dataSource.cloneWithRows(responseData.movies),
loaded: true,
});
})
.done();
}
starter() {
return (
<View >
<Image style={{height: 100}} source={{uri: 'http://i.imgur.com/UePbdph.jpg'}}/>
<IndicatorViewPager
style={{height: height / 2.78, width: width}}
indicator={<PagerDotIndicator pageCount={3}/>}
>
<View style={{backgroundColor: 'red'}}/>
<View style={{backgroundColor: 'green'}}/>
<View style={{backgroundColor: 'yellow'}}/>
</IndicatorViewPager>
</View>
);
}
render() {
if (!this.state.loaded) {
return this.renderLoadingView();
}
return (
<View style={{flex: 1}}>
<IndicatorViewPager
style={{height: height / 2.78}}
indicator={<PagerDotIndicator pageCount={3}/>}
>
<View style={{backgroundColor: 'red'}}/>
<View style={{backgroundColor: 'green'}}/>
<View style={{backgroundColor: 'yellow'}}/>
</IndicatorViewPager>
<ListView
renderHeader={this.starter}
dataSource={this.state.dataSource}
renderRow={this.renderMovie}
style={styles.listView}
/>
</View>
);
}
renderLoadingView() {
return (
<View style={styles.container}>
<Text>Loading Images...</Text>
</View>
);
}
renderMovie(movie) {
return (
<View style={styles.container}>
<Image
source={{uri: movie.posters.thumbnail}}
style={styles.thumbnail}
/>
<View style={styles.rightContainer}>
<Text style={styles.title}>{movie.title}</Text>
<Text style={styles.year}>{movie.year}</Text>
</View>
</View>
);
}
} // End of class 'MyFirstRNProject'
const styles = StyleSheet.create({
container: {
flex: 1,
flexDirection: 'row',
justifyContent: 'center',
alignItems: 'center',
backgroundColor: '#F5FCFF',
},
rightContainer: {
flex: 1,
},
thumbnail: {
marginLeft: 5,
width: 53,
height: 81,
},
title: {
fontSize: 28,
marginBottom: 8,
textAlign: 'center',
},
year: {
textAlign: 'center',
},
listView: {
paddingTop: 20,
backgroundColor: '#F5FCFF',
flex: 1,
},
});
AppRegistry.registerComponent('TestViewPager', () => TestViewPager);
from react-native-viewpager.
It still has problem#2.
Scroll down in the list until list's end and then scroll back up..
ViewPager scrolls like a normal scroll view, instead of snapping to borders.
from react-native-viewpager.
I release a Test Video just now, and it did not give a recurrence. Did you try my code in the test project?
from react-native-viewpager.
Oh you're using iOS. I'm having this issue on Android.
Yes, i tried the code. Still problem#2 on Android.
from react-native-viewpager.
On android platform, this lib is just a wrapper of ViewPagerAndroid. And I tried ViewPagerAndroid component , and still have the problem#2. So it's a problem of ViewPagerAndroid.
And then I search this problem on Google, and find this issue. And then I add this prop removeClippedSubviews={false}
to ListView , and it works!
So you just need to add removeClippedSubviews={false}
to your ListView.
from react-native-viewpager.
Hey yes! Its working! Thanks a lot!
Add this to documentation also 💃
"Use 'removeClippedSubviews={false}' when using inside a ListView. "
from react-native-viewpager.
Related Issues (20)
- initialPage is not working.
- Is there a way to use uri instead of source in iconSource?
- How to align the selected title to center?? HOT 1
- Please add keyboardShouldPersistTap prop HOT 1
- How to control how many component initially rendering
- remove title
- How to load the page only when user selects the tab ? HOT 3
- Is it impossible to use <TouchableOpacity> in child view of ViewPager?
- Getting Warning: ViewPagerAndroid has been extracted from react-native core HOT 4
- I need items to be visible outside of the Viewpager HOT 1
- setPage shows wrong page in iOS HOT 2
- PagerTabIndicator should cache icons
- Typings for IndicatorViewPager Props missing events
- On Landscape IOS scroll possition not set
- How can I customize PageTitleIndicator title.
- viewpager android has been removed from react native HOT 21
- OnPageSelected No overload matches this call.
- ViewPagerAndroid has been extracted from react-native core and will be removed in a future release HOT 1
- ViewPagerAndroid has been removed from react native HOT 1
- TypeError: Cannot read property 'style' of undefined
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from react-native-viewpager.