12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455 |
- //
- // FLNativeViewFactory.m
- // compdfkit_flutter
- //
- // Created by kdanmobile_2 on 2023/7/25.
- //
- #import "FLNativeView.h"
- #import <ComPDFKit/ComPDFKit.h>
- @implementation FLNativeViewFactory {
- NSObject<FlutterBinaryMessenger>* _messenger;
- }
- - (instancetype)initWithMessenger:(NSObject<FlutterBinaryMessenger> *)messenger {
- if (self = [super init]) {
- _messenger = messenger;
- }
- return self;
- }
- #pragma mark - FlutterPlatformViewFactory
- - (NSObject<FlutterPlatformView> *)createWithFrame:(CGRect)frame viewIdentifier:(int64_t)viewId arguments:(id)args {
- return [[FLNativeView alloc] initWithFrame:frame viewIndentifier:viewId argument:args binaryMessenger:_messenger];
- }
- @end
- @implementation FLNativeView {
- UIView *_view;
- CPDFView *_pdfView;
- }
- - (instancetype)initWithFrame:(CGRect)frame viewIndentifier:(int64_t)viewId argument:(id _Nullable)args binaryMessenger:(NSObject<FlutterBinaryMessenger> *)messenger {
- self = [super init];
- if (self) {
- NSString *documentFolder = [NSHomeDirectory() stringByAppendingFormat:@"/%@/%@", @"Documents",@"Samples"];
- NSString *filePath = [NSString stringWithFormat:@"%@/developer_guide_ios.pdf", documentFolder];
- CPDFDocument *document = [[CPDFDocument alloc] initWithURL:[NSURL fileURLWithPath:filePath]];
- _pdfView = [[CPDFView alloc] initWithFrame:CGRectMake(0, 0, [UIScreen mainScreen].bounds.size.width, [UIScreen mainScreen].bounds.size.height)];
- _pdfView.document = document;
-
- _view = [[UIView alloc] init];
- [_view addSubview:_pdfView];
- }
- return self;
- }
- - (UIView *)view {
- return _view;
- }
- @end
|