Browse Source

update prop in example app

master
Henning Hall 5 years ago
parent
commit
159a69e914
6 changed files with 56 additions and 32 deletions
  1. +24
    -20
      android/src/main/java/com/henninghall/date_picker/PickerView.java
  2. +1
    -1
      android/src/main/java/com/henninghall/date_picker/ui/UIManager.java
  3. +12
    -0
      examples/detox/src/examples/Advanced.js
  4. +0
    -2
      examples/detox/src/examples/Minimal.js
  5. +1
    -9
      examples/detox/src/propPickers/DateChange.js
  6. +18
    -0
      examples/detox/src/propPickers/Variant.js

+ 24
- 20
android/src/main/java/com/henninghall/date_picker/PickerView.java View File

@ -1,11 +1,12 @@
package com.henninghall.date_picker;
import android.util.Log;
import android.view.View;
import android.widget.NumberPicker;
import android.widget.RelativeLayout;
import com.facebook.react.bridge.Dynamic;
import com.henninghall.date_picker.props.MaximumDateProp;
import com.henninghall.date_picker.props.MinimumDateProp;
import com.henninghall.date_picker.props.MinuteIntervalProp;
import com.henninghall.date_picker.props.UtcProp;
import com.henninghall.date_picker.props.VariantProp;
import com.henninghall.date_picker.props.DateProp;
import com.henninghall.date_picker.props.FadeToColorProp;
@ -14,15 +15,16 @@ import com.henninghall.date_picker.props.LocaleProp;
import com.henninghall.date_picker.props.ModeProp;
import com.henninghall.date_picker.props.TextColorProp;
import com.henninghall.date_picker.ui.UIManager;
import com.henninghall.date_picker.wheels.AmPmWheel;
import java.util.ArrayList;
import java.util.Date;
public class PickerView extends RelativeLayout {
private UIManager uiManager;
private State state = new State();
private ArrayList<String> updatedProps = new ArrayList<>();
private boolean initialized = false;
public PickerView() {
super(DatePickerManager.context);
@ -30,40 +32,36 @@ public class PickerView extends RelativeLayout {
public void update() {
if(!initialized){
if (didUpdate(VariantProp.name)) {
this.removeAllViewsInLayout();
inflate(getContext(), state.derived.getRootLayout(), this);
uiManager = new UIManager(state, this);
initialized = true;
}
if(updatedProps.contains(FadeToColorProp.name)) {
if (didUpdate(FadeToColorProp.name)) {
uiManager.updateFadeToColor();
}
if(updatedProps.contains(TextColorProp.name)) {
if (didUpdate(TextColorProp.name, VariantProp.name)) {
uiManager.updateTextColor();
}
if(updatedProps.contains(ModeProp.name)) {
if (didUpdate(ModeProp.name, VariantProp.name)) {
uiManager.updateWheelVisibility();
}
if(updatedProps.contains(HeightProp.name)) {
if (didUpdate(HeightProp.name)) {
uiManager.updateHeight();
}
if(updatedProps.contains(ModeProp.name) || updatedProps.contains(LocaleProp.name)) {
if (didUpdate(ModeProp.name, LocaleProp.name, VariantProp.name)) {
uiManager.updateWheelOrder();
}
ArrayList<String> noDisplayValueChangeProps = new ArrayList<String>(){{
add(DateProp.name);
add(FadeToColorProp.name);
add(TextColorProp.name);
}};
updatedProps.removeAll(noDisplayValueChangeProps);
if(updatedProps.size() != 0) {
if (didUpdate(DateProp.name, HeightProp.name, LocaleProp.name,
MaximumDateProp.name, MinimumDateProp.name, MinuteIntervalProp.name, ModeProp.name,
UtcProp.name, VariantProp.name
)) {
uiManager.updateDisplayValues();
}
@ -72,6 +70,13 @@ public class PickerView extends RelativeLayout {
updatedProps = new ArrayList<>();
}
private boolean didUpdate(String... propNames) {
for (String propName : propNames) {
if (updatedProps.contains(propName)) return true;
}
return false;
}
public void updateProp(String propName, Dynamic value) {
state.setProp(propName, value);
updatedProps.add(propName);
@ -98,5 +103,4 @@ public class PickerView extends RelativeLayout {
}
}

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

@ -25,7 +25,6 @@ public class UIManager {
this.state = state;
this.rootView = rootView;
wheels = new Wheels(state, rootView);
// fadingOverlay = new FadingOverlay(state, rootView);
addOnChangeListener();
}
@ -39,6 +38,7 @@ public class UIManager {
public void updateFadeToColor(){
if(state.derived.hasNativeStyle()) return;
fadingOverlay = new FadingOverlay(state, rootView);
fadingOverlay.updateColor();
}

+ 12
- 0
examples/detox/src/examples/Advanced.js View File

@ -13,6 +13,7 @@ import MinuteInterval from '../propPickers/MinuteInterval'
import Scroll from '../propPickers/Scroll'
import CustomPropValue from '../CustomPropValue'
import { readableDate } from '../utils'
import Variant from '../propPickers/Variant'
Date.prototype.addHours = function(h) {
this.setTime(this.getTime() + h * 60 * 60 * 1000)
@ -37,6 +38,7 @@ export default class Advanced extends Component {
timeZoneOffsetInMinutes: undefined,
minuteInterval: 1,
dateString: '',
androidVariant: 'nativeAndroid',
}
render() {
@ -52,6 +54,7 @@ export default class Advanced extends Component {
date={this.state.date}
onDateChange={this.setDate}
onDateStringChange={this.setDateString}
androidVariant={this.state.androidVariant}
locale={this.state.locale}
minuteInterval={this.state.minuteInterval}
minimumDate={this.state.minimumDate}
@ -88,6 +91,15 @@ export default class Advanced extends Component {
/>
),
},
{
name: 'androidVariant',
component: (
<Variant
selected={this.state.androidVariant}
onChange={androidVariant => this.setState({ androidVariant })}
/>
),
},
{
name: 'mode',
component: (

+ 0
- 2
examples/detox/src/examples/Minimal.js View File

@ -8,8 +8,6 @@ export default class MinimalExample extends Component {
<DatePicker
date={this.state.date}
onDateChange={date => this.setState({ date })}
androidVariant="iosClone"
androidVariant="nativeAndroid"
/>
)
}

+ 1
- 9
examples/detox/src/propPickers/DateChange.js View File

@ -1,13 +1,5 @@
import React, { Component } from 'react'
import {
Dimensions,
Button,
View,
StyleSheet,
ScrollView,
Text,
TouchableOpacity,
} from 'react-native'
import { Button, Text } from 'react-native'
export default class extends Component {
render() {

+ 18
- 0
examples/detox/src/propPickers/Variant.js View File

@ -0,0 +1,18 @@
import React, { Component } from 'react'
import PropSlider from '../PropSlider'
const data = [{ name: 'iosClone' }, { name: 'nativeAndroid' }]
export default class extends Component {
render() {
return (
<PropSlider
testID={'variant'}
selectedProp={this.props.selected}
onSelect={this.props.onChange}
data={data}
width={100}
/>
)
}
}

Loading…
Cancel
Save