Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support relative URLs for images in renderers #1244

Closed
6 tasks done
andrewleader opened this issue Mar 9, 2018 · 3 comments
Closed
6 tasks done

Support relative URLs for images in renderers #1244

andrewleader opened this issue Mar 9, 2018 · 3 comments
Labels

Comments

@andrewleader
Copy link
Contributor

andrewleader commented Mar 9, 2018

Implementation status

Today, using a relative URL in an Adaptive Card throws an exception while rendering.

In toasts, it makes sense for us to allow relative URLs to default to ms-appx:///, which is what other XAML surfaces allow, and what existing XML toasts allow. For example, "url": "Assets/Images/dog.jpg" rather than having to write "url": "ms-appx:///Assets/Images/dog.jpg"

{
  "type": "AdaptiveCard",
  "version": "1.0",

  "title": {
    "text": "Dogs are the best!"
  },

  "body": [

    {
      "type": "Image",
      "url": "Assets/Images/dog.jpg",
      "size": "stretch"
    }

  ]
}

This requires a few pieces of work...

  1. Host config where host can optionally specify a base url
  2. Object model code updated to support relative URLs
  3. Renderer code updated to support relative URLs and if relative, prefix the base url

1. Updated host config

{
  "supportsInteractivity": true,
  "imageBaseUrl": "ms-appx:///"
  ...

2. Object model code updated

This line of code needs to be updated to allow relative urls

BEFORE

RETURN_IF_FAILED(uriActivationFactory->CreateUri(imageUri, m_url.GetAddressOf()));

AFTER (idk what the equivalent in C++ is, but this needs to parse a URL that's either relative or absolute, allowing a relative url to be assigned)

imageUri = new Uri(imageUri, UriKind.RelativeOrAbsolute);

3. Renderer code updated

And then while rendering, this line of code needs to be updated to prefix the base url if the url is a relative url.

BEFORE

THROW_IF_FAILED(imageUri->get_SchemeName(&schemeName));

This will throw on relative urls, since relative urls don't have a scheme. Therefore, this should be updated to...

AFTER (written in C#)

// If not an absolute uri
if (!imageUri.IsAbsoluteUri)
{
    // Prefix the host config specified base url
    // Note that hostConfig.BaseUrl is a Uri object too
    imageUri = new Uri(hostConfig.BaseUrl, imageUri);
}

// Then continue with original code of getting scheme name
schemeName = imageUri.SchemeName;
@andrewleader andrewleader added Feature Platform-XAML Bugs or features related to Xaml Renderer Tag-Toasts-V2 Epic labels Mar 9, 2018
@khouzam khouzam changed the title Support relative URLs for images in UWP renderer Support relative URLs for images in renderers Jun 8, 2018
@matthidinger
Copy link
Member

Closing as not applicable to platform

@matthidinger
Copy link
Member

Whoops, docs :)

@matthidinger matthidinger reopened this Sep 10, 2018
@paulcam206
Copy link
Member

Documentation is done and in the mahiding/site1.1 branch.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

4 participants