Skip to content

Commit 0ec235c

Browse files
committed
feat(android): native-api-usage
1 parent 9293bf7 commit 0ec235c

File tree

8 files changed

+170
-0
lines changed

8 files changed

+170
-0
lines changed
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
{
2+
"uses": [
3+
"com.facebook.drawee.drawable:ScalingUtils*",
4+
"com.facebook.drawee.drawable.ScalingUtils:ScaleType*",
5+
"com.facebook.drawee.generic:RoundingParams*",
6+
"com.facebook.drawee.drawable:ProgressBarDrawable*",
7+
"com.facebook.drawee.view:DraweeView*",
8+
"com.facebook.drawee.interfaces:DraweeHierarchy*",
9+
"com.facebook.drawee.interfaces:SettableDraweeHierarchy*",
10+
"com.facebook.drawee.interfaces:SimpleDraweeControllerBuilder*",
11+
"com.facebook.drawee.interfaces:DraweeController*",
12+
"com.facebook.drawee.generic:GenericDraweeHierarchyBuilder*",
13+
"com.facebook.drawee.generic:GenericDraweeHierarchy*",
14+
"com.facebook.imagepipeline.request:ImageRequestBuilder*",
15+
"com.facebook.imagepipeline.request:ImageRequest*",
16+
"com.facebook.imagepipeline.core:ImagePipelineConfig*",
17+
"com.facebook.imagepipeline.common:RotationOptions*",
18+
"com.facebook.imagepipeline.common:ResizeOptions*",
19+
"com.facebook.drawee.backends.pipeline:Fresco*",
20+
"com.facebook.drawee.backends.pipeline:PipelineDraweeControllerBuilder*",
21+
"com.facebook.drawee.backends.pipeline:PipelineDraweeController*",
22+
"com.facebook.drawee.controller:AbstractDraweeControllerBuilder*",
23+
"com.facebook.drawee.controller:AbstractDraweeController*",
24+
"com.facebook.drawee.backends.pipeline.info:ImagePerfDataListener*",
25+
"com.facebook.drawee.backends.pipeline.info:ImagePerfData*",
26+
"com.facebook.drawee.controller:ControllerListener*",
27+
"com.nativescript.image:DraweeView*",
28+
"com.nativescript.image:ScalingBlurPostprocessor*",
29+
"android.graphics.drawable:Animatable",
30+
"com.facebook.imagepipeline.image:ImageInfo*"
31+
]
32+
}
228 Bytes
Binary file not shown.

plugin/platforms/ios/src/NImage.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
#import <UIKit/UIKit.h>
2+
#import <Foundation/Foundation.h>
3+
#import <CoreText/CoreText.h>
4+
5+
#import "NSImageRoundCornerTransformer.h"
6+
#import "NSImageDecodeSizeTransformer.h"
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
#import <SDWebImage/SDImageTransformer.h>
2+
3+
@interface NSImageDecodeSizeTransformer: NSObject <SDImageTransformer>
4+
5+
@property (nonatomic, assign, readonly) CGFloat decodeWidth;
6+
@property (nonatomic, assign, readonly) CGFloat decodeHeight;
7+
8+
- (nonnull instancetype)init NS_UNAVAILABLE;
9+
+ (nonnull instancetype)transformerWithDecodeWidth:(CGFloat)decodeWidth decodeHeight:(CGFloat)decodeHeight;
10+
11+
@end
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
#import "NSImageDecodeSizeTransformer.h"
2+
#import <SDWebImage/SDGraphicsImageRenderer.h>
3+
4+
@interface NSImageDecodeSizeTransformer ()
5+
6+
@property (nonatomic, assign) CGFloat decodeWidth;
7+
@property (nonatomic, assign) CGFloat decodeHeight;
8+
9+
@end
10+
11+
@implementation NSImageDecodeSizeTransformer
12+
+ (nonnull instancetype)transformerWithDecodeWidth:(CGFloat)decodeWidth decodeHeight:(CGFloat)decodeHeight {
13+
NSImageDecodeSizeTransformer *transformer = [NSImageDecodeSizeTransformer new];
14+
transformer.decodeWidth = decodeWidth;
15+
transformer.decodeHeight = decodeHeight;
16+
17+
return transformer;
18+
}
19+
20+
- (NSString *)transformerKey {
21+
return [NSString stringWithFormat:@"NSImageDecodeSizeTransformer(%f,%f)", self.decodeWidth, self.decodeHeight];
22+
}
23+
24+
- (UIImage *)transformedImageWithImage:(UIImage *)image forKey:(NSString *)key {
25+
if (!image) {
26+
return nil;
27+
}
28+
CGFloat widthRatio = 1.0f;
29+
CGFloat heightRatio = 1.0f;
30+
31+
CGFloat width = (CGFloat)image.size.width;
32+
CGFloat height = (CGFloat)image.size.height;
33+
if (self.decodeWidth && self.decodeHeight) {
34+
widthRatio = self.decodeWidth / width;
35+
heightRatio = self.decodeHeight / height;
36+
} else if (self.decodeWidth > 0) {
37+
widthRatio = self.decodeWidth / width;
38+
} else {
39+
heightRatio = self.decodeHeight / height;
40+
}
41+
return [image sd_resizedImageWithSize:CGSizeMake(width * widthRatio, height * heightRatio) scaleMode:2];
42+
}
43+
44+
@end
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
#import <SDWebImage/SDImageTransformer.h>
2+
3+
@interface NSImageRoundCornerTransformer: NSObject <SDImageTransformer>
4+
5+
@property (nonatomic, assign, readonly) CGFloat topLeftRadius;
6+
@property (nonatomic, assign, readonly) CGFloat topRightRadius;
7+
@property (nonatomic, assign, readonly) CGFloat bottomRightRadius;
8+
@property (nonatomic, assign, readonly) CGFloat bottomLeftRadius;
9+
10+
- (nonnull instancetype)init NS_UNAVAILABLE;
11+
+ (nonnull instancetype)transformerWithTopLefRadius:(CGFloat)topLeftRadius topRightRadius:(CGFloat)topRightRadius bottomRightRadius:(CGFloat)bottomRightRadius bottomLeftRadius:(CGFloat)bottomLeftRadius;
12+
13+
@end
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
#import "NSImageRoundCornerTransformer.h"
2+
#import <SDWebImage/SDGraphicsImageRenderer.h>
3+
4+
@interface NSImageRoundCornerTransformer ()
5+
6+
@property (nonatomic, assign) CGFloat topLeftRadius;
7+
@property (nonatomic, assign) CGFloat topRightRadius;
8+
@property (nonatomic, assign) CGFloat bottomRightRadius;
9+
@property (nonatomic, assign) CGFloat bottomLeftRadius;
10+
11+
@end
12+
13+
@implementation NSImageRoundCornerTransformer
14+
+ (instancetype)transformerWithTopLefRadius:(CGFloat)topLeftRadius topRightRadius:(CGFloat)topRightRadius bottomRightRadius:(CGFloat)bottomRightRadius bottomLeftRadius:(CGFloat)bottomLeftRadius {
15+
16+
NSImageRoundCornerTransformer *transformer = [NSImageRoundCornerTransformer new];
17+
transformer.topLeftRadius = topLeftRadius;
18+
transformer.topRightRadius = topRightRadius;
19+
transformer.bottomRightRadius = bottomRightRadius;
20+
transformer.bottomLeftRadius = bottomLeftRadius;
21+
22+
return transformer;
23+
}
24+
25+
- (NSString *)transformerKey {
26+
return [NSString stringWithFormat:@"NSImageRoundCornerTransformer(%f,%f,%f,%f)", self.topLeftRadius,self.topRightRadius,self.bottomRightRadius,self.bottomLeftRadius];
27+
}
28+
29+
- (UIImage *)transformedImageWithImage:(UIImage *)image forKey:(NSString *)key {
30+
if (!image) {
31+
return nil;
32+
}
33+
34+
SDGraphicsImageRendererFormat *format = [[SDGraphicsImageRendererFormat alloc] init];
35+
format.scale = image.scale;
36+
SDGraphicsImageRenderer *renderer = [[SDGraphicsImageRenderer alloc] initWithSize:image.size format:format];
37+
UIImage *resultImage = [renderer imageWithActions:^(CGContextRef _Nonnull context) {
38+
CGRect rect = CGRectMake(0, 0, image.size.width, image.size.height);
39+
40+
UIBezierPath *newPath = [UIBezierPath bezierPath];
41+
42+
CGFloat left = M_PI;
43+
CGFloat up = 1.5*M_PI;
44+
CGFloat down = M_PI_2;
45+
CGFloat right = 0.0;
46+
[newPath addArcWithCenter:CGPointMake( CGRectGetMinX(rect) + self.topLeftRadius, CGRectGetMinY( rect) + self.topLeftRadius) radius: self.topLeftRadius startAngle: left endAngle: up clockwise: true];
47+
[newPath addArcWithCenter:CGPointMake( CGRectGetMaxX(rect) - self.topRightRadius, CGRectGetMinY( rect) + self.topRightRadius) radius: self.topRightRadius startAngle: up endAngle: right clockwise: true];
48+
[newPath addArcWithCenter:CGPointMake( CGRectGetMaxX(rect) - self.bottomRightRadius, CGRectGetMaxY( rect) - self.bottomRightRadius) radius: self.bottomRightRadius startAngle: right endAngle: down clockwise: true];
49+
[newPath addArcWithCenter:CGPointMake(CGRectGetMinX(rect) + self.bottomLeftRadius, CGRectGetMaxY( rect) - self.bottomLeftRadius) radius: self.bottomLeftRadius startAngle: down endAngle: left clockwise: true];
50+
[newPath closePath];
51+
CGContextSaveGState(context);
52+
[newPath addClip];
53+
[image drawInRect:rect];
54+
CGContextRestoreGState(context);
55+
}];
56+
return resultImage;
57+
}
58+
59+
@end
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
module NImage {
2+
umbrella header "NImage.h"
3+
export *
4+
module * { export * }
5+
}

0 commit comments

Comments
 (0)