Skip to content

Commit

Permalink
thumb colors
Browse files Browse the repository at this point in the history
  • Loading branch information
m1ga committed Jun 4, 2024
1 parent 7880589 commit c5a1953
Show file tree
Hide file tree
Showing 4 changed files with 55 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,9 @@
TiC.PROPERTY_TEXT_ALIGN,
TiC.PROPERTY_TINT_COLOR,
TiC.PROPERTY_ACTIVE_TINT_COLOR,
TiC.PROPERTY_VERTICAL_ALIGN
TiC.PROPERTY_VERTICAL_ALIGN,
TiC.EVENT_PROPERTY_ACTIVE_THUMB_COLOR,
TiC.EVENT_PROPERTY_THUMB_COLOR
})
public class SwitchProxy extends TiViewProxy
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,34 @@ public void processProperties(KrollDict d)
setStyle(TiConvert.toInt(d.get(TiC.PROPERTY_STYLE), UIModule.SWITCH_STYLE_SLIDER));
}

if (d.containsKeyAndNotNull(TiC.EVENT_PROPERTY_THUMB_COLOR)
|| d.containsKeyAndNotNull(TiC.EVENT_PROPERTY_ACTIVE_THUMB_COLOR)) {
CompoundButton currentButton = (CompoundButton) getNativeView();
if (currentButton instanceof SwitchMaterial) {

int colActive = d.containsKeyAndNotNull(TiC.EVENT_PROPERTY_ACTIVE_THUMB_COLOR)
? TiConvert.toColor(d, TiC.EVENT_PROPERTY_ACTIVE_THUMB_COLOR)
: TiConvert.toColor(d, TiC.EVENT_PROPERTY_THUMB_COLOR);
int colNormal = d.containsKeyAndNotNull(TiC.EVENT_PROPERTY_THUMB_COLOR)
? TiConvert.toColor(d, TiC.EVENT_PROPERTY_THUMB_COLOR)
: TiConvert.toColor(d, TiC.EVENT_PROPERTY_ACTIVE_THUMB_COLOR);

ColorStateList trackStates = new ColorStateList(
new int[][] {
new int[] { -android.R.attr.state_enabled },
new int[] { android.R.attr.state_checked },
new int[] {}
},
new int[] {
colNormal,
colActive,
colNormal
}
);
((SwitchMaterial) currentButton).setThumbTintList(trackStates);
}
}

if (d.containsKeyAndNotNull(TiC.PROPERTY_TINT_COLOR)
|| d.containsKeyAndNotNull(TiC.PROPERTY_ACTIVE_TINT_COLOR)) {
CompoundButton currentButton = (CompoundButton) getNativeView();
Expand Down
2 changes: 2 additions & 0 deletions android/titanium/src/java/org/appcelerator/titanium/TiC.java
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,8 @@ public class TiC
public static final String EVENT_PROPERTY_TAB = "tab";
public static final String EVENT_PROPERTY_THUMB_OFFSET = "thumbOffset";
public static final String EVENT_PROPERTY_THUMB_SIZE = "thumbSize";
public static final String EVENT_PROPERTY_THUMB_COLOR = "thumbColor";
public static final String EVENT_PROPERTY_ACTIVE_THUMB_COLOR = "activeThumbColor";
public static final String EVENT_PROPERTY_TYPE = "type";
public static final String EVENT_PROPERTY_VELOCITY = "velocity";
public static final String EVENT_PROPERTY_X = "x";
Expand Down
22 changes: 22 additions & 0 deletions apidoc/Titanium/UI/Switch.yml
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,28 @@ properties:
platforms: [android]
since: {android: 12.4.0}

- name: activeThumbColor
summary: The color used to tint the thumb icon of the switch when it is turned on.
description: |
The color used to tint the thumb icon of the switch when it is turned on.
Android: Active thumb color of the Material Switch.
type: [String, Titanium.UI.Color]
default: undefined
platforms: [android]
since: {android: 12.4.0}

- name: thumbColor
summary: The color used to tint the thumb icon of the switch when it is turned off.
description: |
The color used to tint the thumb icon of the switch when it is turned off.
Android: Inactive thumb color of the Material Switch.
type: [String, Titanium.UI.Color]
default: undefined
platforms: [android]
since: {android: 12.4.0}

- name: onTintColor
summary: The color used to tint the appearance of the switch when it is turned on.
type: [String, Titanium.UI.Color]
Expand Down

0 comments on commit c5a1953

Please sign in to comment.