Browse Source

Animating to date at state change.

master
Henning Hall 7 years ago
parent
commit
acd91d4472
3 changed files with 19 additions and 9 deletions
  1. +1
    -1
      android/src/main/java/com/henninghall/date_picker/Utils.java
  2. +7
    -1
      android/src/main/java/com/henninghall/date_picker/wheels/Wheel.java
  3. +11
    -7
      example/App.js

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

@ -13,7 +13,7 @@ public class Utils {
}
public static String printToday(Locale locale) {
return UnitPatterns.of(locale).getYesterdayWord();
return UnitPatterns.of(locale).getTodayWord();
}

+ 7
- 1
android/src/main/java/com/henninghall/date_picker/wheels/Wheel.java View File

@ -51,7 +51,13 @@ public abstract class Wheel {
public void setValue(Date date) {
int index = values.indexOf(format.format(date));
if(index > -1) picker.setValue(index);
if(index > -1) {
// Set value directly during initializing
// After init, always smooth scroll to value
if(picker.getValue() == 0) picker.setValue(index);
else picker.smoothScrollToValue(index);
}
}
public void setLocale(Locale locale) {

+ 11
- 7
example/App.js View File

@ -1,5 +1,5 @@
import React, { Component } from 'react';
import { View, StyleSheet, ScrollView, Text, TouchableOpacity } from 'react-native';
import { Button, View, StyleSheet, ScrollView, Text, TouchableOpacity } from 'react-native';
import SearchInput, { createFilter } from 'react-native-search-filter';
import DeviceInfo from 'react-native-device-info';
import DatePicker from 'react-native-date-picker-x';
@ -21,8 +21,8 @@ export default class App extends Component {
render() {
const result = locales.filter(createFilter(this.state.searchTerm)).slice(0, 5);
console.log({result});
console.log({ result });
return (
<View style={styles.container}>
<DatePicker
@ -34,8 +34,12 @@ export default class App extends Component {
<Text>Current locale: {this.state.locale}</Text>
<Text>Current date: {this.state.chosenDate.toISOString()}</Text>
<Text></Text>
<Button title='Change date'
onPress={() => this.setState({
chosenDate: new Date(this.state.chosenDate.getTime() + 86400000)
})} />
<SearchInput
onChangeText={(term) => { this.searchUpdated(term) }}
style={styles.searchInput}
@ -43,7 +47,7 @@ export default class App extends Component {
/>
<ScrollView>
{result.map(locale => (
<TouchableOpacity onPress={() => this.setState({locale})} key={locale} style={styles.item}>
<TouchableOpacity onPress={() => this.setState({ locale })} key={locale} style={styles.item}>
<Text>{locale}</Text>
</TouchableOpacity>
))
@ -53,7 +57,7 @@ export default class App extends Component {
</View>
);
}
}
const styles = StyleSheet.create({

Loading…
Cancel
Save