Skip to content

Commit

Permalink
Add the ability to set PSPDFConfiguration and PSPDFAppearanceMode whe…
Browse files Browse the repository at this point in the history
…n presenting the document
  • Loading branch information
RadAzzouz committed Mar 30, 2019
1 parent a639318 commit 577548c
Showing 1 changed file with 76 additions and 1 deletion.
77 changes: 76 additions & 1 deletion ios/Classes/PspdfkitPlugin.m
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,12 @@ - (void)handleMethodCall:(FlutterMethodCall*)call result:(FlutterResult)result {
NSString *documentPath = call.arguments[@"document"];
NSAssert(documentPath != nil, @"Document path may not be nil.");
NSAssert(documentPath.length != 0, @"Document path may not be empty.");
NSDictionary *configurationDictionary = call.arguments[@"configuration"];

PSPDFDocument *document = [self PSPDFDocument:documentPath];
PSPDFViewController *pdfViewController = [[PSPDFViewController alloc] initWithDocument:document];
PSPDFConfiguration *psPdfConfiguration = [self PSPDFConfiguration:configurationDictionary forDocument:document];
PSPDFViewController *pdfViewController = [[PSPDFViewController alloc] initWithDocument:document configuration:psPdfConfiguration];
pdfViewController.appearanceModeManager.appearanceMode = [self PSPDFAppearanceMode:configurationDictionary];

UINavigationController *navigationController = [[UINavigationController alloc] initWithRootViewController:pdfViewController];
UIViewController *presentingViewController = [UIApplication sharedApplication].delegate.window.rootViewController;
Expand All @@ -41,6 +45,8 @@ - (void)handleMethodCall:(FlutterMethodCall*)call result:(FlutterResult)result {
}
}

# pragma mark - Private methods

- (PSPDFDocument *)PSPDFDocument:(NSString *)string {
NSURL *url;

Expand All @@ -59,5 +65,74 @@ - (PSPDFDocument *)PSPDFDocument:(NSString *)string {
}
}

- (PSPDFConfiguration *)PSPDFConfiguration:(NSDictionary *)dictionary forDocument:(PSPDFDocument *)document{
PSPDFConfiguration *configuration;
if ([document isKindOfClass:PSPDFImageDocument.class]) {
configuration = PSPDFConfiguration.imageConfiguration;
} else {
configuration = PSPDFConfiguration.defaultConfiguration;
}

if ((id)dictionary == NSNull.null || !dictionary || dictionary.count == 0) {
return configuration;
}

return [configuration configurationUpdatedWithBuilder:^(PSPDFConfigurationBuilder * _Nonnull builder) {
if (dictionary[@"pageScrollDirection"]) {
builder.scrollDirection = [dictionary[@"pageScrollDirection"] isEqualToString:@"pageScrollDirectionHorizontal"] ? PSPDFScrollDirectionHorizontal : PSPDFScrollDirectionVertical;
}
if (dictionary[@"pageScrollContinuous"]) {
builder.pageTransition = dictionary[@"pageScrollContinuous"] ? PSPDFPageTransitionScrollContinuous : PSPDFPageTransitionScrollPerSpread;
}
if (dictionary[@"userInterfaceViewMode"]) {
PSPDFUserInterfaceViewMode userInterfaceMode = PSPDFUserInterfaceViewModeAutomatic;
NSString *value = dictionary[@"userInterfaceViewMode"];
if ([value isEqualToString:@"automatic"]) {
userInterfaceMode = PSPDFUserInterfaceViewModeAutomatic;
} else if ([value isEqualToString:@"alwaysVisible"]) {
userInterfaceMode = PSPDFUserInterfaceViewModeAlways;
} else if ([value isEqualToString:@"alwaysHidden"]) {
userInterfaceMode = PSPDFUserInterfaceViewModeNever;
} else if ([value isEqualToString:@"automaticNoFirstLastPage"]) {
userInterfaceMode = PSPDFUserInterfaceViewModeAutomaticNoFirstLastPage;
}
builder.userInterfaceViewMode = userInterfaceMode;
}
if (dictionary[@"inlineSearch"]) {
builder.searchMode = dictionary[@"inlineSearch"] ? PSPDFSearchModeInline : PSPDFSearchModeModal;
}
if (dictionary[@"showThumbnailBar"]) {
PSPDFThumbnailBarMode thumbnailBarMode = PSPDFThumbnailBarModeScrubberBar;
NSString *value = dictionary[@"showThumbnailBar"];
if ([value isEqualToString:@"default"]) {
thumbnailBarMode = PSPDFThumbnailBarModeScrubberBar;
} else if ([value isEqualToString:@"scrollable"]) {
thumbnailBarMode = PSPDFThumbnailBarModeScrollable;
} else if ([value isEqualToString:@"none"]) {
thumbnailBarMode = PSPDFThumbnailBarModeNone;
}
builder.thumbnailBarMode = thumbnailBarMode;
}
}];
}

- (PSPDFAppearanceMode)PSPDFAppearanceMode:(NSDictionary *)dictionary {
if ((id)dictionary == NSNull.null || !dictionary || dictionary.count == 0) {
return PSPDFAppearanceModeDefault;
}
PSPDFAppearanceMode appearanceMode = PSPDFAppearanceModeDefault;
if (dictionary[@"appearanceMode"]) {
NSString *value = dictionary[@"appearanceMode"];
if ([value isEqualToString:@"default"]) {
appearanceMode = PSPDFAppearanceModeDefault;
} else if ([value isEqualToString:@"night"]) {
appearanceMode = PSPDFAppearanceModeNight;
} else if ([value isEqualToString:@"sepia"]) {
appearanceMode = PSPDFAppearanceModeSepia;
}
}
return appearanceMode;
}

@end

0 comments on commit 577548c

Please sign in to comment.