Skip to content

Commit

Permalink
Register CustomDatePickerIOS
Browse files Browse the repository at this point in the history
  • Loading branch information
pinguinjkeke committed Feb 4, 2018
1 parent 1ad55a0 commit 7708399
Show file tree
Hide file tree
Showing 6 changed files with 74 additions and 8 deletions.
15 changes: 13 additions & 2 deletions Demo/App.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
import React, { Component } from 'react';
import { ScrollView, StyleSheet, Text, View } from 'react-native';
import { DatePicker, Picker } from 'react-native-wheel-datepicker';
import { Picker, registerCustomDatePickerIOS } from 'react-native-wheel-datepicker';
import CustomDatePickerIOS from 'react-native-custom-datepicker-ios';

const DatePicker = registerCustomDatePickerIOS(CustomDatePickerIOS);

const styles = StyleSheet.create({
container: {
Expand All @@ -21,7 +24,11 @@ const styles = StyleSheet.create({
});

export default class App extends Component {
state = {};
state = {
firstDate: new Date(),
secondDate: new Date(),
thirdDate: new Date(),
};

render() {
return (
Expand All @@ -32,17 +39,20 @@ export default class App extends Component {
current date: {this.state.date && this.state.date.toJSON()}
</Text>
<DatePicker
date={this.state.firstDate}
mode="date"
textSize={36}
textColor='red'
onDateChange={date => this.setState({ date })}
style={{ width: '100%' }}
/>

<View style={styles.separator} />
<Text style={styles.text__info}>
current time: {this.state.time && this.state.time.toJSON()}
</Text>
<DatePicker
date={this.state.secondDate}
mode="time"
onDateChange={time => this.setState({ time })}
/>
Expand All @@ -53,6 +63,7 @@ export default class App extends Component {
current datetime: {this.state.datetime && this.state.datetime.toJSON()}
</Text>
<DatePicker
date={this.state.thirdDate}
mode="datetime"
onDateChange={datetime => this.setState({ datetime })}
labelUnit={{ year: 'Y', month: 'M', date: 'D' }}
Expand Down
3 changes: 2 additions & 1 deletion Demo/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@
"prop-types": "^15.6.0",
"react": "16.0.0-beta.5",
"react-native": "0.49.3",
"react-native-wheel-datepicker": "../"
"react-native-wheel-datepicker": "../",
"react-native-custom-datepicker-ios": "^0.0.2"
},
"devDependencies": {
"babel-jest": "21.2.0",
Expand Down
6 changes: 5 additions & 1 deletion Demo/yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -3371,8 +3371,12 @@ react-devtools-core@^2.5.0:
shell-quote "^1.6.1"
ws "^2.0.3"

react-native-custom-datepicker-ios@^0.0.2:
version "0.0.2"
resolved "https://registry.yarnpkg.com/react-native-custom-datepicker-ios/-/react-native-custom-datepicker-ios-0.0.2.tgz#582276eeebfb80dbbd839e7faef50e0d15a7e114"

react-native-wheel-datepicker@../:
version "2.1.5"
version "2.1.10"
dependencies:
moment "^2.19.1"

Expand Down
39 changes: 39 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,45 @@ Configration:
react-native link react-native-wheel-datepicker
```

## Ingegration with CustomDatePickerIOS

By default, package provides default DatePickerIOS on the iOS side to simplify usage on both platforms.

You can install [react-native-custom-datepicker-ios](https://github.com/pinguinjkeke/react-native-wheel-datepicker) package
if you need textColor functionality on IOS platform.

Just install:
```
npm i react-native-custom-datepicker-ios
// or
yarn add react-native-custom-datepicker-ios
```
link dependencies:
```
react-native link react-native-custom-datepicker-ios
```
And register CustomDatePickerIOS inside react-native-wheel-datepicker package.
```js
import { registerCustomDatePickerIOS } from 'react-native-wheel-datepicker';
import CustomDatePickerIOS from 'react-native-custom-datepicker-ios';

registerCustomDatePickerIOS(CustomDatePickerIOS);
```
Then you can use textColored components for both platforms inside render function!
```jsx
import { DatePicker } from 'react-native-wheel-datepicker';

// ...
render() {
return (
<DatePicker
mode="date"
textColor="green"
/>
)
}
```

## Example code

```jsx
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "react-native-wheel-datepicker",
"version": "2.1.10",
"version": "2.2.0",
"description": "React native cross platform iOS-style picker and datepicker.",
"main": "src/index.js",
"scripts": {
Expand Down
17 changes: 14 additions & 3 deletions src/index.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,17 @@
'use strict';

import Picker from './picker'
import DatePicker from './date-picker'
import { Platform } from 'react-native';
import Picker from './picker';
import DatePicker from './date-picker';

module.exports = { Picker, DatePicker }
let DatePickerComponent = DatePicker;

const registerCustomDatePickerIOS = (CustomDatePickerIOS) => {
if (Platform.OS === 'ios') {
DatePickerComponent = CustomDatePickerIOS;
}

return DatePickerComponent;
};

module.exports = { Picker, DatePicker: DatePickerComponent, registerCustomDatePickerIOS };

0 comments on commit 7708399

Please sign in to comment.