|
| 1 | +// |
| 2 | +// Copyright (c) 2016 Google Inc. |
| 3 | +// |
| 4 | +// Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | +// you may not use this file except in compliance with the License. |
| 6 | +// You may obtain a copy of the License at |
| 7 | +// |
| 8 | +// http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | +// |
| 10 | +// Unless required by applicable law or agreed to in writing, software |
| 11 | +// distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | +// See the License for the specific language governing permissions and |
| 14 | +// limitations under the License. |
| 15 | +// |
| 16 | + |
| 17 | +@import UIKit; |
| 18 | + |
| 19 | +#import <FirebaseStorage/FirebaseStorage.h> |
| 20 | +#import <SDWebImage/UIImageView+WebCache.h> |
| 21 | +#import <SDWebImage/UIImage+MultiFormat.h> |
| 22 | + |
| 23 | +NS_ASSUME_NONNULL_BEGIN |
| 24 | + |
| 25 | +@interface UIImageView (FirebaseStorage) |
| 26 | + |
| 27 | +/** |
| 28 | + * Returns the maximum image download size, in bytes. Defaults to 10e6. |
| 29 | + */ |
| 30 | ++ (UInt64)sd_defaultMaxImageSize; |
| 31 | + |
| 32 | +/** |
| 33 | + * Sets the maximum image download size, in bytes. |
| 34 | + * @param size The new maximum image download size. |
| 35 | + */ |
| 36 | ++ (void)sd_setDefaultMaxImageSize:(UInt64)size; |
| 37 | + |
| 38 | +/** |
| 39 | + * The current download task, if the image view is downloading an image. |
| 40 | + * Must be invoked on the main queue. |
| 41 | + */ |
| 42 | +@property (nonatomic, readonly, nullable) FIRStorageDownloadTask *sd_currentDownloadTask; |
| 43 | + |
| 44 | +/** |
| 45 | + * Sets the image view's image to an image downloaded from the Firebase Storage reference. |
| 46 | + * |
| 47 | + * @param storageRef A Firebase Storage reference containing an image. |
| 48 | + * @return Returns a FIRStorageDownloadTask if a download was created (i.e. image |
| 49 | + * could not be found in cache). |
| 50 | + */ |
| 51 | +- (nullable FIRStorageDownloadTask *)sd_setImageWithStorageReference:(FIRStorageReference *)storageRef; |
| 52 | + |
| 53 | +/** |
| 54 | + * Sets the image view's image to an image downloaded from the Firebase Storage reference. |
| 55 | + * Must be invoked on the main queue. |
| 56 | + * |
| 57 | + * @param storageRef A Firebase Storage reference containing an image. |
| 58 | + * @param customKey An custom caching key to append to the storage path. |
| 59 | + * @return Returns a FIRStorageDownloadTask if a download was created (i.e. image |
| 60 | + * could not be found in cache). |
| 61 | + */ |
| 62 | +- (nullable FIRStorageDownloadTask *)sd_setImageWithStorageReference:(FIRStorageReference *)storageRef |
| 63 | + customKey:(NSString*)customKey; |
| 64 | + |
| 65 | +/** |
| 66 | + * Sets the image view's image to an image downloaded from the Firebase Storage reference. |
| 67 | + * Must be invoked on the main queue. |
| 68 | + * |
| 69 | + * @param storageRef A Firebase Storage reference containing an image. |
| 70 | + * @param placeholder An image to display while the download is in progress. |
| 71 | + * @return Returns a FIRStorageDownloadTask if a download was created (i.e. image |
| 72 | + * could not be found in cache). |
| 73 | + */ |
| 74 | +- (nullable FIRStorageDownloadTask *)sd_setImageWithStorageReference:(FIRStorageReference *)storageRef |
| 75 | + placeholderImage:(nullable UIImage *)placeholder; |
| 76 | + |
| 77 | +/** |
| 78 | + * Sets the image view's image to an image downloaded from the Firebase Storage reference. |
| 79 | + * Must be invoked on the main queue. |
| 80 | + * |
| 81 | + * @param storageRef A Firebase Storage reference containing an image. |
| 82 | + * @param placeholder An image to display while the download is in progress. |
| 83 | + * @param completion A closure to handle events when the image finishes downloading. |
| 84 | + * The closure is not guaranteed to be invoked on the main thread. |
| 85 | + * @return Returns a FIRStorageDownloadTask if a download was created (i.e. image |
| 86 | + * could not be found in cache). |
| 87 | + */ |
| 88 | +- (nullable FIRStorageDownloadTask *)sd_setImageWithStorageReference:(FIRStorageReference *)storageRef |
| 89 | + placeholderImage:(nullable UIImage *)placeholder |
| 90 | + completion:(void (^_Nullable)(UIImage *_Nullable, |
| 91 | + NSError *_Nullable, |
| 92 | + SDImageCacheType, |
| 93 | + FIRStorageReference *))completion; |
| 94 | + |
| 95 | +/** |
| 96 | + * Sets the image view's image to an image downloaded from the Firebase Storage reference. |
| 97 | + * Must be invoked on the main queue. |
| 98 | + * |
| 99 | + * @param storageRef A Firebase Storage reference containing an image. |
| 100 | + * @param size The maximum size of the downloaded image. If the downloaded image |
| 101 | + * exceeds this size, an error will be raised in the completion block. |
| 102 | + * @param placeholder An image to display while the download is in progress. |
| 103 | + * @param completion A closure to handle events when the image finishes downloading. |
| 104 | + * The closure is not guaranteed to be invoked on the main thread. |
| 105 | + * @return Returns a FIRStorageDownloadTask if a download was created (i.e. image |
| 106 | + * could not be found in cache). |
| 107 | + */ |
| 108 | +- (nullable FIRStorageDownloadTask *)sd_setImageWithStorageReference:(FIRStorageReference *)storageRef |
| 109 | + maxImageSize:(UInt64)size |
| 110 | + placeholderImage:(nullable UIImage *)placeholder |
| 111 | + completion:(void (^_Nullable)(UIImage *_Nullable, |
| 112 | + NSError *_Nullable, |
| 113 | + SDImageCacheType, |
| 114 | + FIRStorageReference *))completion; |
| 115 | + |
| 116 | +/** |
| 117 | + * Sets the image view's image to an image downloaded from the Firebase Storage reference. |
| 118 | + * Must be invoked on the main queue. |
| 119 | + * |
| 120 | + * @param storageRef A Firebase Storage reference containing an image. |
| 121 | + * @param size The maximum size of the downloaded image. If the downloaded image |
| 122 | + * exceeds this size, an error will be raised in the completion block. |
| 123 | + * @param placeholder An image to display while the download is in progress. |
| 124 | + * @param cache An image cache to check for images before downloading. |
| 125 | + * @param completion A closure to handle events when the image finishes downloading. |
| 126 | + * @return Returns a FIRStorageDownloadTask if a download was created (i.e. image |
| 127 | + * could not be found in cache). |
| 128 | + */ |
| 129 | +- (nullable FIRStorageDownloadTask *)sd_setImageWithStorageReference:(FIRStorageReference *)storageRef |
| 130 | + maxImageSize:(UInt64)size |
| 131 | + placeholderImage:(nullable UIImage *)placeholder |
| 132 | + cache:(nullable SDImageCache *)cache |
| 133 | + completion:(void (^_Nullable)(UIImage *_Nullable, |
| 134 | + NSError *_Nullable, |
| 135 | + SDImageCacheType, |
| 136 | + FIRStorageReference *))completion; |
| 137 | + |
| 138 | +/** |
| 139 | + * Sets the image view's image to an image downloaded from the Firebase Storage reference. |
| 140 | + * Must be invoked on the main queue. |
| 141 | + * |
| 142 | + * @param storageRef A Firebase Storage reference containing an image. |
| 143 | + * @param size The maximum size of the downloaded image. If the downloaded image |
| 144 | + * exceeds this size, an error will be raised in the completion block. |
| 145 | + * @param placeholder An image to display while the download is in progress. |
| 146 | + * @param cache An image cache to check for images before downloading. |
| 147 | + * @param completion A closure to handle events when the image finishes downloading. |
| 148 | + * @param customKey An custom caching key to append to the storage path. |
| 149 | + * @return Returns a FIRStorageDownloadTask if a download was created (i.e. image |
| 150 | + * could not be found in cache). |
| 151 | + */ |
| 152 | +- (nullable FIRStorageDownloadTask *)sd_setImageWithStorageReference:(FIRStorageReference *)storageRef |
| 153 | + maxImageSize:(UInt64)size |
| 154 | + placeholderImage:(nullable UIImage *)placeholder |
| 155 | + cache:(nullable SDImageCache *)cache |
| 156 | + completion:(void (^_Nullable)(UIImage *_Nullable, |
| 157 | + NSError *_Nullable, |
| 158 | + SDImageCacheType, |
| 159 | + FIRStorageReference *))completion |
| 160 | + customKey:(NSString*)customKey; |
| 161 | + |
| 162 | +@end |
| 163 | + |
| 164 | +NS_ASSUME_NONNULL_END |
0 commit comments