Skip to content

Commit de09590

Browse files
Merge pull request #139 from matteobortolazzo/dev
Upgrade to Xamarin.Forms 5
2 parents 8405f1a + 465dbf0 commit de09590

35 files changed

+24389
-5936
lines changed

CHANGELOG.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,13 @@
1+
# 5.1.0
2+
3+
## Update
4+
* Update to `Xamarin.Forms` v5
5+
6+
# 5.0.2
7+
8+
## Bug Fix
9+
* **iOS**: Fix freeze on iOS. [#137](https://github.com/matteobortolazzo/HtmlLabelPlugin/issues/137)
10+
111
# 5.0.0
212

313
## Breaking Changes

LATEST_CHANGE.md

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,2 @@
1-
## Breaking Changes
2-
* **iOS**: The renderer has been implement with `UITextView`.
3-
4-
## Bug Fix
5-
* **iOS**: Custom fonts fix.
6-
* **iOS**: Link tap with multiple lines fix.
7-
* **Android**: Fix bullet point indent.
8-
* **Android**: Fix `tel://` links with whitespaces.
9-
* **All**: `mailto` with no subject or body fix.
1+
## Update
2+
* Update to `Xamarin.Forms` v5

azure-pipelines.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
variables:
22
Major: '5'
3-
Minor: '0'
3+
Minor: '1'
44
Patch: '0'
55
BuildConfiguration: Release
66

src/HtmlLabel.sln

Lines changed: 250 additions & 230 deletions
Large diffs are not rendered by default.
Lines changed: 69 additions & 68 deletions
Original file line numberDiff line numberDiff line change
@@ -1,74 +1,75 @@
1-
<Project Sdk="MSBuild.Sdk.Extras/2.0.54">
2-
<PropertyGroup>
3-
<TargetFrameworks>netstandard2.0;Xamarin.iOS10;MonoAndroid90;MonoAndroid10.0;</TargetFrameworks>
4-
<TargetFrameworks Condition=" '$(OS)' == 'Windows_NT' ">$(TargetFrameworks);uap10.0.17763</TargetFrameworks>
1+
<Project Sdk="MSBuild.Sdk.Extras/3.0.44">
2+
<PropertyGroup>
3+
<TargetFrameworks>netstandard2.0;Xamarin.iOS10;MonoAndroid10.0;</TargetFrameworks>
4+
<TargetFrameworks Condition=" '$(OS)' == 'Windows_NT' ">$(TargetFrameworks);uap10.0.18362</TargetFrameworks>
55
<AssemblyName>HtmlLabel.Forms.Plugin</AssemblyName>
6-
<RootNamespace>LabelHtml.Forms.Plugin</RootNamespace>
7-
<PackageId>Xam.Plugin.HtmlLabel</PackageId>
8-
<Product>HtmlLabel.Forms.Plugin</Product>
9-
<PackageIcon>icon.png</PackageIcon>
10-
<Summary>Xam.Plugin.HtmlLabel: display HTML content in labels</Summary>
11-
<PackageTags>xamarin, windows, uwp, ios, android, xamarin.forms, Xamarin.HtmlLabel, html</PackageTags>
12-
<Title>Xam.Plugin.HtmlLabel</Title>
13-
<Description>Xam.Plugin.HtmlLabel: display HTML content in labels</Description>
14-
<Product>$(AssemblyName) ($(TargetFramework))</Product>
15-
<PackageVersion>$(Version)$(VersionSuffix)</PackageVersion>
16-
<Authors>Matteo Bortolazzo</Authors>
17-
<Owners>Matteo Bortolazzo</Owners>
18-
<NeutralLanguage>en</NeutralLanguage>
19-
<Copyright>© Matteo Bortolazzo. All rights reserved.</Copyright>
20-
<RepositoryUrl>https://github.com/matteobortolazzo/HtmlLabelPlugin</RepositoryUrl>
21-
<DefineConstants>$(DefineConstants);</DefineConstants>
22-
<UseFullSemVerForNuGet>false</UseFullSemVerForNuGet>
23-
<EnableDefaultCompileItems>false</EnableDefaultCompileItems>
24-
<PackageLicenseFile>LICENSE</PackageLicenseFile>
25-
<PackageRequireLicenseAcceptance>true</PackageRequireLicenseAcceptance>
26-
<PackageProjectUrl>https://github.com/matteobortolazzo/HtmlLabelPlugin</PackageProjectUrl>
27-
<DebugType>portable</DebugType>
28-
<Configurations>Debug;Release</Configurations>
29-
<LangVersion>8.0</LangVersion>
30-
<GeneratePackageOnBuild>false</GeneratePackageOnBuild>
31-
</PropertyGroup>
32-
33-
<PropertyGroup Condition=" '$(Configuration)'=='Debug' ">
34-
<DebugSymbols>true</DebugSymbols>
35-
</PropertyGroup>
36-
37-
<PropertyGroup Condition=" '$(Configuration)'=='Release' And '$(OS)' == 'Windows_NT' ">
38-
<!-- sourcelink: Declare that the Repository URL can be published to NuSpec -->
39-
<PublishRepositoryUrl>true</PublishRepositoryUrl>
40-
<!-- sourcelink: Embed source files that are not tracked by the source control manager to the PDB -->
41-
<EmbedUntrackedSources>true</EmbedUntrackedSources>
42-
<!-- sourcelink: Include PDB in the built .nupkg -->
43-
<AllowedOutputExtensionsInPackageBuildOutputFolder>$(AllowedOutputExtensionsInPackageBuildOutputFolder);.pdb</AllowedOutputExtensionsInPackageBuildOutputFolder>
44-
</PropertyGroup>
45-
46-
<ItemGroup Condition=" '$(Configuration)'=='Release' And '$(OS)' == 'Windows_NT' ">
47-
<PackageReference Include="Microsoft.SourceLink.GitHub" Version="1.0.0" PrivateAssets="All" />
48-
</ItemGroup>
49-
50-
<ItemGroup>
51-
<None Include="..\..\LICENSE" PackagePath="" Pack="true" />
52-
<None Include="..\..\Assets\icon.png" PackagePath="" Pack="true" />
53-
<PackageReference Include="Microsoft.CodeAnalysis.FxCopAnalyzers" Version="3.3.0">
54-
<PrivateAssets>all</PrivateAssets>
55-
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
56-
</PackageReference>
57-
<PackageReference Include="Xamarin.Forms" Version="4.8.0.1451" />
58-
<PackageReference Include="Xamarin.Essentials" Version="1.5.3.2" />
59-
<Compile Include="Shared\*.cs" />
60-
</ItemGroup>
61-
6+
<RootNamespace>LabelHtml.Forms.Plugin</RootNamespace>
7+
<PackageId>Xam.Plugin.HtmlLabel</PackageId>
8+
<Product>HtmlLabel.Forms.Plugin</Product>
9+
<PackageIcon>icon.png</PackageIcon>
10+
<Summary>Xam.Plugin.HtmlLabel: display HTML content in labels</Summary>
11+
<PackageTags>xamarin, windows, uwp, ios, android, xamarin.forms, Xamarin.HtmlLabel, html</PackageTags>
12+
<Title>Xam.Plugin.HtmlLabel</Title>
13+
<Description>Xam.Plugin.HtmlLabel: display HTML content in labels</Description>
14+
<Product>$(AssemblyName) ($(TargetFramework))</Product>
15+
<PackageVersion>$(Version)$(VersionSuffix)</PackageVersion>
16+
<Authors>Matteo Bortolazzo</Authors>
17+
<Owners>Matteo Bortolazzo</Owners>
18+
<NeutralLanguage>en</NeutralLanguage>
19+
<Copyright>© Matteo Bortolazzo. All rights reserved.</Copyright>
20+
<RepositoryUrl>https://github.com/matteobortolazzo/HtmlLabelPlugin</RepositoryUrl>
21+
<DefineConstants>$(DefineConstants);</DefineConstants>
22+
<UseFullSemVerForNuGet>false</UseFullSemVerForNuGet>
23+
<EnableDefaultCompileItems>false</EnableDefaultCompileItems>
24+
<PackageLicenseFile>LICENSE</PackageLicenseFile>
25+
<PackageRequireLicenseAcceptance>true</PackageRequireLicenseAcceptance>
26+
<PackageProjectUrl>https://github.com/matteobortolazzo/HtmlLabelPlugin</PackageProjectUrl>
27+
<DebugType>portable</DebugType>
28+
<Configurations>Debug;Release</Configurations>
29+
<LangVersion>8.0</LangVersion>
30+
<GeneratePackageOnBuild>false</GeneratePackageOnBuild>
31+
</PropertyGroup>
32+
33+
<PropertyGroup Condition=" '$(Configuration)'=='Debug' ">
34+
<DebugSymbols>true</DebugSymbols>
35+
</PropertyGroup>
36+
37+
<PropertyGroup Condition=" '$(Configuration)'=='Release' And '$(OS)' == 'Windows_NT' ">
38+
<!-- sourcelink: Declare that the Repository URL can be published to NuSpec -->
39+
<PublishRepositoryUrl>true</PublishRepositoryUrl>
40+
<!-- sourcelink: Embed source files that are not tracked by the source control manager to the PDB -->
41+
<EmbedUntrackedSources>true</EmbedUntrackedSources>
42+
<!-- sourcelink: Include PDB in the built .nupkg -->
43+
<AllowedOutputExtensionsInPackageBuildOutputFolder>$(AllowedOutputExtensionsInPackageBuildOutputFolder);.pdb</AllowedOutputExtensionsInPackageBuildOutputFolder>
44+
</PropertyGroup>
45+
46+
<PropertyGroup Condition=" '$(OS)' == 'Windows_NT' ">
47+
<TargetPlatformVersion>10.0.19041.0</TargetPlatformVersion>
48+
<TargetPlatformMinVersion>10.0.18362.0</TargetPlatformMinVersion>
49+
</PropertyGroup>
50+
51+
<ItemGroup Condition=" '$(Configuration)'=='Release' And '$(OS)' == 'Windows_NT' ">
52+
<PackageReference Include="Microsoft.SourceLink.GitHub" Version="1.0.0" PrivateAssets="All" />
53+
</ItemGroup>
54+
55+
<ItemGroup>
56+
<None Include="..\..\LICENSE" PackagePath="" Pack="true" />
57+
<None Include="..\..\Assets\icon.png" PackagePath="" Pack="true" />
58+
<PackageReference Include="Xamarin.Forms" Version="5.0.0.2196" />
59+
<PackageReference Include="Xamarin.Essentials" Version="1.7.0" />
60+
<Compile Include="Shared\*.cs" />
61+
</ItemGroup>
62+
6263
<ItemGroup Condition=" $(TargetFramework.StartsWith('uap10.0')) ">
63-
<PackageReference Include="Microsoft.Xaml.Behaviors.Uwp.Managed" Version="2.0.1" />
64-
<Compile Include="UWP\*.cs" />
65-
</ItemGroup>
66-
64+
<PackageReference Include="Microsoft.Xaml.Behaviors.Uwp.Managed" Version="2.0.1" />
65+
<Compile Include="UWP\*.cs" />
66+
</ItemGroup>
67+
6768
<ItemGroup Condition=" $(TargetFramework.StartsWith('MonoAndroid')) ">
68-
<Compile Include="Android\*.cs" />
69+
<Compile Include="Android\*.cs" />
6970
</ItemGroup>
7071

71-
<ItemGroup Condition=" $(TargetFramework.StartsWith('Xamarin.iOS')) ">
72-
<Compile Include="iOS\*.cs" />
73-
</ItemGroup>
72+
<ItemGroup Condition=" $(TargetFramework.StartsWith('Xamarin.iOS')) ">
73+
<Compile Include="iOS\*.cs" />
74+
</ItemGroup>
7475
</Project>

src/HtmlLabel/Shared/RendererHelper.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ internal class RendererHelper
2424
Label.FontSizeProperty.PropertyName,
2525
Label.HorizontalTextAlignmentProperty.PropertyName,
2626
Label.TextColorProperty.PropertyName,
27+
Label.PaddingProperty.PropertyName,
2728
HtmlLabel.LinkColorProperty.PropertyName
2829
};
2930

src/HtmlLabel/iOS/BaseTextViewRenderer.cs

Lines changed: 49 additions & 84 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,36 @@
11
using CoreGraphics;
22
using Foundation;
33
using System;
4+
using System.ComponentModel;
45
using System.Linq;
5-
using UIKit;
6+
using LabelHtml.Forms.Plugin.Abstractions;
67
using Xamarin.Forms;
78
using Xamarin.Forms.Platform.iOS;
89

10+
#if __MOBILE__
11+
using UIKit;
12+
using NativeTextView = UIKit.UITextView;
13+
14+
#else
15+
using AppKit;
16+
using NativeTextView = AppKit.NSTextView;
17+
#endif
18+
19+
#if __MOBILE__
920
namespace LabelHtml.Forms.Plugin.iOS
21+
#else
22+
namespace LabelHtml.Forms.Plugin.MacOS
23+
#endif
1024
{
11-
public abstract class BaseTextViewRenderer<TElement> : ViewRenderer<TElement, UITextViewFixedWithKludge>
25+
public abstract class BaseTextViewRenderer<TElement> : ViewRenderer<TElement, NativeTextView>
1226
where TElement : Label
1327
{
1428
private SizeRequest _perfectSize;
1529
private bool _perfectSizeValid;
1630

17-
protected override UITextViewFixedWithKludge CreateNativeControl()
31+
protected override NativeTextView CreateNativeControl()
1832
{
19-
var control = new UITextViewFixedWithKludge(CGRect.Empty)
33+
var control = new NativeTextView(CGRect.Empty)
2034
{
2135
Editable = false,
2236
ScrollEnabled = false,
@@ -28,10 +42,7 @@ protected override UITextViewFixedWithKludge CreateNativeControl()
2842

2943
protected override void OnElementChanged(ElementChangedEventArgs<TElement> e)
3044
{
31-
if (e == null || Element == null)
32-
{
33-
return;
34-
}
45+
_perfectSizeValid = false;
3546

3647
if (e.NewElement != null)
3748
{
@@ -71,8 +82,29 @@ protected override void OnElementChanged(ElementChangedEventArgs<TElement> e)
7182
System.Diagnostics.Debug.WriteLine(@" ERROR: ", ex.Message);
7283
}
7384
}
85+
7486
base.OnElementChanged(e);
7587
}
88+
89+
protected override void OnElementPropertyChanged( object sender, PropertyChangedEventArgs e )
90+
{
91+
base.OnElementPropertyChanged( sender, e );
92+
if ( e != null && RendererHelper.RequireProcess( e.PropertyName ) )
93+
{
94+
try
95+
{
96+
UpdateLineBreakMode();
97+
UpdateHorizontalTextAlignment();
98+
ProcessText();
99+
UpdatePadding();
100+
}
101+
catch ( System.Exception ex )
102+
{
103+
System.Diagnostics.Debug.WriteLine( @" ERROR: ", ex.Message );
104+
}
105+
}
106+
}
107+
76108
protected abstract void ProcessText();
77109
protected abstract bool NavigateToUrl(NSUrl url);
78110

@@ -166,92 +198,25 @@ private void UpdateLineBreakMode()
166198

167199
private void UpdatePadding()
168200
{
169-
if (Element.Padding.IsEmpty)
170-
{
171-
return;
172-
}
173-
174201
#if __MOBILE__
175-
Control.TextContainerInset = new UIEdgeInsets(
176-
(float)Element.Padding.Top,
177-
(float)Element.Padding.Left,
178-
(float)Element.Padding.Bottom,
179-
(float)Element.Padding.Right);
180-
UpdateLayout();
181-
#endif
182-
}
183202

184-
private void UpdateLayout()
185-
{
186-
#if __MOBILE__
187-
LayoutSubviews();
188-
#else
189-
Layout();
190-
#endif
191-
}
192-
193-
private void UpdateTextDecorations()
194-
{
195-
if (Element?.TextType != TextType.Text)
196-
return;
197-
#if __MOBILE__
198-
if (!(Control.AttributedText?.Length > 0))
199-
return;
200-
#else
201-
if (!(Control.AttributedStringValue?.Length > 0))
202-
return;
203-
#endif
204-
205-
var textDecorations = Element.TextDecorations;
206-
#if __MOBILE__
207-
var newAttributedText = new NSMutableAttributedString(Control.AttributedText);
208-
var strikeThroughStyleKey = UIStringAttributeKey.StrikethroughStyle;
209-
var underlineStyleKey = UIStringAttributeKey.UnderlineStyle;
210-
211-
#else
212-
var newAttributedText = new NSMutableAttributedString(Control.AttributedStringValue);
213-
var strikeThroughStyleKey = NSStringAttributeKey.StrikethroughStyle;
214-
var underlineStyleKey = NSStringAttributeKey.UnderlineStyle;
215-
#endif
216-
var range = new NSRange(0, newAttributedText.Length);
217-
218-
if ((textDecorations & TextDecorations.Strikethrough) == 0)
219-
newAttributedText.RemoveAttribute(strikeThroughStyleKey, range);
220-
else
221-
newAttributedText.AddAttribute(strikeThroughStyleKey, NSNumber.FromInt32((int)NSUnderlineStyle.Single), range);
203+
Control.TextContainerInset = new UIEdgeInsets(
204+
(float)Element.Padding.Top,
205+
(float)Element.Padding.Left,
206+
(float)Element.Padding.Bottom,
207+
(float)Element.Padding.Right);
222208

223-
if ((textDecorations & TextDecorations.Underline) == 0)
224-
newAttributedText.RemoveAttribute(underlineStyleKey, range);
225-
else
226-
newAttributedText.AddAttribute(underlineStyleKey, NSNumber.FromInt32((int)NSUnderlineStyle.Single), range);
227-
228-
#if __MOBILE__
229-
Control.AttributedText = newAttributedText;
230-
#else
231-
Control.AttributedStringValue = newAttributedText;
209+
UpdateLayout();
232210
#endif
233-
UpdateCharacterSpacing();
234-
_perfectSizeValid = false;
235211
}
236212

237-
private void UpdateCharacterSpacing()
213+
private void UpdateLayout()
238214
{
239-
240-
if (Element?.TextType != TextType.Text)
241-
return;
242215
#if __MOBILE__
243-
var textAttr = Control.AttributedText.AddCharacterSpacing(Element.Text, Element.CharacterSpacing);
244-
245-
if (textAttr != null)
246-
Control.AttributedText = textAttr;
216+
LayoutSubviews();
247217
#else
248-
var textAttr = Control.AttributedStringValue.AddCharacterSpacing(Element.Text, Element.CharacterSpacing);
249-
250-
if (textAttr != null)
251-
Control.AttributedStringValue = textAttr;
218+
Layout();
252219
#endif
253-
254-
_perfectSizeValid = false;
255220
}
256221

257222
private void UpdateHorizontalTextAlignment()

0 commit comments

Comments
 (0)