无法使用React-native-pdf在Android应用中滚动PDF文件
我在应用程序中使用了React-native-PDF,基本上最高部分是PDF,而在底部可以有链接或文本。
它在iOS上工作正常,这意味着PDF滚动完美,但是在Android中,当底部有很多文本时,它不会滚动。
代码如下:
<Screen>
<ConfirmationDialog.DeleteNews
visible={this.state.showDeleteNewsDialog}
onConfirm={this.onDeleteNews}
onCancel={this.hideDeleteNewsDialog}
/>
<CollapsibleToolbar
title={this.headerTitle()}
bottomComponent={
<Header.NewsDetail
title={newsStore.newsDetail.name}
date={newsStore.newsDetail.available_at}
optionsMenu={this._renderOptionsMenu()}
/>
}
/>
<CollapsibleToolbar.ScrollView
style={stylesWithToolbarStore.scrollView}
hasBottomFloatButton={false}
>
{this._renderImageSwiper()}
{this.renderPdf()}
{this.renderFloatingButton()}
<View style={stylesWithToolbarStore.textContainer}>
<Hyperlink
onPress={this.handleUrl}
linkStyle={{
color: "#3366BB"
}}
>
<Text style={stylesWithToolbarStore.text}>{newsStore.newsDetail.content}</Text>
</Hyperlink>
</View>
{this._renderEditAndSpreadButtons()}
</CollapsibleToolbar.ScrollView>
</Screen>
renderPdf = () => {
const { newsStore, pdfViewStore } = this.state;
if (!newsStore.newsDetail.pdf) {
return null;
}
return (
<Pdf
style={{
width: screenDimensions.width,
height: screenDimensions.height * 0.47,
}}
url={getFullUrl(newsStore.newsDetail.pdf)}
onError={pdfViewStore.setVisible(false)}
onPressLink={(link) => {Linking.openURL(link);}}
/>
);
};```
render() {
const { url, onPressLink, ...rest } = this.props;
return (
<Pdf
fitWidth={true}
fitPolicy={0}
source={{
uri: url,
cache: true
}}
onLoadComplete={(numberOfPages, filePath)=>{
console.log(
`pdf number of pages: ${numberOfPages}`,
`pdf file path: ${filePath}`
);
}}
onPageChanged={(page, numberOfPages)=>{
console.log(
`pdf current page: ${page}`,
`pdf number of pages: ${numberOfPages}`
);
}}
onError={(error)=>{
console.log(`pdf error: ${error}`);
this.onError(error);
}}
onPressLink={onPressLink}
activityIndicator={<ActivityIndicator color={"white"} animating={true} />}
{...rest}
/>
);
}
}
I have used react-native-pdf in my app, basically the top portion is the pdf, while at the bottom part there can be links, or text.
it is working fine in on ios, which means the pdf scrolls perfectly but in android, it is not scrolling when there is a lot of text in the bottom section.
Code is as below:
<Screen>
<ConfirmationDialog.DeleteNews
visible={this.state.showDeleteNewsDialog}
onConfirm={this.onDeleteNews}
onCancel={this.hideDeleteNewsDialog}
/>
<CollapsibleToolbar
title={this.headerTitle()}
bottomComponent={
<Header.NewsDetail
title={newsStore.newsDetail.name}
date={newsStore.newsDetail.available_at}
optionsMenu={this._renderOptionsMenu()}
/>
}
/>
<CollapsibleToolbar.ScrollView
style={stylesWithToolbarStore.scrollView}
hasBottomFloatButton={false}
>
{this._renderImageSwiper()}
{this.renderPdf()}
{this.renderFloatingButton()}
<View style={stylesWithToolbarStore.textContainer}>
<Hyperlink
onPress={this.handleUrl}
linkStyle={{
color: "#3366BB"
}}
>
<Text style={stylesWithToolbarStore.text}>{newsStore.newsDetail.content}</Text>
</Hyperlink>
</View>
{this._renderEditAndSpreadButtons()}
</CollapsibleToolbar.ScrollView>
</Screen>
renderPdf = () => {
const { newsStore, pdfViewStore } = this.state;
if (!newsStore.newsDetail.pdf) {
return null;
}
return (
<Pdf
style={{
width: screenDimensions.width,
height: screenDimensions.height * 0.47,
}}
url={getFullUrl(newsStore.newsDetail.pdf)}
onError={pdfViewStore.setVisible(false)}
onPressLink={(link) => {Linking.openURL(link);}}
/>
);
};```
render() {
const { url, onPressLink, ...rest } = this.props;
return (
<Pdf
fitWidth={true}
fitPolicy={0}
source={{
uri: url,
cache: true
}}
onLoadComplete={(numberOfPages, filePath)=>{
console.log(
`pdf number of pages: ${numberOfPages}`,
`pdf file path: ${filePath}`
);
}}
onPageChanged={(page, numberOfPages)=>{
console.log(
`pdf current page: ${page}`,
`pdf number of pages: ${numberOfPages}`
);
}}
onError={(error)=>{
console.log(`pdf error: ${error}`);
this.onError(error);
}}
onPressLink={onPressLink}
activityIndicator={<ActivityIndicator color={"white"} animating={true} />}
{...rest}
/>
);
}
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
在PDF之前,请使用ScrollView进行滚动PDF文件。
Use ScrollView before Pdf for Scroll the PDF file.