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

Add prop contentFont for android #730

Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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();
}
Expand Down
8 changes: 8 additions & 0 deletions android/src/main/java/com/henninghall/date_picker/State.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,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;
Expand All @@ -46,6 +47,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<String, Prop>() {{
put(DateProp.name, dateProp);
put(ModeProp.name, modeProp);
Expand All @@ -61,6 +64,7 @@ public class State {
put(DividerHeightProp.name, dividerHeightProp);
put(Is24hourSourceProp.name, is24hourSourceProp);
put(IdProp.name, idProp);
put(ContentFontProp.name, contentFontProp);
}};
public DerivedData derived;

Expand All @@ -84,6 +88,10 @@ public String getFadeToColor() {
return (String) fadeToColorProp.getValue();
}

public String getContentFont() {
return (String) contentFontProp.getValue();
}

public String getTextColor() {
return (String) textColorProp.getValue();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import android.view.MotionEvent;
import android.view.accessibility.AccessibilityNodeInfo;
import android.view.accessibility.AccessibilityNodeInfo.AccessibilityAction;
import android.graphics.Typeface;

import cn.carbswang.android.numberpickerview.library.NumberPickerView;

Expand Down Expand Up @@ -64,6 +65,23 @@ 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(getContext().getResources().getAssets(), fontPath);
} catch (Exception ignored) {
}
}
if (typeface != null) {
super.setContentTextTypeface(typeface);
}
}

@Override
public void setOnValueChangeListenerInScrolling(final Picker.OnValueChangeListenerInScrolling listener) {
this.mOnValueChangeListenerInScrolling = listener;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package com.henninghall.date_picker.props;

import com.facebook.react.bridge.Dynamic;

public class ContentFontProp extends Prop<String> {
public static final String name = "contentFont";

@Override
public String toValue(Dynamic value){
return value.asString();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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()));
}
Expand Down
Original file line number Diff line number Diff line change
@@ -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);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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());
Expand Down
5 changes: 5 additions & 0 deletions index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
*/
Expand Down
Loading