Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -246,6 +246,7 @@
"spacing": 5
},
"media": {
"playButton" : "http://adaptivecards.io/content/adaptive-card-50.png",
"allowInlinePlayback" : true
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -50,10 +50,10 @@ - (UIView *)render:(UIView<ACRIContentHoldingView> *)viewGroup
ACRContentHoldingUIView *contentholdingview = nil;

// if poster is available, restrict the image size to the width of superview, and adjust the height accordingly
if(img) {
if (img) {
view = [[UIImageView alloc] initWithImage:img];

if(img.size.width > 0) {
if (img.size.width > 0) {
heightToWidthRatio = img.size.height / img.size.width;
}
contentholdingview = [[ACRContentHoldingUIView alloc] init];
Expand All @@ -63,12 +63,12 @@ - (UIView *)render:(UIView<ACRIContentHoldingView> *)viewGroup
NSNumber *number = [NSNumber numberWithUnsignedLongLong:(unsigned long long)mediaElem.get()];
NSString *key = [number stringValue];
contentholdingview = (ACRContentHoldingUIView *)[rootView getImageView:key];
if(contentholdingview) {
if (contentholdingview) {
view = contentholdingview.subviews[0];
}
}

if(!view) {
if (!view) {
// if poster is not availabl, create a 4:3 blank black backgroudn poster view; 16:9 won't provide enough height in case the media is 4:3
view = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, viewGroup.frame.size.width, viewGroup.frame.size.width * .75)];
view.backgroundColor = UIColor.blackColor;
Expand All @@ -85,44 +85,43 @@ - (UIView *)render:(UIView<ACRIContentHoldingView> *)viewGroup
NSString *piikey = [NSString stringWithCString:[acoConfig getHostConfig]->GetMedia().playButton.c_str() encoding:[NSString defaultCStringEncoding]];
UIImage *playIconImage = imageViewMap[piikey];
UIImageView *playIconImageView = nil;
BOOL drawDefaultPlayIcon = YES;
BOOL hideDefaultPlayIcon = NO;

if(!playIconImage) {
playIconImageView = [rootView getImageView:@"playIconImage"];
}else {
if (!playIconImage) {
NSString *key = [NSString stringWithFormat:@"%llu_playIcon", (unsigned long long)elem.get()];
playIconImageView = [rootView getImageView:key];
} else {
playIconImageView = [[UIImageView alloc] initWithImage:playIconImage];
}

if(playIconImageView) {
drawDefaultPlayIcon = NO;
if (playIconImageView) {
hideDefaultPlayIcon = YES;
playIconImageView.tag = playIconTag;
playIconImageView.translatesAutoresizingMaskIntoConstraints = NO;
}

view.tag = posterTag;
// if play icon is provided from hostconfig, disable play icon drawing in its sublayer, and invalidate the current sublayer, so it will be updated in the next drawring cycle
if(!drawDefaultPlayIcon) {
contentholdingview.hidePlayIcon = YES;
if (hideDefaultPlayIcon) {
[contentholdingview setNeedsLayout];
[view addSubview:playIconImageView];
[NSLayoutConstraint constraintWithItem:playIconImageView attribute:NSLayoutAttributeCenterX relatedBy:NSLayoutRelationEqual toItem:view attribute:NSLayoutAttributeCenterX multiplier:1.0 constant:0].active = YES;
[NSLayoutConstraint constraintWithItem:playIconImageView attribute:NSLayoutAttributeCenterY relatedBy:NSLayoutRelationEqual toItem:view attribute:NSLayoutAttributeCenterY multiplier:1.0 constant:0].active = YES;

}

contentholdingview.hidePlayIcon = YES;
contentholdingview.hidePlayIcon = hideDefaultPlayIcon;

[viewGroup addArrangedSubview:contentholdingview];

if([acoConfig getHostConfig]->GetSupportsInteractivity()){
if ([acoConfig getHostConfig]->GetSupportsInteractivity()){
ACRMediaTarget *mediaTarget = nil;
ACOMediaEvent *mediaEvent = [[ACOMediaEvent alloc] initWithMedia:mediaElem];
if(!mediaEvent.isValid) {
if (!mediaEvent.isValid) {
NSLog(@"warning: invalid mimetype detected, and media element is dropped");
return nil;
}
// create target for gesture recongnizer;
if(![acoConfig getHostConfig]->GetMedia().allowInlinePlayback) {
if (![acoConfig getHostConfig]->GetMedia().allowInlinePlayback) {
mediaTarget = [[ACRMediaTarget alloc] initWithMediaEvent:mediaEvent rootView:rootView config:acoConfig];
} else {
mediaTarget = [[ACRMediaTarget alloc] initWithMediaEvent:mediaEvent rootView:rootView config:acoConfig containingview:contentholdingview];
Expand Down Expand Up @@ -153,7 +152,6 @@ - (void)configUpdateForUIImageView:(ACOBaseCardElement *)acoElem config:(ACOHost
}

contentholdingview.frame = imageView.frame;
contentholdingview.hidePlayIcon = NO;

[NSLayoutConstraint constraintWithItem:imageView attribute:NSLayoutAttributeCenterX relatedBy:NSLayoutRelationEqual toItem:contentholdingview attribute:NSLayoutAttributeCenterX multiplier:1.0 constant:0].active = YES;
[NSLayoutConstraint constraintWithItem:imageView attribute:NSLayoutAttributeCenterY relatedBy:NSLayoutRelationEqual toItem:contentholdingview attribute:NSLayoutAttributeCenterY multiplier:1.0 constant:0].active = YES;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -113,24 +113,6 @@ + (UIView *)renderWithAdaptiveCards:(std::shared_ptr<AdaptiveCard> const &)adapt
[rootView loadBackgroundImageAccordingToResourceResolverIF:backgroundImageProperties key:@"backgroundImage" observerAction:observerAction];
}

if(![config getHostConfig]->GetMedia().playButton.empty()) {
ObserverActionBlock observerAction =
^(NSObject<ACOIResourceResolver>* imageResourceResolver, NSString* key, std::shared_ptr<BaseCardElement> const &elem, NSURL* url, ACRView* rootView) {
UIImageView *view = [imageResourceResolver resolveImageViewResource:url];
if(view) {
[view addObserver:rootView forKeyPath:@"image"
options:NSKeyValueObservingOptionNew
context:nil];

// store the image view for easy retrieval in ACRView::observeValueForKeyPath
[rootView setImageView:key view:view];
}
};
[rootView
loadImageAccordingToResourceResolverIFFromString:[config getHostConfig]->GetMedia().playButton
key:@"playIconImage" observerAction:observerAction];
}

ACRContainerStyle style = ([config getHostConfig]->GetAdaptiveCard().allowCustomStyle)? (ACRContainerStyle)adaptiveCard->GetStyle() : ACRDefault;
style = (style == ACRNone)? ACRDefault : style;
[verticalView setStyle:style];
Expand Down
32 changes: 28 additions & 4 deletions source/ios/AdaptiveCards/AdaptiveCards/AdaptiveCards/ACRView.mm
Original file line number Diff line number Diff line change
Expand Up @@ -287,6 +287,25 @@ - (void)processBaseCardElement:(std::shared_ptr<BaseCardElement> const &)elem
[self loadImageAccordingToResourceResolverIF:elem key:nil observerAction:observerAction];
}

if (![_hostConfig getHostConfig]->GetMedia().playButton.empty()) {
ObserverActionBlock observerAction =
^(NSObject<ACOIResourceResolver>* imageResourceResolver, NSString* key, std::shared_ptr<BaseCardElement> const &elem, NSURL* url, ACRView* rootView) {
UIImageView *view = [imageResourceResolver resolveImageViewResource:url];
if(view) {
[view addObserver:rootView forKeyPath:@"image"
options:NSKeyValueObservingOptionNew
context:nil];
// store the image view for easy retrieval in ACRView::observeValueForKeyPath
[rootView setImageView:key view:view];
}
};

NSNumber *number = [NSNumber numberWithUnsignedLongLong:(unsigned long long)elem.get()];
NSString *key = [NSString stringWithFormat:@"%@_%@", [number stringValue], @"playIcon" ];

[self loadImageAccordingToResourceResolverIFFromString:[_hostConfig getHostConfig]->GetMedia().playButton key:key observerAction:observerAction];
}

break;
}
case CardElementType::TextInput:
Expand Down Expand Up @@ -659,6 +678,10 @@ - (void)loadImageAccordingToResourceResolverIFFromString:(std::string const &)ur
std::shared_ptr<Image> imgElem = std::make_shared<Image>();
imgElem->SetUrl(url);
imgElem->SetImageSize(ImageSize::None);
NSNumber *number = [NSNumber numberWithUnsignedLongLong:(unsigned long long)imgElem.get()];
if (!key) {
key = [number stringValue];
}
[self loadImageAccordingToResourceResolverIF:imgElem key:key observerAction:observerAction];
}

Expand All @@ -668,7 +691,7 @@ - (void)loadImageAccordingToResourceResolverIF:(std::shared_ptr<BaseCardElement>
NSNumber *number = nil;
NSString *nSUrlStr = nil;

if(elem->GetElementType() == CardElementType::Media) {
if (elem->GetElementType() == CardElementType::Media) {
std::shared_ptr<Media> mediaElem = std::static_pointer_cast<Media>(elem);
number = [NSNumber numberWithUnsignedLongLong:(unsigned long long)mediaElem.get()];
nSUrlStr = [NSString stringWithCString:mediaElem->GetPoster().c_str() encoding:[NSString defaultCStringEncoding]];
Expand All @@ -677,7 +700,8 @@ - (void)loadImageAccordingToResourceResolverIF:(std::shared_ptr<BaseCardElement>
number = [NSNumber numberWithUnsignedLongLong:(unsigned long long)imgElem.get()];
nSUrlStr = [NSString stringWithCString:imgElem->GetUrl().c_str() encoding:[NSString defaultCStringEncoding]];
}
if(!key) {

if (!key) {
key = [number stringValue];
}

Expand All @@ -690,8 +714,8 @@ - (void)loadImage:(NSString *)nSUrlStr key:(NSString *)key context:(std::shared_

NSURL *url = [NSURL URLWithString:nSUrlStr];
NSObject<ACOIResourceResolver> *imageResourceResolver = [_hostConfig getResourceResolverForScheme:[url scheme]];
if(imageResourceResolver && ACOImageViewIF == [_hostConfig getResolverIFType:[url scheme]]) {
if(observerAction) {
if (imageResourceResolver && ACOImageViewIF == [_hostConfig getResolverIFType:[url scheme]]) {
if (observerAction) {
observerAction(imageResourceResolver, key, elem, url, self);
}
} else {
Expand Down