diff --git a/ios/sdk/component/view/HippyBackgroundImageCacheManager.m b/ios/sdk/component/view/HippyBackgroundImageCacheManager.m index 8710121c483..caf748c7733 100644 --- a/ios/sdk/component/view/HippyBackgroundImageCacheManager.m +++ b/ios/sdk/component/view/HippyBackgroundImageCacheManager.m @@ -69,7 +69,7 @@ - (void)imageWithUrl:(NSString *)uri completionHandler:(HippyBackgroundImageComp BOOL fileExist = [[NSFileManager defaultManager] fileExistsAtPath:localPath isDirectory:&isDirectory]; if (fileExist && !isDirectory) { NSData *imageData = [NSData dataWithContentsOfFile:localPath]; - UIImage *image = [UIImage imageWithData:imageData]; + UIImage *image = [UIImage imageWithData:imageData scale:[UIScreen mainScreen].scale]; completionHandler(image, nil); } else { diff --git a/ios/sdk/component/view/HippyView.h b/ios/sdk/component/view/HippyView.h index 4aa67f90f88..31563d3dd42 100644 --- a/ios/sdk/component/view/HippyView.h +++ b/ios/sdk/component/view/HippyView.h @@ -20,8 +20,6 @@ * limitations under the License. */ -#import "HippyView.h" - #import #import "HippyBorderStyle.h" @@ -30,11 +28,15 @@ @protocol HippyAutoInsetsProtocol; -@class HippyView; @class HippyGradientObject; +@class HippyBridge; @interface HippyView : UIView +- (instancetype)initWithBridge:(HippyBridge *)bridge; + +@property (nonatomic, weak) HippyBridge *bridge; + /** * Used to control how touch events are processed. */ diff --git a/ios/sdk/component/view/HippyView.m b/ios/sdk/component/view/HippyView.m index e1c960fb21c..b7203b8be9b 100644 --- a/ios/sdk/component/view/HippyView.m +++ b/ios/sdk/component/view/HippyView.m @@ -30,6 +30,7 @@ #import "UIView+Hippy.h" #import "HippyBackgroundImageCacheManager.h" #import "HippyGradientObject.h" +#import "HippyBridge.h" static CGSize makeSizeConstrainWithType(CGSize originSize, CGSize constrainSize, NSString *resizeMode) { // width / height @@ -56,7 +57,7 @@ static CGSize makeSizeConstrainWithType(CGSize originSize, CGSize constrainSize, return originSize; } -dispatch_queue_t global_hpview_queue() { +dispatch_queue_t global_hpview_queue(void) { static dispatch_queue_t g_background_queue = nil; static dispatch_once_t onceToken; dispatch_once(&onceToken, ^{ @@ -167,6 +168,14 @@ @implementation HippyView { @synthesize hippyZIndex = _hippyZIndex; +- (instancetype)initWithBridge:(HippyBridge *)bridge { + self = [super init]; + if (self) { + self.bridge = bridge; + } + return self; +} + - (instancetype)initWithFrame:(CGRect)frame { if ((self = [super initWithFrame:frame])) { _borderWidth = -1; @@ -667,6 +676,7 @@ - (BOOL)getLayerContentForColor:(UIColor *)color completionBlock:(void (^)(UIIma - (HippyBackgroundImageCacheManager *)backgroundCachemanager { if (!_backgroundCachemanager) { _backgroundCachemanager = [[HippyBackgroundImageCacheManager alloc] init]; + _backgroundCachemanager.bridge = [self bridge]; } return _backgroundCachemanager; } diff --git a/ios/sdk/component/view/HippyViewManager.mm b/ios/sdk/component/view/HippyViewManager.mm index b7cdeeb04b1..23b3b91c4f9 100644 --- a/ios/sdk/component/view/HippyViewManager.mm +++ b/ios/sdk/component/view/HippyViewManager.mm @@ -47,7 +47,7 @@ - (dispatch_queue_t)methodQueue { } - (UIView *)view { - return [HippyView new]; + return [[HippyView alloc] initWithBridge:self.bridge]; } - (HippyShadowView *)shadowView { @@ -89,9 +89,13 @@ - (HippyViewManagerUIBlock)uiBlockToAmendWithShadowViewRegistry:(__unused NSDict if (json) { NSString *backgroundImage = [HippyConvert NSString:json]; if ([backgroundImage hasPrefix:@"http"] || - [backgroundImage hasPrefix:@"data:image/"]) { + [backgroundImage hasPrefix:@"data:image/"] || + [backgroundImage hasPrefix:@"hpfile://"]) { view.backgroundImageUrl = backgroundImage; } + else { + HippyAssert(NO, @"backgroundImage %@ not supported", backgroundImage); + } } }