From 05b38da186d1bed23e1b238cefe17f774dac4835 Mon Sep 17 00:00:00 2001 From: PSPDFKit Date: Wed, 28 Feb 2024 00:47:33 +0300 Subject: [PATCH] Release 3.8.2 --- CHANGELOG.md | 10 ++++-- .../pspdfkit/FlutterInstantPdfActivity.kt | 1 - .../flutter/pspdfkit/FlutterPdfActivity.java | 1 - example/ios/Runner.xcodeproj/project.pbxproj | 2 +- .../xcshareddata/xcschemes/Runner.xcscheme | 2 +- example/pubspec.yaml | 2 +- ios/pspdfkit_flutter.podspec | 8 ++--- lib/src/web/pspdfkit_web.dart | 13 ++++--- .../pspdfkit_web_configuration_helper.dart | 16 ++++++--- .../widgets/pspdfkit_widget_controller.dart | 2 -- .../pspdfkit_widget_controller_native.dart | 1 - .../pspdfkit_widget_controller_web.dart | 2 +- lib/src/widgets/pspdfkit_widget_web.dart | 34 +++++++++++-------- pubspec.yaml | 2 +- 14 files changed, 56 insertions(+), 40 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 541a67f8..7bd09ebe 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,10 +1,16 @@ ## Newest Release -### 3.8.1 - 14 Feb 2024 -- Fixes callbacks when Pspdfkit.present() is used. (J#HYB-204) +### 3.8.2 - 27 Feb 2024 + +- Updates for PSPDFKit 13.3.1 for iOS. (#43550) +- Fixes issue where PSPDFKit for Flutter does not work on web with Flutter SDK version 13.19.0 (J#HYB-216) +- Fixes issue where annotation toolbar items are not being displayed on Web. (J#HYB-217) ## Previous Releases +### 3.8.1 - 14 Feb 2024 +- Fixes callbacks when Pspdfkit.present() is used. (J#HYB-204) + ### 3.8.0 - 06 Feb 2024 - Adds Flutter for Web support. (#42151) - Replaces configuration `Map` with a dedicated `PdfConfiguration` class. (#42191) diff --git a/android/src/main/java/com/pspdfkit/flutter/pspdfkit/FlutterInstantPdfActivity.kt b/android/src/main/java/com/pspdfkit/flutter/pspdfkit/FlutterInstantPdfActivity.kt index d91f9493..efba9559 100644 --- a/android/src/main/java/com/pspdfkit/flutter/pspdfkit/FlutterInstantPdfActivity.kt +++ b/android/src/main/java/com/pspdfkit/flutter/pspdfkit/FlutterInstantPdfActivity.kt @@ -39,7 +39,6 @@ class FlutterInstantPdfActivity : InstantPdfActivity() { override fun onDocumentLoaded(pdfDocument: PdfDocument) { super.onDocumentLoaded(pdfDocument) - EventDispatcher.getInstance().notifyDocumentLoaded(pdfDocument) val result = loadedDocumentResult.getAndSet(null) result?.success(true) } diff --git a/android/src/main/java/com/pspdfkit/flutter/pspdfkit/FlutterPdfActivity.java b/android/src/main/java/com/pspdfkit/flutter/pspdfkit/FlutterPdfActivity.java index 59400a1f..7f30b950 100644 --- a/android/src/main/java/com/pspdfkit/flutter/pspdfkit/FlutterPdfActivity.java +++ b/android/src/main/java/com/pspdfkit/flutter/pspdfkit/FlutterPdfActivity.java @@ -60,7 +60,6 @@ protected void onDestroy() { @Override public void onDocumentLoaded(@NonNull PdfDocument pdfDocument) { super.onDocumentLoaded(pdfDocument); - EventDispatcher.getInstance().notifyDocumentLoaded(pdfDocument); Result result = loadedDocumentResult.getAndSet(null); if (result != null) { result.success(true); diff --git a/example/ios/Runner.xcodeproj/project.pbxproj b/example/ios/Runner.xcodeproj/project.pbxproj index 057e9bb9..7c643c89 100644 --- a/example/ios/Runner.xcodeproj/project.pbxproj +++ b/example/ios/Runner.xcodeproj/project.pbxproj @@ -165,7 +165,7 @@ 97C146E61CF9000F007C117D /* Project object */ = { isa = PBXProject; attributes = { - LastUpgradeCheck = 1430; + LastUpgradeCheck = 1510; ORGANIZATIONNAME = "The Chromium Authors"; TargetAttributes = { 97C146ED1CF9000F007C117D = { diff --git a/example/ios/Runner.xcodeproj/xcshareddata/xcschemes/Runner.xcscheme b/example/ios/Runner.xcodeproj/xcshareddata/xcschemes/Runner.xcscheme index 9c585c83..cdef6845 100644 --- a/example/ios/Runner.xcodeproj/xcshareddata/xcschemes/Runner.xcscheme +++ b/example/ios/Runner.xcodeproj/xcshareddata/xcschemes/Runner.xcscheme @@ -1,6 +1,6 @@ =2.17.0 <4.0.0' diff --git a/ios/pspdfkit_flutter.podspec b/ios/pspdfkit_flutter.podspec index ba26fe4c..41eed989 100644 --- a/ios/pspdfkit_flutter.podspec +++ b/ios/pspdfkit_flutter.podspec @@ -5,7 +5,7 @@ # Pod::Spec.new do |s| s.name = "pspdfkit_flutter" - s.version = "3.8.1" + s.version = "3.8.2" s.homepage = "https://PSPDFKit.com" s.documentation_url = "https://pspdfkit.com/guides/flutter" s.license = { type: "Commercial", file: "../LICENSE" } @@ -18,10 +18,10 @@ Pod::Spec.new do |s| s.source_files = "Classes/**/*.{h,m,swift}" s.public_header_files = "Classes/**/*.h" s.dependency("Flutter") - s.dependency("PSPDFKit", "13.3.0") - s.dependency("Instant", "13.3.0") + s.dependency("PSPDFKit", "13.3.1") + s.dependency("Instant", "13.3.1") s.swift_version = "5.0" s.platform = :ios, "15.0" - s.version = "3.8.1" + s.version = "3.8.2" s.pod_target_xcconfig = { "DEFINES_MODULE" => "YES", "SWIFT_INSTALL_OBJC_HEADER" => "NO" } end diff --git a/lib/src/web/pspdfkit_web.dart b/lib/src/web/pspdfkit_web.dart index 8f14ecda..ab358a1b 100644 --- a/lib/src/web/pspdfkit_web.dart +++ b/lib/src/web/pspdfkit_web.dart @@ -7,14 +7,16 @@ /// This notice may not be removed from this file. /// +import 'dart:html'; import 'dart:js'; import 'package:pspdfkit_flutter/src/web/models/pspdfkit_web_toolbar_item.dart'; import 'package:pspdfkit_flutter/src/web/pspdfkit_web_instance.dart'; import 'package:pspdfkit_flutter/src/web/pspdfkit_web_configuration_helper.dart'; - import '../pdf_configuration.dart'; import 'pspdfkit_web_utils.dart'; +const flutterWebProductId = 'FlutterForWeb'; + /// Provides access to PSPDFKit for web. /// /// This class represents the [PSPDFKit](https://pspdfkit.com/api/web/PSPDFKit.html) object in the PSPDFKit Web SDK. @@ -33,6 +35,7 @@ class PSPDFKitWeb { // Try to set the license key to confirm it is valid, then store it in local storage. var config = JsObject.jsify({ 'licenseKey': licenseKey, + 'productId': flutterWebProductId, }); await promiseToFuture(_pspdfkit.callMethod('preloadWorker', [config])) @@ -48,7 +51,7 @@ class PSPDFKitWeb { /// /// The [documentPath] parameter specifies the path to the document that will be loaded. /// - /// The [id] parameter is used to identify the container element in which the PSPDFKit instance will be rendered. + /// The [element] parameter is used to identify the container element in which the PSPDFKit instance will be rendered. /// /// The [configuration] parameter is an optional configuration object that can be used to customize the behavior of PSPDFKit. /// @@ -68,10 +71,10 @@ class PSPDFKitWeb { /// /// // Use the instance to interact with the document. /// ``` - static Future load( - String documentPath, int id, PdfConfiguration? configuration) async { + static Future load(String documentPath, Element element, + PdfConfiguration? configuration) async { var webConfiguration = WebConfigurationHelper.populateWebConfiguration( - id, + element, documentPath, _pspdfkitLicenseKey, configuration, diff --git a/lib/src/web/pspdfkit_web_configuration_helper.dart b/lib/src/web/pspdfkit_web_configuration_helper.dart index 9fbfbe05..7be7e4f4 100644 --- a/lib/src/web/pspdfkit_web_configuration_helper.dart +++ b/lib/src/web/pspdfkit_web_configuration_helper.dart @@ -7,10 +7,11 @@ /// This notice may not be removed from this file. /// +import 'dart:html'; import 'dart:js'; -import 'package:pspdfkit_flutter/src/web/pspdfkit_web_utils.dart'; - import '../../pspdfkit.dart'; +import 'pspdfkit_web.dart'; +import 'pspdfkit_web_utils.dart'; /// This is a utility class used to convert a [PdfConfiguration] to a [PSPDFKit.Configuration](https://pspdfkit.com/api/web/PSPDFKit.Configuration.html) JsObject for Web. /// It is used in [PSPDFKitWeb.load]. This class isolates the js interop code from the rest of the plugin. @@ -28,7 +29,7 @@ class WebConfigurationHelper { /// /// Returns a [PSPDFKit.Configuration](https://pspdfkit.com/api/web/PSPDFKit.Configuration.html) JsObject. static JsObject populateWebConfiguration( - int id, + Element element, String documentPath, String? licenseKey, PdfConfiguration? configuration, @@ -94,7 +95,11 @@ class WebConfigurationHelper { // Return a list of new annotation toolbar items. return JsObject.jsify( - newAnnotationToolbarItems?.map((e) => e.toJsObject()).toList() ?? []); + newAnnotationToolbarItems?.map((e) => e.toJsObject()).toList() ?? + [ + ...callbackOptions.defaultAnnotationToolbarItems + .map((e) => e.toJsObject()) + ]); } // Remove the annotation toolbar items from the configuration. @@ -104,7 +109,8 @@ class WebConfigurationHelper { var map = { 'document': documentPath, 'licenseKey': licenseKey, - 'container': '#pspdfkit-$id', + 'productId': flutterWebProductId, + 'container': element, 'initialViewState': initialViewState, 'password': configuration?.password, 'editableAnnotationTypes': configuration?.editableAnnotationTypes, diff --git a/lib/src/widgets/pspdfkit_widget_controller.dart b/lib/src/widgets/pspdfkit_widget_controller.dart index aeb0509f..e49430c9 100644 --- a/lib/src/widgets/pspdfkit_widget_controller.dart +++ b/lib/src/widgets/pspdfkit_widget_controller.dart @@ -10,8 +10,6 @@ import '../../pspdfkit.dart'; /// A controller for a PSPDFKit widget. abstract class PspdfkitWidgetController { - PspdfkitWidgetController(int id); - /// Sets the value of a form field by specifying its fully qualified field name. Future setFormFieldValue(String value, String fullyQualifiedName); diff --git a/lib/src/widgets/pspdfkit_widget_controller_native.dart b/lib/src/widgets/pspdfkit_widget_controller_native.dart index 2bc8c520..3c0d79c1 100644 --- a/lib/src/widgets/pspdfkit_widget_controller_native.dart +++ b/lib/src/widgets/pspdfkit_widget_controller_native.dart @@ -9,7 +9,6 @@ import 'package:flutter/services.dart'; import '../../pspdfkit.dart'; -import 'pspdfkit_widget_controller.dart'; /// A controller for a PSPDFKit widget for native platforms that use the [MethodChannel]. class PspdfkitWidgetControllerNative implements PspdfkitWidgetController { diff --git a/lib/src/widgets/pspdfkit_widget_controller_web.dart b/lib/src/widgets/pspdfkit_widget_controller_web.dart index 032a7ca3..8578420a 100644 --- a/lib/src/widgets/pspdfkit_widget_controller_web.dart +++ b/lib/src/widgets/pspdfkit_widget_controller_web.dart @@ -16,7 +16,7 @@ import 'pspdfkit_widget_controller.dart'; class PspdfkitWidgetControllerWeb implements PspdfkitWidgetController { final PspdfkitWebInstance pspdfkitInstance; - PspdfkitWidgetControllerWeb(int id, this.pspdfkitInstance); + PspdfkitWidgetControllerWeb(this.pspdfkitInstance); @override Future getAnnotations(int pageIndex, String type) async { diff --git a/lib/src/widgets/pspdfkit_widget_web.dart b/lib/src/widgets/pspdfkit_widget_web.dart index fca7da67..865e9d70 100644 --- a/lib/src/widgets/pspdfkit_widget_web.dart +++ b/lib/src/widgets/pspdfkit_widget_web.dart @@ -9,15 +9,13 @@ library pspdfkit_widget_web; import 'dart:async'; -import 'dart:html'; +import 'dart:html' as html; import 'dart:ui_web' as ui; -import 'package:flutter/cupertino.dart'; -import 'package:flutter/material.dart'; +import 'package:flutter/widgets.dart'; import 'package:pspdfkit_flutter/pspdfkit.dart'; import '../web/pspdfkit_web.dart'; -import 'pspdfkit_widget_controller.dart'; import 'pspdfkit_widget_controller_web.dart'; typedef PspdfkitWidgetCreatedCallback = void Function( @@ -48,17 +46,23 @@ class _PspdfkitWidgetState extends State { Widget build(BuildContext context) { ui.platformViewRegistry.registerViewFactory('pspdfkit-widget', (int viewId) { - return DivElement()..id = 'pspdfkit-$viewId'; + return html.DivElement()..id = 'pspdfkit-$viewId'; }); return HtmlElementView( viewType: 'pspdfkit-widget', onPlatformViewCreated: (int id) { - _onPlatformViewCreated(id); + // Elements are no longer available when onPlatformViewCreated is called. + // Therefore we need to pass the element to the PSPDFKit.load method instead of the id. + // See this GH issue for more details: https://github.com/flutter/flutter/issues/143922#issuecomment-1960133128 + var div = (ui.platformViewRegistry.getViewById(id) as html.Element) + ..style.width = '100%' + ..style.height = '100%'; + _onPlatformViewCreated(div); }); } /// Load the document and create the PSPDFKit instance. - Future _onPlatformViewCreated(int id) async { + Future _onPlatformViewCreated(html.Element id) async { // Prepare the configuration object. // Only pass the configuration if it is a PdfConfiguration. PdfConfiguration? configuration; @@ -73,13 +77,15 @@ class _PspdfkitWidgetState extends State { } else { configuration = null; } - - await PSPDFKitWeb.load(widget.documentPath, id, configuration) - .then((value) { - var controller = PspdfkitWidgetControllerWeb(id, value); - widget.onPspdfkitWidgetCreated?.call(controller); - }).catchError((error) { - throw Exception('Failed to load: $error'); + // Adding a delay to ensure that the view is properly registered before we try to create the PSPDFKit instance. + Future.delayed(const Duration(milliseconds: 10), () async { + await PSPDFKitWeb.load(widget.documentPath, id, configuration) + .then((value) { + var controller = PspdfkitWidgetControllerWeb(value); + widget.onPspdfkitWidgetCreated?.call(controller); + }).catchError((error) { + throw Exception('Failed to load: $error'); + }); }); } } diff --git a/pubspec.yaml b/pubspec.yaml index 5d384fb1..93feaed4 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -1,6 +1,6 @@ name: pspdfkit_flutter description: A Flutter plugin providing a feature-rich PDF viewing and editing experience to your users with the powerful PSPDFKit PDF SDK. -version: 3.8.1 +version: 3.8.2 homepage: https://pspdfkit.com/ repository: https://github.com/PSPDFKit/pspdfkit-flutter issue_tracker: https://support.pspdfkit.com/hc/en-us/requests/new