mirror of
https://github.com/status-im/react-native.git
synced 2025-01-10 01:25:39 +00:00
4c83237511
Summary: This adds a new resize mode for iOS 'repeat' that tiles the image over it's frame. This allow to easily create a view with a repeating background pattern which there is no way to do at the moment without including a bunch of different sized assets. I'm not 100% sure it should be a resizeMode or a separate prop but I went with resizeMode since it made more sense to me and the are not really any use cases where we'd want to use this with another resizeMode other than 'stretch'. **Test plan** Tested mainly by adding a UIExplorer example, also tested that changing the resizeMode prop from and to 'repeat' worked properly. ![screen shot 2016-06-07 at 3 06 17 am](https://cloud.githubusercontent.com/assets/2677334/15848755/d95d8046-2c5c-11e6-9f3d-1ce8a1c9c846.png) I'd like to implement this on Android too but it is a bit trickier since Fresco's ImageView doesn't support image tiling and would require submitting a PR there too :( Closes https://github.com/facebook/react-native/pull/7968 Differential Revision: D3469119 Pulled By: javache fbshipit-source-id: ab9dbfe448a5b0771dbf0c41fcceeb366210f583
81 lines
3.0 KiB
Objective-C
81 lines
3.0 KiB
Objective-C
/**
|
|
* Copyright (c) 2015-present, Facebook, Inc.
|
|
* All rights reserved.
|
|
*
|
|
* This source code is licensed under the BSD-style license found in the
|
|
* LICENSE file in the root directory of this source tree. An additional grant
|
|
* of patent rights can be found in the PATENTS file in the same directory.
|
|
*/
|
|
|
|
#import "RCTImageViewManager.h"
|
|
|
|
#import <UIKit/UIKit.h>
|
|
|
|
#import "RCTConvert.h"
|
|
#import "RCTImageLoader.h"
|
|
#import "RCTImageSource.h"
|
|
#import "RCTImageView.h"
|
|
|
|
@implementation RCTImageViewManager
|
|
|
|
RCT_EXPORT_MODULE()
|
|
|
|
- (UIView *)view
|
|
{
|
|
return [[RCTImageView alloc] initWithBridge:self.bridge];
|
|
}
|
|
|
|
RCT_EXPORT_VIEW_PROPERTY(blurRadius, CGFloat)
|
|
RCT_EXPORT_VIEW_PROPERTY(capInsets, UIEdgeInsets)
|
|
RCT_REMAP_VIEW_PROPERTY(defaultSource, defaultImage, UIImage)
|
|
RCT_EXPORT_VIEW_PROPERTY(onLoadStart, RCTDirectEventBlock)
|
|
RCT_EXPORT_VIEW_PROPERTY(onProgress, RCTDirectEventBlock)
|
|
RCT_EXPORT_VIEW_PROPERTY(onError, RCTDirectEventBlock)
|
|
RCT_EXPORT_VIEW_PROPERTY(onLoad, RCTDirectEventBlock)
|
|
RCT_EXPORT_VIEW_PROPERTY(onLoadEnd, RCTDirectEventBlock)
|
|
RCT_EXPORT_VIEW_PROPERTY(resizeMode, RCTResizeMode)
|
|
RCT_EXPORT_VIEW_PROPERTY(source, RCTImageSource)
|
|
RCT_CUSTOM_VIEW_PROPERTY(tintColor, UIColor, RCTImageView)
|
|
{
|
|
// Default tintColor isn't nil - it's inherited from the superView - but we
|
|
// want to treat a null json value for `tintColor` as meaning 'disable tint',
|
|
// so we toggle `renderingMode` here instead of in `-[RCTImageView setTintColor:]`
|
|
view.tintColor = [RCTConvert UIColor:json] ?: defaultView.tintColor;
|
|
view.renderingMode = json ? UIImageRenderingModeAlwaysTemplate : defaultView.renderingMode;
|
|
}
|
|
|
|
RCT_EXPORT_METHOD(getSize:(NSURLRequest *)request
|
|
successBlock:(RCTResponseSenderBlock)successBlock
|
|
errorBlock:(RCTResponseErrorBlock)errorBlock)
|
|
{
|
|
[self.bridge.imageLoader getImageSizeForURLRequest:request
|
|
block:^(NSError *error, CGSize size) {
|
|
if (error) {
|
|
errorBlock(error);
|
|
} else {
|
|
successBlock(@[@(size.width), @(size.height)]);
|
|
}
|
|
}];
|
|
}
|
|
|
|
RCT_EXPORT_METHOD(prefetchImage:(NSURLRequest *)request
|
|
resolve:(RCTPromiseResolveBlock)resolve
|
|
reject:(RCTPromiseRejectBlock)reject)
|
|
{
|
|
if (!request) {
|
|
reject(@"E_INVALID_URI", @"Cannot prefetch an image for an empty URI", nil);
|
|
return;
|
|
}
|
|
|
|
[self.bridge.imageLoader loadImageWithURLRequest:request
|
|
callback:^(NSError *error, UIImage *image) {
|
|
if (error) {
|
|
reject(@"E_PREFETCH_FAILURE", nil, error);
|
|
return;
|
|
}
|
|
resolve(@YES);
|
|
}];
|
|
}
|
|
|
|
@end
|