本机视图框架不允许后退

时间:2018-07-26 09:08:52

标签: c# react-native react-native-windows

环境

  • react-native -v:0.55.0
  • npm ls rnpm-plugin-windows:0.2.8
  • npm ls react-native-windows:0.55.0-rc.0
  • node -v:8.11.3
  • npm -v:5.6.0
  • yarn --version:1.7.0

  • 目标平台:UWP

  • 目标平台版本:10.0.14393.0
  • 目标设备:台式机
  • 开发操作系统:Windows 10 Desktop
  • Visual Studio版本:2017
  • 内部配置:调试(但在此问题上均相同)

复制步骤

  1. 安装新的本机应用程序
  2. 安装react-native-windows(如“入门”中一样)
  3. 然后,在VS中打开解决方案并在ReactNative / Views / Radaee / RadaeeManager.cs中创建一个新的本机模块
  4. 导入外部库RadaeePdf(这是一个在本机应用程序中编辑pdf的库,您可以在其网站上找到它)
  5. 将Radaee引用到您的应用

RadaeeManager.cs

    class RadaeeManager : SimpleViewManager<MainPage>
    {
        public MainPage _mainPage;
        public override string Name
        {
            get
            {
                return "RCTRadaeeView";
            }
        }

        public RadaeeManager()
        {
            _mainPage = new MainPage();
        }

        protected override MainPage CreateViewInstance(ThemedReactContext reactContext)
        {
            return _mainPage;
        }
    }

MainPage.xaml.cs

    public sealed partial class MainPage : Page
    {
        public MainPage()
        {
            this.InitializeComponent();
        }

        async private void BrowsFile(Object sender, RoutedEventArgs e)
        {
            FileOpenPicker filePicker;
            filePicker = new FileOpenPicker();
            filePicker.ViewMode = PickerViewMode.List;
            filePicker.SuggestedStartLocation = PickerLocationId.DocumentsLibrary;
            filePicker.FileTypeFilter.Add(".PDF");
            filePicker.FileTypeFilter.Add(".pdf");
            StorageFile file = await filePicker.PickSingleFileAsync();
            if (file != null)
            {
                IRandomAccessStream stream = await file.OpenAsync(FileAccessMode.ReadWrite);
                if (stream != null)
                {
                    Frame rootFrame = Window.Current.Content as Frame;
                    rootFrame.Navigate(typeof(PDFReaderPage), stream);
                }
            }
        }
    }

PDFReaderPage.xaml.cs

    public sealed partial class PDFReaderPage : Page, PDFView.PDFViewListener
    {
        IRandomAccessStream m_stream;

        public PDFReaderPage()
        {
            this.InitializeComponent();
            Windows.UI.Core.CoreWindow rcWindow = Window.Current.CoreWindow;
            Rect rcScreen = rcWindow.Bounds;
            mPDFView.Width = rcScreen.Width;
            mPDFView.Height = rcScreen.Height;
        }

        protected override void OnNavigatedTo(NavigationEventArgs e)
        {
            m_stream = (IRandomAccessStream)e.Parameter;
            m_doc = new PDFDoc();
            PDF_ERROR err = m_doc.Open(m_stream, "");
            switch (err)
            {
                case PDF_ERROR.err_ok:
                    m_view = new PDFViewVert(mPDFView);
                    m_view.vOpen(m_doc, 4, 0xFFCCCCCC, this);
                    initOptionPanels();
                    break;
                case PDF_ERROR.err_password:
                    break;
                default:
                    break;
            }
        }
     }

使用此代码,我无法返回到我的react应用程序。 但是,如果我不使用Frame.Navigate,我可以返回,但是与pdf的交互已中断。见下文 RadaeeManager.cs

    class RadaeeManager : SimpleViewManager<PDFReaderPage>
    {
        public PDFReaderPage _mainPage;
        public override string Name
        {
            get
            {
                return "RCTRadaeeView";
            }
        }

        public RadaeeManager()
        {
            _mainPage = new PDFReaderPage();
        }

        protected override PDFReaderPage CreateViewInstance(ThemedReactContext reactContext)
        {
            return _mainPage;
        }
    }

PDFReaderPage.xaml.cs

    public sealed partial class PDFReaderPage : Page, PDFView.PDFViewListener
    {
        IRandomAccessStream m_stream;

        public PDFReaderPage()
        {
            this.InitializeComponent();
            Windows.UI.Core.CoreWindow rcWindow = Window.Current.CoreWindow;
            Rect rcScreen = rcWindow.Bounds;
            mPDFView.Width = rcScreen.Width;
            mPDFView.Height = rcScreen.Height;
            openFile();
        }

        protected override void openFile(NavigationEventArgs e)
        {
            ApplicationData data = ApplicationData.Current;
            StorageFile file = await data.LocalCacheFolder.GetFileAsync("pdf.pdf");
            m_stream = await file.OpenAsync(FileAccessMode.ReadWrite); m_doc = new PDFDoc();
            m_stream = (IRandomAccessStream)e.Parameter;
            m_doc = new PDFDoc();
            PDF_ERROR err = m_doc.Open(m_stream, "");
            switch (err)
            {
                case PDF_ERROR.err_ok:
                    m_view = new PDFViewVert(mPDFView);
                    m_view.vOpen(m_doc, 4, 0xFFCCCCCC, this);
                    initOptionPanels();
                    break;
                case PDF_ERROR.err_password:
                    break;
                default:
                    break;
            }
        }
     }

这是我可以使Radaee发挥出色但无法返回到我的应用的方法。

预期行为

我需要打开本机视图来编辑pdf,然后需要返回到我的应用程序

实际行为

如果我使用Frame.Navigate打开radaee页面,则无法返回我的react应用。 但是,如果我打开radaee页面并返回简单信息,则无法正确使用该插件。

感谢您的帮助!

0 个答案:

没有答案