forked from react-native-maps/react-native-maps
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Issue1176 improve ios marker performance by X100 (react-native-maps#1187
) * Issue1176 attempt to fix UI lag success by re-using UIImage * Now use NSMutableDictionary instead of single UIImage * appearAnimation happen at init rather than setIcon * Init NSMutableDictionary * Remove reference to other app
- Loading branch information
Showing
3 changed files
with
92 additions
and
64 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
// | ||
// GlobalVars.h | ||
// | ||
// Created by Eric Kim on 2017-04-04. | ||
// Copyright © 2017 Apply Digital. All rights reserved. | ||
// | ||
|
||
#import <Foundation/Foundation.h> | ||
#import <UIKit/UIKit.h> | ||
|
||
@interface GlobalVars : NSObject | ||
{ | ||
NSMutableDictionary *dict; | ||
} | ||
|
||
+ (GlobalVars *)sharedInstance; | ||
|
||
- (UIImage *)getSharedUIImage:(NSString *)imageSrc; | ||
|
||
@property(strong, nonatomic, readwrite) NSMutableDictionary *dict; | ||
|
||
@end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
// | ||
// GlobalVars.m | ||
// | ||
// Created by Eric Kim on 2017-04-04. | ||
// Copyright © 2017 Apply Digital. All rights reserved. | ||
// | ||
|
||
#import "GlobalVars.h" | ||
|
||
@implementation GlobalVars | ||
|
||
@synthesize dict = _dict; | ||
|
||
+ (GlobalVars *)sharedInstance { | ||
static dispatch_once_t onceToken; | ||
static GlobalVars *instance = nil; | ||
dispatch_once(&onceToken, ^{ | ||
instance = [[GlobalVars alloc] init]; | ||
}); | ||
return instance; | ||
} | ||
|
||
- (UIImage *)getSharedUIImage:(NSString *)imageSrc { | ||
|
||
UIImage* cachedImage = dict[imageSrc]; | ||
|
||
CGImageRef cgref = [cachedImage CGImage]; | ||
CIImage *cim = [cachedImage CIImage]; | ||
|
||
if (cim == nil && cgref == NULL) { | ||
UIImage *newImage; | ||
if ([imageSrc hasPrefix:@"http://"] || [imageSrc hasPrefix:@"https://"]){ | ||
NSURL *url = [NSURL URLWithString:imageSrc]; | ||
NSData *data = [NSData dataWithContentsOfURL:url]; | ||
newImage = [UIImage imageWithData:data scale:[UIScreen mainScreen].scale]; | ||
} else { | ||
newImage = [UIImage imageWithContentsOfFile:imageSrc]; | ||
} | ||
dict[imageSrc] = newImage; | ||
return newImage; | ||
} else { | ||
return cachedImage; | ||
} | ||
} | ||
|
||
- (id)init { | ||
self = [super init]; | ||
if (self) { | ||
dict = [[NSMutableDictionary alloc] init]; | ||
} | ||
return self; | ||
} | ||
|
||
@end |