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

[Android] Buttons can be round; remove Padding & Shadow by default#1935

Merged
jassmith merged 13 commits into15-5from
fix-issue1909
Mar 5, 2018
Merged

[Android] Buttons can be round; remove Padding & Shadow by default#1935
jassmith merged 13 commits into15-5from
fix-issue1909

Conversation

@samhouts
Copy link
Copy Markdown
Contributor

@samhouts samhouts commented Feb 21, 2018

Description of Change

Removing the Padding and Shadow that were added in #1570 to make the X.F. Buttons mimic the style of a default Android Button. These can be added back to Buttons using new Platform Specifics.

Also adjusting the padding mismatch that made circle Buttons appear to be slightly rectangular.

Before #1570:
before-1570

After #1570:
before

After this change (note, changed the test case for an additional parameter):
screenshot_20180227-124138

Bugs Fixed

API Changes

Added:

  • bool Button.On<Android>().UseDefaultPadding()
  • void Button.On<Android>().SetUseDefaultPadding(true/false)
  • bool Button.On<Android>().UseDefaultShadow()
  • void Button.On<Android>().SetUseDefaultShadow(true/false)

Behavioral Changes

⚠️ Setting the CornerRadius, BackgroundColor, BorderColor, or BorderWidth properties will replace the Background drawable of an Android Button. If you need to use a custom drawable, please incorporate all of these properties into your custom drawable instead of attempting to use the Xamarin.Forms properties to adjust some or all of those values.

PR Checklist

  • Has tests (if omitted, state reason in description)
  • Rebased on top of master at time of PR
  • Changes adhere to coding standard
  • Consolidate commits as makes sense

@samhouts samhouts added the DO-NOT-MERGE-!!! 🛑 This is in progress and needs to be updated before it can be merged. label Feb 22, 2018
@bill2004158
Copy link
Copy Markdown
Contributor

  1.  float PaddingTop
     {
     	get { return (_paddingTop / 2f) + ShadowDy; }
     	set { _paddingTop = value; }
     }
    

if I want to hide the shadow,
however, it seems it still increased the padding Top?
2.
RectF rect = new RectF(0, 0, width, height - 0);
why need -0?

@rmarinho rmarinho requested review from hartez and jassmith February 23, 2018 11:57
@samhouts
Copy link
Copy Markdown
Contributor Author

@bill2004158 Not to worry, we'll be revising this PR to make it possible to hide the shadow. That's why it's marked as do-not-merge right now. Thanks!

@samhouts samhouts changed the title [Android] Buttons can be round [Android] Buttons can be round; remove Padding & Shadow by default Feb 27, 2018
@samhouts samhouts removed the DO-NOT-MERGE-!!! 🛑 This is in progress and needs to be updated before it can be merged. label Feb 28, 2018
@jassmith jassmith merged commit 1ce84e0 into 15-5 Mar 5, 2018
@samhouts samhouts deleted the fix-issue1909 branch March 5, 2018 20:50
@EmilAlipiev
Copy link
Copy Markdown
Contributor

I understand some poeple had problems with previous changes but now reverting or redoing those changes breaks others. I was quite happy with the previous version indeed. would you mind sharing all styles you have removed that we can set in the shared library? because when I look at your commits I am bit lost. some padding are set dynamically looks like.

@samhouts
Copy link
Copy Markdown
Contributor Author

Hi @EmilAlipiev! If you were happy with the way it looked as of #1570, then you want to do:

using Xamarin.Forms.PlatformConfiguration; 
using Xamarin.Forms.PlatformConfiguration.AndroidSpecific;_button.On<Android>().SetUseDefaultPadding(true).SetUseDefaultShadow(true);

I would have liked to have those settings enabled by default, but that was, unfortunately, a behavioral change that would have broken old apps.

Let me know if you have any further questions. Thanks!

@vincentcastagna
Copy link
Copy Markdown

vincentcastagna commented Apr 10, 2018

@samhouts

Is your snippet supposed to be implemented as custom renderer ? What's this _button variable ?

Thanks :)

Update : my bad, for anyone... just extending with custom class Xamarin.Forms.Button and implement @samhouts snippet in your custom button class constructor.

@samhouts
Copy link
Copy Markdown
Contributor Author

That's one way to do it. You can apply this platform specific property to a standard Button, too.

See https://docs.microsoft.com/en-us/xamarin/xamarin-forms/platform/platform-specifics/consuming/android for some examples of how to use platform specifics.

Thanks!

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants