Skip to content

Fix button styling issue #1875

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Dec 1, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
- Fix broken button styling (#1864)
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,12 @@

</FrameLayout>

<Button
<!--
NOTE: This sample app uses this class from the FirebaseUI library to show the Google Sign
in button. However this button is NOT considered part of the public API and you should not
use it in your own app.
-->
<com.firebase.ui.auth.util.ui.SupportVectorDrawablesButton
android:id="@+id/custom_google_signin_button"
style="@style/FirebaseUI.Button.AccountChooser.GoogleButton"
android:layout_width="wrap_content"
Expand Down
7 changes: 6 additions & 1 deletion app/src/main/res/layout/auth_method_picker_custom_layout.xml
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,12 @@

</FrameLayout>

<Button
<!--
NOTE: This sample app uses this class from the FirebaseUI library to show the Google Sign
in button. However this button is NOT considered part of the public API and you should not
use it in your own app.
-->
<com.firebase.ui.auth.util.ui.SupportVectorDrawablesButton
android:id="@+id/custom_google_signin_button"
style="@style/FirebaseUI.Button.AccountChooser.GoogleButton"
android:layout_width="wrap_content"
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
package com.firebase.ui.auth.util.ui;

import android.content.Context;
import android.content.res.TypedArray;
import android.graphics.drawable.Drawable;
import android.os.Build;
import android.util.AttributeSet;

import com.firebase.ui.auth.R;

import androidx.annotation.RestrictTo;
import androidx.appcompat.content.res.AppCompatResources;
import androidx.appcompat.widget.AppCompatButton;
import androidx.core.widget.TextViewCompat;

/**
* A custom button that supports using vector drawables with the {@code
* android:drawable[Start/End/Top/Bottom]} attribute pre-L.
* <p>
* AppCompat can only load vector drawables with srcCompat pre-L and doesn't provide a similar
* compatibility attribute for compound drawables. Thus, we must load compound drawables at runtime
* using AppCompat and inject them into the button to support pre-L devices.
*/
@RestrictTo(RestrictTo.Scope.LIBRARY_GROUP)
public class SupportVectorDrawablesButton extends AppCompatButton {
public SupportVectorDrawablesButton(Context context) {
super(context);
}

public SupportVectorDrawablesButton(Context context, AttributeSet attrs) {
super(context, attrs);
initSupportVectorDrawablesAttrs(attrs);
}

public SupportVectorDrawablesButton(Context context, AttributeSet attrs, int defStyleAttr) {
super(context, attrs, defStyleAttr);
initSupportVectorDrawablesAttrs(attrs);
}

/**
* Loads the compound drawables natively on L+ devices and using AppCompat pre-L.
* <p>
* <i>Note:</i> If we ever need a TextView with compound drawables, this same technique is
* applicable.
*/
private void initSupportVectorDrawablesAttrs(AttributeSet attrs) {
if (attrs == null) { return; }

TypedArray attributeArray = getContext().obtainStyledAttributes(
attrs,
R.styleable.SupportVectorDrawablesButton);

Drawable drawableStart = null;
Drawable drawableEnd = null;
Drawable drawableTop = null;
Drawable drawableBottom = null;

if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
drawableStart = attributeArray.getDrawable(
R.styleable.SupportVectorDrawablesButton_drawableStartCompat);
drawableEnd = attributeArray.getDrawable(
R.styleable.SupportVectorDrawablesButton_drawableEndCompat);
drawableTop = attributeArray.getDrawable(
R.styleable.SupportVectorDrawablesButton_drawableTopCompat);
drawableBottom = attributeArray.getDrawable(
R.styleable.SupportVectorDrawablesButton_drawableBottomCompat);
} else {
int drawableStartId = attributeArray.getResourceId(
R.styleable.SupportVectorDrawablesButton_drawableStartCompat, -1);
int drawableEndId = attributeArray.getResourceId(
R.styleable.SupportVectorDrawablesButton_drawableEndCompat, -1);
int drawableTopId = attributeArray.getResourceId(
R.styleable.SupportVectorDrawablesButton_drawableTopCompat, -1);
int drawableBottomId = attributeArray.getResourceId(
R.styleable.SupportVectorDrawablesButton_drawableBottomCompat, -1);

if (drawableStartId != -1) {
drawableStart = AppCompatResources.getDrawable(getContext(), drawableStartId);
}
if (drawableEndId != -1) {
drawableEnd = AppCompatResources.getDrawable(getContext(), drawableEndId);
}
if (drawableTopId != -1) {
drawableTop = AppCompatResources.getDrawable(getContext(), drawableTopId);
}
if (drawableBottomId != -1) {
drawableBottom = AppCompatResources.getDrawable(getContext(), drawableBottomId);
}
}

TextViewCompat.setCompoundDrawablesRelativeWithIntrinsicBounds(
this, drawableStart, drawableTop, drawableEnd, drawableBottom);

attributeArray.recycle();
}
}
2 changes: 1 addition & 1 deletion auth/src/main/res/layout/fui_idp_button_apple.xml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<Button xmlns:android="http://schemas.android.com/apk/res/android"
<com.firebase.ui.auth.util.ui.SupportVectorDrawablesButton xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/apple_signin_button"
style="@style/FirebaseUI.Button.AccountChooser.AppleButton"
android:text="@string/fui_sign_in_with_apple"/>
3 changes: 2 additions & 1 deletion auth/src/main/res/layout/fui_idp_button_facebook.xml
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
<Button xmlns:android="http://schemas.android.com/apk/res/android"
<com.firebase.ui.auth.util.ui.SupportVectorDrawablesButton
xmlns:android="http://schemas.android.com/apk/res/android"
style="@style/FirebaseUI.Button.AccountChooser.FacebookButton"
android:text="@string/fui_sign_in_with_facebook" />
3 changes: 2 additions & 1 deletion auth/src/main/res/layout/fui_idp_button_github.xml
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
<Button xmlns:android="http://schemas.android.com/apk/res/android"
<com.firebase.ui.auth.util.ui.SupportVectorDrawablesButton
xmlns:android="http://schemas.android.com/apk/res/android"
style="@style/FirebaseUI.Button.AccountChooser.GitHubButton"
android:text="@string/fui_sign_in_with_github" />
3 changes: 2 additions & 1 deletion auth/src/main/res/layout/fui_idp_button_google.xml
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
<Button xmlns:android="http://schemas.android.com/apk/res/android"
<com.firebase.ui.auth.util.ui.SupportVectorDrawablesButton
xmlns:android="http://schemas.android.com/apk/res/android"
style="@style/FirebaseUI.Button.AccountChooser.GoogleButton"
android:text="@string/fui_sign_in_with_google" />
2 changes: 1 addition & 1 deletion auth/src/main/res/layout/fui_idp_button_microsoft.xml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<Button xmlns:android="http://schemas.android.com/apk/res/android"
<com.firebase.ui.auth.util.ui.SupportVectorDrawablesButton xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/microsoft_signin_button"
style="@style/FirebaseUI.Button.AccountChooser.MicrosoftButton"
android:text="@string/fui_sign_in_with_microsoft"/>
3 changes: 2 additions & 1 deletion auth/src/main/res/layout/fui_idp_button_twitter.xml
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
<Button xmlns:android="http://schemas.android.com/apk/res/android"
<com.firebase.ui.auth.util.ui.SupportVectorDrawablesButton
xmlns:android="http://schemas.android.com/apk/res/android"
style="@style/FirebaseUI.Button.AccountChooser.TwitterButton"
android:text="@string/fui_sign_in_with_twitter" />
2 changes: 1 addition & 1 deletion auth/src/main/res/layout/fui_idp_button_yahoo.xml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<Button xmlns:android="http://schemas.android.com/apk/res/android"
<com.firebase.ui.auth.util.ui.SupportVectorDrawablesButton xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/yahoo_signin_button"
style="@style/FirebaseUI.Button.AccountChooser.YahooButton"
android:text="@string/fui_sign_in_with_yahoo" />
2 changes: 1 addition & 1 deletion auth/src/main/res/layout/fui_provider_button_anonymous.xml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<Button
<com.firebase.ui.auth.util.ui.SupportVectorDrawablesButton
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/anonymous_button"
style="@style/FirebaseUI.Button.AccountChooser.AnonymousButton"
Expand Down
2 changes: 1 addition & 1 deletion auth/src/main/res/layout/fui_provider_button_email.xml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<Button
<com.firebase.ui.auth.util.ui.SupportVectorDrawablesButton
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/email_button"
Expand Down
2 changes: 1 addition & 1 deletion auth/src/main/res/layout/fui_provider_button_phone.xml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<Button
<com.firebase.ui.auth.util.ui.SupportVectorDrawablesButton
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/phone_button"
Expand Down
7 changes: 7 additions & 0 deletions auth/src/main/res/values/attrs.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,11 @@
<attr name="spacingProportion" format="float" />
</declare-styleable>

<declare-styleable name="SupportVectorDrawablesButton">
<attr name="drawableStartCompat" format="reference" />
<attr name="drawableEndCompat" format="reference" />
<attr name="drawableTopCompat" format="reference" />
<attr name="drawableBottomCompat" format="reference" />
</declare-styleable>

</resources>