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 8af607ad..1f30ec64 100644 --- a/android/src/main/java/com/henninghall/date_picker/PickerView.java +++ b/android/src/main/java/com/henninghall/date_picker/PickerView.java @@ -21,6 +21,7 @@ import com.henninghall.date_picker.props.TextColorProp; import com.henninghall.date_picker.ui.UIManager; import com.henninghall.date_picker.ui.Accessibility; +import com.henninghall.date_picker.props.ContentFontProp; import java.util.ArrayList; @@ -55,6 +56,10 @@ public void update() { uiManager.updateTextColor(); } + if (didUpdate(ContentFontProp.name)) { + uiManager.updateTextContentFont(); + } + if (didUpdate(ModeProp.name, VariantProp.name, Is24hourSourceProp.name)) { uiManager.updateWheelVisibility(); } diff --git a/android/src/main/java/com/henninghall/date_picker/State.java b/android/src/main/java/com/henninghall/date_picker/State.java index 54ddfc64..cc2e9c99 100644 --- a/android/src/main/java/com/henninghall/date_picker/State.java +++ b/android/src/main/java/com/henninghall/date_picker/State.java @@ -19,6 +19,7 @@ import com.henninghall.date_picker.props.Prop; import com.henninghall.date_picker.props.TextColorProp; import com.henninghall.date_picker.props.TimezoneOffsetInMinutesProp; +import com.henninghall.date_picker.props.ContentFontProp; import java.text.SimpleDateFormat; import java.util.Calendar; @@ -44,6 +45,8 @@ public class State { private final Is24hourSourceProp is24hourSourceProp = new Is24hourSourceProp(); private final IdProp idProp = new IdProp(); + private final ContentFontProp contentFontProp = new ContentFontProp(); + private final HashMap props = new HashMap() {{ put(DateProp.name, dateProp); put(ModeProp.name, modeProp); @@ -59,6 +62,7 @@ public class State { put(DividerHeightProp.name, dividerHeightProp); put(Is24hourSourceProp.name, is24hourSourceProp); put(IdProp.name, idProp); + put(ContentFontProp.name, contentFontProp); }}; public DerivedData derived; @@ -82,6 +86,10 @@ public String getFadeToColor() { return (String) fadeToColorProp.getValue(); } + public String getContentFont() { + return (String) contentFontProp.getValue(); + } + public String getTextColor() { return (String) textColorProp.getValue(); } diff --git a/android/src/main/java/com/henninghall/date_picker/pickers/AndroidNative.java b/android/src/main/java/com/henninghall/date_picker/pickers/AndroidNative.java index 91cc70cf..87230882 100644 --- a/android/src/main/java/com/henninghall/date_picker/pickers/AndroidNative.java +++ b/android/src/main/java/com/henninghall/date_picker/pickers/AndroidNative.java @@ -90,6 +90,12 @@ public View getView() { return this; } + + @Override + public void setContentFont(String fontPath) { + // not supported + } + @Override public void setDividerHeight(int height) { // not supported diff --git a/android/src/main/java/com/henninghall/date_picker/pickers/IosClone.java b/android/src/main/java/com/henninghall/date_picker/pickers/IosClone.java index 7601e00c..6d77c3ff 100644 --- a/android/src/main/java/com/henninghall/date_picker/pickers/IosClone.java +++ b/android/src/main/java/com/henninghall/date_picker/pickers/IosClone.java @@ -64,6 +64,24 @@ public void setTextColor(String color) { setSelectedTextColor(fullColor); } + @Override + public void setContentFont(String fontPath) { + Typeface typeface = null; + if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.O) { + Typeface.Builder builder = new Typeface.Builder(getContext().getResources().getAssets(), fontPath); + typeface = builder.build() + } else { + try { + typeface = Typeface.createFromAsset(assets, fontPath); + typeface = Typeface.create(typeface, style); + } catch (Exception ignored) { + } + } + if (typeface != null) { + super.setContentTextTypeface(typeface); + } + } + @Override public void setOnValueChangeListenerInScrolling(final Picker.OnValueChangeListenerInScrolling listener) { this.mOnValueChangeListenerInScrolling = listener; diff --git a/android/src/main/java/com/henninghall/date_picker/pickers/Picker.java b/android/src/main/java/com/henninghall/date_picker/pickers/Picker.java index b438dcfc..f5887a7a 100644 --- a/android/src/main/java/com/henninghall/date_picker/pickers/Picker.java +++ b/android/src/main/java/com/henninghall/date_picker/pickers/Picker.java @@ -15,6 +15,7 @@ public interface Picker { String[] getDisplayedValues(); int getValue(); void setValue(int value); + void setContentFont(String fontPath); void setTextColor(String value); void setOnValueChangeListenerInScrolling(Picker.OnValueChangeListenerInScrolling listener); void setOnValueChangedListener(Picker.OnValueChangeListener onValueChangeListener); diff --git a/android/src/main/java/com/henninghall/date_picker/ui/UIManager.java b/android/src/main/java/com/henninghall/date_picker/ui/UIManager.java index 01a6ea5a..9c07c15c 100644 --- a/android/src/main/java/com/henninghall/date_picker/ui/UIManager.java +++ b/android/src/main/java/com/henninghall/date_picker/ui/UIManager.java @@ -11,6 +11,7 @@ import com.henninghall.date_picker.wheelFunctions.UpdateVisibility; import com.henninghall.date_picker.wheelFunctions.HorizontalPadding; import com.henninghall.date_picker.wheels.Wheel; +import com.henninghall.date_picker.wheelFunctions.SetContentFont; import java.text.SimpleDateFormat; import java.util.Calendar; @@ -33,6 +34,10 @@ public void updateWheelVisibility(){ wheels.applyOnAll(new UpdateVisibility()); } + public void updateTextContentFont() { + wheels.applyOnAll(new SetContentFont(state.getContentFont())); + } + public void updateTextColor(){ wheels.applyOnAll(new TextColor(state.getTextColor())); } diff --git a/android/src/main/java/com/henninghall/date_picker/wheelFunctions/SetContentFont.java b/android/src/main/java/com/henninghall/date_picker/wheelFunctions/SetContentFont.java new file mode 100644 index 00000000..382c22c1 --- /dev/null +++ b/android/src/main/java/com/henninghall/date_picker/wheelFunctions/SetContentFont.java @@ -0,0 +1,16 @@ +package com.henninghall.date_picker.wheelFunctions; + +import com.henninghall.date_picker.wheels.Wheel; + +public class SetContentFont implements WheelFunction { + private final String fontPath; + + public SetContentFont(String fontPath) { + this.fontPath = fontPath; + } + + @Override + public void apply(Wheel wheel) { + wheel.picker.setContentFont(fontPath); + } +} diff --git a/android/src/newarch/java/com/henninghall/date_picker/DatePickerManager.java b/android/src/newarch/java/com/henninghall/date_picker/DatePickerManager.java index 90e8eeaf..a6b6cd08 100644 --- a/android/src/newarch/java/com/henninghall/date_picker/DatePickerManager.java +++ b/android/src/newarch/java/com/henninghall/date_picker/DatePickerManager.java @@ -18,6 +18,7 @@ import com.henninghall.date_picker.props.TextColorProp; import com.henninghall.date_picker.props.TimezoneOffsetInMinutesProp; import com.henninghall.date_picker.props.VariantProp; +import com.henninghall.date_picker.props.ContentFontProp; import java.util.Map; @@ -35,7 +36,7 @@ public PickerView createViewInstance(ThemedReactContext context) { @ReactPropGroup(names = { DateProp.name, ModeProp.name, LocaleProp.name, MaximumDateProp.name, MinimumDateProp.name, FadeToColorProp.name, TextColorProp.name, TimezoneOffsetInMinutesProp.name, MinuteIntervalProp.name, - VariantProp.name, DividerHeightProp.name, Is24hourSourceProp.name, IdProp.name + VariantProp.name, DividerHeightProp.name, Is24hourSourceProp.name, IdProp.name, ContentFontProp.name }) public void setProps(PickerView view, int index, Dynamic value) { DatePickerManagerImpl.updateProp("setProps", view, index, value, getClass()); diff --git a/android/src/oldarch/java/com/henninghall/date_picker/DatePickerManager.java b/android/src/oldarch/java/com/henninghall/date_picker/DatePickerManager.java index bc392a69..7c9c240a 100644 --- a/android/src/oldarch/java/com/henninghall/date_picker/DatePickerManager.java +++ b/android/src/oldarch/java/com/henninghall/date_picker/DatePickerManager.java @@ -26,7 +26,7 @@ import com.henninghall.date_picker.props.ModeProp; import com.henninghall.date_picker.props.TextColorProp; import com.henninghall.date_picker.props.TimezoneOffsetInMinutesProp; - +import com.henninghall.date_picker.props.ContentFontProp; import java.util.Map; @@ -44,7 +44,7 @@ public PickerView createViewInstance(ThemedReactContext context) { @ReactPropGroup(names = { DateProp.name, ModeProp.name, LocaleProp.name, MaximumDateProp.name, MinimumDateProp.name, FadeToColorProp.name, TextColorProp.name, TimezoneOffsetInMinutesProp.name, MinuteIntervalProp.name, - VariantProp.name, DividerHeightProp.name, Is24hourSourceProp.name + VariantProp.name, DividerHeightProp.name, Is24hourSourceProp.name, ContentFontProp.name }) public void setProps(PickerView view, int index, Dynamic value) { DatePickerManagerImpl.setProps(view, index, value, getClass()); diff --git a/index.d.ts b/index.d.ts index ba1de42c..03f9884c 100644 --- a/index.d.ts +++ b/index.d.ts @@ -69,6 +69,11 @@ export interface DatePickerProps extends ViewProps { */ textColor?: string + /** + * Changes font by name. + */ + contentFont?: string + /** * Changes the divider height of the android variant iosClone */