Browse Source

Merge pull request #208 from henninghall/scrolls-beyond-not-always-trigger-onchange

bugfix: scrolls beyond min/max date not always triggering onChange
master
Henning Hall 5 years ago
committed by GitHub
parent
commit
bd8c2200dd
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 19 additions and 17 deletions
  1. +5
    -2
      android/src/main/java/com/henninghall/date_picker/State.java
  2. +2
    -1
      android/src/main/java/com/henninghall/date_picker/ui/UIManager.java
  3. +3
    -4
      android/src/main/java/com/henninghall/date_picker/ui/WheelChangeListenerImpl.java
  4. +9
    -10
      android/src/main/java/com/henninghall/date_picker/ui/Wheels.java

+ 5
- 2
android/src/main/java/com/henninghall/date_picker/State.java View File

@ -97,9 +97,12 @@ public class State {
return utc ? TimeZone.getTimeZone("UTC") : TimeZone.getDefault(); return utc ? TimeZone.getTimeZone("UTC") : TimeZone.getDefault();
} }
public String getDateString() {
return (String) dateProp.getValue();
}
public Calendar getDate() { public Calendar getDate() {
String date = (String) dateProp.getValue();
return Utils.isoToCalendar(date, getTimeZone());
return Utils.isoToCalendar(getDateString(), getTimeZone());
} }
public Integer getHeight() { public Integer getHeight() {

+ 2
- 1
android/src/main/java/com/henninghall/date_picker/ui/UIManager.java View File

@ -67,11 +67,12 @@ public class UIManager {
return new SimpleDateFormat(wheels.getFormatPattern(), state.getLocale()); return new SimpleDateFormat(wheels.getFormatPattern(), state.getLocale());
} }
String getDateString() {
String getDisplayValueString() {
return wheels.getDisplayValue(); return wheels.getDisplayValue();
} }
void animateToDate(Calendar date) { void animateToDate(Calendar date) {
wheels.applyOnInVisible(new SetDate(date));
wheels.applyOnVisible(new AnimateToDate(date)); wheels.applyOnVisible(new AnimateToDate(date));
} }

+ 3
- 4
android/src/main/java/com/henninghall/date_picker/ui/WheelChangeListenerImpl.java View File

@ -6,7 +6,6 @@ import com.facebook.react.bridge.Arguments;
import com.facebook.react.bridge.WritableMap; import com.facebook.react.bridge.WritableMap;
import com.facebook.react.uimanager.events.RCTEventEmitter; import com.facebook.react.uimanager.events.RCTEventEmitter;
import com.henninghall.date_picker.DatePickerManager; import com.henninghall.date_picker.DatePickerManager;
import com.henninghall.date_picker.PickerView;
import com.henninghall.date_picker.State; import com.henninghall.date_picker.State;
import com.henninghall.date_picker.Utils; import com.henninghall.date_picker.Utils;
import com.henninghall.date_picker.wheels.Wheel; import com.henninghall.date_picker.wheels.Wheel;
@ -44,12 +43,12 @@ public class WheelChangeListenerImpl implements WheelChangeListener {
String toParse = wheels.getDateString(); String toParse = wheels.getDateString();
Date newDate = dateFormat.parse(toParse); Date newDate = dateFormat.parse(toParse);
date.setTime(newDate); date.setTime(newDate);
String dateString = Utils.dateToIso(date);
if (minDate != null && date.before(minDate)) uiManager.animateToDate(minDate); if (minDate != null && date.before(minDate)) uiManager.animateToDate(minDate);
else if (maxDate != null && date.after(maxDate)) uiManager.animateToDate(maxDate); else if (maxDate != null && date.after(maxDate)) uiManager.animateToDate(maxDate);
else { else {
event.putString("date", Utils.dateToIso(date));
event.putString("dateString", uiManager.getDateString());
event.putString("date", dateString);
event.putString("dateString", uiManager.getDisplayValueString());
DatePickerManager.context.getJSModule(RCTEventEmitter.class) DatePickerManager.context.getJSModule(RCTEventEmitter.class)
.receiveEvent(rootView.getId(), "dateChange", event); .receiveEvent(rootView.getId(), "dateChange", event);
} }

+ 9
- 10
android/src/main/java/com/henninghall/date_picker/ui/Wheels.java View File

@ -63,21 +63,20 @@ public class Wheels {
return (Picker) rootView.findViewById(id); return (Picker) rootView.findViewById(id);
} }
private Collection<Wheel> getVisible() {
ArrayList<WheelType> wheelTypes = state.derived.getVisibleWheels();
Collection<Wheel> wheels = new ArrayList<>();
for (WheelType type: wheelTypes){
wheels.add(getWheel(type));
}
return wheels;
}
void applyOnAll(WheelFunction function) { void applyOnAll(WheelFunction function) {
for (Wheel wheel: getAll()) function.apply(wheel); for (Wheel wheel: getAll()) function.apply(wheel);
} }
void applyOnVisible(WheelFunction function) { void applyOnVisible(WheelFunction function) {
for (Wheel wheel: getVisible()) function.apply(wheel);
for(Wheel wheel: getAll()) {
if(wheel.visible()) function.apply(wheel);
}
}
void applyOnInVisible(WheelFunction function) {
for(Wheel wheel: getAll()) {
if(!wheel.visible()) function.apply(wheel);
}
} }
void updateHeight() { void updateHeight() {

Loading…
Cancel
Save