Skip to content
This repository was archived by the owner on May 1, 2024. It is now read-only.

Commit

Permalink
Revert "For consistency with ResourceDictionary, expose the Source fo…
Browse files Browse the repository at this point in the history
…r a StyleSheet (#2589)"

This reverts commit f66a72d.
  • Loading branch information
StephaneDelcroix committed Aug 17, 2018
1 parent f66a72d commit 4facc9b
Show file tree
Hide file tree
Showing 3 changed files with 3 additions and 46 deletions.
2 changes: 0 additions & 2 deletions Xamarin.Forms.Core/StyleSheets/StyleSheet.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,6 @@ public sealed class StyleSheet : IStyle
{
}

public Uri Source { get; internal set; }

internal IDictionary<Selector, Style> Styles { get; set; } = new Dictionary<Selector, Style>();

public static StyleSheet FromAssemblyResource(Assembly assembly, string resourceId, IXmlLineInfo lineInfo = null)
Expand Down
43 changes: 2 additions & 41 deletions Xamarin.Forms.Xaml.UnitTests/StyleSheet.xaml.cs
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
using System;
using System.IO;
using System.Linq;
using System.Reflection;
using NUnit.Framework;

using Xamarin.Forms.Core.UnitTests;
using NUnit.Framework.Constraints;

namespace Xamarin.Forms.Xaml.UnitTests
{
Expand Down Expand Up @@ -43,44 +42,6 @@ public void StyleSheetsAreApplied(bool useCompiledXaml)
Assert.That(layout.label0.TextColor, Is.EqualTo(Color.Azure));
Assert.That(layout.label0.BackgroundColor, Is.EqualTo(Color.AliceBlue));
}

[TestCase(false), TestCase(true)]
public void StyleSheetSourceIsApplied(bool useCompiledXaml)
{
// Having a custom ResourceProvider forces the LoadFromXaml code path
// for both XamlC and non-XamlC
Xamarin.Forms.Internals.ResourceLoader.ResourceProvider = GetResource;

var layout = new StyleSheet(useCompiledXaml);

Assert.AreEqual("css/foo.css", layout.Resources.StyleSheets[0].Source.OriginalString);

// Reset state to its initial
Xamarin.Forms.Internals.ResourceLoader.ResourceProvider = null;
DesignMode.IsDesignModeEnabled = false;
}

string GetResource(AssemblyName name, string path)
{
var assembly = Assembly.Load(name);
var resourceId = assembly
.GetCustomAttributes<XamlResourceIdAttribute>()
.Where(x => x.Path == path)
.Select(x => x.ResourceId)
.FirstOrDefault();

if (!string.IsNullOrEmpty(resourceId))
{
using (var stream = assembly.GetManifestResourceStream(resourceId))
{
if (stream != null)
using (var reader = new StreamReader(stream))
return reader.ReadToEnd();
}
}

return null;
}
}
}
}
4 changes: 1 addition & 3 deletions Xamarin.Forms.Xaml/MarkupExtensions/StyleSheetExtension.cs
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,7 @@ object IValueProvider.ProvideValue(IServiceProvider serviceProvider)
var rootTargetPath = XamlResourceIdAttribute.GetPathForType(rootObjectType);
var resourcePath = ResourceDictionary.RDSourceTypeConverter.GetResourcePath(Source, rootTargetPath);
var resString = DependencyService.Get<IResourcesLoader>().GetResource(resourcePath, rootObjectType.GetTypeInfo().Assembly, lineInfo);
var styleSheet = StyleSheet.FromString(resString);
styleSheet.Source = new Uri(resourcePath, UriKind.Relative);
return styleSheet;
return StyleSheet.FromString(resString);
}

if (!string.IsNullOrEmpty(Style)) {
Expand Down

0 comments on commit 4facc9b

Please sign in to comment.