@momo-kits/date-picker 0.0.6-beta → 0.0.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -128,11 +128,11 @@ class DatePicker extends Component {
128
128
  } : DatePickerHelper.formatDate(propsSelectedDate, props.format);
129
129
  }
130
130
  }
131
- this.createDataDate(this.minDate, this.maxDate, props.minuteArray);
131
+ this.createDataDate(this.minDate, this.maxDate, props.minuteArray, props.rangeHour);
132
132
  this.selectedIndexDate();
133
133
  }
134
134
 
135
- createDataDate(minDate, maxDate, minuteArray) {
135
+ createDataDate(minDate, maxDate, minuteArray, rangeHour) {
136
136
  this.minDay = 1;
137
137
  this.minMonth = 1;
138
138
  this.minYear = 1970;
@@ -159,7 +159,7 @@ class DatePicker extends Component {
159
159
  } else {
160
160
  this.minutes = DatePickerHelper.makeRange(0, 59, true);
161
161
  }
162
- this.ranged = DatePickerHelper.arrayRange;
162
+ this.ranged = rangeHour || DatePickerHelper.arrayRange;
163
163
  }
164
164
 
165
165
  selectedIndexDate() {
@@ -202,11 +202,11 @@ class DatePicker extends Component {
202
202
 
203
203
  this.hourIndex = this.selectedDate
204
204
  ? this.hours.indexOf(valueHours)
205
- : this.hours.indexOf(current.getHours().toString());
205
+ : this.hours.indexOf(current.getHours().toString().length === 1 ? `0${current.getHours().toString()}` : current.getHours().toString());
206
206
 
207
207
  this.minuteIndex = this.selectedDate
208
208
  ? this.minutes.indexOf(valueMinute)
209
- : this.minutes.indexOf(current.getMinutes().toString());
209
+ : this.minutes.indexOf(current.getMinutes().toString().length === 1 ? `0${current.getMinutes().toString()}` : current.getMinutes().toString());
210
210
  }
211
211
  }
212
212
 
@@ -429,10 +429,11 @@ class DatePicker extends Component {
429
429
 
430
430
  renderHeader() {
431
431
  const {
432
- title, placeholder, body, buttonTitle, onButtonPress, headerStyle, iconClosePosition = 'right'
432
+ title, placeholder, body, buttonTitle, onButtonPress, headerStyle, iconClosePosition = 'right', iconType
433
433
  } = this.props;
434
434
  return (
435
435
  <BottomPopupHeader
436
+ iconType={iconType}
436
437
  iconClosePosition={iconClosePosition}
437
438
  body={body}
438
439
  onClose={this.hide}
@@ -582,7 +583,10 @@ DatePicker.propTypes = {
582
583
  renderDescription: PropTypes.any,
583
584
  description: PropTypes.string,
584
585
  renderFooter: PropTypes.any,
585
- style: PropTypes.any
586
+ style: PropTypes.any,
587
+ rangeHour: PropTypes.array,
588
+ iconClosePosition: PropTypes.oneOf(['left', 'right']),
589
+ iconType: PropTypes.oneOf(['icon', 'text']),
586
590
  };
587
591
 
588
592
  DatePicker.defaultProps = {
@@ -0,0 +1,193 @@
1
+ import React, { Component } from 'react';
2
+ import {
3
+ Dimensions, StyleSheet, View
4
+ } from 'react-native';
5
+ import {
6
+ Button, IconSource, TouchableOpacity, Text, Colors, Image, DeviceUtils, SwitchLanguage
7
+ } from '@momo-kits/core';
8
+ import WheelPicker from './WheelPicker';
9
+
10
+ const { isIphoneX } = DeviceUtils;
11
+
12
+ const widthScreen = Dimensions.get('window').width;
13
+
14
+ export default class ListPicker extends Component {
15
+ constructor(props) {
16
+ super(props);
17
+ this.data = 0;
18
+ }
19
+
20
+ hide = () => {
21
+ const { onClose, requestClose } = this.props;
22
+ if (requestClose && typeof requestClose === 'function') {
23
+ requestClose(() => {
24
+ if (onClose && typeof onClose === 'function') {
25
+ onClose();
26
+ }
27
+ });
28
+ }
29
+ }
30
+
31
+ onBeginDrag = () => {
32
+ if (this.refs.picker) {
33
+ this.refs.picker.setScrollEnabled(false);
34
+ }
35
+ }
36
+
37
+ onEndDrag = () => {
38
+ if (this.refs.picker) {
39
+ this.refs.picker.setScrollEnabled(true);
40
+ }
41
+ }
42
+
43
+ onChangeValue = (value) => {
44
+ const { callback } = this.props;
45
+ if (typeof callback === 'function') {
46
+ callback(value);
47
+ }
48
+ }
49
+
50
+ onPressClear = () => {
51
+ this.hide();
52
+ }
53
+
54
+ onPressChoose = () => {
55
+ this.onChangeValue(this.data);
56
+ this.hide();
57
+ }
58
+
59
+ renderRight = () => (
60
+ <TouchableOpacity
61
+ onPress={this.onPressChoose}
62
+ >
63
+ <Text.Title style={{ fontWeight: 'bold', color: Colors.pink_05 }}>{SwitchLanguage.save}</Text.Title>
64
+ </TouchableOpacity>
65
+ );
66
+
67
+ renderLeftIcon = () => (
68
+ <TouchableOpacity onPress={() => this.hide()}>
69
+ <Image
70
+ source={IconSource.ic_close_x_24}
71
+ style={{ width: 25, height: 25, tintColor: Colors.black_17 }}
72
+ />
73
+ </TouchableOpacity>
74
+ );
75
+
76
+ renderHeader() {
77
+ const { title = '' } = this.props;
78
+ return (
79
+ <View style={styles.header}>
80
+ {this.renderLeftIcon()}
81
+ <Text style={styles.title}>
82
+ {title}
83
+ </Text>
84
+ {this.props.typeStyle === 'aboveAction' ? this.renderRight() : <View style={{ width: 25 }} />}
85
+ </View>
86
+ );
87
+ }
88
+
89
+ renderContent() {
90
+ const { arrData = [], stylePicker, initValue } = this.props;
91
+ return (
92
+ <View style={styles.contentStyle}>
93
+ <WheelPicker
94
+ stylePicker={stylePicker}
95
+ bottomOffset={1}
96
+ value={initValue}
97
+ key="picker"
98
+ ref="picker"
99
+ arrayValue={arrData}
100
+ onBeginDrag={this.onBeginDrag}
101
+ onEndDrag={this.onEndDrag}
102
+ onValueChange={(value) => {
103
+ this.data = value;
104
+ }}
105
+ />
106
+
107
+ </View>
108
+ );
109
+ }
110
+
111
+ render() {
112
+ return (
113
+ <View style={styles.view}>
114
+ {this.renderHeader()}
115
+ {this.renderContent()}
116
+ {
117
+ this.props.typeStyle === 'aboveAction'
118
+ ? null
119
+ : (
120
+ <View style={styles.btnView}>
121
+ <Button
122
+ style={{ flex: 1 }}
123
+ title={SwitchLanguage.cancel}
124
+ buttonStyle={{ backgroundColor: Colors.second_text_color }}
125
+ onPress={this.onPressClear}
126
+ />
127
+ <Button
128
+ style={{ flex: 1, marginLeft: 15 }}
129
+ title={SwitchLanguage.choose}
130
+ type="primary"
131
+ onPress={this.onPressChoose}
132
+ />
133
+ </View>
134
+ )
135
+ }
136
+ </View>
137
+ );
138
+ }
139
+ }
140
+
141
+ const styles = StyleSheet.create({
142
+ container: {
143
+ flexDirection: 'row',
144
+ width: widthScreen,
145
+ alignItems: 'center',
146
+ justifyContent: 'center'
147
+ },
148
+ contentStyle: {
149
+ height: 200,
150
+ },
151
+ column: {
152
+ borderWidth: 2,
153
+ borderColor: 'red',
154
+ },
155
+ header: {
156
+ flexDirection: 'row',
157
+ height: 50,
158
+ width: widthScreen,
159
+ paddingHorizontal: 16,
160
+ alignItems: 'center',
161
+ justifyContent: 'space-between',
162
+ backgroundColor: '#fff',
163
+ borderBottomWidth: 1,
164
+ borderColor: '#DADADA',
165
+ },
166
+ view: {
167
+ backgroundColor: 'white',
168
+ paddingBottom: 10 + (isIphoneX() ? 10 : 0)
169
+ },
170
+ title: {
171
+ fontWeight: 'bold',
172
+ color: Colors.black_17,
173
+ flex: 1,
174
+ fontSize: 16,
175
+ textAlign: 'center'
176
+ },
177
+ titleCancel: {
178
+ fontSize: 17,
179
+ color: '#4A90E2'
180
+ },
181
+ titleConfirm: {
182
+ fontSize: 17,
183
+ color: '#4A90E2',
184
+ textAlign: 'right'
185
+ },
186
+ btnView: {
187
+ flexDirection: 'row',
188
+ justifyContent: 'space-between',
189
+ marginHorizontal: 15,
190
+ height: 60,
191
+ alignItems: 'center'
192
+ }
193
+ });
package/index.js CHANGED
@@ -1,7 +1,9 @@
1
1
  import DatePicker from './datePicker/DatePicker';
2
2
  import DatePickerInput from './datePicker/DatePickerInput';
3
+ import ListPicker from './datePicker/ListPicker';
3
4
 
4
5
  export {
5
6
  DatePicker,
6
- DatePickerInput
7
+ DatePickerInput,
8
+ ListPicker
7
9
  };
package/package.json CHANGED
@@ -1,17 +1,16 @@
1
1
  {
2
- "name": "@momo-kits/date-picker",
3
- "version": "0.0.6-beta",
4
- "private": false,
5
- "main": "index.js",
6
- "dependencies": {},
7
- "peerDependencies": {
8
- "react-native": ">=0.55",
9
- "prop-types": "^15.7.2",
10
- "react": "16.9.0",
11
- "lodash": "^4.17.15",
12
- "@momo-kits/core": ">=0.0.5-beta"
13
- },
14
- "devDependencies": {},
15
- "license": "MoMo"
16
- }
17
-
2
+ "name": "@momo-kits/date-picker",
3
+ "version": "0.0.6",
4
+ "private": false,
5
+ "main": "index.js",
6
+ "dependencies": {},
7
+ "peerDependencies": {
8
+ "react-native": ">=0.55",
9
+ "prop-types": "^15.7.2",
10
+ "react": "16.9.0",
11
+ "@momo-kits/core": ">=0.0.5-beta",
12
+ "lodash": "^4.17.15"
13
+ },
14
+ "devDependencies": {},
15
+ "license": "MoMo"
16
+ }