示例#1
0
        public async Task HorizontalTextAlignmentInitializesCorrectly()
        {
            var xplatHorizontalTextAlignment = TextAlignment.End;

            var labelStub = new LabelStub()
            {
                Text = "Test",
                HorizontalTextAlignment = xplatHorizontalTextAlignment
            };

            var values = await GetValueAsync(labelStub, (handler) =>
            {
                return(new
                {
                    ViewValue = labelStub.HorizontalTextAlignment,
                    PlatformViewValue = GetNativeHorizontalTextAlignment(handler)
                });
            });

            Assert.Equal(xplatHorizontalTextAlignment, values.ViewValue);

            (var gravity, var textAlignment) = values.PlatformViewValue;

            // Device Tests runner has RTL support enabled, so we expect TextAlignment values
            // (If it didn't, we'd have to fall back to gravity)
            var expectedValue = ATextAlignemnt.ViewEnd;

            Assert.Equal(expectedValue, textAlignment);
        }
示例#2
0
        public async Task FontFamilyInitializesCorrectly(string family)
        {
            var label = new LabelStub()
            {
                Text = "Test",
                Font = Font.OfSize(family, 10)
            };

            var handler = await CreateHandlerAsync(label);

            var nativeLabel = GetNativeLabel(handler);

            var fontManager = App.Services.GetRequiredService <IFontManager>();

            var nativeFont = fontManager.GetTypeface(Font.OfSize(family, 0.0));

            Assert.Equal(nativeFont, nativeLabel.Typeface);

            if (string.IsNullOrEmpty(family))
            {
                Assert.Equal(fontManager.DefaultTypeface, nativeLabel.Typeface);
            }
            else
            {
                Assert.NotEqual(fontManager.DefaultTypeface, nativeLabel.Typeface);
            }
        }
示例#3
0
        public async Task CanSetAlignmentAndLineHeight()
        {
            // Verifying that setting LineHeight (which requires an attributed string on iOS)
            // doesn't cancel out the text alignment value (which can be set without an attributed string)

            var    xplatHorizontalTextAlignment = TextAlignment.End;
            double xplatLineHeight = 2;

            var label = new LabelStub()
            {
                Text = "Test",
                HorizontalTextAlignment = xplatHorizontalTextAlignment,
                LineHeight = xplatLineHeight
            };

            var expectedAlignment  = UITextAlignment.Right;
            var expectedLineHeight = xplatLineHeight;

            var handler = await CreateHandlerAsync(label);

            var actualAlignment = await InvokeOnMainThreadAsync(() => GetNativeHorizontalTextAlignment(handler));

            var actualLineHeight = await InvokeOnMainThreadAsync(() => GetNativeLineHeight(handler));

            Assert.Equal(expectedLineHeight, actualLineHeight);
            Assert.Equal(expectedAlignment, actualAlignment);
        }
示例#4
0
        public async Task TextInitializesCorrectly()
        {
            var label = new LabelStub()
            {
                Text = "Test"
            };

            await ValidatePropertyInitValue(label, () => label.Text, GetNativeText, label.Text);
        }
示例#5
0
        public async Task CharacterSpacingInitializesCorrectly()
        {
            var label = new LabelStub()
            {
                Text             = "Test CharacterSpacing",
                CharacterSpacing = 4.0
            };

            await ValidatePropertyInitValue(label, () => label.CharacterSpacing, GetNativeCharacterSpacing, label.CharacterSpacing);
        }
示例#6
0
        public async Task BackgroundColorInitializesCorrectly()
        {
            var label = new LabelStub()
            {
                BackgroundColor = Color.Blue,
                Text            = "Test"
            };

            await ValidateNativeBackgroundColor(label, Color.Blue);
        }
示例#7
0
        public async Task TextColorInitializesCorrectly()
        {
            var label = new LabelStub()
            {
                Text      = "Test",
                TextColor = Color.Red
            };

            await ValidatePropertyInitValue(label, () => label.TextColor, GetNativeTextColor, label.TextColor);
        }
示例#8
0
        public async Task FontSizeInitializesCorrectly(int fontSize)
        {
            var label = new LabelStub()
            {
                Text = "Test",
                Font = Font.OfSize("Arial", fontSize)
            };

            await ValidatePropertyInitValue(label, () => label.Font.FontSize, GetNativeUnscaledFontSize, label.Font.FontSize);
        }
示例#9
0
        public async Task AttributesInitializeCorrectly(FontAttributes attributes, bool isBold, bool isItalic)
        {
            var label = new LabelStub()
            {
                Text = "Test",
                Font = Font.OfSize("Arial", 10).WithAttributes(attributes)
            };

            await ValidatePropertyInitValue(label, () => label.Font.FontAttributes.HasFlag(FontAttributes.Bold), GetNativeIsBold, isBold);
            await ValidatePropertyInitValue(label, () => label.Font.FontAttributes.HasFlag(FontAttributes.Italic), GetNativeIsItalic, isItalic);
        }
示例#10
0
        public async Task NegativeMaxValueWithWrapIsCorrect()
        {
            var label = new LabelStub()
            {
                Text          = "Lorem ipsum dolor sit amet, consectetur adipiscing elit",
                MaxLines      = -1,
                LineBreakMode = LineBreakMode.WordWrap
            };

            var nativeValue = await GetValueAsync(label, GetNativeMaxLines);

            Assert.Equal(int.MaxValue, nativeValue);
        }
示例#11
0
        public async Task TextDoesNotAffectCharacterSpacing(string initialText, string newText)
        {
            var label = new LabelStub
            {
                Text             = initialText,
                CharacterSpacing = 5,
            };

            await ValidateUnrelatedPropertyUnaffected(
                label,
                GetNativeCharacterSpacing,
                nameof(ILabel.Text),
                () => label.Text = newText);
        }
示例#12
0
        public async Task CharacterSpacingUpdatesCorrectly(double setValue, double unsetValue)
        {
            var label = new LabelStub
            {
                Text = "This is TEXT!"
            };

            await ValidatePropertyUpdatesValue(
                label,
                nameof(ILabel.CharacterSpacing),
                GetNativeCharacterSpacing,
                setValue,
                unsetValue);
        }
示例#13
0
        public async Task FontDoesNotAffectCharacterSpacing()
        {
            var label = new LabelStub
            {
                Text             = "This is TEXT!",
                CharacterSpacing = 5,
                Font             = Font.SystemFontOfSize(20)
            };

            await ValidateUnrelatedPropertyUnaffected(
                label,
                GetNativeCharacterSpacing,
                nameof(ILabel.Font),
                () => label.Font = Font.SystemFontOfSize(15));
        }
示例#14
0
        public async Task PaddingInitializesCorrectly()
        {
            var label = new LabelStub()
            {
                Text    = "Test",
                Padding = new Thickness(5, 10, 15, 20)
            };

            var handler = await CreateHandlerAsync(label);

            var insets = ((MauiLabel)handler.NativeView).TextInsets;

            Assert.Equal(5, insets.Left);
            Assert.Equal(10, insets.Top);
            Assert.Equal(15, insets.Right);
            Assert.Equal(20, insets.Bottom);
        }
示例#15
0
        public async Task TextDecorationsAppliedWhenTextAdded()
        {
            TextDecorations xplatTextDecorations = TextDecorations.Underline;

            var label = new LabelStub()
            {
                TextDecorations = xplatTextDecorations
            };                                                                                  // No text set

            var handler = await CreateHandlerAsync(label);

            label.Text = "Now we have text";
            await InvokeOnMainThreadAsync(() => handler.UpdateValue(nameof(label.Text)));

            var attributedText = await InvokeOnMainThreadAsync(() => GetAttributedText(handler));

            attributedText.AssertHasUnderline();
        }
示例#16
0
        public async Task CharacterSpacingAppliedWhenTextAdded()
        {
            double xplatCharacterSpacing    = 1.5;
            var    expectedCharacterSpacing = xplatCharacterSpacing;

            var label = new LabelStub()
            {
                CharacterSpacing = xplatCharacterSpacing
            };                                                                                    // No text set

            var handler = await CreateHandlerAsync(label);

            label.Text = "Now we have text";
            await InvokeOnMainThreadAsync(() => handler.UpdateValue(nameof(label.Text)));

            var actualCharacterSpacing = await InvokeOnMainThreadAsync(() => GetNativeCharacterSpacing(handler));

            Assert.Equal(expectedCharacterSpacing, actualCharacterSpacing);
        }
示例#17
0
        public async Task LineHeightAppliedWhenTextAdded()
        {
            double xplatLineHeight    = 2;
            var    expectedLineHeight = xplatLineHeight;

            var label = new LabelStub()
            {
                LineHeight = xplatLineHeight
            };                                                                        // No text set

            var handler = await CreateHandlerAsync(label);

            label.Text = "Now we have text";
            await InvokeOnMainThreadAsync(() => handler.UpdateValue(nameof(label.Text)));

            var actualLineHeight = await InvokeOnMainThreadAsync(() => GetNativeLineHeight(handler));

            Assert.Equal(expectedLineHeight, actualLineHeight);
        }
示例#18
0
        public async Task ValidateMaxLinesSettingTextDecorations()
        {
            int xplatMaxLines = 2;

            var labelHandler = new LabelStub()
            {
                MaxLines      = xplatMaxLines,
                LineBreakMode = LineBreakMode.TailTruncation
            };

            var values = await GetValueAsync(labelHandler, (handler) =>
            {
                return(new
                {
                    ViewValue = labelHandler.MaxLines,
                    PlatformViewValue = GetNativeMaxLines(handler)
                });
            });

            Assert.Equal(xplatMaxLines, values.ViewValue);
        }
示例#19
0
        public async Task HorizontalTextAlignmentAdjustsForFlowDirection(TextAlignment alignment, FlowDirection flowDirection, UITextAlignment expected)
        {
            var label = new LabelStub
            {
                Text = "This is TEXT!",
                HorizontalTextAlignment = alignment,
                FlowDirection           = flowDirection
            };


            var values = await GetValueAsync(label, (handler) =>
            {
                return(new
                {
                    ViewValue = label.HorizontalTextAlignment,
                    NativeViewValue = GetNativeHorizontalTextAlignment(handler)
                });
            });

            Assert.Equal(expected, values.NativeViewValue);
        }
示例#20
0
        public async Task TextDecorationsInitializesCorrectly()
        {
            var xplatTextDecorations = TextDecorations.Underline;

            var labelHandler = new LabelStub()
            {
                TextDecorations = xplatTextDecorations
            };

            var values = await GetValueAsync(labelHandler, (handler) =>
            {
                return(new
                {
                    ViewValue = labelHandler.TextDecorations,
                    NativeViewValue = GetNativeTextDecorations(handler)
                });
            });

            Assert.Equal(xplatTextDecorations, values.ViewValue);
            Assert.True(values.NativeViewValue != null);
        }
示例#21
0
        public async Task TextDecorationsInitializesCorrectly()
        {
            var xplatTextDecorations = TextDecorations.Underline;

            var labelHandler = new LabelStub()
            {
                Text            = "Test",      // Native values won't actually apply unless there's text
                TextDecorations = xplatTextDecorations
            };

            var values = await GetValueAsync(labelHandler, (handler) =>
            {
                return(new
                {
                    ViewValue = labelHandler.TextDecorations,
                    GetNativeLabel(handler).AttributedText
                });
            });

            Assert.Equal(xplatTextDecorations, values.ViewValue);
            values.AttributedText.AssertHasUnderline();
        }
示例#22
0
        public async Task LineHeightSurvivesTextDecorations()
        {
            TextDecorations xplatTextDecorations = TextDecorations.Underline;
            double          xplatLineHeight      = 2;
            var             expectedLineHeight   = xplatLineHeight;

            var label = new LabelStub()
            {
                Text = "test", LineHeight = xplatLineHeight
            };

            var handler = await CreateHandlerAsync(label);

            label.TextDecorations = xplatTextDecorations;
            await InvokeOnMainThreadAsync(() => handler.UpdateValue(nameof(label.TextDecorations)));

            var actualLineHeight = await InvokeOnMainThreadAsync(() => GetNativeLineHeight(handler));

            var attributedText = await InvokeOnMainThreadAsync(() => GetAttributedText(handler));

            Assert.Equal(expectedLineHeight, actualLineHeight);
            attributedText.AssertHasUnderline();
        }
示例#23
0
        public async Task LineHeightInitializesCorrectly()
        {
            var xplatLineHeight = 1.5d;

            var labelHandler = new LabelStub()
            {
                LineHeight = xplatLineHeight
            };

            var values = await GetValueAsync(labelHandler, (handler) =>
            {
                return(new
                {
                    ViewValue = labelHandler.LineHeight,
                    NativeViewValue = GetNativeLineHeight(handler)
                });
            });

            float expectedValue = 1.5f;

            Assert.Equal(xplatLineHeight, values.ViewValue);
            Assert.Equal(expectedValue, values.NativeViewValue);
        }
示例#24
0
        public async Task TextDecorationsInitializesCorrectly()
        {
            var xplatTextDecorations = TextDecorations.Underline;

            var labelHandler = new LabelStub()
            {
                TextDecorations = xplatTextDecorations
            };

            var values = await GetValueAsync(labelHandler, (handler) =>
            {
                return(new
                {
                    ViewValue = labelHandler.TextDecorations,
                    PlatformViewValue = GetNativeTextDecorations(handler)
                });
            });

            PaintFlags expectedValue = PaintFlags.UnderlineText;

            Assert.Equal(xplatTextDecorations, values.ViewValue);
            values.PlatformViewValue.AssertHasFlag(expectedValue);
        }
示例#25
0
        public async Task PaddingInitializesCorrectly()
        {
            var label = new LabelStub()
            {
                Text    = "Test",
                Padding = new Thickness(5, 10, 15, 20)
            };

            var handler = await CreateHandlerAsync(label);

            var(left, top, right, bottom) = GetNativePadding((TextView)handler.PlatformView);

            var context = handler.PlatformView.Context;

            var expectedLeft   = context.ToPixels(5);
            var expectedTop    = context.ToPixels(10);
            var expectedRight  = context.ToPixels(15);
            var expectedBottom = context.ToPixels(20);

            Assert.Equal(expectedLeft, left);
            Assert.Equal(expectedTop, top);
            Assert.Equal(expectedRight, right);
            Assert.Equal(expectedBottom, bottom);
        }
示例#26
0
        public async Task LineHeightSurvivesCharacterSpacing()
        {
            double xplatCharacterSpacing    = 1.5;
            var    expectedCharacterSpacing = xplatCharacterSpacing;
            double xplatLineHeight          = 2;
            var    expectedLineHeight       = xplatLineHeight;

            var label = new LabelStub()
            {
                Text = "test", LineHeight = xplatLineHeight
            };

            var handler = await CreateHandlerAsync(label);

            label.CharacterSpacing = xplatCharacterSpacing;
            await InvokeOnMainThreadAsync(() => handler.UpdateValue(nameof(label.CharacterSpacing)));

            var actualLineHeight = await InvokeOnMainThreadAsync(() => GetNativeLineHeight(handler));

            var actualCharacterSpacing = await InvokeOnMainThreadAsync(() => GetNativeCharacterSpacing(handler));

            Assert.Equal(expectedLineHeight, actualLineHeight);
            Assert.Equal(expectedCharacterSpacing, actualCharacterSpacing);
        }
示例#27
0
        public async Task HorizontalTextAlignmentInitializesCorrectly()
        {
            var xplatHorizontalTextAlignment = TextAlignment.End;

            var labelStub = new LabelStub()
            {
                Text = "Test",
                HorizontalTextAlignment = xplatHorizontalTextAlignment
            };

            UITextAlignment expectedValue = UITextAlignment.Right;

            var values = await GetValueAsync(labelStub, (handler) =>
            {
                return(new
                {
                    ViewValue = labelStub.HorizontalTextAlignment,
                    NativeViewValue = GetNativeHorizontalTextAlignment(handler)
                });
            });

            Assert.Equal(xplatHorizontalTextAlignment, values.ViewValue);
            values.NativeViewValue.AssertHasFlag(expectedValue);
        }
示例#28
0
        public async Task FontFamilyInitializesCorrectly(string family)
        {
            var label = new LabelStub()
            {
                Text = "Test",
                Font = Font.OfSize(family, 10)
            };

            var(services, nativeFont) = await GetValueAsync(label, handler => (handler.Services, GetNativeLabel(handler).Font));

            var fontManager = services.GetRequiredService <IFontManager>();

            var expectedNativeFont = fontManager.GetFont(Font.OfSize(family, 0.0));

            Assert.Equal(expectedNativeFont.FamilyName, nativeFont.FamilyName);
            if (string.IsNullOrEmpty(family))
            {
                Assert.Equal(fontManager.DefaultFont.FamilyName, nativeFont.FamilyName);
            }
            else
            {
                Assert.NotEqual(fontManager.DefaultFont.FamilyName, nativeFont.FamilyName);
            }
        }