Skip to content

Commit c9780cd

Browse files
committed
fix: android use correct oultine button now.
Though it is broken with androidXMaterial 1.2.1!!!
1 parent ab44892 commit c9780cd

File tree

4 files changed

+40
-12
lines changed

4 files changed

+40
-12
lines changed
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<com.google.android.material.button.MaterialButton xmlns:android="http://schemas.android.com/apk/res/android"
3+
style="@style/OutlinedButton.Custom">
4+
</com.google.android.material.button.MaterialButton>

packages/button/platforms/android/res/values/materialbuttonstyles.xml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,15 @@
1919
<item name="android:insetTop">0dp</item>
2020
<item name="android:insetBottom">0dp</item>
2121
</style>
22+
<style name="OutlinedButton.Custom" parent="@style/Widget.MaterialComponents.Button.OutlinedButton">
23+
<item name="android:padding">0dp</item>
24+
<item name="android:minWidth">88dp</item>
25+
<item name="android:minHeight">36dp</item>
26+
<item name="android:insetLeft">0dp</item>
27+
<item name="android:insetRight">0dp</item>
28+
<item name="android:insetTop">0dp</item>
29+
<item name="android:insetBottom">0dp</item>
30+
</style>
2231
<style name="Button.Custom" parent="@style/Widget.MaterialComponents.Button">
2332
<item name="android:padding">0dp</item>
2433
<item name="android:minWidth">88dp</item>

src/button/button.android.ts

Lines changed: 27 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,25 @@
11
import { VerticalTextAlignment, verticalTextAlignmentProperty } from '@nativescript-community/text';
22
import { dynamicElevationOffsetProperty, elevationProperty, rippleColorProperty } from '@nativescript-community/ui-material-core';
33
import { createStateListAnimator, getLayout, isPostLollipop } from '@nativescript-community/ui-material-core/android/utils';
4-
import { Background, Color, Length, TextTransform, androidDynamicElevationOffsetProperty, androidElevationProperty, backgroundInternalProperty, profile, textTransformProperty } from '@nativescript/core';
4+
import {
5+
Background,
6+
Color,
7+
Length,
8+
TextTransform,
9+
androidDynamicElevationOffsetProperty,
10+
androidElevationProperty,
11+
backgroundInternalProperty,
12+
profile,
13+
textTransformProperty,
14+
} from '@nativescript/core';
515
import { ButtonBase } from './button-common';
616

717
let LayoutInflater: typeof android.view.LayoutInflater;
818

919
let textId;
1020
let containedId;
1121
let flatId;
22+
let outlineId;
1223
let grayColorStateList: android.content.res.ColorStateList;
1324

1425
export class Button extends ButtonBase {
@@ -22,7 +33,7 @@ export class Button extends ButtonBase {
2233
let layoutId;
2334
const variant = this.variant;
2435
// let layoutIdName = 'material_button';
25-
if (variant === 'text' || variant === 'outline') {
36+
if (variant === 'text') {
2637
if (!textId) {
2738
textId = getLayout('material_button_text');
2839
}
@@ -32,6 +43,11 @@ export class Button extends ButtonBase {
3243
flatId = getLayout('material_button_flat');
3344
}
3445
layoutId = flatId;
46+
} else if (variant === 'outline') {
47+
if (!outlineId) {
48+
outlineId = getLayout('material_button_outline');
49+
}
50+
layoutId = outlineId;
3551
} else {
3652
if (!containedId) {
3753
containedId = getLayout('material_button');
@@ -48,15 +64,16 @@ export class Button extends ButtonBase {
4864
if (!LayoutInflater) {
4965
LayoutInflater = android.view.LayoutInflater;
5066
}
67+
console.log('test', this.variant, layoutId);
5168
const view = android.view.LayoutInflater.from(this._context).inflate(layoutId, null, false) as com.google.android.material.button.MaterialButton;
5269

53-
if (variant === 'outline') {
54-
view.setStrokeWidth(1);
55-
if (!grayColorStateList) {
56-
grayColorStateList = android.content.res.ColorStateList.valueOf(new Color('gray').android);
57-
}
58-
view.setStrokeColor(grayColorStateList);
59-
}
70+
// if (variant === 'outline') {
71+
// view.setStrokeWidth(1);
72+
// if (!grayColorStateList) {
73+
// grayColorStateList = android.content.res.ColorStateList.valueOf(new Color('gray').android);
74+
// }
75+
// view.setStrokeColor(grayColorStateList);
76+
// }
6077
return view;
6178
}
6279

@@ -115,7 +132,7 @@ export class Button extends ButtonBase {
115132
this.nativeViewProtected.setStrokeWidth(value);
116133
}
117134
[textTransformProperty.setNative](value: TextTransform) {
118-
this.nativeViewProtected.setAllCaps((value !== 'none')) ;
135+
this.nativeViewProtected.setAllCaps(value !== 'none');
119136
}
120137
[backgroundInternalProperty.setNative](value: android.graphics.drawable.Drawable | Background) {
121138
const view = this.nativeTextViewProtected;

src/floatingactionbutton/floatingactionbutton.android.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@ export class FloatingActionButton extends FloatingActionButtonBase {
1515
}
1616
const view = new MDCFabButton(this._context);
1717
this.defaultPadding = view.getPaddingTop();
18-
console.log('defaultPadding', this.defaultPadding);
1918
return view;
2019
}
2120

@@ -93,7 +92,6 @@ export class FloatingActionButton extends FloatingActionButtonBase {
9392
this.nativeViewProtected.setRippleColor(android.content.res.ColorStateList.valueOf(color.android));
9493
}
9594
[expandedProperty.setNative](value: boolean) {
96-
console.log('expandedProperty', value);
9795
if (value) {
9896
this.nativeViewProtected.extend();
9997
} else {

0 commit comments

Comments
 (0)