Skip to content

Commit

Permalink
Merge branch 'main' into feature/update-vue-docs
Browse files Browse the repository at this point in the history
  • Loading branch information
open-hippy authored Nov 6, 2023
2 parents 94dc5ec + 47869b8 commit 1b15e99
Show file tree
Hide file tree
Showing 10 changed files with 150 additions and 289 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -22,18 +22,18 @@

#import <UIKit/UIKit.h>
#import "HippyImageProviderProtocol.h"
#import "NativeRenderAnimatedImageView.h"
#import "HippyAnimatedImageView.h"

extern const NSTimeInterval kAnimatedImageDelayTimeIntervalMinimum;

//
// An `NativeRenderAnimatedImage`'s job is to deliver frames in a highly performant way and works in conjunction with `NativeRenderAnimatedImageView`.
// An `HippyAnimatedImage`'s job is to deliver frames in a highly performant way and works in conjunction with `HippyAnimatedImageView`.
// It subclasses `NSObject` and not `UIImage` because it's only an "image" in the sense that a sea lion is a lion.
// It tries to intelligently choose the frame cache size depending on the image and memory situation with the goal to lower CPU usage for smaller
// ones, lower memory usage for larger ones and always deliver frames for high performant play-back. Note: `posterImage`, `size`, `loopCount`,
// `delayTimes` and `frameCount` don't change after successful initialization.
//
@interface NativeRenderAnimatedImage : NSObject
@interface HippyAnimatedImage : NSObject

@property (nonatomic, strong, readonly) UIImage *posterImage; // Guaranteed to be loaded; usually equivalent to `-imageLazilyCachedAtIndex:0`
@property (nonatomic, assign, readonly) CGSize size; // The `.posterImage`'s `.size`
Expand All @@ -51,7 +51,7 @@ extern const NSTimeInterval kAnimatedImageDelayTimeIntervalMinimum;
// After an initial loading time, depending on `frameCacheSize`, frames should be available immediately from the cache.
- (UIImage *)imageLazilyCachedAtIndex:(NSUInteger)index;

// Pass either a `UIImage` or an `NativeRenderAnimatedImage` and get back its size
// Pass either a `UIImage` or an `HippyAnimatedImage` and get back its size
+ (CGSize)sizeForImage:(id)image;

- (UIImage *)imageAtIndex:(NSUInteger)index;
Expand All @@ -62,7 +62,7 @@ extern const NSTimeInterval kAnimatedImageDelayTimeIntervalMinimum;
predrawingEnabled:(BOOL)isPredrawingEnabled;
+ (instancetype)animatedImageWithAnimatedImageProvider:(id<HippyImageProviderProtocol>)imageProvider;

// On success, the initializers return an `NativeRenderAnimatedImage` with all fields initialized, on failure they return `nil` and an error will be logged.
// On success, the initializers return an `HippyAnimatedImage` with all fields initialized, on failure they return `nil` and an error will be logged.
- (instancetype)initWithAnimatedGIFData:(NSData *)data;
// Pass 0 for optimalFrameCacheSize to get the default, predrawing is enabled by default.
- (instancetype)initWithAnimatedGIFData:(NSData *)data
Expand All @@ -84,18 +84,13 @@ typedef NS_ENUM(NSUInteger, RAILogLevel) {
RAILogLevelVerbose
};

@interface NativeRenderAnimatedImage (Logging)
@interface HippyAnimatedImage (Logging)

+ (void)setLogBlock:(void (^)(NSString *logString, RAILogLevel logLevel))logBlock logLevel:(RAILogLevel)logLevel;
+ (void)logStringFromBlock:(NSString * (^)(void))stringBlock withLevel:(RAILogLevel)level;

@end

#define RAILog(logLevel, format, ...)
//[NativeRenderAnimatedImage logStringFromBlock:^NSString *{ return [NSString stringWithFormat:(format), ## __VA_ARGS__]; } withLevel:(logLevel)]
//[HippyAnimatedImage logStringFromBlock:^NSString *{ return [NSString stringWithFormat:(format), ## __VA_ARGS__]; } withLevel:(logLevel)]

@interface NativeRenderWeakProxy : NSProxy

+ (instancetype)weakProxyForObject:(id)targetObject;

@end

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -22,19 +22,19 @@

#import <UIKit/UIKit.h>

@class NativeRenderAnimatedImage;
@class HippyAnimatedImage;
//
// An `NativeRenderAnimatedImageView` can take an `NativeRenderAnimatedImage` and plays it automatically when in view hierarchy and stops when removed.
// An `HippyAnimatedImageView` can take an `HippyAnimatedImage` and plays it automatically when in view hierarchy and stops when removed.
// The animation can also be controlled with the `UIImageView` methods `-start/stop/isAnimating`.
// It is a fully compatible `UIImageView` subclass and can be used as a drop-in component to work with existing code paths expecting to display a
// `UIImage`. Under the hood it uses a `CADisplayLink` for playback, which can be inspected with `currentFrame` & `currentFrameIndex`.
//
@interface NativeRenderAnimatedImageView : UIImageView
@interface HippyAnimatedImageView : UIImageView

// Setting `[UIImageView.image]` to a non-`nil` value clears out existing `animatedImage`.
// And vice versa, setting `animatedImage` will initially populate the `[UIImageView.image]` to its `posterImage` and then start animating and hold
// `currentFrame`.
@property (nonatomic, strong) NativeRenderAnimatedImage *animatedImage;
@property (nonatomic, strong) HippyAnimatedImage *animatedImage;
@property (nonatomic, copy) void (^loopCompletionBlock)(NSUInteger loopCountRemaining);

@property (nonatomic, strong, readonly) UIImage *currentFrame;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,11 @@
* limitations under the License.
*/

#import "NativeRenderAnimatedImageView.h"
#import "NativeRenderAnimatedImage.h"
#import "HippyAnimatedImageView.h"
#import "HippyAnimatedImage.h"
#import "HippyWeakProxy.h"

@interface NativeRenderAnimatedImageView ()
@interface HippyAnimatedImageView ()

// Override of public `readonly` properties as private `readwrite`
@property (nonatomic, strong, readwrite) UIImage *currentFrame;
Expand All @@ -39,7 +40,7 @@ @interface NativeRenderAnimatedImageView ()

@end

@implementation NativeRenderAnimatedImageView
@implementation HippyAnimatedImageView
@synthesize runLoopMode = _runLoopMode;

#pragma mark - Initializers
Expand Down Expand Up @@ -90,7 +91,7 @@ - (void)commonInit {
#pragma mark - Accessors
#pragma mark Public

- (void)setAnimatedImage:(NativeRenderAnimatedImage *)animatedImage {
- (void)setAnimatedImage:(HippyAnimatedImage *)animatedImage {
if (![_animatedImage isEqual:animatedImage]) {
if (animatedImage) {
// Clear out the image.
Expand Down Expand Up @@ -268,7 +269,7 @@ - (void)startAnimating {
// will retain its target until it is invalidated. We use a weak proxy so that the image view will get deallocated
// independent of the display link's lifetime. Upon image view deallocation, we invalidate the display
// link which will lead to the deallocation of both the display link and the weak proxy.
NativeRenderWeakProxy *weakProxy = [NativeRenderWeakProxy weakProxyForObject:self];
HippyWeakProxy *weakProxy = [HippyWeakProxy weakProxyForObject:self];
self.displayLink = [CADisplayLink displayLinkWithTarget:weakProxy selector:@selector(displayDidRefresh:)];

[self.displayLink addToRunLoop:[NSRunLoop mainRunLoop] forMode:self.runLoopMode];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,41 +23,41 @@
#import <UIKit/UIKit.h>
#import "HippyComponent.h"
#import "HippyConvert.h"
#import "NativeRenderAnimatedImageView.h"
#import "HippyAnimatedImageView.h"
#import "HippyImageProviderProtocol.h"

@class NativeRenderImageView;
@class HippyImageView;

@interface NativeRenderAnimatedImageOperation : NSOperation {
@interface HippyAnimatedImageOperation : NSOperation {
NSData *_animatedImageData;
NSString *_url;
__weak NativeRenderImageView *_imageView;
__weak HippyImageView *_imageView;
id<HippyImageProviderProtocol> _imageProvider;
}

- (id)initWithAnimatedImageData:(NSData *)data imageView:(NativeRenderImageView *)imageView imageURL:(NSString *)url;
- (id)initWithAnimatedImageProvider:(id<HippyImageProviderProtocol>)imageProvider imageView:(NativeRenderImageView *)imageView imageURL:(NSString *)url;
- (id)initWithAnimatedImageData:(NSData *)data imageView:(HippyImageView *)imageView imageURL:(NSString *)url;
- (id)initWithAnimatedImageProvider:(id<HippyImageProviderProtocol>)imageProvider imageView:(HippyImageView *)imageView imageURL:(NSString *)url;

@end

typedef NS_ENUM(NSInteger, NativeRenderResizeMode) {
NativeRenderResizeModeCover = UIViewContentModeScaleAspectFill,
NativeRenderResizeModeContain = UIViewContentModeScaleAspectFit,
NativeRenderResizeModeStretch = UIViewContentModeScaleToFill,
NativeRenderResizeModeCenter = UIViewContentModeCenter,
NativeRenderResizeModeRepeat = -1, // Use negative values to avoid conflicts with iOS enum values.
typedef NS_ENUM(NSInteger, HippyResizeMode) {
HippyResizeModeCover = UIViewContentModeScaleAspectFill,
HippyResizeModeContain = UIViewContentModeScaleAspectFit,
HippyResizeModeStretch = UIViewContentModeScaleToFill,
HippyResizeModeCenter = UIViewContentModeCenter,
HippyResizeModeRepeat = -1, // Use negative values to avoid conflicts with iOS enum values.
};

typedef NS_ENUM(NSInteger, NativeRenderShapeMode) {
NativeRenderResizeModeDefalt = 0,
NativeRenderResizeModeCircle,
typedef NS_ENUM(NSInteger, HippyShapeMode) {
HippyResizeModeDefalt = 0,
HippyResizeModeCircle,
};

@interface NativeRenderImageView : NativeRenderAnimatedImageView
@interface HippyImageView : HippyAnimatedImageView

@property (nonatomic, assign) CGFloat blurRadius;
@property (nonatomic, assign) UIEdgeInsets capInsets;
@property (nonatomic, assign) NativeRenderResizeMode resizeMode;
@property (nonatomic, assign) HippyResizeMode resizeMode;
@property (nonatomic, copy) NSArray *source;
@property (nonatomic, strong) UIImage *defaultImage;
@property (nonatomic, assign) UIImageRenderingMode renderingMode;
Expand All @@ -67,7 +67,7 @@ typedef NS_ENUM(NSInteger, NativeRenderShapeMode) {
@property (nonatomic, assign) CGFloat borderBottomLeftRadius;
@property (nonatomic, assign) CGFloat borderBottomRightRadius;
@property (nonatomic, assign) CGFloat borderRadius;
@property (nonatomic, assign) NativeRenderShapeMode shape;
@property (nonatomic, assign) HippyShapeMode shape;

@property (nonatomic, copy) HippyDirectEventBlock onLoadStart;
@property (nonatomic, copy) HippyDirectEventBlock onProgress;
Expand All @@ -86,9 +86,9 @@ typedef NS_ENUM(NSInteger, NativeRenderShapeMode) {
- (BOOL)needsUpdateCornerRadiusManully;
@end

@interface HippyConvert (NativeRenderResizeMode)
@interface HippyConvert (HippyResizeMode)

+ (NativeRenderResizeMode)NativeRenderResizeMode:(id)json;
+ (NativeRenderShapeMode)NativeRenderShapeMode:(id)json;
+ (HippyResizeMode)HippyResizeMode:(id)json;
+ (HippyShapeMode)HippyShapeMode:(id)json;

@end
Loading

0 comments on commit 1b15e99

Please sign in to comment.