diff --git a/doric-demo/src/ImageDemo.ts b/doric-demo/src/ImageDemo.ts index bdedd666..36a7f160 100644 --- a/doric-demo/src/ImageDemo.ts +++ b/doric-demo/src/ImageDemo.ts @@ -119,9 +119,9 @@ class ImageDemo extends Panel { scaleType: ScaleType.ScaleToFill, layoutConfig: layoutConfig().just(), stretchInset: { - left: 374, + left: 125, top: 0, - right: 66, + right: 22, bottom: 0 } }) diff --git a/doric-iOS/Pod/Classes/Shader/DoricImageNode.m b/doric-iOS/Pod/Classes/Shader/DoricImageNode.m index c9c965b8..c33a2921 100644 --- a/doric-iOS/Pod/Classes/Shader/DoricImageNode.m +++ b/doric-iOS/Pod/Classes/Shader/DoricImageNode.m @@ -40,6 +40,7 @@ @interface DoricImageNode () @property(nonatomic, strong) NSNumber *errorColor; @property(nonatomic, strong) NSString *errorImage; @property(nonatomic, strong) UIVisualEffectView *blurEffectView; +@property(nonatomic, strong) NSDictionary *stretchInsetDic; @end @implementation DoricImageNode @@ -227,16 +228,20 @@ - (void)blendView:(UIImageView *)view forPropName:(NSString *)name propValue:(id } } } else if ([@"stretchInset" isEqualToString:name]) { - NSDictionary * stretchInsetDic = (NSDictionary *)prop; - CGFloat left = [stretchInsetDic[@"left"] floatValue]; - CGFloat top = [stretchInsetDic[@"top"] floatValue]; - CGFloat right = [stretchInsetDic[@"right"] floatValue]; - CGFloat bottom = [stretchInsetDic[@"bottom"] floatValue]; - UIImage *scaled = [[UIImage alloc] initWithCGImage:view.image.CGImage scale:[[UIScreen mainScreen] scale] orientation:view.image.imageOrientation]; - UIImage *result = [scaled resizableImageWithCapInsets:UIEdgeInsetsMake(0, 125, 0, 22) resizingMode:UIImageResizingModeStretch]; - view.image = result; + self.stretchInsetDic = (NSDictionary *)prop; } else { [super blendView:view forPropName:name propValue:prop]; } } + +- (void)afterBlended:(NSDictionary *)props { + if (self.stretchInsetDic != nil) { + CGFloat left = [self.stretchInsetDic[@"left"] floatValue]; + CGFloat top = [self.stretchInsetDic[@"top"] floatValue]; + CGFloat right = [self.stretchInsetDic[@"right"] floatValue]; + CGFloat bottom = [self.stretchInsetDic[@"bottom"] floatValue]; + UIImage *result = [self.view.image resizableImageWithCapInsets:UIEdgeInsetsMake(top, left, bottom, right) resizingMode:UIImageResizingModeStretch]; + self.view.image = result; + } +} @end