[All] Bindable span #1850
[All] Bindable span #1850
Conversation
@@ -5,163 +5,160 @@ | |||
|
|||
namespace Xamarin.Forms | |||
{ | |||
public partial class VisualElement | |||
sealed class MergedStyle : IStyle |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
All I did here was remove the public partial class VisualElement line.
Didn't make any formatting changes, Github just thinks its all different.
Xamarin.Forms.Core/Label.cs
Outdated
{ | ||
var formattedString = (FormattedString)newvalue; | ||
formattedString.PropertyChanged += ((Label)bindable).OnFormattedTextChanged; | ||
SetInheritedBindingContext(formattedString, bindable.BindingContext); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Changes the BindingContext when it is updated on the Label.
{ | ||
base.OnBindingContextChanged(); | ||
for (int i = 0; i < Spans.Count; i++) | ||
SetInheritedBindingContext(Spans[i], BindingContext); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sets BindingContext of Spans when the FormattedText BindingContext changes
formattedString.Spans.Add (new Span { BackgroundColor = Color.Red, ForegroundColor = Color.Olive, Text = "Span 1 " }); | ||
formattedString.Spans.Add (new Span { BackgroundColor = Color.Black, ForegroundColor = Color.White, Text = "Span 2 " }); | ||
formattedString.Spans.Add (new Span { BackgroundColor = Color.Pink, ForegroundColor = Color.Purple, Text = "Span 3" }); | ||
formattedString.Spans.Add (new Span { BackgroundColor = Color.Red, TextColor = Color.Olive, Text = "Span 1 " }); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These are changed because the ForegroundColor is now obsolete, as per Stephane's request.
set { _fontElement.SetValue(FontElement.FontProperty, value); } | ||
public static readonly BindableProperty TextColorProperty = TextElement.TextColorProperty; | ||
|
||
public Color TextColor |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
TextColor property now used, to align with rest of XF framework, from ITextElement interface.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks pretty good, there are plenty of places where double GetValue calls occur but those were there in the past too. If you want to go the extra mile and clean those up, great, otherwise its nowhere near a blocker.
Im wondering if it might make sense to have all the bindings in here be OneTime by default. I doubt that generally speaking spans need dynamic binding and OneTime bindings are much cheaper. We have an opportunity here to make things fast by default in this area at least, even if we cant change it elsewhere. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It looks good, but I think that, as the Parent/Children concept is missing, you won't be able to apply css styles, dynamic resources, ...
I can look at that when I have a few minutes, but in the mean time, do not merge this PR
Thats a really good point stephane. At the bare minimum the Parent will need to be set on the BindableSpan. |
@StephaneDelcroix - I set the parent going down. The FormattedText was changed to inherit from Element, then parent set, and Parent set on all Spans. @jassmith - I assume the GetValue multiple calls was the Text property is called a lot of times, I made minor changes to reduce the number of calls. Down to 1 on iOS and UWP. Down to 2 from 4 on Android. As for OneTime bindings, I didn't know they existed. How would you implement them? |
Just set the default binding mode on the BindableProperty to be OneTime instead of not specifying it (which defaults to OneWay). |
f5d8a4c
to
5b9546d
Compare
@jassmith - ok, added them. BindingMode.OneTime was only added 10 days ago, so I needed to rebase. Didn't know OneTime binding was available. |
Yeah its new :) |
@@ -66,7 +66,7 @@ public sealed class BindableProperty | |||
throw new ArgumentNullException("declaringType"); | |||
|
|||
// don't use Enum.IsDefined as its redonkulously expensive for what it does | |||
if (defaultBindingMode != BindingMode.Default && defaultBindingMode != BindingMode.OneWay && defaultBindingMode != BindingMode.OneWayToSource && defaultBindingMode != BindingMode.TwoWay) | |||
if (defaultBindingMode != BindingMode.Default && defaultBindingMode != BindingMode.OneWay && defaultBindingMode != BindingMode.OneWayToSource && defaultBindingMode != BindingMode.TwoWay && defaultBindingMode != BindingMode.OneTime) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Woops
Any Updates on this? Thank you @adamped for your work |
build |
} | ||
|
||
[Obsolete("Foreground is obsolete as of version 2.6.0. Please use the TextColor property instead.")] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We'll want to change this (and probably others in the repo) to 3.0.0 at some point).
@@ -56,9 +56,9 @@ private static string GenerateMarkupText(Span span) | |||
} | |||
|
|||
// ForegroundColor => |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
obsolete comment
Build is failing related to docs issues |
@adamped passed docs! thanks |
Good I want to get this in |
@jassmith me too, underlines are a big deal |
@StephaneDelcroix - Styles work, I even have a unit test for it. Haven't tested on XAML with a Style though, but in code it works. CSS I haven't tried. Haven't tested merged styles either. |
In she goes! Congratulations adam, this is a major feature! |
Awesome, thanks @jassmith Will forge ahead with tappable spans now, have slowly been working on them, will be ready for another review soon. |
excellent |
I love this feature! When will this come to nuget? |
You can get it now on the nightly build. From the xamarin nightly repository. |
@adamped This is great. I'm really interested in tappable spans, do you still plan on implementing that? Eta? Thx! |
@VincentH-Net - Its already implemented - #2173 |
Really excited about this feature. Installed 3.1.0 pre release to test this out but I keep getting the following error: System.MissingFieldException: Field 'Xamarin.Forms.Span.TextProperty' not found. My code is as followed: |
Description of Change
This allows Text to be Bindable on a Span.
It also added the Style property to the Span, to set the Font Elements.
fixes #1340
Bugs Fixed
N/A
API Changes
Added:
Marked Obsolete:
Behavioral Changes
N/A
PR Checklist