Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 9 additions & 12 deletions Libraries/FBLazyVector/FBLazyVector/FBLazyIterator.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ class LazyIterator {
LazyIterator() = default;

LazyIterator(U vector, convert_type convert, size_type i)
: _v(vector), _i(i), _convert(std::move(convert)) {}
: _v(vector), _i(i), _convert(std::move(convert)) {}

bool operator==(const LazyIterator &other) const {
return _i == other._i && _v == other._v;
Expand Down Expand Up @@ -98,33 +98,30 @@ class LazyIterator {
};

template <typename T, typename U>
LazyIterator<T, U> operator+(typename LazyIterator<T, U>::difference_type n,
const LazyIterator<T, U> &i) {
LazyIterator<T, U> operator+(
typename LazyIterator<T, U>::difference_type n,
const LazyIterator<T, U> &i) {
return i + n;
}

template <typename T, typename U>
bool operator!=(const LazyIterator<T, U> &a,
const LazyIterator<T, U> &b) {
bool operator!=(const LazyIterator<T, U> &a, const LazyIterator<T, U> &b) {
return !(a == b);
}

template <typename T, typename U>
bool operator<=(const LazyIterator<T, U> &a,
const LazyIterator<T, U> &b) {
bool operator<=(const LazyIterator<T, U> &a, const LazyIterator<T, U> &b) {
return a < b || a == b;
}

template <typename T, typename U>
bool operator>(const LazyIterator<T, U> &a,
const LazyIterator<T, U> &b) {
bool operator>(const LazyIterator<T, U> &a, const LazyIterator<T, U> &b) {
return b < a;
}

template <typename T, typename U>
bool operator>=(const LazyIterator<T, U> &a,
const LazyIterator<T, U> &b) {
bool operator>=(const LazyIterator<T, U> &a, const LazyIterator<T, U> &b) {
return a > b || a == b;
}

}
} // namespace FB
15 changes: 9 additions & 6 deletions Libraries/FBLazyVector/FBLazyVector/FBLazyVector.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,9 @@
namespace FB {

/**
* Presents a type-safe wrapper around an arbitrary object that represents an _immutable_ array of objects.
* Each item is constructed lazily on demand and reconstructed on each access; there is no caching.
* Presents a type-safe wrapper around an arbitrary object that represents an
* _immutable_ array of objects. Each item is constructed lazily on demand and
* reconstructed on each access; there is no caching.
*/
template <typename T, typename U>
class LazyVector {
Expand All @@ -30,7 +31,8 @@ class LazyVector {
using size_type = std::int32_t;
using convert_type = std::function<T(U)>;

static LazyVector<T, U> fromUnsafeRawValue(U v, size_type size, convert_type convert) {
static LazyVector<T, U>
fromUnsafeRawValue(U v, size_type size, convert_type convert) {
return {v, size, convert};
}

Expand All @@ -48,7 +50,8 @@ class LazyVector {

const_reference at(size_type pos) const {
#ifndef _LIBCPP_NO_EXCEPTIONS
if (!(pos < _size)) throw std::out_of_range("out of range");
if (!(pos < _size))
throw std::out_of_range("out of range");
#else
assert(pos < _size || !"out of range");
#endif
Expand Down Expand Up @@ -89,11 +92,11 @@ class LazyVector {
private:
/** Wrapped vector */
LazyVector(U vector, size_type size, convert_type convert)
: _v(vector), _size(size), _convert(convert) {}
: _v(vector), _size(size), _convert(convert) {}

U _v;
size_type _size;
convert_type _convert;
};

}
} // namespace FB
10 changes: 4 additions & 6 deletions Libraries/Image/RCTImageCache.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,16 @@
* LICENSE file in the root directory of this source tree.
*/

#import <UIKit/UIKit.h>
#import <Foundation/Foundation.h>
#import <UIKit/UIKit.h>

#import <React/RCTResizeMode.h>

@interface UIImage (React)

/**
* Memory bytes of the image with the default calculation of static image or GIF. Custom calculations of decoded bytes can be assigned manually.
* Memory bytes of the image with the default calculation of static image or GIF. Custom calculations of decoded bytes
* can be assigned manually.
*/
@property (nonatomic, assign) NSInteger reactDecodedImageBytes;

Expand All @@ -24,10 +25,7 @@
*/
@protocol RCTImageCache <NSObject>

- (UIImage *)imageForUrl:(NSString *)url
size:(CGSize)size
scale:(CGFloat)scale
resizeMode:(RCTResizeMode)resizeMode;
- (UIImage *)imageForUrl:(NSString *)url size:(CGSize)size scale:(CGFloat)scale resizeMode:(RCTResizeMode)resizeMode;

- (void)addImageToCache:(UIImage *)image
URL:(NSString *)url
Expand Down
2 changes: 1 addition & 1 deletion Libraries/Image/RCTImageDataDecoder.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@
#import <UIKit/UIKit.h>

#import <React/RCTBridge.h>
#import <React/RCTImageURLLoader.h>
#import <React/RCTResizeMode.h>
#import <React/RCTURLRequestHandler.h>
#import <React/RCTImageURLLoader.h>

/**
* Provides the interface needed to register an image decoder. Image decoders
Expand Down
14 changes: 7 additions & 7 deletions Libraries/Image/RCTImageLoader.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,20 +9,20 @@

#import <React/RCTBridge.h>
#import <React/RCTDefines.h>
#import <React/RCTResizeMode.h>
#import <React/RCTURLRequestHandler.h>
#import <React/RCTImageDataDecoder.h>
#import <React/RCTImageURLLoader.h>
#import <React/RCTImageCache.h>
#import <React/RCTImageLoaderProtocol.h>
#import <React/RCTImageDataDecoder.h>
#import <React/RCTImageLoaderLoggable.h>
#import <React/RCTImageLoaderProtocol.h>
#import <React/RCTImageURLLoader.h>
#import <React/RCTResizeMode.h>
#import <React/RCTURLRequestHandler.h>

@interface RCTImageLoader : NSObject <RCTBridgeModule, RCTImageLoaderProtocol, RCTImageLoaderLoggableProtocol>
- (instancetype)init;
- (instancetype)initWithRedirectDelegate:(id<RCTImageRedirectProtocol>)redirectDelegate NS_DESIGNATED_INITIALIZER;
- (instancetype)initWithRedirectDelegate:(id<RCTImageRedirectProtocol>)redirectDelegate
loadersProvider:(NSArray<id<RCTImageURLLoader>> * (^)(void))getLoaders
decodersProvider:(NSArray<id<RCTImageDataDecoder>> * (^)(void))getDecoders;
loadersProvider:(NSArray<id<RCTImageURLLoader>> * (^)(void))getLoaders
decodersProvider:(NSArray<id<RCTImageDataDecoder>> * (^)(void))getDecoders;
@end

/**
Expand Down
31 changes: 14 additions & 17 deletions Libraries/Image/RCTImageLoaderProtocol.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,11 @@
#import <UIKit/UIKit.h>

#import <React/RCTBridge.h>
#import <React/RCTResizeMode.h>
#import <React/RCTURLRequestHandler.h>
#import <React/RCTImageCache.h>
#import <React/RCTImageDataDecoder.h>
#import <React/RCTImageURLLoader.h>
#import <React/RCTImageCache.h>
#import <React/RCTResizeMode.h>
#import <React/RCTURLRequestHandler.h>

NS_ASSUME_NONNULL_BEGIN

Expand All @@ -34,12 +34,9 @@ NS_ASSUME_NONNULL_BEGIN
* Use PriorityPrefetch to prefetch images at a lower priority.
* The priority logic is up to each @RCTImageLoaderProtocol implementation
*/
typedef NS_ENUM(NSUInteger, RCTImageLoaderPriority) {
RCTImageLoaderPriorityImmediate,
RCTImageLoaderPriorityPrefetch
};
typedef NS_ENUM(NSUInteger, RCTImageLoaderPriority) { RCTImageLoaderPriorityImmediate, RCTImageLoaderPriorityPrefetch };

@protocol RCTImageLoaderProtocol<RCTURLRequestHandler>
@protocol RCTImageLoaderProtocol <RCTURLRequestHandler>

/**
* The maximum number of concurrent image loading tasks. Loading and decoding
Expand Down Expand Up @@ -80,14 +77,14 @@ typedef NS_ENUM(NSUInteger, RCTImageLoaderPriority) {
callback:(RCTImageLoaderCompletionBlock)callback;

/**
* As above, but includes target `size`, `scale` and `resizeMode`, which are used to
* select the optimal dimensions for the loaded image. The `clipped` option
* controls whether the image will be clipped to fit the specified size exactly,
* or if the original aspect ratio should be retained.
* `partialLoadBlock` is meant for custom image loaders that do not ship with the core RN library.
* It is meant to be called repeatedly while loading the image as higher quality versions are decoded,
* for instance with progressive JPEGs.
*/
* As above, but includes target `size`, `scale` and `resizeMode`, which are used to
* select the optimal dimensions for the loaded image. The `clipped` option
* controls whether the image will be clipped to fit the specified size exactly,
* or if the original aspect ratio should be retained.
* `partialLoadBlock` is meant for custom image loaders that do not ship with the core RN library.
* It is meant to be called repeatedly while loading the image as higher quality versions are decoded,
* for instance with progressive JPEGs.
*/
- (nullable RCTImageLoaderCancellationBlock)loadImageWithURLRequest:(NSURLRequest *)imageURLRequest
size:(CGSize)size
scale:(CGFloat)scale
Expand Down Expand Up @@ -116,7 +113,7 @@ typedef NS_ENUM(NSUInteger, RCTImageLoaderPriority) {
* the information, and won't decode the image if it doesn't have to.
*/
- (RCTImageLoaderCancellationBlock)getImageSizeForURLRequest:(NSURLRequest *)imageURLRequest
block:(void(^)(NSError *error, CGSize size))completionBlock;
block:(void (^)(NSError *error, CGSize size))completionBlock;
/**
* Determines whether given image URLs are cached locally. The `requests` array is expected
* to contain objects convertible to NSURLRequest. The return value maps URLs to strings:
Expand Down
4 changes: 2 additions & 2 deletions Libraries/Image/RCTImageLoaderWithAttributionProtocol.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
RCT_EXTERN BOOL RCTImageLoadingPerfInstrumentationEnabled(void);
RCT_EXTERN void RCTEnableImageLoadingPerfInstrumentation(BOOL enabled);

@protocol RCTImageLoaderWithAttributionProtocol<RCTImageLoaderProtocol, RCTImageLoaderLoggableProtocol>
@protocol RCTImageLoaderWithAttributionProtocol <RCTImageLoaderProtocol, RCTImageLoaderLoggableProtocol>

// TODO (T61325135): Remove C++ checks
#ifdef __cplusplus
Expand All @@ -26,7 +26,7 @@ RCT_EXTERN void RCTEnableImageLoadingPerfInstrumentation(BOOL enabled);
scale:(CGFloat)scale
clipped:(BOOL)clipped
resizeMode:(RCTResizeMode)resizeMode
priority: (RCTImageLoaderPriority)priority
priority:(RCTImageLoaderPriority)priority
attribution:(const facebook::react::ImageURLLoaderAttribution &)attribution
progressBlock:(RCTImageLoaderProgressBlock)progressBlock
partialLoadBlock:(RCTImageLoaderPartialLoadBlock)partialLoadBlock
Expand Down
19 changes: 11 additions & 8 deletions Libraries/Image/RCTImageURLLoader.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,13 @@ NS_ASSUME_NONNULL_BEGIN

typedef void (^RCTImageLoaderProgressBlock)(int64_t progress, int64_t total);
typedef void (^RCTImageLoaderPartialLoadBlock)(UIImage *image);
typedef void (^RCTImageLoaderCompletionBlock)(NSError * _Nullable error, UIImage * _Nullable image);
typedef void (^RCTImageLoaderCompletionBlock)(NSError *_Nullable error, UIImage *_Nullable image);
// Metadata is passed as a id in an additional parameter because there are forks of RN without this parameter,
// and the complexity of RCTImageLoader would make using protocols here difficult to typecheck.
typedef void (^RCTImageLoaderCompletionBlockWithMetadata)(NSError * _Nullable error, UIImage * _Nullable image, id _Nullable metadata);
typedef void (^RCTImageLoaderCompletionBlockWithMetadata)(
NSError *_Nullable error,
UIImage *_Nullable image,
id _Nullable metadata);
typedef dispatch_block_t RCTImageLoaderCancellationBlock;

/**
Expand All @@ -41,12 +44,12 @@ typedef dispatch_block_t RCTImageLoaderCancellationBlock;
* applicable.
*/
- (nullable RCTImageLoaderCancellationBlock)loadImageForURL:(NSURL *)imageURL
size:(CGSize)size
scale:(CGFloat)scale
resizeMode:(RCTResizeMode)resizeMode
progressHandler:(RCTImageLoaderProgressBlock)progressHandler
partialLoadHandler:(RCTImageLoaderPartialLoadBlock)partialLoadHandler
completionHandler:(RCTImageLoaderCompletionBlock)completionHandler;
size:(CGSize)size
scale:(CGFloat)scale
resizeMode:(RCTResizeMode)resizeMode
progressHandler:(RCTImageLoaderProgressBlock)progressHandler
partialLoadHandler:(RCTImageLoaderPartialLoadBlock)partialLoadHandler
completionHandler:(RCTImageLoaderCompletionBlock)completionHandler;

@optional

Expand Down
10 changes: 6 additions & 4 deletions Libraries/Image/RCTImageURLLoaderWithAttribution.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@
* LICENSE file in the root directory of this source tree.
*/

#import <React/RCTImageURLLoader.h>
#import <React/RCTImageLoaderProtocol.h>
#import <React/RCTImageLoaderLoggable.h>
#import <React/RCTImageLoaderProtocol.h>
#import <React/RCTImageURLLoader.h>

// TODO (T61325135): Remove C++ checks
#ifdef __cplusplus
Expand All @@ -31,7 +31,9 @@ struct ImageURLLoaderAttribution {
@property (nonatomic, strong, readonly) NSURL *imageURL;
@property (nonatomic, copy, readonly) RCTImageLoaderCancellationBlock cancellationBlock;

- (instancetype)initWithRequestId:(NSString *)requestId imageURL:(NSURL *)imageURL cancellationBlock:(RCTImageLoaderCancellationBlock)cancellationBlock;
- (instancetype)initWithRequestId:(NSString *)requestId
imageURL:(NSURL *)imageURL
cancellationBlock:(RCTImageLoaderCancellationBlock)cancellationBlock;
- (void)cancel;

@end
Expand All @@ -53,7 +55,7 @@ struct ImageURLLoaderAttribution {
scale:(CGFloat)scale
resizeMode:(RCTResizeMode)resizeMode
requestId:(NSString *)requestId
priority: (RCTImageLoaderPriority)priority
priority:(RCTImageLoaderPriority)priority
attribution:(const facebook::react::ImageURLLoaderAttribution &)attribution
progressHandler:(RCTImageLoaderProgressBlock)progressHandler
partialLoadHandler:(RCTImageLoaderPartialLoadBlock)partialLoadHandler
Expand Down
37 changes: 19 additions & 18 deletions Libraries/Image/RCTImageUtils.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,35 +18,40 @@ NS_ASSUME_NONNULL_BEGIN
* calculates the rectangle to draw the image into so that it will be sized and
* positioned correctly according to the specified resizeMode.
*/
RCT_EXTERN CGRect RCTTargetRect(CGSize sourceSize, CGSize destSize,
CGFloat destScale, RCTResizeMode resizeMode);
RCT_EXTERN CGRect RCTTargetRect(CGSize sourceSize, CGSize destSize, CGFloat destScale, RCTResizeMode resizeMode);

/**
* This function takes a source size (typically from an image), a target rect
* that it will be drawn into (typically relative to a CGContext), and works out
* the transform needed to draw the image at the correct scale and position.
*/
RCT_EXTERN CGAffineTransform RCTTransformFromTargetRect(CGSize sourceSize,
CGRect targetRect);
RCT_EXTERN CGAffineTransform RCTTransformFromTargetRect(CGSize sourceSize, CGRect targetRect);

/**
* This function takes an input content size & scale (typically from an image),
* a target size & scale at which it will be displayed (typically in a
* UIImageView) and then calculates the optimal size at which to redraw the
* image so that it will be displayed correctly with the specified resizeMode.
*/
RCT_EXTERN CGSize RCTTargetSize(CGSize sourceSize, CGFloat sourceScale,
CGSize destSize, CGFloat destScale,
RCTResizeMode resizeMode, BOOL allowUpscaling);
RCT_EXTERN CGSize RCTTargetSize(
CGSize sourceSize,
CGFloat sourceScale,
CGSize destSize,
CGFloat destScale,
RCTResizeMode resizeMode,
BOOL allowUpscaling);

/**
* This function takes an input content size & scale (typically from an image),
* a target size & scale that it will be displayed at, and determines if the
* source will need to be upscaled to fit (which may result in pixelization).
*/
RCT_EXTERN BOOL RCTUpscalingRequired(CGSize sourceSize, CGFloat sourceScale,
CGSize destSize, CGFloat destScale,
RCTResizeMode resizeMode);
RCT_EXTERN BOOL RCTUpscalingRequired(
CGSize sourceSize,
CGFloat sourceScale,
CGSize destSize,
CGFloat destScale,
RCTResizeMode resizeMode);

/**
* This function takes the source data for an image and decodes it at the
Expand All @@ -55,10 +60,8 @@ RCT_EXTERN BOOL RCTUpscalingRequired(CGSize sourceSize, CGFloat sourceScale,
* width/height of the returned image is guaranteed to be >= destSize.
* Pass a destSize of CGSizeZero to decode the image at its original size.
*/
RCT_EXTERN UIImage *__nullable RCTDecodeImageWithData(NSData *data,
CGSize destSize,
CGFloat destScale,
RCTResizeMode resizeMode);
RCT_EXTERN UIImage *__nullable
RCTDecodeImageWithData(NSData *data, CGSize destSize, CGFloat destScale, RCTResizeMode resizeMode);

/**
* This function takes the source data for an image and decodes just the
Expand All @@ -80,10 +83,8 @@ RCT_EXTERN NSData *__nullable RCTGetImageData(UIImage *image, float quality);
* and `destScale` is its scale. The `transform` argument controls how the
* source image will be mapped to the destination image.
*/
RCT_EXTERN UIImage *__nullable RCTTransformImage(UIImage *image,
CGSize destSize,
CGFloat destScale,
CGAffineTransform transform);
RCT_EXTERN UIImage *__nullable
RCTTransformImage(UIImage *image, CGSize destSize, CGFloat destScale, CGAffineTransform transform);

/*
* Return YES if image has an alpha component
Expand Down
Loading