无法使用React-native-pdf在Android应用中滚动PDF文件

发布于 2025-01-27 13:32:37 字数 3483 浏览 2 评论 0原文

我在应用程序中使用了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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

淡淡的优雅 2025-02-03 13:32:37

在PDF之前,请使用ScrollView进行滚动PDF文件。

render() {
    const { url, onPressLink, ...rest } = this.props;
    return (
    <ScrollView >
    <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} />}
           
    /></ScrollView>

 );
  }
}

Use ScrollView before Pdf for Scroll the PDF file.

render() {
    const { url, onPressLink, ...rest } = this.props;
    return (
    <ScrollView >
    <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} />}
           
    /></ScrollView>

 );
  }
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文