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

Regression: Xamarin.Forms Button Image position broken on Android #4354

Closed
napalmDaz opened this issue Nov 8, 2018 · 8 comments · Fixed by #4967
Closed

Regression: Xamarin.Forms Button Image position broken on Android #4354

napalmDaz opened this issue Nov 8, 2018 · 8 comments · Fixed by #4967

Comments

@napalmDaz
Copy link

napalmDaz commented Nov 8, 2018

Description

When setting an image, text and ContentLayout on a button, the image is not positioned correctly on Android when using Xamarin Forms 3.3. This worked as expected in XF 3.1. iOS does not seem to be affected.

There are a couple problems here

  1. the code here 3090843 needs to be copied to the fast renderer
  2. The code used to check if the padding has been set won't work because the Padding BP uses a defaultValueCreator and because it uses a defaultValueCreator then IsSet isn't reliable to check because ClearValue doesn't cause IsSet to return to false

Steps to Reproduce

<?xml version="1.0" encoding="utf-8"?>
<ContentPage xmlns="http://xamarin.com/schemas/2014/forms" xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml" xmlns:local="clr-namespace:Buttons" x:Class="Buttons.MainPage">
<Grid x:Name="bottomLayout" ColumnSpacing="0" Margin="0" Padding="0">
    <Grid.ColumnDefinitions>
        <ColumnDefinition Width="*"/>
            <ColumnDefinition Width="74"/>
            <ColumnDefinition Width="74"/>
        </Grid.ColumnDefinitions>
        <StackLayout Orientation="Horizontal" x:Name="RoomSelectionOptions" Grid.Column="0" >
			<!-- Things -->
        </StackLayout>
        <Button Grid.Column="1" 
            x:Name="ControlsButton" 
            HorizontalOptions="EndAndExpand" 
            BackgroundColor="Transparent" 
            ContentLayout="Top,0" 
            FontSize="Micro" 
            Image="ic_brightness50" 
            TextColor="{StaticResource PrimaryDark}" 
            Text="Control" 
            Clicked="ControlsCommandButton_Clicked" />
        <Button Grid.Column="2" 
            x:Name="PowerCommandButton" 
            HorizontalOptions="Start" 
            BackgroundColor="Transparent" 
            ContentLayout="Top,0" 
            FontSize="Micro" 
            Image="ic_powerswitch" 
            TextColor="{StaticResource PrimaryDark}" 
            Text="Power" 
            Clicked="PowerCommandButton_Clicked" />
    </Grid>
</ContentPage>

Expected Behavior

Button image is centered as in previous versions (and also iOS) and relationship specified in ContentLayout is respected.

Actual Behavior

On Android, the button image is offset (no margin / padding) and not displayed in the expected location towards the center of the button.

Basic Information

  • Version with issue: 3.3.0.967583
  • Last known good version: 3.1
  • IDE: VS 2017 Enterprise
  • Platform Target Frameworks:
    • Android: 8.1 Oreo

Screenshots

https://imgur.com/f3PSDDA

@napalmDaz
Copy link
Author

Possibly related to #2426

I can conditionally add top padding to compensate for now.

@PureWeen
Copy link
Contributor

PureWeen commented Nov 9, 2018

@napalmDaz are you using Fast Renderers??

It looks like this PR needs to be copied to the Fast Renderer

3090843

@napalmDaz
Copy link
Author

@PureWeen Unless fast renderers are enabled by default in XF3.3, then I don't think so as I'm not opting in via the flag in MainActivity.

Here is a view hierarchy dump for confirmation:
https://imgur.com/a/VaLMW1p

@PureWeen PureWeen added the e/3 🕒 3 label Nov 10, 2018
@PureWeen
Copy link
Contributor

@napalmDaz Are you updated to AppCompat? The non AppCompat button renderer also doesn't have the code in place to preserve the padding so maybe that's it?

@napalmDaz
Copy link
Author

@PureWeen
I believe so:
public partial class MainActivity : global::Xamarin.Forms.Platform.Android.FormsAppCompatActivity,

Nuget:
Xamarin.Android.Support.v7.AppCompat 27.0.2.1

@PureWeen
Copy link
Contributor

Alright I'm guessing it's this line
https://github.com/xamarin/Xamarin.Forms/pull/2426/files#diff-08a5663cd61b123664c0ac0fd19c3255R62

Either way I've seen a few things that need to be fixed so we'll get this addressed.

@mattleibow
Copy link
Contributor

I have fixed this in #4967

@agrisyst-slo
Copy link

I just upgraded Xamarin.Forms to version 3.6.0.220655 and the ImagePosition of the buttons was no longer as it should be.

See attached picture with the buttons as they should be, and how they are in this latest version.

I have downgraded Xamarin.Forms to version 3.1.0.697729 and the buttons are again as they should be.

Kind regards, Saskia

ImagePositionBroken

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

Successfully merging a pull request may close this issue.

4 participants