Skip to content

Commit

Permalink
fix(ios): fix bug when hippyview uses local image
Browse files Browse the repository at this point in the history
  • Loading branch information
ozonelmy authored and zoomchan-cxj committed Aug 9, 2021
1 parent c4808c8 commit 4849c26
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 7 deletions.
2 changes: 1 addition & 1 deletion ios/sdk/component/view/HippyBackgroundImageCacheManager.m
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
8 changes: 5 additions & 3 deletions ios/sdk/component/view/HippyView.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,6 @@
* limitations under the License.
*/

#import "HippyView.h"

#import <UIKit/UIKit.h>

#import "HippyBorderStyle.h"
Expand All @@ -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.
*/
Expand Down
12 changes: 11 additions & 1 deletion ios/sdk/component/view/HippyView.m
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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, ^{
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;
}
Expand Down
8 changes: 6 additions & 2 deletions ios/sdk/component/view/HippyViewManager.mm
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ - (dispatch_queue_t)methodQueue {
}

- (UIView *)view {
return [HippyView new];
return [[HippyView alloc] initWithBridge:self.bridge];
}

- (HippyShadowView *)shadowView {
Expand Down Expand Up @@ -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);
}
}
}

Expand Down

0 comments on commit 4849c26

Please sign in to comment.