|
7 | 7 | */ |
8 | 8 |
|
9 | 9 | #import "SDImageLottieCoder.h" |
| 10 | +#import "SDWebImageLottieLoaderDefine.h" |
10 | 11 | #if __has_include(<rlottie/rlottie_capi.h>) |
11 | 12 | #import <rlottie/rlottie_capi.h> |
12 | 13 | #elif __has_include(<librlottie/librlottie.h>) |
@@ -118,11 +119,17 @@ - (UIImage *)decodedImageWithData:(NSData *)data options:(SDImageCoderOptions *) |
118 | 119 | if (preserveAspectRatioValue != nil) { |
119 | 120 | preserveAspectRatio = preserveAspectRatioValue.boolValue; |
120 | 121 | } |
121 | | - NSBundle *bundle = NSBundle.mainBundle; |
122 | | - const char *resourcePath = [bundle.resourcePath cStringUsingEncoding:NSUTF8StringEncoding]; |
| 122 | + NSString *resourcePath = NSBundle.mainBundle.resourcePath; |
| 123 | + SDWebImageContext *context = options[SDImageCoderWebImageContext]; |
| 124 | + if (context[SDWebImageContextLottieResourcePath]) { |
| 125 | + resourcePath = context[SDWebImageContextLottieResourcePath]; |
| 126 | + } else if (options[SDImageCoderDecodeLottieResourcePath]) { |
| 127 | + resourcePath = options[SDImageCoderDecodeLottieResourcePath]; |
| 128 | + } |
123 | 129 | NSString *jsonString = [[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding]; |
124 | | - const char *jsonData = [jsonString cStringUsingEncoding:NSUTF8StringEncoding]; |
125 | | - Lottie_Animation *animation = lottie_animation_from_data(jsonData, "", resourcePath); |
| 130 | + const char *jsonDataBuffer = [jsonString cStringUsingEncoding:NSUTF8StringEncoding]; |
| 131 | + const char *resourcePathBuffer = [resourcePath cStringUsingEncoding:NSUTF8StringEncoding]; |
| 132 | + Lottie_Animation *animation = lottie_animation_from_data(jsonDataBuffer, "", resourcePathBuffer); |
126 | 133 | if (!animation) { |
127 | 134 | return nil; |
128 | 135 | } |
@@ -200,11 +207,17 @@ - (NSData *)encodedDataWithImage:(UIImage *)image format:(SDImageFormat)format o |
200 | 207 | - (instancetype)initWithAnimatedImageData:(NSData *)data options:(SDImageCoderOptions *)options { |
201 | 208 | self = [super init]; |
202 | 209 | if (self) { |
203 | | - NSBundle *bundle = NSBundle.mainBundle; |
204 | | - const char *resourcePath = [bundle.resourcePath cStringUsingEncoding:NSUTF8StringEncoding]; |
| 210 | + NSString *resourcePath = NSBundle.mainBundle.resourcePath; |
| 211 | + SDWebImageContext *context = options[SDImageCoderWebImageContext]; |
| 212 | + if (context[SDWebImageContextLottieResourcePath]) { |
| 213 | + resourcePath = context[SDWebImageContextLottieResourcePath]; |
| 214 | + } else if (options[SDImageCoderDecodeLottieResourcePath]) { |
| 215 | + resourcePath = options[SDImageCoderDecodeLottieResourcePath]; |
| 216 | + } |
205 | 217 | NSString *jsonString = [[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding]; |
206 | | - const char *jsonData = [jsonString cStringUsingEncoding:NSUTF8StringEncoding]; |
207 | | - Lottie_Animation *animation = lottie_animation_from_data(jsonData, "", resourcePath); |
| 218 | + const char *jsonDataBuffer = [jsonString cStringUsingEncoding:NSUTF8StringEncoding]; |
| 219 | + const char *resourcePathBuffer = [resourcePath cStringUsingEncoding:NSUTF8StringEncoding]; |
| 220 | + Lottie_Animation *animation = lottie_animation_from_data(jsonDataBuffer, "", resourcePathBuffer); |
208 | 221 | if (!animation) { |
209 | 222 | return nil; |
210 | 223 | } |
|
0 commit comments