Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

1.2.5 #267

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open

1.2.5 #267

Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion android/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,6 @@ android {
}

dependencies {
implementation 'com.github.mhiew:android-pdf-viewer:3.2.0-beta.1'
implementation 'com.github.mhiew:android-pdf-viewer:3.2.0-beta.3'
}

2 changes: 1 addition & 1 deletion android/proguard-rules.pro
Original file line number Diff line number Diff line change
@@ -1 +1 @@
-keep class com.shockwave.**
-keep class com.shockwave.** { *; }
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
import com.github.barteksc.pdfviewer.listener.*;
import com.github.barteksc.pdfviewer.util.Constants;
import com.github.barteksc.pdfviewer.util.FitPolicy;

import android.graphics.Color;
import com.github.barteksc.pdfviewer.link.LinkHandler;

public class FlutterPDFView implements PlatformView, MethodCallHandler {
Expand All @@ -35,7 +35,7 @@ public class FlutterPDFView implements PlatformView, MethodCallHandler {

methodChannel = new MethodChannel(messenger, "plugins.endigo.io/pdfview_" + id);
methodChannel.setMethodCallHandler(this);

pdfView.setBackgroundColor(Color.LTGRAY);
linkHandler = new PDFLinkHandler(context, pdfView, methodChannel, preventLinkNavigation);

Configurator config = null;
Expand All @@ -59,8 +59,10 @@ else if (params.get("pdfData") != null) {
.pageSnap(getBoolean(params, "pageSnap"))
.pageFitPolicy(getFitPolicy(params))
.enableAnnotationRendering(true)
.linkHandler(linkHandler).
enableAntialiasing(false)
.linkHandler(linkHandler)
.spacing(10)
.enableAntialiasing(false)

// .fitEachPage(getBoolean(params,"fitEachPage"))
.onPageChange(new OnPageChangeListener() {
@Override
Expand Down
37 changes: 23 additions & 14 deletions ios/Classes/FlutterPDFView.m
Original file line number Diff line number Diff line change
Expand Up @@ -46,24 +46,24 @@ - (instancetype)initWithFrame:(CGRect)frame
binaryMessenger:(NSObject<FlutterBinaryMessenger>*)messenger {
if ([super init]) {
_viewId = viewId;

NSString* channelName = [NSString stringWithFormat:@"plugins.endigo.io/pdfview_%lld", viewId];
_channel = [FlutterMethodChannel methodChannelWithName:channelName binaryMessenger:messenger];

_pdfView = [[PDFView alloc] initWithFrame: [[UIScreen mainScreen] bounds]];
__weak __typeof__(self) weakSelf = self;
_pdfView.delegate = self;


[_channel setMethodCallHandler:^(FlutterMethodCall* call, FlutterResult result) {
[weakSelf onMethodCall:call result:result];
}];

BOOL autoSpacing = [args[@"autoSpacing"] boolValue];
BOOL pageFling = [args[@"pageFling"] boolValue];
BOOL enableSwipe = [args[@"enableSwipe"] boolValue];
_preventLinkNavigation = [args[@"preventLinkNavigation"] boolValue];

NSInteger defaultPage = [args[@"defaultPage"] integerValue];

NSString* filePath = args[@"filePath"];
Expand Down Expand Up @@ -94,14 +94,14 @@ - (instancetype)initWithFrame:(CGRect)frame
}

_pdfView.autoScales = autoSpacing;

[_pdfView usePageViewController:pageFling withViewOptions:nil];
_pdfView.displayMode = enableSwipe ? kPDFDisplaySinglePageContinuous : kPDFDisplaySinglePage;
_pdfView.document = document;

_pdfView.maxScaleFactor = 4.0;
_pdfView.minScaleFactor = _pdfView.scaleFactorForSizeToFit;

NSString* password = args[@"password"];
if ([password isKindOfClass:[NSString class]] && [_pdfView.document isEncrypted]) {
[_pdfView.document unlockWithPassword:password];
Expand All @@ -125,24 +125,33 @@ - (instancetype)initWithFrame:(CGRect)frame
[weakSelf handleRenderCompleted:[NSNumber numberWithUnsignedLong: [document pageCount]]];
});
}

if (@available(iOS 11.0, *)) {
UIScrollView *_scrollView;

for (id subview in _pdfView.subviews) {
if ([subview isKindOfClass: [UIScrollView class]]) {
_scrollView = subview;
}
} else {
for (UIView *subsubview in [subview subviews]) {
if ([subsubview isKindOfClass:[UIScrollView class]]) {
_scrollView = (UIScrollView *)subsubview;
}
}
}
}
if (_scrollView != NULL) {
_scrollView.showsVerticalScrollIndicator = false;
_scrollView.showsHorizontalScrollIndicator = false;
}

_scrollView.contentInsetAdjustmentBehavior = UIScrollViewContentInsetAdjustmentNever;
if (@available(iOS 13.0, *)) {
_scrollView.automaticallyAdjustsScrollIndicatorInsets = NO;
}
}

[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(handlePageChanged:) name:PDFViewPageChangedNotification object:_pdfView];

}
return self;
}
Expand Down Expand Up @@ -179,7 +188,7 @@ - (void)getCurrentPage:(FlutterMethodCall*)call result:(FlutterResult)result {
- (void)setPage:(FlutterMethodCall*)call result:(FlutterResult)result {
NSDictionary<NSString*, NSNumber*>* arguments = [call arguments];
NSNumber* page = arguments[@"page"];

[_pdfView goToPage: [_pdfView.document pageAtIndex: page.unsignedLongValue ]];
result([NSNumber numberWithBool: YES]);
}
Expand Down
32 changes: 24 additions & 8 deletions lib/flutter_pdfview.dart
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,8 @@ class PDFView extends StatefulWidget {
this.defaultPage = 0,
this.fitPolicy = FitPolicy.WIDTH,
this.preventLinkNavigation = false,
})
: assert(filePath != null || pdfData != null),
this.useHybridComposition = false,
}) : assert(filePath != null || pdfData != null),
super(key: key);

@override
Expand All @@ -53,6 +53,7 @@ class PDFView extends StatefulWidget {
final ErrorCallback? onError;
final PageErrorCallback? onPageError;
final LinkHandlerCallback? onLinkHandler;
final bool useHybridComposition;

/// Which gestures should be consumed by the pdf view.
///
Expand Down Expand Up @@ -83,24 +84,39 @@ class PDFView extends StatefulWidget {
}

class _PDFViewState extends State<PDFView> {
final Completer<PDFViewController> _controller =
Completer<PDFViewController>();
final Completer<PDFViewController> _controller = Completer<PDFViewController>();

@override
Widget build(BuildContext context) {
if (defaultTargetPlatform == TargetPlatform.android) {
return PlatformViewLink(
viewType: 'plugins.endigo.io/pdfview',
surfaceFactory: (BuildContext context,
PlatformViewController controller,) {
surfaceFactory: (
BuildContext context,
PlatformViewController controller,
) {
return AndroidViewSurface(
controller: controller as AndroidViewController,
gestureRecognizers: widget.gestureRecognizers ??
const <Factory<OneSequenceGestureRecognizer>>{},
gestureRecognizers: widget.gestureRecognizers ?? const <Factory<OneSequenceGestureRecognizer>>{},
hitTestBehavior: PlatformViewHitTestBehavior.opaque,
);
},
onCreatePlatformView: (PlatformViewCreationParams params) {
if (widget.useHybridComposition) {
return PlatformViewsService.initExpensiveAndroidView(
id: params.id,
viewType: 'plugins.endigo.io/pdfview',
layoutDirection: TextDirection.rtl,
creationParams: _CreationParams.fromWidget(widget).toMap(),
creationParamsCodec: const StandardMessageCodec(),
)
..addOnPlatformViewCreatedListener(params
.onPlatformViewCreated)..addOnPlatformViewCreatedListener((
int id) {
_onPlatformViewCreated(id);
})
..create();
}
return PlatformViewsService.initSurfaceAndroidView(
id: params.id,
viewType: 'plugins.endigo.io/pdfview',
Expand Down