Skip to content

Commit

Permalink
fixed view not loading when background image load fails (#1504)
Browse files Browse the repository at this point in the history
  • Loading branch information
jwoo-msft authored and Gilles Khouzam committed Jun 11, 2018
1 parent 2cc68ef commit fa2687f
Showing 1 changed file with 14 additions and 12 deletions.
26 changes: 14 additions & 12 deletions source/ios/AdaptiveCards/AdaptiveCards/AdaptiveCards/ACRView.mm
Expand Up @@ -99,21 +99,23 @@ - (UIView *)render
}
std::string backgroundImage = [_adaptiveCard card]->GetBackgroundImage();
NSString* imgUrl = nil;
if(!backgroundImage.empty())
if(!backgroundImage.empty()){
imgUrl = [[NSString alloc] initWithCString:backgroundImage.c_str() encoding:NSUTF8StringEncoding];
if (imgUrl)
{
}
if (imgUrl){
NSURL *url = [NSURL URLWithString:imgUrl];
UIImage *img = [UIImage imageWithData:[NSData dataWithContentsOfURL:url]];
UIImageView *imgView = [[UIImageView alloc] initWithImage:img];
[newView addSubview:imgView];
[newView sendSubviewToBack:imgView];
[newView setContentHuggingPriority:UILayoutPriorityDefaultLow forAxis:UILayoutConstraintAxisHorizontal];
[newView setContentHuggingPriority:UILayoutPriorityDefaultLow forAxis:UILayoutConstraintAxisVertical];
NSArray<NSString *> *visualFormats = [NSArray arrayWithObjects:@"H:|[imgView]", @"V:|[imgView]|", nil];
NSDictionary *viewMap = NSDictionaryOfVariableBindings(imgView);
for(NSString *constraint in visualFormats){
[NSLayoutConstraint activateConstraints:[NSLayoutConstraint constraintsWithVisualFormat:constraint options:0 metrics:nil views:viewMap]];
if(img){
UIImageView *imgView = [[UIImageView alloc] initWithImage:img];
[newView addSubview:imgView];
[newView sendSubviewToBack:imgView];
[newView setContentHuggingPriority:UILayoutPriorityDefaultLow forAxis:UILayoutConstraintAxisHorizontal];
[newView setContentHuggingPriority:UILayoutPriorityDefaultLow forAxis:UILayoutConstraintAxisVertical];
NSArray<NSString *> *visualFormats = [NSArray arrayWithObjects:@"H:|[imgView]", @"V:|[imgView]|", nil];
NSDictionary *viewMap = NSDictionaryOfVariableBindings(imgView);
for(NSString *constraint in visualFormats){
[NSLayoutConstraint activateConstraints:[NSLayoutConstraint constraintsWithVisualFormat:constraint options:0 metrics:nil views:viewMap]];
}
}
}
[self callDidLoadElementsIfNeeded];
Expand Down

0 comments on commit fa2687f

Please sign in to comment.