mirror of
https://github.com/NativeScript/NativeScript.git
synced 2025-11-05 13:26:48 +08:00
Add some docs and PoC in the nativescript modules
This commit is contained in:
2
build.sh
2
build.sh
@@ -1,5 +1,6 @@
|
|||||||
#!/bin/sh
|
#!/bin/sh
|
||||||
|
|
||||||
|
echo "Clean dist"
|
||||||
rm -rf dist
|
rm -rf dist
|
||||||
mkdir dist
|
mkdir dist
|
||||||
mkdir dist/package
|
mkdir dist/package
|
||||||
@@ -25,7 +26,6 @@ cp LICENSE.md dist/package/LICENSE.md
|
|||||||
cp README.md dist/package/README.md
|
cp README.md dist/package/README.md
|
||||||
cp package.json dist/package/package.json
|
cp package.json dist/package/package.json
|
||||||
|
|
||||||
# npm pack
|
|
||||||
echo "NPM pack"
|
echo "NPM pack"
|
||||||
cd dist/package
|
cd dist/package
|
||||||
PACKAGE="$(npm pack)"
|
PACKAGE="$(npm pack)"
|
||||||
|
|||||||
@@ -6,10 +6,18 @@
|
|||||||
// Copyright © 2016 Telerik A D. All rights reserved.
|
// Copyright © 2016 Telerik A D. All rights reserved.
|
||||||
//
|
//
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@interface UIImage (TNSBlocks)
|
@interface UIImage (TNSBlocks)
|
||||||
|
|
||||||
+ (void) tns_imageNamed: (NSString*) name completion: (void (^) (UIImage*))callback;
|
/**
|
||||||
|
* Similar to imageNamed: however it runs on a separate queue so the UI thread is not blocked.
|
||||||
|
* It also draws the UIImage in a small thumb to force decoding potentially avoiding UI hicckups when displayed.
|
||||||
|
*/
|
||||||
|
+ (void) tns_safeDecodeImageNamed: (NSString*) name completion: (void (^) (UIImage*))callback;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Same as imageNamed, however calls to this method are sinchronized to be thread safe in iOS8 along with calls to tns_safeImageNamed and tns_safeDecodeImageNamed:completion:
|
||||||
|
* imageNamed is thread safe in iOS 9 and later so in later versions this methods simply fallbacks to imageNamed:
|
||||||
|
*/
|
||||||
|
+ (UIImage*) tns_safeImageNamed: (NSString*) name;
|
||||||
|
|
||||||
@end
|
@end
|
||||||
|
|||||||
@@ -10,28 +10,56 @@
|
|||||||
|
|
||||||
@implementation UIImage (TNSBlocks)
|
@implementation UIImage (TNSBlocks)
|
||||||
|
|
||||||
|
static NSLock* image_lock_handle;
|
||||||
static dispatch_queue_t image_queue;
|
static dispatch_queue_t image_queue;
|
||||||
|
|
||||||
|
void image_lock() {
|
||||||
|
if (image_lock_handle) {
|
||||||
|
[image_lock_handle lock];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void image_unlock() {
|
||||||
|
if (image_lock_handle) {
|
||||||
|
[image_lock_handle unlock];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
+ (void) initialize {
|
+ (void) initialize {
|
||||||
image_queue = dispatch_queue_create("org.nativescript.TNSWidgets.image", NULL);
|
image_queue = dispatch_queue_create("org.nativescript.TNSWidgets.image", NULL);
|
||||||
|
if ([[NSProcessInfo processInfo] operatingSystemVersion].majorVersion >= 9) {
|
||||||
|
// UIImage imageNamed: is said to be thread safe, in iOS9 and later, in offical Apple reference.
|
||||||
|
image_lock_handle = nil;
|
||||||
|
} else {
|
||||||
|
image_lock_handle = [NSLock new];
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void) tns_decompressImage {
|
- (void) tns_decompressImage {
|
||||||
CGImageRef cgImg = [self CGImage];
|
UIGraphicsBeginImageContext(CGSizeMake(1, 1));
|
||||||
// TODO: Do performance tests if actual drawing is necessary
|
[self drawAtPoint:CGPointZero];
|
||||||
|
UIGraphicsEndImageContext();
|
||||||
// UIGraphicsBeginImageContext(CGSizeMake(1, 1));
|
|
||||||
// [self drawAtPoint:CGPointZero];
|
|
||||||
// UIGraphicsEndImageContext();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
+ (void) tns_imageNamed: (NSString*) name completion: (void (^) (UIImage*))callback {
|
+ (void) tns_safeDecodeImageNamed: (NSString*) name completion: (void (^) (UIImage*))callback {
|
||||||
dispatch_async(image_queue, ^(void){
|
dispatch_async(image_queue, ^(void){
|
||||||
|
image_lock();
|
||||||
UIImage* image = [UIImage imageNamed: name];
|
UIImage* image = [UIImage imageNamed: name];
|
||||||
[image tns_decompressImage];
|
if (image) {
|
||||||
|
[image tns_decompressImage];
|
||||||
|
}
|
||||||
|
image_unlock();
|
||||||
dispatch_async(dispatch_get_main_queue(), ^(void) {
|
dispatch_async(dispatch_get_main_queue(), ^(void) {
|
||||||
callback(image);
|
callback(image);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
+ (UIImage*) tns_safeImageNamed: (NSString*) name {
|
||||||
|
image_lock();
|
||||||
|
UIImage* image = [UIImage imageNamed: name];
|
||||||
|
image_unlock();
|
||||||
|
return image;
|
||||||
|
}
|
||||||
|
|
||||||
@end
|
@end
|
||||||
|
|||||||
Reference in New Issue
Block a user