Skip to content

Commit

Permalink
divider height prop
Browse files Browse the repository at this point in the history
  • Loading branch information
henninghall committed Jul 28, 2020
1 parent e5f0c60 commit 0f1905e
Show file tree
Hide file tree
Showing 12 changed files with 67 additions and 4 deletions.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,8 @@ export default () => {
| locale | The locale for the date picker. Changes language, date order and am/pm preferences. Value needs to be a <a title="react native datepicker locale id" href="https://developer.apple.com/library/content/documentation/MacOSX/Conceptual/BPInternational/LanguageandLocaleIDs/LanguageandLocaleIDs.html">Locale ID.</a> | <img src="docs/locale-ios.png" alt="React Native Date picker locale language ios" height="120px" /> | <img src="docs/locale-android.png" alt="React Native Date picker locale language android" height="120px" /> |
| textColor | Changes the text color. ⚠ Colors other than black (#000000) or white (#ffffff) will replace the "Today" string with a date on iOS 13 or higher. | <img src="docs/colors-ios.png" alt="react native datepicker text color background color ios" height="120px" /> | <img src="docs/colors-android.png" alt="Text color background color android" height="120px" /> |
| timeZoneOffsetInMinutes | Timezone offset in minutes (default: device's timezone) |
| dividerHeight | Change the divider height (only supported for iosClone) |


## About

Expand Down
2 changes: 1 addition & 1 deletion android/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ android {
dependencies {
implementation fileTree(include: ['*.jar'], dir: 'libs')
implementation 'com.facebook.react:react-native:+'
implementation 'com.henninghall.android:NumberPickerView:1.1.2'
implementation 'com.henninghall.android:NumberPickerView:1.1.3'
implementation 'org.apache.commons:commons-lang3:3.7'
implementation group: 'net.time4j', name: 'time4j-android', version: '4.2-2018i'
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import com.facebook.react.uimanager.SimpleViewManager;
import com.facebook.react.uimanager.ThemedReactContext;
import com.facebook.react.uimanager.annotations.ReactPropGroup;
import com.henninghall.date_picker.props.DividerHeightProp;
import com.henninghall.date_picker.props.VariantProp;
import com.henninghall.date_picker.props.DateProp;
import com.henninghall.date_picker.props.FadeToColorProp;
Expand Down Expand Up @@ -43,7 +44,7 @@ public PickerView createViewInstance(ThemedReactContext reactContext) {

@ReactPropGroup(names = { DateProp.name, ModeProp.name, LocaleProp.name, MaximumDateProp.name,
MinimumDateProp.name, FadeToColorProp.name, TextColorProp.name, UtcProp.name, MinuteIntervalProp.name,
VariantProp.name
VariantProp.name, DividerHeightProp.name
})
public void setProps(PickerView view, int index, Dynamic value) {
updateProp("setProps", view, index, value);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import android.widget.RelativeLayout;

import com.facebook.react.bridge.Dynamic;
import com.henninghall.date_picker.props.DividerHeightProp;
import com.henninghall.date_picker.props.MaximumDateProp;
import com.henninghall.date_picker.props.MinimumDateProp;
import com.henninghall.date_picker.props.MinuteIntervalProp;
Expand Down Expand Up @@ -54,6 +55,10 @@ public void update() {
uiManager.updateHeight();
}

if (didUpdate(DividerHeightProp.name)) {
uiManager.updateDividerHeight();
}

if (didUpdate(ModeProp.name, LocaleProp.name, VariantProp.name)) {
uiManager.updateWheelOrder();
}
Expand Down
6 changes: 6 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 @@ -3,6 +3,7 @@
import com.facebook.react.bridge.Dynamic;
import com.henninghall.date_picker.models.Mode;
import com.henninghall.date_picker.models.Variant;
import com.henninghall.date_picker.props.DividerHeightProp;
import com.henninghall.date_picker.props.VariantProp;
import com.henninghall.date_picker.props.DateProp;
import com.henninghall.date_picker.props.FadeToColorProp;
Expand Down Expand Up @@ -34,6 +35,7 @@ public class State {
private final UtcProp utcProp = new UtcProp();
private final HeightProp heightProp = new HeightProp();
private final VariantProp variantProp = new VariantProp();
private final DividerHeightProp dividerHeightProp = new DividerHeightProp();

private final HashMap props = new HashMap<String, Prop>() {{
put(DateProp.name, dateProp);
Expand All @@ -47,6 +49,7 @@ public class State {
put(UtcProp.name, utcProp);
put(HeightProp.name, heightProp);
put(VariantProp.name, variantProp);
put(DividerHeightProp.name, dividerHeightProp);
}};
public DerivedData derived;

Expand Down Expand Up @@ -117,4 +120,7 @@ public Variant getVariant(){
return variantProp.getValue();
}

public int getDividerHeightProp() {
return dividerHeightProp.getValue();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,10 @@ public View getView() {
return this;
}

@Override
public void setDividerHeight(int height) {
// not supported
}

@Override
public void smoothScrollToValue(final int value) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ public interface Picker {
View getView();
void setVisibility(int visibility);
void setWrapSelectorWheel(boolean wrapSelectorWheel);
void setDividerHeight(int height);

interface OnValueChangeListenerInScrolling {
void onValueChangeInScrolling(Picker picker, int oldVal, int newVal);
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 DividerHeightProp extends Prop<Integer> {
public static final String name = "dividerHeight";

@Override
public Integer toValue(Dynamic value){
return value.asInt();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -58,5 +58,10 @@ void setShownCount(int shownCount) {
}
}


public void setDividerHeight(int height) {
for (int id : emptyWheelIds) {
NumberPickerView view = (NumberPickerView) rootView.findViewById(id);
if(view != null) view.setDividerHeight(height);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import com.henninghall.date_picker.wheelFunctions.AnimateToDate;
import com.henninghall.date_picker.wheelFunctions.Refresh;
import com.henninghall.date_picker.wheelFunctions.SetDate;
import com.henninghall.date_picker.wheelFunctions.SetDividerHeight;
import com.henninghall.date_picker.wheelFunctions.TextColor;
import com.henninghall.date_picker.wheelFunctions.UpdateVisibility;
import com.henninghall.date_picker.wheels.Wheel;
Expand Down Expand Up @@ -80,4 +81,8 @@ private void addOnChangeListener(){
WheelChangeListener onWheelChangeListener = new WheelChangeListenerImpl(wheels, state, this, rootView);
wheels.applyOnAll(new AddOnChangeListener(onWheelChangeListener));
}

public void updateDividerHeight() {
wheels.updateDividerHeight();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import com.henninghall.date_picker.Utils;
import com.henninghall.date_picker.models.WheelType;
import com.henninghall.date_picker.models.Mode;
import com.henninghall.date_picker.wheelFunctions.SetDividerHeight;
import com.henninghall.date_picker.wheelFunctions.SetShowCount;
import com.henninghall.date_picker.wheelFunctions.WheelFunction;
import com.henninghall.date_picker.wheels.AmPmWheel;
Expand All @@ -21,7 +22,6 @@

import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.HashMap;
import java.util.List;

Expand Down Expand Up @@ -85,6 +85,12 @@ void updateHeight() {
emptyWheels.setShownCount(shownCount);
}

void updateDividerHeight() {
int height = state.getDividerHeightProp();
applyOnAll(new SetDividerHeight(height));
emptyWheels.setDividerHeight(height);
}

void updateWheelOrder() {
pickerWrapper.removeAll();
addInOrder();
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 SetDividerHeight implements WheelFunction {
private final int height;

public SetDividerHeight(int height) {
this.height = height;
}

@Override
public void apply(Wheel wheel) {
wheel.picker.setDividerHeight(height);
}
}

0 comments on commit 0f1905e

Please sign in to comment.