From 7708399e57f4dc01d60a2ddfaf8d2345dcc0276c Mon Sep 17 00:00:00 2001 From: pinguinjkeke Date: Sun, 4 Feb 2018 22:23:42 +0300 Subject: [PATCH] Register CustomDatePickerIOS --- Demo/App.js | 15 +++++++++++++-- Demo/package.json | 3 ++- Demo/yarn.lock | 6 +++++- README.md | 39 +++++++++++++++++++++++++++++++++++++++ package.json | 2 +- src/index.js | 17 ++++++++++++++--- 6 files changed, 74 insertions(+), 8 deletions(-) diff --git a/Demo/App.js b/Demo/App.js index 37074e1..3d6cd4e 100644 --- a/Demo/App.js +++ b/Demo/App.js @@ -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: { @@ -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 ( @@ -32,10 +39,12 @@ export default class App extends Component { current date: {this.state.date && this.state.date.toJSON()} this.setState({ date })} + style={{ width: '100%' }} /> @@ -43,6 +52,7 @@ export default class App extends Component { current time: {this.state.time && this.state.time.toJSON()} this.setState({ time })} /> @@ -53,6 +63,7 @@ export default class App extends Component { current datetime: {this.state.datetime && this.state.datetime.toJSON()} this.setState({ datetime })} labelUnit={{ year: 'Y', month: 'M', date: 'D' }} diff --git a/Demo/package.json b/Demo/package.json index 0aaba94..f0c8a46 100644 --- a/Demo/package.json +++ b/Demo/package.json @@ -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", diff --git a/Demo/yarn.lock b/Demo/yarn.lock index abd56ec..03fdaf2 100644 --- a/Demo/yarn.lock +++ b/Demo/yarn.lock @@ -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" diff --git a/README.md b/README.md index aebf77f..3216aa1 100644 --- a/README.md +++ b/README.md @@ -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 ( + + ) +} +``` + ## Example code ```jsx diff --git a/package.json b/package.json index a11f8c4..d8687a5 100644 --- a/package.json +++ b/package.json @@ -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": { diff --git a/src/index.js b/src/index.js index 20c5736..3be9f97 100644 --- a/src/index.js +++ b/src/index.js @@ -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 };