FLNativeView.m 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. //
  2. // FLNativeViewFactory.m
  3. // compdfkit_flutter
  4. //
  5. // Created by kdanmobile_2 on 2023/7/25.
  6. //
  7. #import "FLNativeView.h"
  8. #import <ComPDFKit/ComPDFKit.h>
  9. @implementation FLNativeViewFactory {
  10. NSObject<FlutterBinaryMessenger>* _messenger;
  11. }
  12. - (instancetype)initWithMessenger:(NSObject<FlutterBinaryMessenger> *)messenger {
  13. if (self = [super init]) {
  14. _messenger = messenger;
  15. }
  16. return self;
  17. }
  18. #pragma mark - FlutterPlatformViewFactory
  19. - (NSObject<FlutterPlatformView> *)createWithFrame:(CGRect)frame viewIdentifier:(int64_t)viewId arguments:(id)args {
  20. return [[FLNativeView alloc] initWithFrame:frame viewIndentifier:viewId argument:args binaryMessenger:_messenger];
  21. }
  22. @end
  23. @implementation FLNativeView {
  24. UIView *_view;
  25. CPDFView *_pdfView;
  26. }
  27. - (instancetype)initWithFrame:(CGRect)frame viewIndentifier:(int64_t)viewId argument:(id _Nullable)args binaryMessenger:(NSObject<FlutterBinaryMessenger> *)messenger {
  28. self = [super init];
  29. if (self) {
  30. NSString *documentFolder = [NSHomeDirectory() stringByAppendingFormat:@"/%@/%@", @"Documents",@"Samples"];
  31. NSString *filePath = [NSString stringWithFormat:@"%@/developer_guide_ios.pdf", documentFolder];
  32. CPDFDocument *document = [[CPDFDocument alloc] initWithURL:[NSURL fileURLWithPath:filePath]];
  33. _pdfView = [[CPDFView alloc] initWithFrame:CGRectMake(0, 0, [UIScreen mainScreen].bounds.size.width, [UIScreen mainScreen].bounds.size.height)];
  34. _pdfView.document = document;
  35. _view = [[UIView alloc] init];
  36. [_view addSubview:_pdfView];
  37. }
  38. return self;
  39. }
  40. - (UIView *)view {
  41. return _view;
  42. }
  43. @end