Skip to content
This repository was archived by the owner on Mar 16, 2019. It is now read-only.

Commit 4c133d6

Browse files
author
amoreno
committed
refs #51397 Added parameters to UIDocumentInteractionController
1 parent fffae8d commit 4c133d6

File tree

1 file changed

+41
-3
lines changed

1 file changed

+41
-3
lines changed

ios/RNFetchBlob/RNFetchBlob.m

+41-3
Original file line numberDiff line numberDiff line change
@@ -315,7 +315,6 @@ - (NSDictionary *)constantsToExport
315315
#pragma mark - fs.stat
316316
RCT_EXPORT_METHOD(stat:(NSString *)target callback:(RCTResponseSenderBlock) callback)
317317
{
318-
319318
[RNFetchBlobFS getPathFromUri:target completionHandler:^(NSString *path, ALAssetRepresentation *asset) {
320319
__block NSMutableArray * result;
321320
if(path != nil)
@@ -536,11 +535,40 @@ - (NSDictionary *)constantsToExport
536535

537536
# pragma mark - open file with UIDocumentInteractionController and delegate
538537

539-
RCT_EXPORT_METHOD(openDocument:(NSString*)uri scheme:(NSString *)scheme name:(NSString*)name resolver:(RCTPromiseResolveBlock)resolve rejecter:(RCTPromiseRejectBlock)reject)
538+
- (void)openDocument:(NSString *)uri
539+
scheme:(NSString *)scheme
540+
resolver:(RCTPromiseResolveBlock)resolve
541+
rejecter:(RCTPromiseRejectBlock)reject
542+
fontFamily:(NSString *)fontFamily
543+
fontSize:(float)fontSize
544+
hexString:(NSString *)hexString
540545
{
541546
NSString * utf8uri = [uri stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
542547
NSURL * url = [[NSURL alloc] initWithString:utf8uri];
543548
// NSURL * url = [[NSURL alloc] initWithString:uri];
549+
if (fontFamily) {
550+
NSMutableDictionary *titleBarAttributes = [NSMutableDictionary dictionaryWithDictionary: [[UINavigationBar appearance] titleTextAttributes]];
551+
[titleBarAttributes setValue:[UIFont fontWithName:fontFamily size:fontSize] forKey:NSFontAttributeName];
552+
unsigned rgbValue = 0;
553+
NSScanner *scanner = [NSScanner scannerWithString:hexString];
554+
[scanner setScanLocation:1]; // bypass '#' character
555+
[scanner scanHexInt:&rgbValue];
556+
[titleBarAttributes setValue:[UIColor colorWithRed:((float)((rgbValue & 0xFF0000) >> 16))/255.0 \
557+
green:((float)((rgbValue & 0x00FF00) >> 8))/255.0 \
558+
blue:((float)((rgbValue & 0x0000FF) >> 0))/255.0 \
559+
alpha:1.0] forKey:NSForegroundColorAttributeName];
560+
[[UINavigationBar appearance] setTitleTextAttributes:titleBarAttributes];
561+
562+
NSMutableDictionary *attributes = [NSMutableDictionary dictionaryWithDictionary: [[UIBarButtonItem appearance] titleTextAttributesForState:UIControlStateNormal]];
563+
[attributes setValue:[UIFont fontWithName:fontFamily size:fontSize] forKey:NSFontAttributeName];
564+
[[UIBarButtonItem appearance] setTitleTextAttributes:attributes forState:UIControlStateNormal];
565+
[[UIBarButtonItem appearance] setTintColor: [UIColor colorWithRed:((float)((rgbValue & 0xFF0000) >> 16))/255.0 \
566+
green:((float)((rgbValue & 0x00FF00) >> 8))/255.0 \
567+
blue:((float)((rgbValue & 0x0000FF) >> 0))/255.0 \
568+
alpha:1.0]];
569+
[[UINavigationBar appearance] setBarTintColor: [UIColor whiteColor]];
570+
}
571+
544572
documentController = [UIDocumentInteractionController interactionControllerWithURL:url];
545573
documentController.delegate = self;
546574
documentController.name = name;
@@ -555,6 +583,16 @@ - (NSDictionary *)constantsToExport
555583
}
556584
}
557585

586+
RCT_EXPORT_METHOD(openDocument:(NSString*)uri scheme:(NSString*)scheme resolver:(RCTPromiseResolveBlock)resolve rejecter:(RCTPromiseRejectBlock)reject fontFamily:(NSString*)fontFamily fontSize:(float)fontSize hexString:(NSString*)hexString)
587+
{
588+
[self openDocument:uri scheme:scheme resolver:resolver rejecter:rejecter fontFamily:fontFamily fontSize:fontSize hexString:hexString];
589+
}
590+
591+
RCT_EXPORT_METHOD(openDocument:(NSString*)uri scheme:(NSString *)scheme name:(NSString*)name resolver:(RCTPromiseResolveBlock)resolve rejecter:(RCTPromiseRejectBlock)reject)
592+
{
593+
[self openDocument:uri scheme:scheme resolver:resolver rejecter:rejecter fontFamily:nil fontSize:NULL hexString:nil];
594+
}
595+
558596
# pragma mark - exclude from backup key
559597

560598
RCT_EXPORT_METHOD(excludeFromBackupKey:(NSString *)url resolver:(RCTPromiseResolveBlock)resolve rejecter:(RCTPromiseRejectBlock)reject)
@@ -576,7 +614,7 @@ - (NSDictionary *)constantsToExport
576614
[RNFetchBlobFS df:callback];
577615
}
578616

579-
- (UIViewController *) documentInteractionControllerViewControllerForPreview: (UIDocumentInteractionController *) controller
617+
- (UIViewController *)documentInteractionControllerViewControllerForPreview:(UIDocumentInteractionController *)controller
580618
{
581619
UIWindow *window = [UIApplication sharedApplication].keyWindow;
582620
return window.rootViewController;

0 commit comments

Comments
 (0)