diff --git a/.gitignore b/.gitignore index 6672061..108c654 100644 --- a/.gitignore +++ b/.gitignore @@ -33,3 +33,4 @@ local.properties node_modules/ npm-debug.log *.iml +/.project diff --git a/DateTime.android.js b/DateTime.android.js index 1420bc7..d1af31e 100644 --- a/DateTime.android.js +++ b/DateTime.android.js @@ -28,6 +28,7 @@ export default class DateTimePicker extends Component { showDatePicker(date, callback) { date = date || new Date(); + callback = callback || this.props.onDateChange; var options = { ...this.props, year:date.getFullYear(), @@ -44,6 +45,7 @@ export default class DateTimePicker extends Component { showTimePicker(date, callback) { date = date || new Date(); + callback = callback || this.props.onDateChange; var options = { ...this.props, hour:date.getHours(), @@ -58,6 +60,7 @@ export default class DateTimePicker extends Component { showDateTimePicker(date, callback) { date = date || new Date(); + callback = callback || this.props.onDateChange; var options = { ...this.props, year:date.getFullYear(), @@ -79,4 +82,4 @@ export default class DateTimePicker extends Component { render() { return null; } -} \ No newline at end of file +} diff --git a/DateTime.ios.js b/DateTime.ios.js index c0d581c..33a2d4b 100644 --- a/DateTime.ios.js +++ b/DateTime.ios.js @@ -36,7 +36,7 @@ export default class DateTimePicker extends Component { } showDatePicker(date, callback) { - this.callback = callback; + this.callback = callback || this.props.onDateChange; date = (date || new Date()); this.setState({ @@ -47,7 +47,7 @@ export default class DateTimePicker extends Component { } showTimePicker(date, callback) { - this.callback = callback; + this.callback = callback || this.props.onDateChange; date = (date || new Date()); this.setState({ @@ -58,7 +58,7 @@ export default class DateTimePicker extends Component { } showDateTimePicker(date, callback) { - this.callback = callback; + this.callback = callback || this.props.onDateChange; date = (date || new Date()); this.setState({ @@ -78,7 +78,7 @@ export default class DateTimePicker extends Component { this.setState({ visible: false }); - this.callback(this.state.date); + this.callback(this.props.date); } onDateChange(date) { @@ -94,22 +94,19 @@ export default class DateTimePicker extends Component { style={styles.touchableOpacity} activeOpacity={1} onPress={()=>this.onClose()} /> - this.onDateChange(date)} - style = {styles.datePicker} - /> - this.onComplete()} style={styles.button}> { this.props.okText } - this.onClose()} /> + + this.onDateChange(date)} + style = {styles.datePicker} + {...this.props} + /> ); @@ -132,16 +129,16 @@ const _styles = StyleSheet.create({ }, datePicker: { backgroundColor: 'white', - alignItems: 'center', }, touchableOpacity: { flex: 1, }, button: { + paddingHorizontal: 10, paddingVertical: 10, backgroundColor: 'white', - justifyContent: 'center', - alignItems: 'center' + justifyContent: 'flex-end', + alignItems: 'flex-end' }, separator: { height: 1, diff --git a/README.md b/README.md index a965c96..30f3d94 100644 --- a/README.md +++ b/README.md @@ -3,7 +3,7 @@ A datetime-picker for react-native support for android and ios(base on @remobile ## Installation ```sh -npm install react-native-datetime --save +npm install react-native-yunpeng-datetime --save ``` ### Installation (iOS) diff --git a/android/build.gradle b/android/build.gradle index 9a73961..096f1fb 100644 --- a/android/build.gradle +++ b/android/build.gradle @@ -21,5 +21,5 @@ android { dependencies { compile fileTree(dir: 'libs', include: ['*.jar']) compile 'com.android.support:appcompat-v7:23.0.1' - compile 'com.facebook.react:react-native:0.25.+' + compile 'com.facebook.react:react-native:0.20.+' } diff --git a/android/src/main/java/com/keyee/datetime/RCTDateTimePicker.java b/android/src/main/java/com/keyee/datetime/RCTDateTimePicker.java index 044537b..106cae8 100644 --- a/android/src/main/java/com/keyee/datetime/RCTDateTimePicker.java +++ b/android/src/main/java/com/keyee/datetime/RCTDateTimePicker.java @@ -10,11 +10,9 @@ import com.facebook.react.bridge.ReadableMap; public class RCTDateTimePicker extends ReactContextBaseJavaModule { - private Activity activity; - public RCTDateTimePicker(ReactApplicationContext reactContext, Activity activity) { + public RCTDateTimePicker(ReactApplicationContext reactContext) { super(reactContext); - this.activity = activity; } @Override @@ -25,18 +23,18 @@ public String getName() { @ReactMethod public void showDatePicker(ReadableMap options, Callback callback) { DialogFragment datePicker = new DatePicker(options, callback); - datePicker.show(activity.getFragmentManager(), "datePicker"); + datePicker.show(getCurrentActivity().getFragmentManager(), "datePicker"); } @ReactMethod public void showTimePicker(ReadableMap options, Callback callback) { DialogFragment timePicker = new TimePicker(options, callback); - timePicker.show(activity.getFragmentManager(), "timePicker"); + timePicker.show(getCurrentActivity().getFragmentManager(), "timePicker"); } @ReactMethod public void showDateTimePicker(ReadableMap options, Callback callback) { DialogFragment datetimePicker = new DateTimePicker(options, callback); - datetimePicker.show(activity.getFragmentManager(), "datetimePicker"); + datetimePicker.show(getCurrentActivity().getFragmentManager(), "datetimePicker"); } -} \ No newline at end of file +} diff --git a/android/src/main/java/com/keyee/datetime/RCTDateTimePickerPackage.java b/android/src/main/java/com/keyee/datetime/RCTDateTimePickerPackage.java index 4953e97..13ed6bd 100644 --- a/android/src/main/java/com/keyee/datetime/RCTDateTimePickerPackage.java +++ b/android/src/main/java/com/keyee/datetime/RCTDateTimePickerPackage.java @@ -13,13 +13,11 @@ import android.app.Activity; public class RCTDateTimePickerPackage implements ReactPackage { - - private Activity activity; + private RCTDateTimePicker mModuleInstance; - public RCTDateTimePickerPackage(Activity activity) { + public RCTDateTimePickerPackage() { super(); - this.activity = activity; } @Override @@ -27,7 +25,7 @@ public List createNativeModules( ReactApplicationContext reactContext) { List modules = new ArrayList<>(); - modules.add(new RCTDateTimePicker(reactContext, activity)); + modules.add(new RCTDateTimePicker(reactContext)); return modules; } @@ -41,4 +39,4 @@ public List> createJSModules() { public List createViewManagers(ReactApplicationContext reactContext) { return Collections.emptyList(); } -} \ No newline at end of file +} diff --git a/package.json b/package.json index e94cc6b..4e84473 100644 --- a/package.json +++ b/package.json @@ -1,11 +1,11 @@ { - "name": "react-native-datetime", - "version": "0.1.2", + "name": "react-native-yunpeng-datetime", + "version": "0.1.4", "description": "A datetime-picker for react-native support for android and ios", "main": "index.js", "repository": { "type": "git", - "url": "git+https://github.com/cnjon/react-native-datetime.git" + "url": "git+https://github.com/yptech/react-native-datetime.git" }, "keywords": [ "react-component", @@ -17,11 +17,11 @@ "datetime" ], "author": { - "name": "cnjon", - "url": "https://github.com/cnjon" + "name": "iday", + "url": "https://github.com/iday" }, "license": "MIT", "bugs": { - "url": "https://github.com/cnjon/react-native-datetime/issues" + "url": "https://github.com/yptech/react-native-datetime/issues" } }