From 89b0bf0a208fda9457198cba0016606c768bb9bc Mon Sep 17 00:00:00 2001 From: Henning Hall Date: Wed, 22 Aug 2018 22:24:01 +0200 Subject: [PATCH] Added textColor property (android) --- .../date_picker/DatePickerManager.java | 5 ++++ .../henninghall/date_picker/PickerView.java | 2 -- .../com/henninghall/date_picker/Style.java | 10 ++++++++ .../date_picker/wheelFunctions/TextColor.java | 24 +++++++++++++++++++ .../henninghall/date_picker/wheels/Wheel.java | 2 +- example/App.js | 6 ++--- example/examples/Advanced.js | 20 +++++++++++++--- 7 files changed, 60 insertions(+), 9 deletions(-) create mode 100644 android/src/main/java/com/henninghall/date_picker/wheelFunctions/TextColor.java diff --git a/android/src/main/java/com/henninghall/date_picker/DatePickerManager.java b/android/src/main/java/com/henninghall/date_picker/DatePickerManager.java index 63e7a13..748daaf 100644 --- a/android/src/main/java/com/henninghall/date_picker/DatePickerManager.java +++ b/android/src/main/java/com/henninghall/date_picker/DatePickerManager.java @@ -67,6 +67,11 @@ public class DatePickerManager extends SimpleViewManager { view.style.setFadeToColor(color); } + @ReactProp(name = "textColor") + public void setTextColor(PickerView view, @Nullable String color) { + view.style.setTextColor(color); + } + @ReactProp(name = "minuteInterval") public void setMinuteInterval(PickerView view, @Nullable int interval) throws Exception { if (interval < 0 || interval > 59) throw new Exception("Minute interval out of bounds"); diff --git a/android/src/main/java/com/henninghall/date_picker/PickerView.java b/android/src/main/java/com/henninghall/date_picker/PickerView.java index 5c87356..5dfa47e 100644 --- a/android/src/main/java/com/henninghall/date_picker/PickerView.java +++ b/android/src/main/java/com/henninghall/date_picker/PickerView.java @@ -1,11 +1,9 @@ package com.henninghall.date_picker; -import android.annotation.SuppressLint; import android.view.View; import android.widget.RelativeLayout; import com.facebook.react.bridge.Arguments; -import com.facebook.react.bridge.ReadableMap; import com.facebook.react.bridge.WritableMap; import com.facebook.react.uimanager.events.RCTEventEmitter; import com.henninghall.date_picker.wheelFunctions.AnimateToDate; diff --git a/android/src/main/java/com/henninghall/date_picker/Style.java b/android/src/main/java/com/henninghall/date_picker/Style.java index 0d935b7..cc6fd66 100644 --- a/android/src/main/java/com/henninghall/date_picker/Style.java +++ b/android/src/main/java/com/henninghall/date_picker/Style.java @@ -4,12 +4,18 @@ import android.graphics.Color; import android.graphics.drawable.GradientDrawable; import android.widget.ImageView; +import com.henninghall.date_picker.wheelFunctions.TextColor; + +import org.w3c.dom.Text; + class Style { private final GradientDrawable gradientBottom; private final GradientDrawable gradientTop; + private final PickerView pickerView; public Style(PickerView pickerView) { + this.pickerView = pickerView; ImageView overlayTop = (ImageView) pickerView.findViewById(R.id.overlay_top); ImageView overlayBottom = (ImageView) pickerView.findViewById(R.id.overlay_bottom); this.gradientTop = (GradientDrawable) overlayTop.getDrawable(); @@ -28,6 +34,10 @@ class Style { } } + public void setTextColor(String color) { + this.pickerView.applyOnAllWheels(new TextColor(color)); + } + private boolean validColor(String color){ return color != null && color.length() == 7; } diff --git a/android/src/main/java/com/henninghall/date_picker/wheelFunctions/TextColor.java b/android/src/main/java/com/henninghall/date_picker/wheelFunctions/TextColor.java new file mode 100644 index 0000000..2dafa78 --- /dev/null +++ b/android/src/main/java/com/henninghall/date_picker/wheelFunctions/TextColor.java @@ -0,0 +1,24 @@ +package com.henninghall.date_picker.wheelFunctions; + +import android.graphics.Color; + +import com.henninghall.date_picker.wheels.Wheel; + +public class TextColor implements WheelFunction { + + private final String color; + + public TextColor(String color) { + this.color = color; + } + + @Override + public void apply(Wheel wheel) { + int fullColor= Color.parseColor(color); + int fadedColor = Color.parseColor("#70"+ color.substring(1)); + wheel.picker.setNormalTextColor(fadedColor); + wheel.picker.setSelectedTextColor(fullColor); + } +} + + diff --git a/android/src/main/java/com/henninghall/date_picker/wheels/Wheel.java b/android/src/main/java/com/henninghall/date_picker/wheels/Wheel.java index f1ca947..4863813 100644 --- a/android/src/main/java/com/henninghall/date_picker/wheels/Wheel.java +++ b/android/src/main/java/com/henninghall/date_picker/wheels/Wheel.java @@ -19,7 +19,7 @@ public abstract class Wheel { ArrayList values; ArrayList displayValues; - NumberPickerView picker; + public NumberPickerView picker; public SimpleDateFormat format; SimpleDateFormat displayFormat; diff --git a/example/App.js b/example/App.js index 3409ceb..121a804 100644 --- a/example/App.js +++ b/example/App.js @@ -10,7 +10,7 @@ export default class App extends Component { state = { picker: undefined, - backgroundColor: undefined, + backgroundColor: "#ffffff", } render() { @@ -62,11 +62,11 @@ export default class App extends Component { const styles = StyleSheet.create({ container: { flex: 1, - backgroundColor: '#abcdef', - marginTop: 15, + paddingTop: 15, }, content: { alignItems: 'center', + flex: 1, }, text: { color: 'dodgerblue', diff --git a/example/examples/Advanced.js b/example/examples/Advanced.js index c86d1b4..6674a1a 100644 --- a/example/examples/Advanced.js +++ b/example/examples/Advanced.js @@ -16,6 +16,7 @@ export default class Advanced extends Component { chosenDate: new Date(), searchTerm: '', locale: DeviceInfo.getDeviceLocale(), + textColor: '#000000', } render() { @@ -30,6 +31,7 @@ export default class Advanced extends Component { minimumDate={new Date()} maximumDate={(new Date()).addHours(24 * 5)} fadeToColor={this.props.backgroundColor} + textColor={this.state.textColor} /> Current locale: {this.state.locale} @@ -56,23 +58,28 @@ export default class Advanced extends Component { -