Skip to content
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

feat(ios,android): expose Ti.UI.Slider „tintColor“ and „trackTintColor“ #11074

Merged
merged 7 commits into from
Oct 8, 2019
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@
TiC.PROPERTY_SPLIT_TRACK,
"leftTrackImage",
"rightTrackImage",
TiC.PROPERTY_TINT_COLOR,
TiC.PROPERTY_TRACK_TINT_COLOR,
TiC.PROPERTY_VALUE
})
// clang-format on
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ public void processProperties(KrollDict d)
if (d.containsKey(TiC.PROPERTY_TINT_COLOR)) {
handleSetTintColor(TiConvert.toColor(d, TiC.PROPERTY_TINT_COLOR));
}
if (d.containsKey(TiC.PROPERTY_TINT_COLOR)) {
if (d.containsKey(TiC.PROPERTY_TRACK_TINT_COLOR)) {
handleSetTrackTintColor(TiConvert.toColor(d, TiC.PROPERTY_TRACK_TINT_COLOR));
}
updateProgress();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
import org.appcelerator.titanium.util.TiUIHelper;
import org.appcelerator.titanium.view.TiUIView;

import android.content.res.ColorStateList;
import android.graphics.Rect;
import android.graphics.drawable.ClipDrawable;
import android.graphics.drawable.Drawable;
Expand Down Expand Up @@ -101,6 +102,12 @@ public void processProperties(KrollDict d)
if (d.containsKey("leftTrackImage") || d.containsKey("rightTrackImage")) {
updateTrackingImages(seekBar, d);
}
if (d.containsKeyAndNotNull(TiC.PROPERTY_TINT_COLOR)) {
handleSetTintColor(TiConvert.toColor(d, TiC.PROPERTY_TINT_COLOR));
}
if (d.containsKeyAndNotNull(TiC.PROPERTY_TRACK_TINT_COLOR)) {
handleSetTrackTintColor(TiConvert.toColor(d, TiC.PROPERTY_TRACK_TINT_COLOR));
}
updateRange();
updateControl();
updateRightDrawable();
Expand Down Expand Up @@ -224,7 +231,12 @@ public void propertyChanged(String key, Object oldValue, Object newValue, KrollP
if (Log.isDebugModeEnabled()) {
Log.d(TAG, "Property: " + key + " old: " + oldValue + " new: " + newValue, Log.DEBUG_MODE);
}

SeekBar seekBar = (SeekBar) getNativeView();
if (seekBar == null) {
return;
}

if (key.equals(TiC.PROPERTY_VALUE)) {
pos = TiConvert.toFloat(newValue);
int curPos = (int) Math.floor(scaleFactor * (pos + offset));
Expand Down Expand Up @@ -268,6 +280,16 @@ public void propertyChanged(String key, Object oldValue, Object newValue, KrollP
updateControl();
int curPos = (int) Math.floor(scaleFactor * (pos + offset));
onProgressChanged(seekBar, curPos, true);
} else if (key.equals(TiC.PROPERTY_TINT_COLOR)) {
String stringValue = TiConvert.toString(newValue);
if (stringValue != null) {
handleSetTintColor(TiConvert.toColor(stringValue));
}
} else if (key.equals(TiC.PROPERTY_TRACK_TINT_COLOR)) {
String stringValue = TiConvert.toString(newValue);
if (stringValue != null) {
handleSetTrackTintColor(TiConvert.toColor(stringValue));
}
} else if (key.equals("thumbImage")) {
//updateThumb(seekBar, proxy.getDynamicProperties());
//seekBar.invalidate();
Expand Down Expand Up @@ -350,6 +372,26 @@ public void onStopTrackingTouch(SeekBar seekBar)
fireEvent(TiC.EVENT_STOP, data, false);
}

protected void handleSetTintColor(int color)
{
SeekBar seekBar = (SeekBar) getNativeView();

if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
ColorStateList singleColorStateList = ColorStateList.valueOf(color);
seekBar.setProgressTintList(singleColorStateList);
}
}

protected void handleSetTrackTintColor(int color)
{
SeekBar seekBar = (SeekBar) getNativeView();

ColorStateList singleColorStateList = ColorStateList.valueOf(color);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
seekBar.setProgressBackgroundTintList(singleColorStateList);
}
}

private float scaledValue()
{
return pos + min;
Expand Down
12 changes: 12 additions & 0 deletions apidoc/Titanium/UI/Slider.yml
Original file line number Diff line number Diff line change
Expand Up @@ -391,6 +391,18 @@ properties:
type: [String, Titanium.Blob]
platforms: [android, iphone, ipad]

- name: tintColor
summary: The color shown for the portion of the progress bar that is filled.
since: {iphone: "3.1.3", ipad: "3.1.3", android: "8.3.0"}
osver: {android: {min: "5.0"}}

- name: trackTintColor
summary: The color shown for the portion of the progress bar that is not filled.
type: String
platforms: [iphone, ipad, android]
since: {iphone: "8.3.0", ipad: "8.3.0", android: "8.3.0"}
osver: {android: {min: "5.0"}}

- name: value
summary: Current value of the slider.
type: String
6 changes: 6 additions & 0 deletions iphone/Classes/TiUISlider.m
Original file line number Diff line number Diff line change
Expand Up @@ -253,6 +253,12 @@ - (void)setEnabled_:(id)value
[[self sliderView] setEnabled:[TiUtils boolValue:value]];
}

- (void)setTrackTintColor_:(id)value
{
UIColor *newColor = [[TiUtils colorValue:value] _color];
[[self sliderView] setMaximumTrackTintColor:newColor];
}

- (CGFloat)verifyHeight:(CGFloat)suggestedHeight
{
CGFloat result = [[self sliderView] sizeThatFits:CGSizeZero].height;
Expand Down
21 changes: 21 additions & 0 deletions tests/Resources/ti.ui.slider.addontest.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
/*
* Appcelerator Titanium Mobile
* Copyright (c) 2015-Present by Axway, Inc. All Rights Reserved.
* Licensed under the terms of the Apache Public License
* Please see the LICENSE included with this distribution for details.
*/
/* eslint-env mocha */
/* eslint no-unused-expressions: "off" */
'use strict';
const should = require('./utilities/assertions');

describe('Titanium.UI.Slider', function () {
it.windowsMissing('tintColor/trackTintColor', () => {
const slider = Ti.UI.createSlider({
tintColor: 'red',
trackTintColor: 'green'
});
should(slider.tintColor).be.eql('red');
should(slider.trackTintColor).be.eql('green');
});
});