我在我的应用程序中使用了react-native-pdf,我们希望在应用程序中滚动该pdf,但是它在ios上运行良好,但是在android中,它无法完全滚动到最多4页。 pdf中有20页。我在我的应用中使用了以下代码:-
render () {
const source = require('./../../../assets/assets/pdfs/pdfname.pdf');
return (
<View style={styles.container}>
<Pdf
source={source}
onLoadComplete={(numberOfPages,filePath)=>{
console.log(`number of pages: ${numberOfPages}`);
}}
onPageChanged={(page,numberOfPages)=>{
console.log(`current page: ${page}`);
}}
onError={(error)=>{
console.log(error);
}}
style={styles.pdf}/>
</View>
)
}
}
const styles = StyleSheet.create({
container: {
flex: 1,
justifyContent: 'flex-start',
alignItems: 'center',
marginTop: 5,
},
pdf: {
flex:1,
width:Dimensions.get('window').width - 20,
}
});
render () {
const source = require('./../../../assets/assets/pdfs/ebook_1.pdf');
return (
<View style={styles.container}>
<Pdf
source={source}
onLoadComplete={(numberOfPages,filePath)=>{
console.log(`number of pages: ${numberOfPages}`);
}}
onPageChanged={(page,numberOfPages)=>{
console.log(`current page: ${page}`);
}}
onError={(error)=>{
console.log(error);
}}
style={styles.pdf}/>
</View>
)
}
}
const styles = StyleSheet.create({
container: {
flex: 1,
justifyContent: 'flex-start',
alignItems: 'center',
marginTop: 5,
},
pdf: {
flex:1,
width:Dimensions.get('window').width - 20,
}
});
我希望我的pdf完全在应用程序中滚动。
答案 0 :(得分:0)
尝试在ScrollView中包装,对我有用。
<View style={styles.container}>
<ScrollView contentContainerStyle={{ flex: 1 }}>
<Pdf
source={source}
onLoadComplete={()=>{
console.log(`number of pages: ${numberOfPages}`);
}}
onPageChanged={()=>{
console.log(`current page: ${page}`);
}}
onError={(error)=>{
console.log(error);
}}
style={styles.pdf}/>
</ScrollView>
</View>
const styles = StyleSheet.create({
container: {
flex: 1,
justifyContent: 'flex-start',
alignItems: 'center',
marginTop: 5
},
pdf: {
flex:1,
width:Dimensions.get('window').width - 20
}
});
答案 1 :(得分:0)
尝试为PDF添加一些高度,然后将其与滚动一起使用
我的pdf样式
pdfStyles: {
height: screenHeight - 200,
width: screenWidth
},
这是我的pdf
<Pdf style={Styles.pdfStyles}
source={{
uri: '/storage/emulated/0/Download/sample.pdf',
cache: true
}}
onLoadComplete={(numberOfPages, filePath) => {
console.log(`number of pages: ${numberOfPages}`);
}}
onPageChanged={(page, numberOfPages) => {
console.log(`current page: ${page}`);
}}
onError={(error) => {
console.log(error);
}}
onPressLink={(uri) => {
console.log(`Link presse: ${uri}`)
}}
/>